-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Group entity #175
Open
zugnachpankow
wants to merge
32
commits into
master
Choose a base branch
from
group_entity
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Group entity #175
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d89dd45
Added structure for group entity
zugnachpankow ffc4927
Update group.py
zugnachpankow 7aebe13
social_system
zugnachpankow 710242a
typo cleanup
zugnachpankow 1ffd331
Fix Social Update
zugnachpankow c0994c4
Implementing Individual to Group relationships via a group_membership…
zugnachpankow 2895209
Implement Network Solution for Group Memberships
zugnachpankow 9c473e1
Update run_groups_test_seven_dwarfs.py
zugnachpankow 284b877
Merge remote-tracking branch 'origin/group_entity' into group_entity
zugnachpankow fbb26f6
Group now gets culture and further things over being part of a world.
zugnachpankow bdeb128
little fix
zugnachpankow 9747ce5
run_group_test_seven_dwarfs.py now demonstrates minimum features of t…
zugnachpankow 032528c
run_group_test_seven_dwarfs.py now demonstrates minimum features of t…
zugnachpankow b3bc2c6
- Change group from living in World to living in Culture
zugnachpankow 4019e10
add/adjust documentation
zugnachpankow 30409da
Added structure for group entity
zugnachpankow 03ff3a0
Update group.py
zugnachpankow 9b4aaa9
social_system
zugnachpankow f088423
typo cleanup
zugnachpankow 329ab84
Implementing Individual to Group relationships via a group_membership…
zugnachpankow 696eb74
Group now gets culture and further things over being part of a world.
zugnachpankow 75580f4
little fix
zugnachpankow 244a601
run_group_test_seven_dwarfs.py now demonstrates minimum features of t…
zugnachpankow 53f58d9
run_group_test_seven_dwarfs.py now demonstrates minimum features of t…
zugnachpankow b602e71
- Change group from living in World to living in Culture
zugnachpankow 07035ab
add/adjust documentation
zugnachpankow ae3024d
Merge remote-tracking branch 'origin/group_entity' into group_entity
zugnachpankow 356df4b
- bypassed AttributeErrors in base implementation for group by gettin…
zugnachpankow 76474cd
Add simple test function and plot groupmembership for a single dwarf …
zugnachpankow 447b6b8
Make illustration study more clear
zugnachpankow 34904c6
Make illustration study more clear
zugnachpankow bf446bf
resolve #175
zugnachpankow File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,33 @@ | ||
"""Master data model for group.""" | ||
|
||
"""https://github.com/pik-copan/pycopancore/blob/master/docs/framework_documentation/abstract_level/entity_types/group.rst""" | ||
|
||
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: core@pik-potsdam.de | ||
# 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: core@pik-potsdam.de | ||
# 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 | ||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not add absolute url paths to the code.