hestia-earth-models 0.72.2__py3-none-any.whl → 0.73.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 (130) hide show
  1. hestia_earth/models/{akagiEtAl2011AndIpcc2006 → akagiEtAl2011}/__init__.py +1 -1
  2. hestia_earth/models/akagiEtAl2011/ch4ToAirCropResidueBurning.py +32 -0
  3. hestia_earth/models/akagiEtAl2011/nh3ToAirCropResidueBurning.py +32 -0
  4. hestia_earth/models/akagiEtAl2011/noxToAirCropResidueBurning.py +32 -0
  5. hestia_earth/models/akagiEtAl2011/pm25ToAirCropResidueBurning.py +32 -0
  6. hestia_earth/models/akagiEtAl2011/so2ToAirCropResidueBurning.py +32 -0
  7. hestia_earth/models/akagiEtAl2011/utils.py +45 -0
  8. hestia_earth/models/aware/scarcityWeightedWaterUse.py +2 -2
  9. hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsTotalLandUseEffects.py +1 -1
  10. hestia_earth/models/chaudharyBrooks2018/utils.py +1 -1
  11. hestia_earth/models/config/Cycle.json +48 -7
  12. hestia_earth/models/config/ImpactAssessment.json +22 -0
  13. hestia_earth/models/cycle/completeness/soilAmendment.py +1 -1
  14. hestia_earth/models/cycle/product/economicValueShare.py +3 -1
  15. hestia_earth/models/cycle/product/price.py +35 -10
  16. hestia_earth/models/cycle/product/revenue.py +5 -2
  17. hestia_earth/models/dammgen2009/noxToAirExcreta.py +14 -18
  18. hestia_earth/models/ecoinventV3/__init__.py +11 -6
  19. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +1 -1
  20. hestia_earth/models/emepEea2019/utils.py +2 -1
  21. hestia_earth/models/faostat2018/liveweightPerHead.py +1 -1
  22. hestia_earth/models/faostat2018/product/price.py +2 -2
  23. hestia_earth/models/faostat2018/seed.py +3 -2
  24. hestia_earth/models/faostat2018/utils.py +6 -5
  25. hestia_earth/models/geospatialDatabase/altitude.py +2 -1
  26. hestia_earth/models/geospatialDatabase/drainageClass.py +2 -1
  27. hestia_earth/models/geospatialDatabase/organicCarbonPerKgSoil.py +2 -1
  28. hestia_earth/models/geospatialDatabase/totalNitrogenPerKgSoil.py +2 -1
  29. hestia_earth/models/geospatialDatabase/totalPhosphorusPerKgSoil.py +2 -1
  30. hestia_earth/models/geospatialDatabase/utils.py +1 -1
  31. hestia_earth/models/globalCropWaterModel2008/rootingDepth.py +1 -1
  32. hestia_earth/models/hestia/brackishWater.py +1 -1
  33. hestia_earth/models/hestia/default_emissions.py +105 -0
  34. hestia_earth/models/hestia/default_resourceUse.py +110 -0
  35. hestia_earth/models/hestia/freshWater.py +1 -1
  36. hestia_earth/models/hestia/inorganicFertiliser.py +12 -12
  37. hestia_earth/models/hestia/landCover.py +7 -5
  38. hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +3 -0
  39. hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +3 -0
  40. hestia_earth/models/hestia/liveAnimal.py +1 -1
  41. hestia_earth/models/hestia/management.py +1 -1
  42. hestia_earth/models/hestia/netPrimaryProduction.py +1 -1
  43. hestia_earth/models/hestia/organicCarbonPerHa.py +2 -2
  44. hestia_earth/models/hestia/salineWater.py +1 -1
  45. hestia_earth/models/hestia/seed_emissions.py +34 -20
  46. hestia_earth/models/hestia/totalNitrogenPerKgSoil.py +1 -1
  47. hestia_earth/models/hestia/waterSalinity.py +2 -1
  48. hestia_earth/models/ipcc2006/aboveGroundCropResidueRemoved.py +2 -2
  49. hestia_earth/models/ipcc2006/aboveGroundCropResidueTotal.py +10 -6
  50. hestia_earth/models/ipcc2006/belowGroundCropResidue.py +12 -8
  51. hestia_earth/models/ipcc2019/animal/utils.py +1 -1
  52. hestia_earth/models/ipcc2019/belowGroundCropResidue.py +1 -1
  53. hestia_earth/models/ipcc2019/carbonContent.py +1 -1
  54. hestia_earth/models/ipcc2019/ch4ToAirAquacultureSystems.py +17 -9
  55. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +6 -6
  56. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +4 -2
  57. hestia_earth/models/ipcc2019/co2ToAirUreaHydrolysis.py +1 -1
  58. hestia_earth/models/ipcc2019/croppingDuration.py +4 -2
  59. hestia_earth/models/ipcc2019/ligninContent.py +1 -1
  60. hestia_earth/models/{akagiEtAl2011AndIpcc2006 → ipcc2019}/n2OToAirCropResidueBurningDirect.py +8 -4
  61. hestia_earth/models/ipcc2019/nitrogenContent.py +1 -1
  62. hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +6 -2
  63. hestia_earth/models/ipcc2019/pastureGrass_utils.py +13 -12
  64. hestia_earth/models/ipcc2019/utils.py +6 -2
  65. hestia_earth/models/koble2014/residueBurnt.py +6 -3
  66. hestia_earth/models/koble2014/residueRemoved.py +1 -1
  67. hestia_earth/models/mocking/search-results.json +1577 -1573
  68. hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py +1 -1
  69. hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py +1 -1
  70. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +1 -1
  71. hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +1 -1
  72. hestia_earth/models/pooreNemecek2018/longFallowDuration.py +1 -1
  73. hestia_earth/models/pooreNemecek2018/nurseryDensity.py +1 -1
  74. hestia_earth/models/pooreNemecek2018/nurseryDuration.py +1 -1
  75. hestia_earth/models/pooreNemecek2018/plantationDensity.py +1 -1
  76. hestia_earth/models/pooreNemecek2018/plantationLifespan.py +1 -1
  77. hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py +3 -1
  78. hestia_earth/models/pooreNemecek2018/saplingsDepreciatedAmountPerCycle.py +1 -1
  79. hestia_earth/models/resourceUseNotRelevant/__init__.py +65 -0
  80. hestia_earth/models/schererPfister2015/nErosionSoilFlux.py +5 -3
  81. hestia_earth/models/schererPfister2015/pErosionSoilFlux.py +5 -3
  82. hestia_earth/models/schererPfister2015/utils.py +5 -4
  83. hestia_earth/models/stehfestBouwman2006/n2OToAirSoilFlux_utils.py +1 -1
  84. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirSoilFlux_utils.py +3 -3
  85. hestia_earth/models/utils/background_emissions.py +14 -10
  86. hestia_earth/models/utils/blank_node.py +6 -4
  87. hestia_earth/models/utils/crop.py +1 -1
  88. hestia_earth/models/utils/cropResidue.py +16 -0
  89. hestia_earth/models/utils/cycle.py +1 -1
  90. hestia_earth/models/utils/ecoClimateZone.py +2 -2
  91. hestia_earth/models/utils/excretaManagement.py +1 -1
  92. hestia_earth/models/utils/feedipedia.py +3 -3
  93. hestia_earth/models/utils/fertiliser.py +7 -1
  94. hestia_earth/models/utils/inorganicFertiliser.py +2 -2
  95. hestia_earth/models/utils/input.py +34 -1
  96. hestia_earth/models/utils/liveAnimal.py +2 -2
  97. hestia_earth/models/utils/lookup.py +1 -1
  98. hestia_earth/models/utils/measurement.py +5 -4
  99. hestia_earth/models/utils/productivity.py +1 -1
  100. hestia_earth/models/utils/property.py +4 -2
  101. hestia_earth/models/utils/site.py +2 -1
  102. hestia_earth/models/version.py +1 -1
  103. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.0.dist-info}/METADATA +1 -1
  104. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.0.dist-info}/RECORD +124 -113
  105. tests/models/akagiEtAl2011/test_ch4ToAirCropResidueBurning.py +33 -0
  106. tests/models/akagiEtAl2011/test_nh3ToAirCropResidueBurning.py +33 -0
  107. tests/models/{akagiEtAl2011AndIpcc2006 → akagiEtAl2011}/test_noxToAirCropResidueBurning.py +5 -17
  108. tests/models/akagiEtAl2011/test_pm25ToAirCropResidueBurning.py +33 -0
  109. tests/models/akagiEtAl2011/test_so2ToAirCropResidueBurning.py +33 -0
  110. tests/models/akagiEtAl2011/test_utils.py +18 -0
  111. tests/models/cycle/product/test_price.py +1 -11
  112. tests/models/dammgen2009/test_noxToAirExcreta.py +30 -10
  113. tests/models/geospatialDatabase/test_utils.py +2 -1
  114. tests/models/hestia/test_default_emissions.py +25 -0
  115. tests/models/hestia/test_default_resourceUse.py +26 -0
  116. tests/models/hestia/test_landCover.py +2 -2
  117. tests/models/ipcc2019/test_ch4ToAirAquacultureSystems.py +2 -2
  118. tests/models/{akagiEtAl2011AndIpcc2006/test_nh3ToAirCropResidueBurning.py → ipcc2019/test_n2OToAirCropResidueBurningDirect.py} +2 -2
  119. tests/models/test_resourceUseNotRelevant.py +27 -0
  120. tests/models/{akagiEtAl2011AndIpcc2006/test_utils.py → utils/test_cropResidue.py} +6 -6
  121. hestia_earth/models/akagiEtAl2011AndIpcc2006/ch4ToAirCropResidueBurning.py +0 -57
  122. hestia_earth/models/akagiEtAl2011AndIpcc2006/nh3ToAirCropResidueBurning.py +0 -57
  123. hestia_earth/models/akagiEtAl2011AndIpcc2006/noxToAirCropResidueBurning.py +0 -57
  124. hestia_earth/models/akagiEtAl2011AndIpcc2006/utils.py +0 -15
  125. tests/models/akagiEtAl2011AndIpcc2006/test_ch4ToAirCropResidueBurning.py +0 -45
  126. tests/models/akagiEtAl2011AndIpcc2006/test_n2OToAirCropResidueBurningDirect.py +0 -46
  127. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.0.dist-info}/LICENSE +0 -0
  128. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.0.dist-info}/WHEEL +0 -0
  129. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.0.dist-info}/top_level.txt +0 -0
  130. /tests/models/{akagiEtAl2011AndIpcc2006 → akagiEtAl2011}/__init__.py +0 -0
@@ -0,0 +1,33 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_emission
4
+
5
+ from hestia_earth.models.akagiEtAl2011.utils import MODEL
6
+ from hestia_earth.models.akagiEtAl2011.ch4ToAirCropResidueBurning import TERM_ID, run
7
+
8
+ class_path_utils = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
22
+
23
+
24
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
25
+ def test_run_data_complete(*args):
26
+ with open(f"{fixtures_folder}/no-product-data-complete/cycle.jsonld", encoding='utf-8') as f:
27
+ cycle = json.load(f)
28
+
29
+ with open(f"{fixtures_folder}/no-product-data-complete/result.jsonld", encoding='utf-8') as f:
30
+ expected = json.load(f)
31
+
32
+ value = run(cycle)
33
+ assert value == expected
@@ -0,0 +1,33 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_emission
4
+
5
+ from hestia_earth.models.akagiEtAl2011.utils import MODEL
6
+ from hestia_earth.models.akagiEtAl2011.nh3ToAirCropResidueBurning import TERM_ID, run
7
+
8
+ class_path_utils = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
22
+
23
+
24
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
25
+ def test_run_data_complete(*args):
26
+ with open(f"{fixtures_folder}/no-product-data-complete/cycle.jsonld", encoding='utf-8') as f:
27
+ cycle = json.load(f)
28
+
29
+ with open(f"{fixtures_folder}/no-product-data-complete/result.jsonld", encoding='utf-8') as f:
30
+ expected = json.load(f)
31
+
32
+ value = run(cycle)
33
+ assert value == expected
@@ -2,26 +2,14 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_emission
4
4
 
5
- from hestia_earth.models.akagiEtAl2011AndIpcc2006.noxToAirCropResidueBurning import MODEL, TERM_ID, run, _should_run
5
+ from hestia_earth.models.akagiEtAl2011.utils import MODEL
6
+ from hestia_earth.models.akagiEtAl2011.noxToAirCropResidueBurning import TERM_ID, run
6
7
 
7
- class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ class_path_utils = f"hestia_earth.models.{MODEL}.utils"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
10
 
10
11
 
11
- @patch(f"{class_path}._get_crop_residue_burnt_value")
12
- def test_should_run(mock_product_value, *args):
13
- # no products => no run
14
- mock_product_value.return_value = []
15
- should_run, *args = _should_run({})
16
- assert not should_run
17
-
18
- # with products => run
19
- mock_product_value.return_value = [0]
20
- should_run, *args = _should_run({})
21
- assert should_run is True
22
-
23
-
24
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
12
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
25
13
  def test_run(*args):
26
14
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
27
15
  cycle = json.load(f)
@@ -33,7 +21,7 @@ def test_run(*args):
33
21
  assert value == expected
34
22
 
35
23
 
36
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
24
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
37
25
  def test_run_data_complete(*args):
38
26
  with open(f"{fixtures_folder}/no-product-data-complete/cycle.jsonld", encoding='utf-8') as f:
39
27
  cycle = json.load(f)
@@ -0,0 +1,33 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_emission
4
+
5
+ from hestia_earth.models.akagiEtAl2011.utils import MODEL
6
+ from hestia_earth.models.akagiEtAl2011.pm25ToAirCropResidueBurning import TERM_ID, run
7
+
8
+ class_path_utils = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
22
+
23
+
24
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
25
+ def test_run_data_complete(*args):
26
+ with open(f"{fixtures_folder}/no-product-data-complete/cycle.jsonld", encoding='utf-8') as f:
27
+ cycle = json.load(f)
28
+
29
+ with open(f"{fixtures_folder}/no-product-data-complete/result.jsonld", encoding='utf-8') as f:
30
+ expected = json.load(f)
31
+
32
+ value = run(cycle)
33
+ assert value == expected
@@ -0,0 +1,33 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_emission
4
+
5
+ from hestia_earth.models.akagiEtAl2011.utils import MODEL
6
+ from hestia_earth.models.akagiEtAl2011.so2ToAirCropResidueBurning import TERM_ID, run
7
+
8
+ class_path_utils = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
22
+
23
+
24
+ @patch(f"{class_path_utils}._new_emission", side_effect=fake_new_emission)
25
+ def test_run_data_complete(*args):
26
+ with open(f"{fixtures_folder}/no-product-data-complete/cycle.jsonld", encoding='utf-8') as f:
27
+ cycle = json.load(f)
28
+
29
+ with open(f"{fixtures_folder}/no-product-data-complete/result.jsonld", encoding='utf-8') as f:
30
+ expected = json.load(f)
31
+
32
+ value = run(cycle)
33
+ assert value == expected
@@ -0,0 +1,18 @@
1
+ from unittest.mock import patch
2
+
3
+ from hestia_earth.models.akagiEtAl2011.utils import MODEL, _should_run
4
+
5
+ class_path = f"hestia_earth.models.{MODEL}.utils"
6
+
7
+
8
+ @patch(f"{class_path}.get_crop_residue_burnt_value")
9
+ def test_should_run(mock_product_value, *args):
10
+ # no products => no run
11
+ mock_product_value.return_value = []
12
+ should_run, *args = _should_run('', {})
13
+ assert not should_run
14
+
15
+ # with products => run
16
+ mock_product_value.return_value = [0]
17
+ should_run, *args = _should_run('', {})
18
+ assert should_run is True
@@ -1,22 +1,12 @@
1
1
  import json
2
2
  from tests.utils import fixtures_path
3
3
 
4
- from hestia_earth.models.cycle.product.price import (
5
- MODEL, MODEL_KEY, run, _should_run_product_by_share_0
6
- )
4
+ from hestia_earth.models.cycle.product.price import MODEL, MODEL_KEY, run
7
5
 
8
6
  class_path = f"hestia_earth.models.{MODEL}.product.{MODEL_KEY}"
9
7
  fixtures_folder = f"{fixtures_path}/{MODEL}/product/{MODEL_KEY}"
10
8
 
11
9
 
12
- def test_should_run_product_by_share_0():
13
- product = {'term': {'@id': 'citrusFruit', 'termType': 'crop'}}
14
- assert not _should_run_product_by_share_0({}, product)
15
-
16
- product = {'term': {'@id': 'nitrogenUptakeEdiblePart', 'termType': 'crop'}}
17
- assert _should_run_product_by_share_0({}, product) is True
18
-
19
-
20
10
  def test_run():
21
11
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
22
12
  cycle = json.load(f)
@@ -2,27 +2,47 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_emission
4
4
 
5
- from hestia_earth.models.dammgen2009.noxToAirExcreta import MODEL, TERM_ID, run, _should_run
5
+ from hestia_earth.models.dammgen2009.noxToAirExcreta import MODEL, TERM_ID, run, _should_run, N2O_TERM_ID
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
- @patch(f"{class_path}.total_excreta", return_value=None)
12
- @patch(f"{class_path}.get_lookup_factor", return_value=None)
13
- def test_should_run(mock_get_lookup_factor, mock_excreta):
11
+ def test_should_run():
14
12
  # no practice factor => no run
15
13
  should_run, *args = _should_run({})
16
14
  assert not should_run
17
15
 
18
- # no excreta => no run
19
- mock_get_lookup_factor.return_value = 10
20
- should_run, *args = _should_run({})
16
+ # without N20 term in cycle.emissions => no run
17
+ should_run, *args = _should_run(
18
+ {
19
+ "type": "Cycle",
20
+ "emissions": [{
21
+ "@type": "Emission",
22
+ "term": {
23
+ "@id": "ch4ToAirExcreta",
24
+ "termType": "emission"
25
+ },
26
+ "value": [8.7],
27
+ }]
28
+ }
29
+ )
21
30
  assert not should_run
22
31
 
23
- # with excretaKgN => run
24
- mock_excreta.return_value = 10
25
- should_run, *args = _should_run({})
32
+ # with N20 term in cycle => run
33
+ should_run, *args = _should_run(
34
+ {
35
+ "type": "Cycle",
36
+ "emissions": [{
37
+ "@type": "Emission",
38
+ "term": {
39
+ "@id": N2O_TERM_ID,
40
+ "termType": "emission"
41
+ },
42
+ "value": [10.7],
43
+ }]
44
+ }
45
+ )
26
46
  assert should_run is True
27
47
 
28
48
 
@@ -14,7 +14,8 @@ COUNTRY = {
14
14
 
15
15
  def test_get_region_factor():
16
16
  site = {'country': COUNTRY}
17
- assert get_region_factor('croppingIntensity', site, TermTermType.LANDUSEMANAGEMENT) == 0.9999775685587958
17
+ value = get_region_factor('croppingIntensity', site, TermTermType.LANDUSEMANAGEMENT)
18
+ assert round(value, 5) == 0.99998
18
19
 
19
20
 
20
21
  @patch(f"{class_path}.download_term", return_value={'area': AREA})
@@ -0,0 +1,25 @@
1
+ import os
2
+ import json
3
+ import pytest
4
+ from unittest.mock import patch
5
+
6
+ from tests.utils import fixtures_path, fake_new_emission
7
+ from hestia_earth.models.hestia.default_emissions import MODEL, MODEL_KEY, run
8
+
9
+ class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
11
+ _folders = [d for d in os.listdir(fixtures_folder) if os.path.isdir(os.path.join(fixtures_folder, d))]
12
+
13
+
14
+ @pytest.mark.parametrize("subfolder", _folders)
15
+ @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
16
+ def test_run(mock, subfolder: str):
17
+ folder = f"{fixtures_folder}/{subfolder}"
18
+ with open(f"{folder}/cycle.jsonld", encoding='utf-8') as f:
19
+ cycle = json.load(f)
20
+
21
+ with open(f"{folder}/result.jsonld", encoding='utf-8') as f:
22
+ expected = json.load(f)
23
+
24
+ result = run(cycle)
25
+ assert result == expected
@@ -0,0 +1,26 @@
1
+ import os
2
+ import json
3
+ import pytest
4
+ from unittest.mock import patch
5
+
6
+ from tests.utils import fixtures_path, fake_new_indicator
7
+ from hestia_earth.models.hestia.default_resourceUse import MODEL, MODEL_KEY, run
8
+
9
+ class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
11
+ _folders = [d for d in os.listdir(fixtures_folder) if os.path.isdir(os.path.join(fixtures_folder, d))]
12
+
13
+
14
+ @pytest.mark.parametrize("subfolder", _folders)
15
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
16
+ def test_run(mock, subfolder: str):
17
+ folder = f"{fixtures_folder}/{subfolder}"
18
+ with open(f"{folder}/impact.jsonld", encoding='utf-8') as f:
19
+ impact = json.load(f)
20
+
21
+ with open(f"{folder}/result.jsonld", encoding='utf-8') as f:
22
+ expected = json.load(f)
23
+
24
+ result = run(impact)
25
+ print(json.dumps(result, indent=2))
26
+ assert result == expected
@@ -6,7 +6,7 @@ from unittest.mock import patch
6
6
  from tests.utils import fixtures_path, fake_new_management
7
7
  from hestia_earth.models.faostat2018.utils import MODEL as FAOSTAT_MODEL
8
8
  from hestia_earth.models.hestia.landCover import (
9
- MODEL, MODEL_KEY, get_changes, _estimate_maximum_forest_change,
9
+ MODEL, MODEL_KEY, _get_changes, _estimate_maximum_forest_change,
10
10
  run, site_area_sum_to_100, _get_sums_of_crop_expansion, _get_sum_for_land_category, scale_values_to_one,
11
11
  _get_most_common_or_alphabetically_first
12
12
  )
@@ -66,7 +66,7 @@ def test_get_most_common_or_alphabetically_first(terms, expected_output):
66
66
 
67
67
 
68
68
  def test_get_changes():
69
- result, missing_values = get_changes(
69
+ result, missing_values = _get_changes(
70
70
  country_id="GADM-AFG",
71
71
  end_year=2010
72
72
  )
@@ -37,14 +37,14 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
37
37
  {
38
38
  'cycleDuration': 150,
39
39
  'functionalUnit': 'relative',
40
- 'site': {'area': 1000, 'measurements': [{'term': {'@id': 'salineWater'}}]}
40
+ 'site': {'area': 1000, 'measurements': [{'term': {'@id': 'salineWater', 'termType': 'measurement'}}]}
41
41
  },
42
42
  True
43
43
  )
44
44
  ]
45
45
  )
46
46
  def test_should_run(test_name, cycle, expected_should_run):
47
- should_run = _should_run(cycle)
47
+ should_run, *args = _should_run(cycle)
48
48
  assert should_run == expected_should_run, test_name
49
49
 
50
50
 
@@ -2,13 +2,13 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_emission
4
4
 
5
- from hestia_earth.models.akagiEtAl2011AndIpcc2006.nh3ToAirCropResidueBurning import MODEL, TERM_ID, run, _should_run
5
+ from hestia_earth.models.ipcc2019.n2OToAirCropResidueBurningDirect import MODEL, TERM_ID, run, _should_run
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
- @patch(f"{class_path}._get_crop_residue_burnt_value")
11
+ @patch(f"{class_path}.get_crop_residue_burnt_value")
12
12
  def test_should_run(mock_product_value, *args):
13
13
  # no products => no run
14
14
  mock_product_value.return_value = []
@@ -0,0 +1,27 @@
1
+ import os
2
+ import json
3
+ import pytest
4
+ from unittest.mock import Mock, patch
5
+ from tests.utils import fixtures_path, fake_new_indicator
6
+
7
+ from hestia_earth.models.resourceUseNotRelevant import MODEL, run
8
+
9
+ class_path = f"hestia_earth.models.{MODEL}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}"
11
+ _folders = [d for d in os.listdir(fixtures_folder) if os.path.isdir(os.path.join(fixtures_folder, d))]
12
+
13
+
14
+ @pytest.mark.parametrize('folder', _folders)
15
+ @patch(f"{class_path}.get_land_cover_term_id")
16
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
17
+ def test_run_forest(mock_new_indicator: Mock, mock_land_cover: Mock, folder: str):
18
+ mock_land_cover.return_value = folder
19
+
20
+ with open(f"{fixtures_folder}/{folder}/impact.jsonld", encoding='utf-8') as f:
21
+ impact = json.load(f)
22
+
23
+ with open(f"{fixtures_folder}/{folder}/result.jsonld", encoding='utf-8') as f:
24
+ expected = json.load(f)
25
+
26
+ result = run('all', impact)
27
+ assert result == expected, folder
@@ -1,26 +1,26 @@
1
1
  from unittest.mock import patch
2
2
 
3
- from hestia_earth.models.akagiEtAl2011AndIpcc2006.utils import _get_crop_residue_burnt_value
3
+ from hestia_earth.models.utils.cropResidue import get_crop_residue_burnt_value
4
4
 
5
- class_path = 'hestia_earth.models.akagiEtAl2011AndIpcc2006.utils'
5
+ class_path = 'hestia_earth.models.utils.cropResidue'
6
6
 
7
7
 
8
8
  @patch(f"{class_path}.find_term_match", return_value=None)
9
9
  @patch(f"{class_path}._is_term_type_complete", return_value=False)
10
- def test_get_crop_residue_burnt_value(mock_data_complete, mock_find_product):
10
+ def testget_crop_residue_burnt_value(mock_data_complete, mock_find_product):
11
11
  # product not found no data complete
12
12
  mock_data_complete.return_value = False
13
13
  mock_find_product.return_value = {}
14
- value = _get_crop_residue_burnt_value({})
14
+ value = get_crop_residue_burnt_value({})
15
15
  assert value == []
16
16
 
17
17
  # product not found and data complete
18
18
  mock_data_complete.return_value = True
19
19
  mock_find_product.return_value = {}
20
- value = _get_crop_residue_burnt_value({})
20
+ value = get_crop_residue_burnt_value({})
21
21
  assert value == [0]
22
22
 
23
23
  # product found
24
24
  mock_find_product.return_value = {'value': [100]}
25
- value = _get_crop_residue_burnt_value({})
25
+ value = get_crop_residue_burnt_value({})
26
26
  assert value == [100, 100]
@@ -1,57 +0,0 @@
1
- from hestia_earth.schema import EmissionMethodTier
2
-
3
- from hestia_earth.models.log import logRequirements, logShouldRun
4
- from hestia_earth.models.utils.emission import _new_emission
5
- from .utils import _get_crop_residue_burnt_value
6
- from . import MODEL
7
-
8
- REQUIREMENTS = {
9
- "Cycle": {
10
- "or": {
11
- "products": [{
12
- "@type": "Product",
13
- "term.@id": ["aboveGroundCropResidueBurnt", "discardedCropBurnt"],
14
- "value": ""
15
- }],
16
- "completeness.cropResidue": "True"
17
- }
18
- }
19
- }
20
- RETURNS = {
21
- "Emission": [{
22
- "value": "",
23
- "methodTier": "tier 1"
24
- }]
25
- }
26
- TERM_ID = 'ch4ToAirCropResidueBurning'
27
- TIER = EmissionMethodTier.TIER_1.value
28
- DRY_MATTER_FACTOR_TO_CH4 = 5.82/1000
29
-
30
-
31
- def _emission(value: float):
32
- emission = _new_emission(TERM_ID, MODEL)
33
- emission['value'] = [value]
34
- emission['methodTier'] = TIER
35
- return emission
36
-
37
-
38
- def _run(product_value: list):
39
- value = sum(product_value)
40
- return [_emission(value * DRY_MATTER_FACTOR_TO_CH4)]
41
-
42
-
43
- def _should_run(cycle: dict):
44
- crop_residue_burnt_value = _get_crop_residue_burnt_value(cycle)
45
- has_crop_residue_burnt = len(crop_residue_burnt_value) > 0
46
-
47
- logRequirements(cycle, model=MODEL, term=TERM_ID,
48
- has_crop_residue_burnt=has_crop_residue_burnt)
49
-
50
- should_run = all([has_crop_residue_burnt])
51
- logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
52
- return should_run, crop_residue_burnt_value
53
-
54
-
55
- def run(cycle: dict):
56
- should_run, crop_residue_burnt_value = _should_run(cycle)
57
- return _run(crop_residue_burnt_value) if should_run else []
@@ -1,57 +0,0 @@
1
- from hestia_earth.schema import EmissionMethodTier
2
-
3
- from hestia_earth.models.log import logRequirements, logShouldRun
4
- from hestia_earth.models.utils.emission import _new_emission
5
- from .utils import _get_crop_residue_burnt_value
6
- from . import MODEL
7
-
8
- REQUIREMENTS = {
9
- "Cycle": {
10
- "or": {
11
- "products": [{
12
- "@type": "Product",
13
- "term.@id": ["aboveGroundCropResidueBurnt", "discardedCropBurnt"],
14
- "value": ""
15
- }],
16
- "completeness.cropResidue": "True"
17
- }
18
- }
19
- }
20
- RETURNS = {
21
- "Emission": [{
22
- "value": "",
23
- "methodTier": "tier 1"
24
- }]
25
- }
26
- TERM_ID = 'nh3ToAirCropResidueBurning'
27
- TIER = EmissionMethodTier.TIER_1.value
28
- DRY_MATTER_FACTOR_TO_NH3 = 2.17/1000
29
-
30
-
31
- def _emission(value: float):
32
- emission = _new_emission(TERM_ID, MODEL)
33
- emission['value'] = [value]
34
- emission['methodTier'] = TIER
35
- return emission
36
-
37
-
38
- def _run(product_value: list):
39
- value = sum(product_value)
40
- return [_emission(value * DRY_MATTER_FACTOR_TO_NH3)]
41
-
42
-
43
- def _should_run(cycle: dict):
44
- crop_residue_burnt_value = _get_crop_residue_burnt_value(cycle)
45
- has_crop_residue_burnt = len(crop_residue_burnt_value) > 0
46
-
47
- logRequirements(cycle, model=MODEL, term=TERM_ID,
48
- has_crop_residue_burnt=has_crop_residue_burnt)
49
-
50
- should_run = all([has_crop_residue_burnt])
51
- logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
52
- return should_run, crop_residue_burnt_value
53
-
54
-
55
- def run(cycle: dict):
56
- should_run, crop_residue_burnt_value = _should_run(cycle)
57
- return _run(crop_residue_burnt_value) if should_run else []
@@ -1,57 +0,0 @@
1
- from hestia_earth.schema import EmissionMethodTier
2
-
3
- from hestia_earth.models.log import logRequirements, logShouldRun
4
- from hestia_earth.models.utils.emission import _new_emission
5
- from .utils import _get_crop_residue_burnt_value
6
- from . import MODEL
7
-
8
- REQUIREMENTS = {
9
- "Cycle": {
10
- "or": {
11
- "products": [{
12
- "@type": "Product",
13
- "term.@id": ["aboveGroundCropResidueBurnt", "discardedCropBurnt"],
14
- "value": ""
15
- }],
16
- "completeness.cropResidue": "True"
17
- }
18
- }
19
- }
20
- RETURNS = {
21
- "Emission": [{
22
- "value": "",
23
- "methodTier": "tier 1"
24
- }]
25
- }
26
- TERM_ID = 'noxToAirCropResidueBurning'
27
- TIER = EmissionMethodTier.TIER_1.value
28
- DRY_MATTER_FACTOR_TO_NOX = 3.11/1000
29
-
30
-
31
- def _emission(value: float):
32
- emission = _new_emission(TERM_ID, MODEL)
33
- emission['value'] = [value]
34
- emission['methodTier'] = TIER
35
- return emission
36
-
37
-
38
- def _run(product_value: list):
39
- value = sum(product_value)
40
- return [_emission(value * DRY_MATTER_FACTOR_TO_NOX)]
41
-
42
-
43
- def _should_run(cycle: dict):
44
- crop_residue_burnt_value = _get_crop_residue_burnt_value(cycle)
45
- has_crop_residue_burnt = len(crop_residue_burnt_value) > 0
46
-
47
- logRequirements(cycle, model=MODEL, term=TERM_ID,
48
- has_crop_residue_burnt=has_crop_residue_burnt)
49
-
50
- should_run = all([has_crop_residue_burnt])
51
- logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
52
- return should_run, crop_residue_burnt_value
53
-
54
-
55
- def run(cycle: dict):
56
- should_run, crop_residue_burnt_value = _should_run(cycle)
57
- return _run(crop_residue_burnt_value) if should_run else []
@@ -1,15 +0,0 @@
1
- from hestia_earth.schema import TermTermType
2
- from hestia_earth.utils.model import find_term_match
3
- from hestia_earth.utils.tools import flatten
4
-
5
- from hestia_earth.models.utils.completeness import _is_term_type_complete
6
-
7
-
8
- def _get_crop_residue_burnt_value(cycle: dict):
9
- products = cycle.get('products', [])
10
- value = flatten([
11
- find_term_match(products, 'aboveGroundCropResidueBurnt').get('value', []),
12
- find_term_match(products, 'discardedCropBurnt').get('value', [])
13
- ])
14
- data_complete = _is_term_type_complete(cycle, TermTermType.CROPRESIDUE)
15
- return [0] if len(value) == 0 and data_complete else value