Count/Concentration Assignment
In this section, we will explain how to add counts or concentrations to species in order to simulate them. We start by defining some base species and giving them some characteristics and combining them.
[1]:
from mobspy import *
Age, Color, Size = BaseSpecies()
Age.young, Age.old,
Color.blue, Color.red,
Size.small, Size.big
Tree = Age*Color*Size
model = set_counts({All[Tree]:30, 'Tree.blue.old':100})
S = Simulation(Tree)
print(S.compile())
Species
Tree.big.blue.old,30
Tree.big.blue.young,30
Tree.big.red.old,30
Tree.big.red.young,30
Tree.small.blue.old,100
Tree.small.blue.young,30
Tree.small.red.old,30
Tree.small.red.young,30
Mappings
Tree :
Tree.big.blue.old
Tree.big.blue.young
Tree.big.red.old
Tree.big.red.young
Tree.small.blue.old
Tree.small.blue.young
Tree.small.red.old
Tree.small.red.young
Parameters
volume,1
Reactions
Compiling model
To assign counts to the Tree species we use the call operator:
[2]:
Tree(100)
print(Tree._species_counts)
[{'characteristics': 'std$', 'quantity': 100}]
Mobspy will assign this count to the default state of Tree. The default state is constructed by taking the first characteristics that was added to each of it’s inheritors. So in this case the state that is assigned the count of 100 is the following:
Tree.young.blue.small = 100
To assign counts to different states one must perform a query:
[3]:
Tree.red.big(150)
print(Tree._species_counts)
[{'characteristics': 'std$', 'quantity': 100}, {'characteristics': {'red', 'big'}, 'quantity': 150}]
In this case all the coordinates in the meta-species vector space that have not been specified will be replaced by the default. The only missing coordinate missing refers to the Age meta-species for which the default value is young. Thus the count Tree.red.big(150) will be assigned to:
Tree.young.red.big = 150
MobsPy also allows for the usage of a operator called All. This operator allows one to assing counts to all the characteristics of a meta-species at the same time.
[4]:
All[Tree](10)
print(Tree._species_counts)
[{'characteristics': 'std$', 'quantity': 100}, {'characteristics': {'red', 'big'}, 'quantity': 150}, {'characteristics': {'all$'}, 'quantity': 10}]
The All operator assignment is not prioritazed when compared to specific assignments, so here the states Tree.young.red.big and Tree.young.red.big will retain the old counts which have been assigned to them individualy.
Finally, one can also perform queries using the All assignment:
[5]:
All[Tree.big](100)
print(Tree._species_counts)
[{'characteristics': 'std$', 'quantity': 100}, {'characteristics': {'red', 'big'}, 'quantity': 150}, {'characteristics': {'all$'}, 'quantity': 10}, {'characteristics': {'big', 'all$'}, 'quantity': 100}]
Now the compilation:
[6]:
S = Simulation(Tree)
print(S.compile())
Species
Tree.big.blue.old,100
Tree.big.blue.young,100
Tree.big.red.old,100
Tree.big.red.young,150
Tree.small.blue.old,10
Tree.small.blue.young,100
Tree.small.red.old,10
Tree.small.red.young,10
Mappings
Tree :
Tree.big.blue.old
Tree.big.blue.young
Tree.big.red.old
Tree.big.red.young
Tree.small.blue.old
Tree.small.blue.young
Tree.small.red.old
Tree.small.red.young
Parameters
volume,1
Reactions
Compiling model
Set count function
Another way of adding counts to species is by using the set_count function. The set count function receives a argument a dictionary. The keys for this dictionary are either meta-species or strings and the items are values. The set_count function is compatible with the All operator. Also, the set count function returns a model with all the meta-species used in the keys, allowing for easy simulation after count assignment.
[8]:
model = set_counts({All[Tree]:30, 'Tree.blue.old':100})
S = Simulation(model)
print(S.compile())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-511b38f65f86> in <module>
----> 1 model = set_counts({All[Tree]:30, 'Tree.blue.old':100})
2 S = Simulation(model)
3 print(S.compile())
~/opt/anaconda3/lib/python3.8/site-packages/mobspy/modules/set_counts_module.py in set_counts(count_dic)
49 for key in count_dic:
50 if type(key) == str:
---> 51 all_found_species = find_species()
52
53 model = set()
~/opt/anaconda3/lib/python3.8/site-packages/mobspy/modules/set_counts_module.py in find_species()
34 for key, item in global_names.items():
35 try:
---> 36 if item.is_species() and type(item) != type:
37 found_species.add(item)
38 except AttributeError:
TypeError: 'Simulation' object is not callable
[ ]: