hestia-earth-models 0.61.8__py3-none-any.whl → 0.62.1__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/blonkConsultants2016/utils.py +3 -2
- hestia_earth/models/cycle/completeness/electricityFuel.py +5 -1
- hestia_earth/models/cycle/post_checks/__init__.py +3 -2
- hestia_earth/models/cycle/post_checks/otherSites.py +40 -0
- hestia_earth/models/cycle/pre_checks/__init__.py +2 -1
- hestia_earth/models/cycle/pre_checks/otherSites.py +42 -0
- hestia_earth/models/cycle/pre_checks/site.py +1 -1
- hestia_earth/models/cycle/product/economicValueShare.py +47 -31
- hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +1 -1
- hestia_earth/models/emepEea2019/utils.py +4 -3
- hestia_earth/models/geospatialDatabase/heavyWinterPrecipitation.py +1 -1
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +36 -30
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +30 -4
- hestia_earth/models/ipcc2019/n2OToAirExcretaDirect.py +6 -2
- hestia_earth/models/ipcc2019/n2OToAirExcretaIndirect.py +1 -1
- hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +1 -1
- hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +1 -1
- hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +1 -1
- hestia_earth/models/ipcc2019/organicCarbonPerHa.py +4 -6
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +4 -2
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +12 -11
- hestia_earth/models/ipcc2019/pastureGrass.py +40 -22
- hestia_earth/models/ipcc2019/pastureGrass_utils.py +43 -60
- hestia_earth/models/mocking/search-results.json +261 -257
- hestia_earth/models/schererPfister2015/utils.py +2 -2
- hestia_earth/models/site/brackishWater.py +1 -1
- hestia_earth/models/site/flowingWater.py +1 -1
- hestia_earth/models/site/freshWater.py +1 -1
- hestia_earth/models/site/management.py +29 -11
- hestia_earth/models/site/pre_checks/cache_sources.py +9 -13
- hestia_earth/models/site/salineWater.py +1 -1
- hestia_earth/models/stehfestBouwman2006/n2OToAirCropResidueDecompositionDirect.py +12 -2
- hestia_earth/models/stehfestBouwman2006/n2OToAirExcretaDirect.py +12 -2
- hestia_earth/models/stehfestBouwman2006/n2OToAirInorganicFertiliserDirect.py +11 -1
- hestia_earth/models/stehfestBouwman2006/n2OToAirOrganicFertiliserDirect.py +11 -1
- hestia_earth/models/stehfestBouwman2006/noxToAirCropResidueDecomposition.py +12 -2
- hestia_earth/models/stehfestBouwman2006/noxToAirExcreta.py +12 -2
- hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py +11 -1
- hestia_earth/models/stehfestBouwman2006/noxToAirOrganicFertiliser.py +11 -1
- hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirCropResidueDecomposition.py +12 -2
- hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirExcreta.py +12 -2
- hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirInorganicFertiliser.py +11 -1
- hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirOrganicFertiliser.py +11 -1
- hestia_earth/models/utils/blank_node.py +159 -146
- hestia_earth/models/utils/constant.py +2 -0
- hestia_earth/models/utils/lookup.py +19 -6
- hestia_earth/models/utils/source.py +1 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.61.8.dist-info → hestia_earth_models-0.62.1.dist-info}/METADATA +3 -3
- {hestia_earth_models-0.61.8.dist-info → hestia_earth_models-0.62.1.dist-info}/RECORD +64 -59
- tests/models/cycle/post_checks/test_otherSites.py +15 -0
- tests/models/cycle/pre_checks/test_otherSites.py +21 -0
- tests/models/cycle/product/test_economicValueShare.py +8 -0
- tests/models/ipcc2019/animal/test_pastureGrass.py +2 -2
- tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -2
- tests/models/ipcc2019/test_organicCarbonPerHa.py +2 -1
- tests/models/ipcc2019/test_pastureGrass.py +0 -16
- tests/models/site/pre_checks/test_cache_sources.py +6 -10
- tests/models/site/test_management.py +162 -2
- tests/models/utils/test_blank_node.py +154 -296
- tests/models/utils/test_lookup.py +10 -0
- {hestia_earth_models-0.61.8.dist-info → hestia_earth_models-0.62.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.61.8.dist-info → hestia_earth_models-0.62.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.61.8.dist-info → hestia_earth_models-0.62.1.dist-info}/top_level.txt +0 -0
|
@@ -88,7 +88,7 @@ def _should_run(cycle: dict):
|
|
|
88
88
|
no3_n=no3_n,
|
|
89
89
|
nh3_n=nh3_n,
|
|
90
90
|
nox_n=nox_n,
|
|
91
|
-
|
|
91
|
+
term_type_fertiliser_complete=term_type_complete)
|
|
92
92
|
|
|
93
93
|
should_run = all([no3_n is not None, nh3_n is not None, nox_n is not None, term_type_complete])
|
|
94
94
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -88,7 +88,7 @@ def _should_run(cycle: dict):
|
|
|
88
88
|
no3_n=no3_n,
|
|
89
89
|
nh3_n=nh3_n,
|
|
90
90
|
nox_n=nox_n,
|
|
91
|
-
|
|
91
|
+
term_type_fertiliser_complete=term_type_complete)
|
|
92
92
|
|
|
93
93
|
should_run = all([no3_n is not None, nh3_n is not None, nox_n is not None, term_type_complete])
|
|
94
94
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -139,13 +139,11 @@ def run(site: dict) -> list[dict]:
|
|
|
139
139
|
"""
|
|
140
140
|
should_run, run_data = _should_run(site)
|
|
141
141
|
_log_data(site, should_run, run_data)
|
|
142
|
-
return
|
|
143
|
-
(
|
|
144
|
-
|
|
145
|
-
if run_data[method]["should_run"]
|
|
146
|
-
),
|
|
142
|
+
return reduce(
|
|
143
|
+
lambda result, method: result + _run_method(method, **run_data[method]),
|
|
144
|
+
run_data,
|
|
147
145
|
list()
|
|
148
|
-
)
|
|
146
|
+
)
|
|
149
147
|
|
|
150
148
|
|
|
151
149
|
def _should_run(site: dict) -> tuple[bool, dict[ModuleType, dict]]:
|
|
@@ -19,10 +19,11 @@ from typing import Callable, Optional, Union
|
|
|
19
19
|
|
|
20
20
|
from hestia_earth.schema import MeasurementMethodClassification, SiteSiteType, TermTermType
|
|
21
21
|
from hestia_earth.utils.model import find_term_match, filter_list_term_type
|
|
22
|
+
from hestia_earth.utils.blank_node import get_node_value
|
|
22
23
|
|
|
23
24
|
from hestia_earth.models.utils.array_builders import gen_seed
|
|
24
25
|
from hestia_earth.models.utils.blank_node import (
|
|
25
|
-
cumulative_nodes_match, cumulative_nodes_lookup_match, cumulative_nodes_term_match,
|
|
26
|
+
cumulative_nodes_match, cumulative_nodes_lookup_match, cumulative_nodes_term_match,
|
|
26
27
|
node_lookup_match, node_term_match, group_nodes_by_year
|
|
27
28
|
)
|
|
28
29
|
from hestia_earth.models.utils.descriptive_stats import calc_descriptive_stats
|
|
@@ -1952,6 +1953,7 @@ def _get_carbon_input_kwargs(
|
|
|
1952
1953
|
crop_residue_management_nodes = filter_list_term_type(management_nodes, [TermTermType.CROPRESIDUEMANAGEMENT])
|
|
1953
1954
|
land_cover_nodes = filter_list_term_type(management_nodes, [TermTermType.LANDCOVER])
|
|
1954
1955
|
land_use_management_nodes = filter_list_term_type(management_nodes, [TermTermType.LANDUSEMANAGEMENT])
|
|
1956
|
+
system_nodes = filter_list_term_type(management_nodes, [TermTermType.SYSTEM])
|
|
1955
1957
|
water_regime_nodes = filter_list_term_type(management_nodes, [TermTermType.WATERREGIME])
|
|
1956
1958
|
|
|
1957
1959
|
has_animal_manure_used = any(
|
|
@@ -2006,7 +2008,7 @@ def _get_carbon_input_kwargs(
|
|
|
2006
2008
|
node_lookup_match(node, PRACTICE_INCREASING_C_INPUT_LOOKUP, True)
|
|
2007
2009
|
and not node_term_match(node, EXCLUDED_PRACTICE_TERM_IDS)
|
|
2008
2010
|
),
|
|
2009
|
-
land_use_management_nodes,
|
|
2011
|
+
land_use_management_nodes + system_nodes,
|
|
2010
2012
|
cumulative_threshold=MIN_AREA_THRESHOLD
|
|
2011
2013
|
)
|
|
2012
2014
|
|
|
@@ -19,13 +19,14 @@ from hestia_earth.schema import (
|
|
|
19
19
|
)
|
|
20
20
|
from hestia_earth.utils.model import find_term_match, filter_list_term_type
|
|
21
21
|
from hestia_earth.utils.tools import flatten, list_sum, non_empty_list
|
|
22
|
+
from hestia_earth.utils.blank_node import get_node_value
|
|
22
23
|
|
|
23
24
|
from hestia_earth.models.utils.array_builders import (
|
|
24
25
|
avg_run_in_columnwise, gen_seed, grouped_avg, repeat_1d_array_as_columns
|
|
25
26
|
)
|
|
26
27
|
from hestia_earth.models.utils.blank_node import (
|
|
27
|
-
cumulative_nodes_lookup_match, cumulative_nodes_term_match,
|
|
28
|
-
group_nodes_by_year_and_month, GroupNodesByYearMode
|
|
28
|
+
cumulative_nodes_lookup_match, cumulative_nodes_term_match, group_nodes_by_year,
|
|
29
|
+
group_nodes_by_year_and_month, GroupNodesByYearMode, node_term_match
|
|
29
30
|
)
|
|
30
31
|
from hestia_earth.models.utils.cycle import check_cycle_site_ids_identical
|
|
31
32
|
from hestia_earth.models.utils.descriptive_stats import calc_descriptive_stats
|
|
@@ -1227,15 +1228,15 @@ def _check_12_months(inner_dict: dict, keys: set[Any]):
|
|
|
1227
1228
|
def _get_grouped_climate_measurements(grouped_measurements: dict) -> dict:
|
|
1228
1229
|
return {
|
|
1229
1230
|
year: {
|
|
1230
|
-
_InventoryKey.TEMP_MONTHLY: non_empty_list(
|
|
1231
|
-
|
|
1232
|
-
),
|
|
1233
|
-
_InventoryKey.PRECIP_MONTHLY: non_empty_list(
|
|
1234
|
-
|
|
1235
|
-
),
|
|
1236
|
-
_InventoryKey.PET_MONTHLY: non_empty_list(
|
|
1237
|
-
|
|
1238
|
-
)
|
|
1231
|
+
_InventoryKey.TEMP_MONTHLY: non_empty_list(flatten(
|
|
1232
|
+
node.get("value", []) for node in measurements if node_term_match(node, _TEMPERATURE_MONTHLY_TERM_ID)
|
|
1233
|
+
)),
|
|
1234
|
+
_InventoryKey.PRECIP_MONTHLY: non_empty_list(flatten(
|
|
1235
|
+
node.get("value", []) for node in measurements if node_term_match(node, _PRECIPITATION_MONTHLY_TERM_ID)
|
|
1236
|
+
)),
|
|
1237
|
+
_InventoryKey.PET_MONTHLY: non_empty_list(flatten(
|
|
1238
|
+
node.get("value", []) for node in measurements if node_term_match(node, _PET_MONTHLY_TERM_ID)
|
|
1239
|
+
))
|
|
1239
1240
|
} for year, measurements in grouped_measurements.items()
|
|
1240
1241
|
}
|
|
1241
1242
|
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
2
|
+
Cycle Pasture Grass
|
|
3
3
|
|
|
4
4
|
This model estimates the energetic requirements of ruminants and can be used to estimate the amount of grass they graze.
|
|
5
5
|
Source:
|
|
6
6
|
[IPCC 2019, Vol.4, Chapter 10](https://www.ipcc-nggip.iges.or.jp/public/2019rf/pdf/4_Volume4/19R_V4_Ch10_Livestock.pdf).
|
|
7
|
+
|
|
8
|
+
This version of the model will run at the Cycle level, if at least one Cycle Input is given as feed
|
|
9
|
+
(see https://www.hestia.earth/schema/Input#isAnimalFeed).
|
|
7
10
|
"""
|
|
8
11
|
from hestia_earth.schema import TermTermType
|
|
9
12
|
from hestia_earth.utils.model import filter_list_term_type
|
|
10
13
|
from hestia_earth.utils.tools import list_sum
|
|
11
14
|
|
|
12
|
-
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
15
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, debugValues
|
|
13
16
|
from hestia_earth.models.utils.input import _new_input
|
|
14
17
|
from hestia_earth.models.utils.term import get_wool_terms
|
|
15
18
|
from hestia_earth.models.utils.completeness import _is_term_type_complete, _is_term_type_incomplete
|
|
@@ -30,7 +33,7 @@ from .pastureGrass_utils import (
|
|
|
30
33
|
REQUIREMENTS = {
|
|
31
34
|
"Cycle": {
|
|
32
35
|
"completeness.animalFeed": "True",
|
|
33
|
-
"completeness.animalPopulation": "
|
|
36
|
+
"completeness.animalPopulation": "True",
|
|
34
37
|
"completeness.freshForage": "False",
|
|
35
38
|
"site": {
|
|
36
39
|
"@type": "Site",
|
|
@@ -45,6 +48,19 @@ REQUIREMENTS = {
|
|
|
45
48
|
"term.termType": "landCover"
|
|
46
49
|
}
|
|
47
50
|
}],
|
|
51
|
+
"inputs": [{
|
|
52
|
+
"@type": "Input",
|
|
53
|
+
"term.units": "kg",
|
|
54
|
+
"value": "> 0",
|
|
55
|
+
"isAnimalFeed": "True",
|
|
56
|
+
"optional": {
|
|
57
|
+
"properties": [{
|
|
58
|
+
"@type": "Property",
|
|
59
|
+
"value": "",
|
|
60
|
+
"term.@id": ["neutralDetergentFibreContent", "energyContentHigherHeatingValue"]
|
|
61
|
+
}]
|
|
62
|
+
}
|
|
63
|
+
}],
|
|
48
64
|
"animals": [{
|
|
49
65
|
"@type": "Animal",
|
|
50
66
|
"value": "> 0",
|
|
@@ -93,19 +109,6 @@ REQUIREMENTS = {
|
|
|
93
109
|
}
|
|
94
110
|
}],
|
|
95
111
|
"optional": {
|
|
96
|
-
"inputs": [{
|
|
97
|
-
"@type": "Input",
|
|
98
|
-
"term.units": "kg",
|
|
99
|
-
"value": "> 0",
|
|
100
|
-
"isAnimalFeed": "True",
|
|
101
|
-
"optional": {
|
|
102
|
-
"properties": [{
|
|
103
|
-
"@type": "Property",
|
|
104
|
-
"value": "",
|
|
105
|
-
"term.@id": ["neutralDetergentFibreContent", "energyContentHigherHeatingValue"]
|
|
106
|
-
}]
|
|
107
|
-
}
|
|
108
|
-
}],
|
|
109
112
|
"products": [{
|
|
110
113
|
"@type": "Product",
|
|
111
114
|
"value": "",
|
|
@@ -162,13 +165,24 @@ def calculate_NEwool(cycle: dict) -> float:
|
|
|
162
165
|
def _calculate_GE(
|
|
163
166
|
cycle: dict, animals: list, REM: float, REG: float, NEwool: float, NEm_feed: float, NEg_feed: float, system: dict
|
|
164
167
|
) -> float:
|
|
165
|
-
values = [get_animal_values(cycle, animal, system) for animal in animals]
|
|
168
|
+
values = [get_animal_values(cycle, animal, system, log_node=cycle) for animal in animals]
|
|
166
169
|
NEm = _sum_values(values, 0)
|
|
167
170
|
NEa = _sum_values(values, 1)
|
|
168
171
|
NEl = _sum_values(values, 2)
|
|
169
172
|
NEwork = _sum_values(values, 3)
|
|
170
173
|
NEp = _sum_values(values, 4)
|
|
171
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
|
+
|
|
172
186
|
return (NEm + NEa + NEl + NEwork + NEp - NEm_feed)/REM + (NEg + NEwool - NEg_feed)/REG
|
|
173
187
|
|
|
174
188
|
|
|
@@ -195,7 +209,7 @@ def _run_practice(cycle: dict, meanDE: float, meanECHHV: float, system: dict):
|
|
|
195
209
|
NEm_feed=NEm_feed,
|
|
196
210
|
NEg_feed=NEg_feed,
|
|
197
211
|
GE=GE,
|
|
198
|
-
|
|
212
|
+
practice_key_id=key_id)
|
|
199
213
|
|
|
200
214
|
logShouldRun(cycle, MODEL, input_term_id, True, model_key=MODEL_KEY)
|
|
201
215
|
|
|
@@ -207,17 +221,20 @@ def _run_practice(cycle: dict, meanDE: float, meanECHHV: float, system: dict):
|
|
|
207
221
|
def _should_run(cycle: dict, practices: dict):
|
|
208
222
|
systems = filter_list_term_type(cycle.get('practices', []), TermTermType.SYSTEM)
|
|
209
223
|
animalFeed_complete = _is_term_type_complete(cycle, 'animalFeed')
|
|
210
|
-
|
|
224
|
+
animalPopulation_complete = _is_term_type_complete(cycle, 'animalPopulation')
|
|
211
225
|
freshForage_incomplete = _is_term_type_incomplete(cycle, 'freshForage')
|
|
212
226
|
all_animals_have_value = all([a.get('value', 0) > 0 for a in cycle.get('animals', [])])
|
|
213
227
|
|
|
228
|
+
has_cycle_inputs_feed = any([i.get('isAnimalFeed', False) for i in cycle.get('inputs', [])])
|
|
229
|
+
|
|
214
230
|
meanDE = calculate_meanDE(practices)
|
|
215
231
|
meanECHHV = calculate_meanECHHV(practices)
|
|
216
232
|
|
|
217
233
|
should_run = all([
|
|
218
234
|
animalFeed_complete,
|
|
219
|
-
|
|
235
|
+
animalPopulation_complete,
|
|
220
236
|
freshForage_incomplete,
|
|
237
|
+
has_cycle_inputs_feed,
|
|
221
238
|
all_animals_have_value,
|
|
222
239
|
len(systems) > 0,
|
|
223
240
|
len(practices) > 0,
|
|
@@ -225,11 +242,12 @@ def _should_run(cycle: dict, practices: dict):
|
|
|
225
242
|
meanECHHV > 0
|
|
226
243
|
])
|
|
227
244
|
|
|
228
|
-
for term_id in [
|
|
245
|
+
for term_id in [practice_input_id(p) for p in practices] or [MODEL_KEY]:
|
|
229
246
|
logRequirements(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
230
247
|
term_type_animalFeed_complete=animalFeed_complete,
|
|
231
|
-
|
|
248
|
+
term_type_animalPopulation_complete=animalPopulation_complete,
|
|
232
249
|
term_type_freshForage_incomplete=freshForage_incomplete,
|
|
250
|
+
has_cycle_inputs_feed=has_cycle_inputs_feed,
|
|
233
251
|
all_animals_have_value=all_animals_have_value,
|
|
234
252
|
meanDE=meanDE,
|
|
235
253
|
meanECHHV=meanECHHV)
|
|
@@ -3,7 +3,7 @@ from hestia_earth.utils.api import download_hestia
|
|
|
3
3
|
from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data
|
|
4
4
|
from hestia_earth.utils.tools import list_sum, safe_parse_float
|
|
5
5
|
|
|
6
|
-
from hestia_earth.models.log import debugValues
|
|
6
|
+
from hestia_earth.models.log import debugValues
|
|
7
7
|
from hestia_earth.models.utils.input import get_feed_inputs
|
|
8
8
|
from hestia_earth.models.utils.term import get_lookup_value
|
|
9
9
|
from hestia_earth.models.utils.property import get_node_property, get_node_property_value, node_property_lookup_value
|
|
@@ -25,20 +25,20 @@ 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) -> float:
|
|
28
|
+
def _get_activityCoefficient(cycle: dict, animal: dict, system: dict, log_node: 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(
|
|
35
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
36
36
|
activityCoefficient=activityCoefficient)
|
|
37
37
|
|
|
38
38
|
return activityCoefficient
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def _calculate_NEm(cycle: dict, animal: dict) -> float:
|
|
41
|
+
def _calculate_NEm(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
42
42
|
term = animal.get('term', {})
|
|
43
43
|
term_id = term.get('@id')
|
|
44
44
|
|
|
@@ -50,7 +50,7 @@ def _calculate_NEm(cycle: dict, animal: dict) -> float:
|
|
|
50
50
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
51
51
|
NEm = mjDayKgCfiNetEnergyMaintenance * pow(liveweightPerHead, 0.75) * animal_value * cycleDuration
|
|
52
52
|
|
|
53
|
-
debugValues(
|
|
53
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
54
54
|
mjDayKgCfiNetEnergyMaintenance=mjDayKgCfiNetEnergyMaintenance,
|
|
55
55
|
liveweightPerHead=liveweightPerHead,
|
|
56
56
|
NEm=NEm)
|
|
@@ -58,32 +58,32 @@ def _calculate_NEm(cycle: dict, animal: dict) -> float:
|
|
|
58
58
|
return NEm
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
|
|
61
|
+
def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float, log_node: dict) -> float:
|
|
62
62
|
term = animal.get('term', {})
|
|
63
63
|
term_id = term.get('@id')
|
|
64
64
|
|
|
65
|
-
activityCoefficient = _get_activityCoefficient(cycle, animal, system)
|
|
65
|
+
activityCoefficient = _get_activityCoefficient(cycle, animal, system, log_node)
|
|
66
66
|
|
|
67
67
|
NEa = activityCoefficient * NEm
|
|
68
68
|
|
|
69
|
-
debugValues(
|
|
69
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
70
70
|
NEa=NEa)
|
|
71
71
|
|
|
72
72
|
return NEa
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float) -> float:
|
|
75
|
+
def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float, log_node: dict) -> float:
|
|
76
76
|
term = animal.get('term', {})
|
|
77
77
|
term_id = term.get('@id')
|
|
78
78
|
|
|
79
|
-
activityCoefficient = _get_activityCoefficient(cycle, animal, system)
|
|
79
|
+
activityCoefficient = _get_activityCoefficient(cycle, animal, system, log_node)
|
|
80
80
|
|
|
81
81
|
liveweightPerHead = get_node_property(animal, 'liveweightPerHead', False).get('value', 0)
|
|
82
82
|
animal_value = animal.get('value', 0)
|
|
83
83
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
84
84
|
NEa = activityCoefficient * liveweightPerHead * animal_value * cycleDuration
|
|
85
85
|
|
|
86
|
-
debugValues(
|
|
86
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
87
87
|
liveweightPerHead=liveweightPerHead,
|
|
88
88
|
NEa=NEa)
|
|
89
89
|
|
|
@@ -96,12 +96,12 @@ _NEa_BY_GROUPING = {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
|
|
99
|
+
def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float, log_node: dict) -> float:
|
|
100
100
|
grouping = _get_grouping(animal)
|
|
101
|
-
return _NEa_BY_GROUPING.get(grouping, lambda *args:
|
|
101
|
+
return _NEa_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, system, NEm, log_node)
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
104
|
+
def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
105
105
|
term = animal.get('term', {})
|
|
106
106
|
term_id = term.get('@id')
|
|
107
107
|
|
|
@@ -112,7 +112,7 @@ def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
|
112
112
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
113
113
|
NEl = milkYield * (1.47 + (0.4 * fatContent)) * animal_value * cycleDuration
|
|
114
114
|
|
|
115
|
-
debugValues(
|
|
115
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
116
116
|
milkYield=milkYield,
|
|
117
117
|
fatContent=fatContent,
|
|
118
118
|
NEl=NEl)
|
|
@@ -120,7 +120,7 @@ def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
|
120
120
|
return NEl
|
|
121
121
|
|
|
122
122
|
|
|
123
|
-
def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
|
|
123
|
+
def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
124
124
|
term = animal.get('term', {})
|
|
125
125
|
term_id = term.get('@id')
|
|
126
126
|
|
|
@@ -140,7 +140,7 @@ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
|
|
|
140
140
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
141
141
|
NEl = milkYield * (EV_milk * fatContent/default_fatContent) * animal_value * cycleDuration
|
|
142
142
|
|
|
143
|
-
debugValues(
|
|
143
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
144
144
|
milkYield=milkYield,
|
|
145
145
|
EV_milk=EV_milk,
|
|
146
146
|
NEl=NEl)
|
|
@@ -154,19 +154,19 @@ _NEl_BY_GROUPING = {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def _calculate_NEl(cycle: dict, animal: dict) -> float:
|
|
157
|
+
def _calculate_NEl(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
158
158
|
grouping = _get_grouping(animal)
|
|
159
|
-
return _NEl_BY_GROUPING.get(grouping, lambda *args:
|
|
159
|
+
return _NEl_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, log_node)
|
|
160
160
|
|
|
161
161
|
|
|
162
|
-
def _calculate_NEwork(cycle: dict, animal: dict, NEm: float) -> float:
|
|
162
|
+
def _calculate_NEwork(cycle: dict, animal: dict, NEm: float, log_node: dict) -> float:
|
|
163
163
|
term = animal.get('term', {})
|
|
164
164
|
term_id = term.get('@id')
|
|
165
165
|
|
|
166
166
|
hoursWorkedPerDay = get_node_property(animal, 'hoursWorkedPerDay').get('value', 0)
|
|
167
167
|
NEwork = 0.1 * NEm * hoursWorkedPerDay
|
|
168
168
|
|
|
169
|
-
debugValues(
|
|
169
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
170
170
|
hoursWorkedPerDay=hoursWorkedPerDay,
|
|
171
171
|
NEwork=NEwork)
|
|
172
172
|
|
|
@@ -193,7 +193,7 @@ def _get_pregnancy_ratio(animal: dict) -> float:
|
|
|
193
193
|
return _get_pregnancy_ratio_per_birth(animal, value) if ';' in value else safe_parse_float(value, 0)
|
|
194
194
|
|
|
195
195
|
|
|
196
|
-
def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
|
|
196
|
+
def _calculate_NEp(cycle: dict, animal: dict, NEm: float, log_node: dict) -> float:
|
|
197
197
|
term = animal.get('term', {})
|
|
198
198
|
term_id = term.get('@id')
|
|
199
199
|
|
|
@@ -201,7 +201,7 @@ def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
|
|
|
201
201
|
pregnancyRateTotal = get_node_property(animal, 'pregnancyRateTotal').get('value', 0)
|
|
202
202
|
NEp = ratioCPregnancyNetEnergyPregnancy * pregnancyRateTotal/100 * NEm
|
|
203
203
|
|
|
204
|
-
debugValues(
|
|
204
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
205
205
|
ratioCPregnancyNetEnergyPregnancy=ratioCPregnancyNetEnergyPregnancy,
|
|
206
206
|
pregnancyRateTotal=pregnancyRateTotal,
|
|
207
207
|
NEp=NEp)
|
|
@@ -209,7 +209,7 @@ def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
|
|
|
209
209
|
return NEp
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
212
|
+
def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
213
213
|
term = animal.get('term', {})
|
|
214
214
|
term_id = term.get('@id')
|
|
215
215
|
|
|
@@ -228,7 +228,7 @@ def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
|
228
228
|
ratioCNetEnergyGrowthCattleBuffalo * weightAtMaturity > 0
|
|
229
229
|
]) else 0
|
|
230
230
|
|
|
231
|
-
debugValues(
|
|
231
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
232
232
|
ratioCNetEnergyGrowthCattleBuffalo=ratioCNetEnergyGrowthCattleBuffalo,
|
|
233
233
|
liveweightPerHead=liveweightPerHead,
|
|
234
234
|
weightAtMaturity=weightAtMaturity,
|
|
@@ -238,7 +238,7 @@ def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
|
|
|
238
238
|
return NEg
|
|
239
239
|
|
|
240
240
|
|
|
241
|
-
def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict) -> float:
|
|
241
|
+
def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
242
242
|
term = animal.get('term', {})
|
|
243
243
|
term_id = term.get('@id')
|
|
244
244
|
|
|
@@ -253,7 +253,7 @@ def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict) -> float:
|
|
|
253
253
|
cycleDuration = cycle.get('cycleDuration', 365)
|
|
254
254
|
NEg = (BWf - BWi) * (MjKg_a + 0.5 * MjKg_b * (BWi + BWf)) / 365 * animal_value * cycleDuration
|
|
255
255
|
|
|
256
|
-
debugValues(
|
|
256
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
257
257
|
MjKg_a=MjKg_a,
|
|
258
258
|
MjKg_b=MjKg_b,
|
|
259
259
|
BWi=BWi,
|
|
@@ -269,9 +269,9 @@ _NEg_BY_GROUPING = {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
|
|
272
|
-
def _calculate_NEg(cycle: dict, animal: dict) -> float:
|
|
272
|
+
def _calculate_NEg(cycle: dict, animal: dict, log_node: dict) -> float:
|
|
273
273
|
grouping = _get_grouping(animal)
|
|
274
|
-
return _NEg_BY_GROUPING.get(grouping, lambda *args:
|
|
274
|
+
return _NEg_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, log_node)
|
|
275
275
|
|
|
276
276
|
|
|
277
277
|
def _pastureGrass_key_property_value(practice: dict, column: dict):
|
|
@@ -291,14 +291,14 @@ def calculate_REG(energy: float = 0) -> float:
|
|
|
291
291
|
return 1.164 - (5.16/1000 * energy) + (1.308/100000 * pow(energy, 2)) - (37.4/energy) if energy > 0 else 0
|
|
292
292
|
|
|
293
293
|
|
|
294
|
-
def _calculate_feed_meanDE(
|
|
294
|
+
def _calculate_feed_meanDE(log_node: dict, input: dict) -> float:
|
|
295
295
|
term_id = input.get('term', {}).get('@id')
|
|
296
296
|
|
|
297
297
|
energyContent = get_node_property_value(MODEL, input, 'energyContentHigherHeatingValue')
|
|
298
298
|
energyDigestibility = get_node_property_value(MODEL, input, 'energyDigestibilityRuminants')
|
|
299
299
|
meanDE = energyContent * energyDigestibility if all([energyContent, energyDigestibility]) else 0
|
|
300
300
|
|
|
301
|
-
debugValues(
|
|
301
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
302
302
|
energyContent=energyContent,
|
|
303
303
|
energyDigestibility=energyDigestibility,
|
|
304
304
|
meanDE=meanDE)
|
|
@@ -306,26 +306,26 @@ def _calculate_feed_meanDE(node: dict, input: dict) -> float:
|
|
|
306
306
|
return meanDE
|
|
307
307
|
|
|
308
308
|
|
|
309
|
-
def _calculate_NEfeed_m(
|
|
309
|
+
def _calculate_NEfeed_m(log_node: dict, input: dict, meanDE: float) -> float:
|
|
310
310
|
term_id = input.get('term', {}).get('@id')
|
|
311
311
|
|
|
312
312
|
energyDigestibility = get_node_property_value(MODEL, input, 'energyDigestibilityRuminants', default=0)
|
|
313
313
|
REm = calculate_REM(energyDigestibility * 100)
|
|
314
314
|
|
|
315
|
-
debugValues(
|
|
315
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
316
316
|
REm=REm)
|
|
317
317
|
|
|
318
318
|
input_value = list_sum(input.get('value'))
|
|
319
319
|
return meanDE * REm * input_value
|
|
320
320
|
|
|
321
321
|
|
|
322
|
-
def _calculate_NEfeed_g(
|
|
322
|
+
def _calculate_NEfeed_g(log_node: dict, input: dict, meanDE: float) -> float:
|
|
323
323
|
term_id = input.get('term', {}).get('@id')
|
|
324
324
|
|
|
325
325
|
energyDigestibility = get_node_property_value(MODEL, input, 'energyDigestibilityRuminants', default=0)
|
|
326
326
|
REg = calculate_REG(energyDigestibility * 100)
|
|
327
327
|
|
|
328
|
-
debugValues(
|
|
328
|
+
debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
329
329
|
REg=REg)
|
|
330
330
|
|
|
331
331
|
input_value = list_sum(input.get('value'))
|
|
@@ -346,23 +346,13 @@ def calculate_NEfeed(node: dict) -> tuple:
|
|
|
346
346
|
return (NEfeed_m, NEfeed_g)
|
|
347
347
|
|
|
348
348
|
|
|
349
|
-
def get_animal_values(cycle: dict, animal: dict, system: dict):
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
NEp = _calculate_NEp(cycle, animal, NEm)
|
|
357
|
-
NEg = _calculate_NEg(cycle, animal)
|
|
358
|
-
|
|
359
|
-
logRequirements(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
360
|
-
NEm=NEm,
|
|
361
|
-
NEa=NEa,
|
|
362
|
-
NEl=NEl,
|
|
363
|
-
NEwork=NEwork,
|
|
364
|
-
NEp=NEp,
|
|
365
|
-
NEg=NEg)
|
|
349
|
+
def get_animal_values(cycle: dict, animal: dict, system: dict, log_node: dict):
|
|
350
|
+
NEm = _calculate_NEm(cycle, animal, log_node=log_node)
|
|
351
|
+
NEa = _calculate_NEa(cycle, animal, system, NEm, log_node=log_node)
|
|
352
|
+
NEl = _calculate_NEl(cycle, animal, log_node=log_node)
|
|
353
|
+
NEwork = _calculate_NEwork(cycle, animal, NEm, log_node=log_node)
|
|
354
|
+
NEp = _calculate_NEp(cycle, animal, NEm, log_node=log_node)
|
|
355
|
+
NEg = _calculate_NEg(cycle, animal, log_node=log_node)
|
|
366
356
|
|
|
367
357
|
return (NEm, NEa, NEl, NEwork, NEp, NEg)
|
|
368
358
|
|
|
@@ -394,14 +384,7 @@ def should_run_practice(cycle: dict):
|
|
|
394
384
|
term_id = practice.get('term', {}).get('@id')
|
|
395
385
|
key_term_type = practice.get('key', {}).get('termType')
|
|
396
386
|
value = practice.get('value', [])
|
|
397
|
-
|
|
398
|
-
logRequirements(cycle, model=MODEL, term=term_id,
|
|
399
|
-
practice_value=list_sum(value),
|
|
400
|
-
practice_key_term_type=key_term_type)
|
|
401
|
-
|
|
402
|
-
should_run = all([len(value) > 0, term_id == MODEL_KEY, key_term_type in KEY_TERM_TYPES])
|
|
403
|
-
logShouldRun(cycle, MODEL, term_id, should_run)
|
|
404
|
-
return should_run
|
|
387
|
+
return all([len(value) > 0, term_id == MODEL_KEY, key_term_type in KEY_TERM_TYPES])
|
|
405
388
|
|
|
406
389
|
return should_run
|
|
407
390
|
|