hestia-earth-models 0.62.1__py3-none-any.whl → 0.62.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hestia-earth-models might be problematic. Click here for more details.
- hestia_earth/models/cycle/coldCarcassWeightPerHead.py +4 -2
- hestia_earth/models/cycle/coldDressedCarcassWeightPerHead.py +2 -2
- hestia_earth/models/cycle/concentrateFeed.py +3 -3
- hestia_earth/models/cycle/feedConversionRatio/feedConversionRatioNitrogen.py +2 -1
- hestia_earth/models/cycle/readyToCookWeightPerHead.py +2 -2
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +50 -40
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +208 -39
- hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +2 -6
- hestia_earth/models/ipcc2019/pastureGrass.py +43 -41
- hestia_earth/models/ipcc2019/pastureGrass_utils.py +63 -109
- hestia_earth/models/mocking/search-results.json +393 -249
- hestia_earth/models/site/management.py +52 -29
- hestia_earth/models/utils/blank_node.py +38 -0
- hestia_earth/models/utils/property.py +6 -6
- hestia_earth/models/utils/site.py +7 -0
- hestia_earth/models/utils/term.py +21 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.2.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.2.dist-info}/RECORD +25 -25
- tests/models/ipcc2019/test_organicCarbonPerHa.py +9 -20
- tests/models/ipcc2019/test_organicCarbonPerHa_tier_2_utils.py +0 -8
- tests/models/site/test_management.py +31 -3
- {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.2.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.2.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.2.dist-info}/top_level.txt +0 -0
|
@@ -12,7 +12,8 @@ from hestia_earth.schema import TermTermType
|
|
|
12
12
|
from hestia_earth.utils.model import filter_list_term_type
|
|
13
13
|
from hestia_earth.utils.tools import list_sum
|
|
14
14
|
|
|
15
|
-
from hestia_earth.models.log import logRequirements, logShouldRun,
|
|
15
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
|
16
|
+
from hestia_earth.models.utils.blank_node import lookups_logs, properties_logs
|
|
16
17
|
from hestia_earth.models.utils.input import _new_input
|
|
17
18
|
from hestia_earth.models.utils.term import get_wool_terms
|
|
18
19
|
from hestia_earth.models.utils.completeness import _is_term_type_complete, _is_term_type_incomplete
|
|
@@ -25,6 +26,7 @@ from .pastureGrass_utils import (
|
|
|
25
26
|
calculate_REM,
|
|
26
27
|
calculate_REG,
|
|
27
28
|
calculate_NEfeed,
|
|
29
|
+
calculate_GE,
|
|
28
30
|
product_wool_energy,
|
|
29
31
|
get_animals,
|
|
30
32
|
get_animal_values
|
|
@@ -119,7 +121,8 @@ REQUIREMENTS = {
|
|
|
119
121
|
}
|
|
120
122
|
LOOKUPS = {
|
|
121
123
|
"animalManagement": [
|
|
122
|
-
"mjKgEvMilkIpcc2019"
|
|
124
|
+
"mjKgEvMilkIpcc2019",
|
|
125
|
+
"defaultFatContentEvMilkIpcc2019"
|
|
123
126
|
],
|
|
124
127
|
"animalProduct": ["mjKgEvWoolNetEnergyWoolIpcc2019"],
|
|
125
128
|
"liveAnimal": [
|
|
@@ -127,7 +130,8 @@ LOOKUPS = {
|
|
|
127
130
|
"mjDayKgCfiNetEnergyMaintenanceIpcc2019",
|
|
128
131
|
"ratioCPregnancyNetEnergyPregnancyIpcc2019",
|
|
129
132
|
"ratioCNetEnergyGrowthCattleBuffaloIpcc2019",
|
|
130
|
-
"mjKgABNetEnergyGrowthSheepGoatsIpcc2019"
|
|
133
|
+
"mjKgABNetEnergyGrowthSheepGoatsIpcc2019",
|
|
134
|
+
"isWoolProducingAnimal"
|
|
131
135
|
],
|
|
132
136
|
"system-liveAnimal-activityCoefficient-ipcc2019": "using animal term @id",
|
|
133
137
|
"crop-property": ["energyDigestibilityRuminants", "energyContentHigherHeatingValue"],
|
|
@@ -150,9 +154,6 @@ def _input(term_id: str, value: float):
|
|
|
150
154
|
return node
|
|
151
155
|
|
|
152
156
|
|
|
153
|
-
def _sum_values(values: list, index=0): return list_sum([v[index] for v in values])
|
|
154
|
-
|
|
155
|
-
|
|
156
157
|
def calculate_NEwool(cycle: dict) -> float:
|
|
157
158
|
term_ids = get_wool_terms()
|
|
158
159
|
products = [p for p in cycle.get('products', []) if p.get('term', {}).get('@id') in term_ids]
|
|
@@ -162,39 +163,20 @@ def calculate_NEwool(cycle: dict) -> float:
|
|
|
162
163
|
return sum([value * lookup_value for (value, lookup_value) in product_values])
|
|
163
164
|
|
|
164
165
|
|
|
165
|
-
def _calculate_GE(
|
|
166
|
-
cycle: dict, animals: list, REM: float, REG: float, NEwool: float, NEm_feed: float, NEg_feed: float, system: dict
|
|
167
|
-
) -> float:
|
|
168
|
-
values = [get_animal_values(cycle, animal, system, log_node=cycle) for animal in animals]
|
|
169
|
-
NEm = _sum_values(values, 0)
|
|
170
|
-
NEa = _sum_values(values, 1)
|
|
171
|
-
NEl = _sum_values(values, 2)
|
|
172
|
-
NEwork = _sum_values(values, 3)
|
|
173
|
-
NEp = _sum_values(values, 4)
|
|
174
|
-
NEg = _sum_values(values, 5)
|
|
175
|
-
|
|
176
|
-
debugValues(cycle, model=MODEL, term=MODEL_KEY, model_key=MODEL_KEY,
|
|
177
|
-
NEm=NEm,
|
|
178
|
-
NEa=NEa,
|
|
179
|
-
NEl=NEl,
|
|
180
|
-
NEwork=NEwork,
|
|
181
|
-
NEp=NEp,
|
|
182
|
-
NEg=NEg,
|
|
183
|
-
NEm_feed=NEm_feed,
|
|
184
|
-
NEg_feed=NEg_feed)
|
|
185
|
-
|
|
186
|
-
return (NEm + NEa + NEl + NEwork + NEp - NEm_feed)/REM + (NEg + NEwool - NEg_feed)/REG
|
|
187
|
-
|
|
188
|
-
|
|
189
166
|
def _run_practice(cycle: dict, meanDE: float, meanECHHV: float, system: dict):
|
|
190
167
|
animals = get_animals(cycle)
|
|
191
168
|
REM = calculate_REM(meanDE)
|
|
192
169
|
REG = calculate_REG(meanDE)
|
|
193
170
|
NEwool = calculate_NEwool(cycle)
|
|
194
171
|
NEm_feed, NEg_feed = calculate_NEfeed(cycle)
|
|
172
|
+
|
|
173
|
+
animal_values = [{
|
|
174
|
+
'animalId': animal.get('term', {}).get('@id')
|
|
175
|
+
} | get_animal_values(cycle, animal, system) for animal in animals]
|
|
176
|
+
|
|
195
177
|
GE = (
|
|
196
|
-
|
|
197
|
-
) if
|
|
178
|
+
calculate_GE(animal_values, REM, REG, NEwool, NEm_feed, NEg_feed) / (meanDE/100)
|
|
179
|
+
) if meanDE else 0
|
|
198
180
|
|
|
199
181
|
def run(practice: dict):
|
|
200
182
|
key = practice.get('key', {})
|
|
@@ -202,14 +184,34 @@ def _run_practice(cycle: dict, meanDE: float, meanECHHV: float, system: dict):
|
|
|
202
184
|
input_term_id = practice_input_id(practice)
|
|
203
185
|
value = (GE / meanECHHV) * (list_sum(practice.get('value', [0])) / 100)
|
|
204
186
|
|
|
187
|
+
logs = log_as_table([v | {
|
|
188
|
+
'practiceKeyId': key_id,
|
|
189
|
+
'REM': REM,
|
|
190
|
+
'REG': REG,
|
|
191
|
+
'NEwool': NEwool,
|
|
192
|
+
'NEmFeed': NEm_feed,
|
|
193
|
+
'NEgFeed': NEg_feed,
|
|
194
|
+
'GE': GE,
|
|
195
|
+
'meanECHHV': meanECHHV,
|
|
196
|
+
'meanDE': meanDE
|
|
197
|
+
} for v in animal_values])
|
|
198
|
+
animal_lookups = lookups_logs(MODEL, animals, LOOKUPS, model_key=MODEL_KEY, term=input_term_id)
|
|
199
|
+
animal_properties = properties_logs(animals, properties=[
|
|
200
|
+
'liveweightPerHead',
|
|
201
|
+
'hoursWorkedPerDay',
|
|
202
|
+
'animalsPerBirth',
|
|
203
|
+
'pregnancyRateTotal',
|
|
204
|
+
'weightAtMaturity',
|
|
205
|
+
'liveweightGain',
|
|
206
|
+
'weightAtWeaning',
|
|
207
|
+
'weightAtOneYear',
|
|
208
|
+
'weightAtSlaughter'
|
|
209
|
+
])
|
|
210
|
+
|
|
205
211
|
logRequirements(cycle, model=MODEL, term=input_term_id, model_key=MODEL_KEY,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
NEm_feed=NEm_feed,
|
|
210
|
-
NEg_feed=NEg_feed,
|
|
211
|
-
GE=GE,
|
|
212
|
-
practice_key_id=key_id)
|
|
212
|
+
animal_logs=logs,
|
|
213
|
+
animal_lookups=animal_lookups,
|
|
214
|
+
animal_properties=animal_properties)
|
|
213
215
|
|
|
214
216
|
logShouldRun(cycle, MODEL, input_term_id, True, model_key=MODEL_KEY)
|
|
215
217
|
|
|
@@ -249,8 +251,8 @@ def _should_run(cycle: dict, practices: dict):
|
|
|
249
251
|
term_type_freshForage_incomplete=freshForage_incomplete,
|
|
250
252
|
has_cycle_inputs_feed=has_cycle_inputs_feed,
|
|
251
253
|
all_animals_have_value=all_animals_have_value,
|
|
252
|
-
meanDE=
|
|
253
|
-
meanECHHV=
|
|
254
|
+
meanDE=calculate_meanDE(practices, term=term_id),
|
|
255
|
+
meanECHHV=calculate_meanECHHV(practices, term=term_id))
|
|
254
256
|
|
|
255
257
|
logShouldRun(cycle, MODEL, term_id, should_run, model_key=MODEL_KEY)
|
|
256
258
|
|
|
@@ -25,22 +25,18 @@ def _get_grouping(animal: dict) -> str:
|
|
|
25
25
|
return get_lookup_value(term, 'ipcc2019AnimalTypeGrouping', model=MODEL, model_key=MODEL_KEY)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def _get_activityCoefficient(cycle: dict, animal: dict, system: dict
|
|
28
|
+
def _get_activityCoefficient(cycle: dict, animal: dict, system: dict) -> float:
|
|
29
29
|
term = animal.get('term', {})
|
|
30
30
|
term_id = term.get('@id')
|
|
31
31
|
system_id = system.get('term', {}).get('@id')
|
|
32
32
|
lookup = download_lookup('system-liveAnimal-activityCoefficient-ipcc2019.csv')
|
|
33
33
|
activityCoefficient = safe_parse_float(get_table_value(lookup, 'termid', system_id, column_name(term_id)), 0)
|
|
34
34
|
|
|
35
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
36
|
-
activityCoefficient=activityCoefficient)
|
|
37
|
-
|
|
38
35
|
return activityCoefficient
|
|
39
36
|
|
|
40
37
|
|
|
41
|
-
def _calculate_NEm(cycle: dict, animal: dict
|
|
38
|
+
def _calculate_NEm(cycle: dict, animal: dict) -> float:
|
|
42
39
|
term = animal.get('term', {})
|
|
43
|
-
term_id = term.get('@id')
|
|
44
40
|
|
|
45
41
|
mjDayKgCfiNetEnergyMaintenance = safe_parse_float(
|
|
46
42
|
get_lookup_value(term, 'mjDayKgCfiNetEnergyMaintenanceIpcc2019', model=MODEL, model_key=MODEL_KEY), 0
|
|
@@ -50,43 +46,25 @@ def _calculate_NEm(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
|
50
46
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
51
47
|
NEm = mjDayKgCfiNetEnergyMaintenance * pow(liveweightPerHead, 0.75) * animal_value * cycleDuration
|
|
52
48
|
|
|
53
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
54
|
-
mjDayKgCfiNetEnergyMaintenance=mjDayKgCfiNetEnergyMaintenance,
|
|
55
|
-
liveweightPerHead=liveweightPerHead,
|
|
56
|
-
NEm=NEm)
|
|
57
|
-
|
|
58
49
|
return NEm
|
|
59
50
|
|
|
60
51
|
|
|
61
|
-
def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float
|
|
62
|
-
|
|
63
|
-
term_id = term.get('@id')
|
|
64
|
-
|
|
65
|
-
activityCoefficient = _get_activityCoefficient(cycle, animal, system, log_node)
|
|
52
|
+
def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
|
|
53
|
+
activityCoefficient = _get_activityCoefficient(cycle, animal, system)
|
|
66
54
|
|
|
67
55
|
NEa = activityCoefficient * NEm
|
|
68
56
|
|
|
69
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
70
|
-
NEa=NEa)
|
|
71
|
-
|
|
72
57
|
return NEa
|
|
73
58
|
|
|
74
59
|
|
|
75
|
-
def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float
|
|
76
|
-
|
|
77
|
-
term_id = term.get('@id')
|
|
78
|
-
|
|
79
|
-
activityCoefficient = _get_activityCoefficient(cycle, animal, system, log_node)
|
|
60
|
+
def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float) -> float:
|
|
61
|
+
activityCoefficient = _get_activityCoefficient(cycle, animal, system)
|
|
80
62
|
|
|
81
63
|
liveweightPerHead = get_node_property(animal, 'liveweightPerHead', False).get('value', 0)
|
|
82
64
|
animal_value = animal.get('value', 0)
|
|
83
65
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
84
66
|
NEa = activityCoefficient * liveweightPerHead * animal_value * cycleDuration
|
|
85
67
|
|
|
86
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
87
|
-
liveweightPerHead=liveweightPerHead,
|
|
88
|
-
NEa=NEa)
|
|
89
|
-
|
|
90
68
|
return NEa
|
|
91
69
|
|
|
92
70
|
|
|
@@ -96,15 +74,12 @@ _NEa_BY_GROUPING = {
|
|
|
96
74
|
}
|
|
97
75
|
|
|
98
76
|
|
|
99
|
-
def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float
|
|
77
|
+
def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
|
|
100
78
|
grouping = _get_grouping(animal)
|
|
101
|
-
return _NEa_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, system, NEm
|
|
79
|
+
return _NEa_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, system, NEm)
|
|
102
80
|
|
|
103
81
|
|
|
104
|
-
def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict
|
|
105
|
-
term = animal.get('term', {})
|
|
106
|
-
term_id = term.get('@id')
|
|
107
|
-
|
|
82
|
+
def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
108
83
|
milkYieldPractice = get_milkYield_practice(animal)
|
|
109
84
|
milkYield = list_sum(milkYieldPractice.get('value', []))
|
|
110
85
|
fatContent = get_node_property(milkYieldPractice, 'fatContent').get('value', 0)
|
|
@@ -112,18 +87,10 @@ def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict, log_node: dict) -
|
|
|
112
87
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
113
88
|
NEl = milkYield * (1.47 + (0.4 * fatContent)) * animal_value * cycleDuration
|
|
114
89
|
|
|
115
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
116
|
-
milkYield=milkYield,
|
|
117
|
-
fatContent=fatContent,
|
|
118
|
-
NEl=NEl)
|
|
119
|
-
|
|
120
90
|
return NEl
|
|
121
91
|
|
|
122
92
|
|
|
123
|
-
def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict
|
|
124
|
-
term = animal.get('term', {})
|
|
125
|
-
term_id = term.get('@id')
|
|
126
|
-
|
|
93
|
+
def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
|
|
127
94
|
milkYieldPractice = get_milkYield_practice(animal)
|
|
128
95
|
milkYield = list_sum(milkYieldPractice.get('value', []))
|
|
129
96
|
EV_milk = safe_parse_float(
|
|
@@ -131,8 +98,9 @@ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> fl
|
|
|
131
98
|
0
|
|
132
99
|
)
|
|
133
100
|
default_fatContent = safe_parse_float(
|
|
134
|
-
get_lookup_value(
|
|
135
|
-
|
|
101
|
+
get_lookup_value(
|
|
102
|
+
milkYieldPractice.get('term', {}), 'defaultFatContentEvMilkIpcc2019', model=MODEL, model_key=MODEL_KEY
|
|
103
|
+
),
|
|
136
104
|
7
|
|
137
105
|
)
|
|
138
106
|
fatContent = get_node_property(milkYieldPractice, 'fatContent').get('value', 0)
|
|
@@ -140,11 +108,6 @@ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> fl
|
|
|
140
108
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
141
109
|
NEl = milkYield * (EV_milk * fatContent/default_fatContent) * animal_value * cycleDuration
|
|
142
110
|
|
|
143
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
144
|
-
milkYield=milkYield,
|
|
145
|
-
EV_milk=EV_milk,
|
|
146
|
-
NEl=NEl)
|
|
147
|
-
|
|
148
111
|
return NEl
|
|
149
112
|
|
|
150
113
|
|
|
@@ -154,22 +117,15 @@ _NEl_BY_GROUPING = {
|
|
|
154
117
|
}
|
|
155
118
|
|
|
156
119
|
|
|
157
|
-
def _calculate_NEl(cycle: dict, animal: dict
|
|
120
|
+
def _calculate_NEl(cycle: dict, animal: dict) -> float:
|
|
158
121
|
grouping = _get_grouping(animal)
|
|
159
|
-
return _NEl_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal
|
|
160
|
-
|
|
122
|
+
return _NEl_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal)
|
|
161
123
|
|
|
162
|
-
def _calculate_NEwork(cycle: dict, animal: dict, NEm: float, log_node: dict) -> float:
|
|
163
|
-
term = animal.get('term', {})
|
|
164
|
-
term_id = term.get('@id')
|
|
165
124
|
|
|
125
|
+
def _calculate_NEwork(cycle: dict, animal: dict, NEm: float) -> float:
|
|
166
126
|
hoursWorkedPerDay = get_node_property(animal, 'hoursWorkedPerDay').get('value', 0)
|
|
167
127
|
NEwork = 0.1 * NEm * hoursWorkedPerDay
|
|
168
128
|
|
|
169
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
170
|
-
hoursWorkedPerDay=hoursWorkedPerDay,
|
|
171
|
-
NEwork=NEwork)
|
|
172
|
-
|
|
173
129
|
return NEwork
|
|
174
130
|
|
|
175
131
|
|
|
@@ -193,25 +149,16 @@ def _get_pregnancy_ratio(animal: dict) -> float:
|
|
|
193
149
|
return _get_pregnancy_ratio_per_birth(animal, value) if ';' in value else safe_parse_float(value, 0)
|
|
194
150
|
|
|
195
151
|
|
|
196
|
-
def _calculate_NEp(cycle: dict, animal: dict, NEm: float
|
|
197
|
-
term = animal.get('term', {})
|
|
198
|
-
term_id = term.get('@id')
|
|
199
|
-
|
|
152
|
+
def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
|
|
200
153
|
ratioCPregnancyNetEnergyPregnancy = _get_pregnancy_ratio(animal)
|
|
201
154
|
pregnancyRateTotal = get_node_property(animal, 'pregnancyRateTotal').get('value', 0)
|
|
202
155
|
NEp = ratioCPregnancyNetEnergyPregnancy * pregnancyRateTotal/100 * NEm
|
|
203
156
|
|
|
204
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
205
|
-
ratioCPregnancyNetEnergyPregnancy=ratioCPregnancyNetEnergyPregnancy,
|
|
206
|
-
pregnancyRateTotal=pregnancyRateTotal,
|
|
207
|
-
NEp=NEp)
|
|
208
|
-
|
|
209
157
|
return NEp
|
|
210
158
|
|
|
211
159
|
|
|
212
|
-
def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict
|
|
160
|
+
def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
213
161
|
term = animal.get('term', {})
|
|
214
|
-
term_id = term.get('@id')
|
|
215
162
|
|
|
216
163
|
ratioCNetEnergyGrowthCattleBuffalo = safe_parse_float(
|
|
217
164
|
get_lookup_value(term, 'ratioCNetEnergyGrowthCattleBuffaloIpcc2019', model=MODEL, model_key=MODEL_KEY), 0
|
|
@@ -228,22 +175,14 @@ def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict, log_node: dict) -
|
|
|
228
175
|
ratioCNetEnergyGrowthCattleBuffalo * weightAtMaturity > 0
|
|
229
176
|
]) else 0
|
|
230
177
|
|
|
231
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
232
|
-
ratioCNetEnergyGrowthCattleBuffalo=ratioCNetEnergyGrowthCattleBuffalo,
|
|
233
|
-
liveweightPerHead=liveweightPerHead,
|
|
234
|
-
weightAtMaturity=weightAtMaturity,
|
|
235
|
-
liveweightGain=liveweightGain,
|
|
236
|
-
NEg=NEg)
|
|
237
|
-
|
|
238
178
|
return NEg
|
|
239
179
|
|
|
240
180
|
|
|
241
|
-
def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict
|
|
181
|
+
def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict) -> float:
|
|
242
182
|
term = animal.get('term', {})
|
|
243
|
-
term_id = term.get('@id')
|
|
244
183
|
|
|
245
184
|
MjKgABNetEnergyGrowthSheepGoats = get_lookup_value(
|
|
246
|
-
term, '
|
|
185
|
+
term, 'mjKgABNetEnergyGrowthSheepGoatsIpcc2019', model=MODEL, model_key=MODEL_KEY)
|
|
247
186
|
MjKg_a = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'a'), 0)
|
|
248
187
|
MjKg_b = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'b'), 0)
|
|
249
188
|
BWi = get_node_property(animal, 'weightAtWeaning').get('value', 0)
|
|
@@ -253,13 +192,6 @@ def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> fl
|
|
|
253
192
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
254
193
|
NEg = (BWf - BWi) * (MjKg_a + 0.5 * MjKg_b * (BWi + BWf)) / 365 * animal_value * cycleDuration
|
|
255
194
|
|
|
256
|
-
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
257
|
-
MjKg_a=MjKg_a,
|
|
258
|
-
MjKg_b=MjKg_b,
|
|
259
|
-
BWi=BWi,
|
|
260
|
-
BWf=BWf,
|
|
261
|
-
NEg=NEg)
|
|
262
|
-
|
|
263
195
|
return NEg
|
|
264
196
|
|
|
265
197
|
|
|
@@ -269,18 +201,19 @@ _NEg_BY_GROUPING = {
|
|
|
269
201
|
}
|
|
270
202
|
|
|
271
203
|
|
|
272
|
-
def _calculate_NEg(cycle: dict, animal: dict
|
|
204
|
+
def _calculate_NEg(cycle: dict, animal: dict) -> float:
|
|
273
205
|
grouping = _get_grouping(animal)
|
|
274
|
-
return _NEg_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal
|
|
206
|
+
return _NEg_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal)
|
|
275
207
|
|
|
276
208
|
|
|
277
|
-
def _pastureGrass_key_property_value(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
209
|
+
def _pastureGrass_key_property_value(column: dict, **log_args):
|
|
210
|
+
def get_value(practice: dict):
|
|
211
|
+
term_id = practice_input_id(practice)
|
|
212
|
+
term = download_hestia(term_id)
|
|
213
|
+
value = list_sum(practice.get('value', [0]))
|
|
214
|
+
lookup_value = node_property_lookup_value(MODEL, term, column, default=0, **log_args)
|
|
215
|
+
return (lookup_value, value)
|
|
216
|
+
return get_value
|
|
284
217
|
|
|
285
218
|
|
|
286
219
|
def calculate_REM(energy: float = 0) -> float:
|
|
@@ -346,27 +279,48 @@ def calculate_NEfeed(node: dict) -> tuple:
|
|
|
346
279
|
return (NEfeed_m, NEfeed_g)
|
|
347
280
|
|
|
348
281
|
|
|
349
|
-
def get_animal_values(cycle: dict, animal: dict, system: dict
|
|
350
|
-
NEm = _calculate_NEm(cycle, animal
|
|
351
|
-
NEa = _calculate_NEa(cycle, animal, system, NEm
|
|
352
|
-
NEl = _calculate_NEl(cycle, animal
|
|
353
|
-
NEwork = _calculate_NEwork(cycle, animal, NEm
|
|
354
|
-
NEp = _calculate_NEp(cycle, animal, NEm
|
|
355
|
-
NEg = _calculate_NEg(cycle, animal
|
|
282
|
+
def get_animal_values(cycle: dict, animal: dict, system: dict) -> dict:
|
|
283
|
+
NEm = _calculate_NEm(cycle, animal)
|
|
284
|
+
NEa = _calculate_NEa(cycle, animal, system, NEm)
|
|
285
|
+
NEl = _calculate_NEl(cycle, animal)
|
|
286
|
+
NEwork = _calculate_NEwork(cycle, animal, NEm)
|
|
287
|
+
NEp = _calculate_NEp(cycle, animal, NEm)
|
|
288
|
+
NEg = _calculate_NEg(cycle, animal)
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
'NEm': NEm,
|
|
292
|
+
'NEa': NEa,
|
|
293
|
+
'NEl': NEl,
|
|
294
|
+
'NEwork': NEwork,
|
|
295
|
+
'NEp': NEp,
|
|
296
|
+
'NEg': NEg
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _sum_values(values: list, key: str): return list_sum([v.get(key) for v in values])
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def calculate_GE(values: list, REM: float, REG: float, NEwool: float, NEm_feed: float, NEg_feed: float) -> float:
|
|
304
|
+
NEm = _sum_values(values, 'NEm')
|
|
305
|
+
NEa = _sum_values(values, 'NEa')
|
|
306
|
+
NEl = _sum_values(values, 'NEl')
|
|
307
|
+
NEwork = _sum_values(values, 'NEwork')
|
|
308
|
+
NEp = _sum_values(values, 'NEp')
|
|
309
|
+
NEg = _sum_values(values, 'NEg')
|
|
356
310
|
|
|
357
|
-
return (NEm
|
|
311
|
+
return ((NEm + NEa + NEl + NEwork + NEp - NEm_feed)/REM + (NEg + NEwool - NEg_feed)/REG) if all([REM, REG]) else 0
|
|
358
312
|
|
|
359
313
|
|
|
360
|
-
def calculate_meanECHHV(practices: list) -> float:
|
|
361
|
-
values = list(map(
|
|
314
|
+
def calculate_meanECHHV(practices: list, **log_args) -> float:
|
|
315
|
+
values = list(map(_pastureGrass_key_property_value('energyContentHigherHeatingValue', **log_args), practices))
|
|
362
316
|
total_weight = sum([weight/100 for _value, weight in values])
|
|
363
317
|
return sum([
|
|
364
318
|
(value * weight/100 if all([value, weight]) else 0) for value, weight in values
|
|
365
319
|
]) / total_weight if total_weight > 0 else 0
|
|
366
320
|
|
|
367
321
|
|
|
368
|
-
def calculate_meanDE(practices: list) -> float:
|
|
369
|
-
values = list(map(
|
|
322
|
+
def calculate_meanDE(practices: list, **log_args) -> float:
|
|
323
|
+
values = list(map(_pastureGrass_key_property_value('energyDigestibilityRuminants', **log_args), practices))
|
|
370
324
|
total_weight = sum([weight/100 for _value, weight in values])
|
|
371
325
|
meanDE = sum([
|
|
372
326
|
(value * weight/100 if all([value, weight]) else 0) for value, weight in values
|