hestia-earth-models 0.69.0__py3-none-any.whl → 0.70.0__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.
Files changed (75) hide show
  1. hestia_earth/models/cache_sites.py +3 -2
  2. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +2 -1
  3. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +3 -2
  4. hestia_earth/models/config/Cycle.json +35 -1
  5. hestia_earth/models/{koble2014 → cycle}/aboveGroundCropResidue.py +1 -3
  6. hestia_earth/models/cycle/aboveGroundCropResidueTotal.py +1 -1
  7. hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +1 -1
  8. hestia_earth/models/cycle/animal/input/properties.py +1 -1
  9. hestia_earth/models/cycle/cycleDuration.py +2 -2
  10. hestia_earth/models/cycle/energyContentLowerHeatingValue.py +1 -1
  11. hestia_earth/models/cycle/input/hestiaAggregatedData.py +12 -14
  12. hestia_earth/models/cycle/input/properties.py +1 -1
  13. hestia_earth/models/cycle/siteDuration.py +3 -3
  14. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +1 -1
  15. hestia_earth/models/geospatialDatabase/croppingIntensity.py +4 -4
  16. hestia_earth/models/geospatialDatabase/longFallowRatio.py +4 -4
  17. hestia_earth/models/geospatialDatabase/region.py +3 -2
  18. hestia_earth/models/geospatialDatabase/utils.py +6 -5
  19. hestia_earth/models/haversineFormula/transport/distance.py +5 -4
  20. hestia_earth/models/hestia/landCover.py +1 -5
  21. hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +2 -1
  22. hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +2 -1
  23. hestia_earth/models/hestia/seed_emissions.py +1 -1
  24. hestia_earth/models/impact_assessment/emissions.py +1 -1
  25. hestia_earth/models/impact_assessment/product/economicValueShare.py +1 -1
  26. hestia_earth/models/impact_assessment/product/value.py +1 -1
  27. hestia_earth/models/ipcc2019/animal/fatContent.py +2 -2
  28. hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +2 -2
  29. hestia_earth/models/ipcc2019/animal/trueProteinContent.py +2 -2
  30. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +7 -2
  31. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +1 -0
  32. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +2 -1
  33. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +2 -1
  34. hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +1 -0
  35. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1.py +8 -8
  36. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2.py +40 -12
  37. hestia_earth/models/koble2014/cropResidueManagement.py +1 -1
  38. hestia_earth/models/koble2014/residueBurnt.py +1 -1
  39. hestia_earth/models/koble2014/residueRemoved.py +1 -1
  40. hestia_earth/models/koble2014/utils.py +3 -3
  41. hestia_earth/models/mocking/search-results.json +1179 -1137
  42. hestia_earth/models/pooreNemecek2018/excretaKgN.py +1 -1
  43. hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +1 -1
  44. hestia_earth/models/pooreNemecek2018/utils.py +6 -3
  45. hestia_earth/models/schmidt2007/ch4ToAirWasteTreatment.py +1 -3
  46. hestia_earth/models/schmidt2007/h2SToAirWasteTreatment.py +1 -3
  47. hestia_earth/models/schmidt2007/n2OToAirWasteTreatmentDirect.py +1 -3
  48. hestia_earth/models/schmidt2007/nh3ToAirWasteTreatment.py +1 -3
  49. hestia_earth/models/site/management.py +5 -3
  50. hestia_earth/models/site/pre_checks/country.py +4 -2
  51. hestia_earth/models/transformation/input/excreta.py +1 -1
  52. hestia_earth/models/utils/aggregated.py +12 -15
  53. hestia_earth/models/utils/blank_node.py +15 -1
  54. hestia_earth/models/utils/product.py +1 -1
  55. hestia_earth/models/utils/source.py +2 -1
  56. hestia_earth/models/utils/term.py +26 -1
  57. hestia_earth/models/version.py +1 -1
  58. {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/METADATA +1 -1
  59. {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/RECORD +75 -75
  60. tests/models/cycle/input/test_hestiaAggregatedData.py +18 -16
  61. tests/models/{koble2014 → cycle}/test_aboveGroundCropResidue.py +3 -3
  62. tests/models/geospatialDatabase/test_region.py +1 -1
  63. tests/models/geospatialDatabase/test_utils.py +1 -1
  64. tests/models/haversineFormula/transport/test_distance.py +2 -2
  65. tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +11 -0
  66. tests/models/ipcc2019/test_nonCo2EmissionsToAirNaturalVegetationBurning.py +19 -6
  67. tests/models/ipcc2019/test_organicCarbonPerHa.py +4 -2
  68. tests/models/pooreNemecek2018/test_landOccupationDuringCycle.py +3 -0
  69. tests/models/site/pre_checks/test_country.py +4 -3
  70. tests/models/test_ecoinventV3.py +2 -2
  71. tests/models/utils/test_source.py +15 -5
  72. tests/orchestrator/test_models.py +1 -0
  73. {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/LICENSE +0 -0
  74. {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/WHEEL +0 -0
  75. {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/top_level.txt +0 -0
@@ -13,11 +13,13 @@ TERMS_BY_ID = {
13
13
  'energyDigestibilityPoultry': {'units': '%'},
14
14
  'neutralDetergentFibreContent': {'units': '%'}
15
15
  }
16
+ IONOPHORE_TERMS = ['ionophores', 'ionophoreAntibiotics']
16
17
 
17
18
 
18
19
  def fake_download_term(term_id: str, *args): return TERMS_BY_ID[term_id]
19
20
 
20
21
 
22
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
21
23
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
22
24
  @patch(f"{class_path}.get_default_digestibility", return_value=70)
23
25
  @patch(f"{class_path}.find_primary_product", return_value={'term': {'@id': 'pig'}})
@@ -52,6 +54,7 @@ def test_should_run(mock_feed, mock_lookup_value, *args):
52
54
  assert should_run is True
53
55
 
54
56
 
57
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
55
58
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
56
59
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
57
60
  # patch get_node_property to read value from lookups only
@@ -68,6 +71,7 @@ def test_run(*args):
68
71
  assert result == expected
69
72
 
70
73
 
74
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
71
75
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
72
76
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
73
77
  # patch get_node_property to read value from lookups only
@@ -84,6 +88,7 @@ def test_run_dairy(*args):
84
88
  assert result == expected
85
89
 
86
90
 
91
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
87
92
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=['milkYieldPerBuffaloRaw'])
88
93
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
89
94
  # patch get_node_property to read value from lookups only
@@ -100,6 +105,7 @@ def test_run_with_milkYield(*args):
100
105
  assert result == expected
101
106
 
102
107
 
108
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
103
109
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
104
110
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
105
111
  # patch get_node_property to read value from lookups only
@@ -116,6 +122,7 @@ def test_run_non_dairy(*args):
116
122
  assert result == expected
117
123
 
118
124
 
125
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
119
126
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
120
127
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
121
128
  # patch get_node_property to read value from lookups only
@@ -132,6 +139,7 @@ def test_run_with_ionophores(*args):
132
139
  assert result == expected
133
140
 
134
141
 
142
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
135
143
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
136
144
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
137
145
  # patch get_node_property to read value from lookups only
@@ -148,6 +156,7 @@ def test_run_without_ionophores(*args):
148
156
  assert result == expected
149
157
 
150
158
 
159
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
151
160
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
152
161
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
153
162
  # patch get_node_property to read value from lookups only
@@ -161,6 +170,7 @@ def test_run_no_feed(*args):
161
170
  assert result == []
162
171
 
163
172
 
173
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
164
174
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
165
175
  @patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
166
176
  # patch get_node_property to read value from lookups only
@@ -177,6 +187,7 @@ def test_run_with_system(*args):
177
187
  assert result == expected
178
188
 
179
189
 
190
+ @patch(f"{class_path}.get_ionophore_terms", return_value=IONOPHORE_TERMS)
180
191
  @patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=[])
181
192
  @patch("hestia_earth.models.utils.property.download_term", return_value={})
182
193
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
@@ -6,10 +6,19 @@ from unittest.mock import MagicMock, patch
6
6
 
7
7
  from tests.utils import fake_new_emission, fixtures_path, order_list
8
8
 
9
- from hestia_earth.models.ipcc2019.nonCo2EmissionsToAirNaturalVegetationBurning import run, _should_run
10
-
11
- class_path = 'hestia_earth.models.ipcc2019.nonCo2EmissionsToAirNaturalVegetationBurning'
12
- fixtures_folder = f"{fixtures_path}/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning"
9
+ from hestia_earth.models.ipcc2019.nonCo2EmissionsToAirNaturalVegetationBurning import MODEL, run, _should_run
10
+
11
+ class_path = f"hestia_earth.models.{MODEL}.nonCo2EmissionsToAirNaturalVegetationBurning"
12
+ fixtures_folder = f"{fixtures_path}/{MODEL}/nonCo2EmissionsToAirNaturalVegetationBurning"
13
+ biomass_utils_path = f"hestia_earth.models.{MODEL}.biomass_utils"
14
+
15
+ COVER_CROP_PROPERTY_TERM_IDS = [
16
+ "catchCrop",
17
+ "coverCrop",
18
+ "groundCover",
19
+ "longFallowCrop",
20
+ "shortFallowCrop"
21
+ ]
13
22
 
14
23
 
15
24
  def _load_fixture(path: str, default=None):
@@ -40,11 +49,13 @@ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
40
49
 
41
50
  @mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
42
51
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
52
+ @patch(f"{biomass_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
43
53
  @patch(f"{class_path}.related_cycles")
44
54
  @patch(f"{class_path}._get_site")
45
55
  def test_run(
46
56
  get_site_mock: MagicMock,
47
57
  related_cycles_mock: MagicMock,
58
+ _get_cover_crop_property_terms_mock: MagicMock,
48
59
  _new_emission_mock: MagicMock,
49
60
  subfolder: str,
50
61
  num_cycles: int,
@@ -66,7 +77,8 @@ def test_run(
66
77
  assert order_list(result) == order_list(expected)
67
78
 
68
79
 
69
- def test_should_run_no_data():
80
+ @patch(f"{biomass_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
81
+ def test_should_run_no_data(*args):
70
82
  CYCLE = {}
71
83
  EXPECTED = False
72
84
 
@@ -74,8 +86,9 @@ def test_should_run_no_data():
74
86
  assert result == EXPECTED
75
87
 
76
88
 
89
+ @patch(f"{biomass_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
77
90
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
78
- def test_run_no_data(*_):
91
+ def test_run_no_data(*args):
79
92
  CYCLE = {}
80
93
  EXPECTED = []
81
94
 
@@ -216,7 +216,8 @@ PARAMS_SHOULD_RUN = [
216
216
  ("tier-2/with-manure-liquid-kg-mass", True), # Closes issue 763
217
217
  ("tier-2/with-manure-dry-kg-n", True), # Closes issue 763
218
218
  ("tier-2/with-manure-fresh-kg-n", True), # Closes issue 763
219
- ("tier-2/with-manure-liquid-kg-n", True) # Closes issue 763
219
+ ("tier-2/with-manure-liquid-kg-n", True), # Closes issue 763
220
+ ("tier-2/with-split-years", True) # Closes issue 1177
220
221
  ]
221
222
  IDS_SHOULD_RUN = [p[0] for p in PARAMS_SHOULD_RUN]
222
223
 
@@ -268,12 +269,13 @@ def test_should_run(
268
269
 
269
270
 
270
271
  @patch(f"{tier_2_utils_path}.related_cycles", return_value=[])
272
+ @patch(f"{utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
271
273
  @patch(f"{term_path}.search")
272
274
  @patch(f"{property_path}.download_term")
273
275
  def test_should_run_no_data(
274
276
  download_term_mock: MagicMock,
275
277
  search_mock: MagicMock,
276
- _related_cycles_mock: MagicMock
278
+ *args
277
279
  ):
278
280
  SITE = {}
279
281
  EXPECTED = []
@@ -9,6 +9,7 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
10
 
11
11
 
12
+ @patch(f"{class_path}.get_landCover_term_id_from_site_type", return_value='cropland')
12
13
  @patch(f"{class_path}.get_landCover_term_id", return_value='cropland')
13
14
  @patch(f"{class_path}.land_occupation_per_kg", return_value=None)
14
15
  def test_should_run(mock_land_occupation, *args):
@@ -23,6 +24,7 @@ def test_should_run(mock_land_occupation, *args):
23
24
  assert should_run is True
24
25
 
25
26
 
27
+ @patch(f"{class_path}.get_landCover_term_id_from_site_type", return_value='cropland')
26
28
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
27
29
  def test_run(*args):
28
30
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -35,6 +37,7 @@ def test_run(*args):
35
37
  assert value == expected
36
38
 
37
39
 
40
+ @patch(f"{class_path}.get_landCover_term_id_from_site_type", return_value='cropland')
38
41
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
39
42
  def test_run_with_plantation(*args):
40
43
  with open(f"{fixtures_folder}/with-orchard-crop/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -1,12 +1,13 @@
1
1
  from unittest.mock import Mock, patch
2
+ from hestia_earth.schema import TermTermType
2
3
 
3
4
  from hestia_earth.models.site.pre_checks.country import run
4
5
 
5
6
  class_path = 'hestia_earth.models.site.pre_checks.country'
6
7
 
7
8
 
8
- @patch(f"{class_path}.download_hestia")
9
- def test_run(mock_download_hestia: Mock):
9
+ @patch(f"{class_path}.download_term")
10
+ def test_run(mock_download_term: Mock):
10
11
  site = {'country': {'@type': 'Term', '@id': 'GADM-GBR'}}
11
12
  run(site)
12
- mock_download_hestia.assert_called_once_with('GADM-GBR')
13
+ mock_download_term.assert_called_once_with('GADM-GBR', TermTermType.REGION)
@@ -39,12 +39,12 @@ TERMS_BY_ID = {
39
39
  }
40
40
 
41
41
 
42
- def fake_download_hestia(term, *args):
42
+ def fake_download_term(term, *args):
43
43
  term_id = term.get('@id') if isinstance(term, dict) else term
44
44
  return TERMS_BY_ID.get(term_id, {})
45
45
 
46
46
 
47
- @patch('hestia_earth.models.utils.blank_node.download_term', side_effect=fake_download_hestia)
47
+ @patch('hestia_earth.models.utils.blank_node.download_term', side_effect=fake_download_term)
48
48
  @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
49
49
  def test_run(*args):
50
50
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
@@ -13,11 +13,21 @@ search_results = [{
13
13
 
14
14
  def test_list_sources():
15
15
  sources = _list_sources()
16
- # test `BIBLIO_TITLE`
17
- assert 'Soil organic carbon sequestration rates in vineyard agroecosystems under different soil management practices: A meta-analysis' in sources # noqa: E501
18
- # test `OTHER_BIBLIO_TITLES`
19
- assert '2006 IPCC Guidelines for National Greenhouse Gas Inventories' in sources
20
- assert 'COMMISSION DECISION of 10 June 2010 on guidelines for the calculation of land carbon stocks for the purpose of Annex V to Directive 2009/28/EC' in sources # noqa: E501
16
+ assert sorted(sources) == [
17
+ '2006 IPCC Guidelines for National Greenhouse Gas Inventories',
18
+ '2019 Refinement to the 2006 IPCC Guidelines for National Greenhouse Gas Inventories',
19
+ 'A critical review of the conventional SOC to SOM conversion factor',
20
+ 'An Enhanced Global Elevation Model Generalized From Multiple Higher Resolution Source Datasets',
21
+ 'Biofuels: a new methodology to estimate GHG emissions from global land use change',
22
+ 'COMMISSION DECISION of 10 June 2010 on guidelines for the calculation of land carbon stocks for the purpose of Annex V to Directive 2009/28/EC', # noqa: E501
23
+ 'Contribution of Organic Matter and Clay to Soil Cation-Exchange Capacity as Affected by the pH of the Saturating Solution', # noqa: E501
24
+ 'ERA5: Fifth generation of ECMWF atmospheric reanalyses of the global climate',
25
+ 'Harmonized World Soil Database Version 1.2. Food and Agriculture Organization of the United Nations (FAO).', # noqa: E501
26
+ 'Harmonized World Soil Database Version 2.0.',
27
+ 'Modelling spatially explicit impacts from phosphorus emissions in agriculture',
28
+ 'Reducing food’s environmental impacts through producers and consumers',
29
+ 'Soil organic carbon sequestration rates in vineyard agroecosystems under different soil management practices: A meta-analysis', # noqa: E501
30
+ ]
21
31
 
22
32
 
23
33
  @patch(f"{class_path}.search", return_value=search_results)
@@ -10,6 +10,7 @@ class_path = 'hestia_earth.orchestrator.models'
10
10
  folder_path = os.path.join(fixtures_path, 'orchestrator', 'cycle')
11
11
 
12
12
 
13
+ @patch('hestia_earth.models.utils.source.find_sources', return_value=[])
13
14
  @patch('hestia_earth.orchestrator.strategies.merge._merge_version', return_value='0.0.0')
14
15
  def test_run(*args):
15
16
  with open(os.path.join(folder_path, 'config.json'), encoding='utf-8') as f: