-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bioprocessor_functions.py
175 lines (140 loc) · 5.28 KB
/
bioprocessor_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"""
Author: Siebrant Hendriks.
Supplementary script for bioprocessor use
"""
import pandas as pd
import global_data as gd
def biopro_no_mulch(harvest_stores):
"""
Get crops from harvest_stores that can "only" be used for bioprocessor.
Parameters
----------
harvest_stores : pd.Series
Contains all harvested crops and their stored amounts.
Returns
-------
bio_crops : pd.Series
Contains crops suitable for bioprocessor and their stored Kg amount.
"""
bio_crops = harvest_stores.where(gd.plant_data['bioprocessor_use'] == True)
bio_crops = bio_crops.where(gd.plant_data['mulch_use'] == False)
bio_crops = bio_crops.where(bio_crops > 0)
bio_crops.dropna(inplace=True)
return bio_crops
def biopro_with_mulch(harvest_stores):
"""
Get crops that can be used either for mulch or bioprocessor.
Parameters
----------
harvest_stores : pd.Series
Contains all harvested crops and their stored amounts.
Returns
-------
bio_crops : pd.Series
Contains crops suitable for bioprocessor and their stored Kg amount.
"""
bio_crops = harvest_stores.where(gd.plant_data['bioprocessor_use'] == True)
bio_crops = bio_crops.where(gd.plant_data['mulch_use'] == True)
bio_crops = bio_crops.where(bio_crops > 0)
bio_crops.dropna(inplace=True)
return bio_crops
def get_deep_litter(animals_on_farm):
"""
Calculate the Kg amount of deep litter produced by the animals on the farm.
Parameters
----------
animals_on_farm : pd.Series
Keeps track of which animals are on the farm and in what amount they
are present.
Returns
-------
deep_litter : pd.Series
Kg amount of deep litter produced.
"""
deep_litter = sum(animals_on_farm *
gd.animal_data['deep_litter_production'])
deep_litter = {'deep_litter': deep_litter}
deep_litter = pd.Series(deep_litter)
return deep_litter
def biopro_manure():
"""
Select imported manure suitable for the bioprocessor.
Returns
-------
bio_anim : pd.Series
Contains matter types suitable for bioprocessor and their Kg amount.
"""
chicken_manure = gd.estate_values['import_chicken_manure']
horse_manure = gd.estate_values['import_horse_manure']
bio_anim = {'chicken_manure': chicken_manure, 'horse_manure': horse_manure}
bio_anim = pd.Series(bio_anim)
return bio_anim
def biopro_all(harvest_stores, animals_on_farm):
"""
Get all matter suitable for bioprocessor in order of preferred use.
Parameters
----------
harvest_stores : pd.Series
Contains all harvested crops and their stored amounts.
animals_on_farm : pd.Series
Keeps track of which animals are on the farm and in what amount they
are present.
Returns
-------
biopro_available : pd.Series
Contains matter types suitable for bioprocessor and their Kg amount.
Series is ordered to have preferred matter appear first.
"""
biopro_available = biopro_manure()
biopro_available = pd.concat([biopro_available,
biopro_no_mulch(harvest_stores)])
biopro_available = pd.concat([biopro_available,
get_deep_litter(animals_on_farm)])
biopro_available = pd.concat([biopro_available,
biopro_with_mulch(harvest_stores)])
return biopro_available
def biopro_to_use(bio_available):
"""
Determine how much matter will be used by the bioprocessor this year.
Parameters
----------
bio_available : pd.Series
Contains matter types suitable for bioprocessor and their Kg amount.
Series is ordered to have preferred matter appear first.
Returns
-------
to_use : pd.Series
Contains matter types suitable for bioprocessor and their Kg amount
that will be used by the bioprocessor.
"""
digest_max = gd.estate_values['maximum_digestate_spreadable']
to_use = pd.Series(0.0, index=bio_available.index)
for label, amount in bio_available.items():
digest_yield = amount * gd.biodigestor_data['digestate'].loc[label]
if digest_yield > digest_max:
amount = digest_max / gd.biodigestor_data['digestate'].loc[label]
to_use[label] = amount
digest_max -= amount * gd.biodigestor_data['digestate'].loc[label]
if digest_max <= 0:
break
return to_use
def make_biopro_products(bio_input):
"""
Apply all product yields generated by bioprocessor.
Parameters
----------
bio_input : pd.Series
Contains matter types suitable for bioprocessor and their Kg amount
that will be used by the bioprocessor.
Returns
-------
None;
All yields are added to global variables.
"""
for label, amount in bio_input.items():
digestate = gd.biodigestor_data['digestate'].loc[label] * amount
electricity = gd.biodigestor_data['electricity'].loc[label] * amount
methane = gd.biodigestor_data['biomethane'].loc[label] * amount
gd.results['digestate_produced'].loc[f'year_{gd.year}'] += digestate
gd.results['electricity_balance'].loc[f'year_{gd.year}'] += electricity
gd.results['biomethane_produced'].loc[f'year_{gd.year}'] += methane