-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from pik-copan/group_entity
Group entity
- Loading branch information
Showing
28 changed files
with
745 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ cff-version: 1.2.0 | |
message: If you use this software, please cite it using the metadata from this file. | ||
type: software | ||
title: 'pycopancore: Reference implementation of the copan:CORE World-Earth modelling framework' | ||
version: 0.6.0 | ||
date-released: '2020-04-28' | ||
version: 0.7.0 | ||
date-released: '2024-07-04' | ||
abstract: The pycopancore package is a python implementation of the copan:CORE | ||
modeling framework as described in this paper. The framework is designed to | ||
allow an easy implementation of World-Earth (i.e., global social-ecological) | ||
|
@@ -14,6 +14,10 @@ abstract: The pycopancore package is a python implementation of the copan:CORE | |
stochastic and deterministic events and therefore allows to compare different | ||
model and component types and implementations. | ||
authors: | ||
- family-names: Bechthold | ||
given-names: Max | ||
email: [email protected] | ||
orcid: 0009-0007-7113-4814 | ||
- family-names: Heitzig | ||
given-names: Jobst | ||
email: [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Master data model for group.""" | ||
|
||
from .. import Variable | ||
|
||
from networkx import Graph | ||
|
||
class Group: | ||
|
||
#TODO: specify edges | ||
|
||
intra_group_network = \ | ||
Variable("intra group network", | ||
"""Basic undirected social network between | ||
Group members.""", | ||
scale='nominal', | ||
datatype=Graph) | ||
|
||
has_leader = \ | ||
Variable("has a leader", | ||
"whether the group has a leader", | ||
scale="ordinal", levels=[False, True], default=False) | ||
|
||
has_headquarter = \ | ||
Variable("has a headquarter", | ||
"whether the group has a headquarter located in a cell", | ||
scale="ordinal", levels=[False, True], default=False) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Abstract Group entity type class, inherited by base model component.""" | ||
|
||
# This file is part of pycopancore. | ||
# | ||
# Copyright (C) 2016-2017 by COPAN team at Potsdam Institute for Climate | ||
# Impact Research | ||
# | ||
# URL: <http://www.pik-potsdam.de/copan/software> | ||
# Contact: [email protected] | ||
# License: BSD 2-clause license | ||
|
||
from ...private import _AbstractEntityMixin | ||
from ...data_model import OrderedSet | ||
|
||
|
||
class Group (_AbstractEntityMixin): | ||
"""Abstract Group entity type class. | ||
Inherited by base model component. | ||
""" | ||
|
||
variables = OrderedSet() | ||
"""All variables occurring in this entity type""" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
pycopancore/model_components/base/implementation/group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
""" """ | ||
|
||
# This file is part of pycopancore. | ||
# | ||
# Copyright (C) 2016-2017 by COPAN team at Potsdam Institute for Climate | ||
# Impact Research | ||
# | ||
# URL: <http://www.pik-potsdam.de/copan/software> | ||
# Contact: [email protected] | ||
# License: BSD 2-clause license | ||
|
||
# only used in this component, not in others: | ||
from ... import abstract | ||
from .... import master_data_model as D | ||
from ....private import unknown | ||
|
||
from .. import interface as I | ||
|
||
|
||
class Group (I.Group, abstract.Group): | ||
"""Gropp entity type mixin implementation class. | ||
Base component's Group mixin that every model must use in composing | ||
their Group class. Inherits from I.Group as the interface with all | ||
necessary variables and parameters. | ||
""" | ||
|
||
# standard methods: | ||
|
||
def __init__(self, | ||
*, | ||
culture, | ||
world, | ||
**kwargs | ||
): | ||
"""Initialize an instance of Group. | ||
Parameters | ||
---------- | ||
culture: obj | ||
Culture the Group belongs to | ||
world: obj | ||
World the Group belongs to (to bypass AttributeErrors for now) | ||
**kwargs | ||
keyword arguments passed to super() | ||
""" | ||
super().__init__(**kwargs) # must be the first line | ||
|
||
# init and set variables implemented via properties: | ||
self._culture = None | ||
self.culture = culture | ||
self._world = None | ||
self.world = world | ||
|
||
if self.culture: | ||
self.culture.group_membership_network.add_node(self, type="Group", color="green") | ||
|
||
def deactivate(self): | ||
"""Deactivate a group. | ||
In particular, deregister from all networks. | ||
""" | ||
# deregister from all networks: | ||
if self.culture: | ||
self.culture.group_membership_network.remove_node(self) | ||
super().deactivate() # must be the last line | ||
|
||
def reactivate(self): | ||
"""Reactivate a group. | ||
In particular, deregister with all mandatory networks. | ||
""" | ||
super().reactivate() # must be the first line | ||
# reregister with all mandatory networks: | ||
if self.culture: | ||
self.culture.group_membership_network.add_node(self, type="Group", color="green") | ||
|
||
|
||
# getters and setters for references: | ||
|
||
#culture needs to be before world, as group gets its world etc. over its culture | ||
@property | ||
def culture(self): | ||
"""Get culture group is part of.""" | ||
return self._culture | ||
|
||
@culture.setter | ||
def culture(self, c): | ||
"""Set culture group is part of.""" | ||
if self._culture is not None: | ||
# first deregister from previous culture's list of worlds: | ||
self._culture.groups.remove(self) | ||
if c is not None: | ||
assert isinstance(c, I.Culture), \ | ||
"Culture must be taxon type Culture" | ||
c._groups.add(self) | ||
self._culture = c | ||
|
||
@property | ||
def world(self): | ||
"""Get the World the Group is part of.""" | ||
return self._world | ||
|
||
@world.setter | ||
def world(self, w): | ||
"""Set the World the Group is part of.""" | ||
if self._world is not None: | ||
# first deregister from previous world's list of cells: | ||
self._world.groups.remove(self) | ||
assert isinstance(w, I.World), "world must be of entity type World" | ||
w._groups.add(self) | ||
self._world = w | ||
|
||
# getters for backwards references and convenience variables: | ||
|
||
@property # read-only | ||
def environment(self): | ||
"""Get the Environment of which the Group is a part.""" | ||
return self._world.environment | ||
|
||
@property # read-only | ||
def metabolism(self): | ||
"""Get the Metabolism of which the Group is a part.""" | ||
return self._world.metabolism | ||
|
||
@property | ||
def group_members(self): | ||
"""Get the set of Individuals associated with this Group.""" | ||
# return self.culture.group_membership_network.neighbors(self) | ||
return self.culture.group_membership_network.predecessors(self) # .predecessors as network is directed from inds to groups | ||
|
||
|
||
# no process-related methods | ||
|
||
processes = [] # no processes in base | ||
|
||
|
Oops, something went wrong.