hestia-earth-models 0.73.7__py3-none-any.whl → 0.74.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.

Potentially problematic release.


This version of hestia-earth-models might be problematic. Click here for more details.

Files changed (99) hide show
  1. hestia_earth/models/aware/scarcityWeightedWaterUse.py +7 -6
  2. hestia_earth/models/aware2_0/__init__.py +14 -0
  3. hestia_earth/models/aware2_0/scarcityWeightedWaterUse.py +115 -0
  4. hestia_earth/models/config/Cycle.json +121 -29
  5. hestia_earth/models/config/ImpactAssessment.json +240 -200
  6. hestia_earth/models/config/__init__.py +26 -2
  7. hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +2 -2
  8. hestia_earth/models/cycle/animal/input/properties.py +6 -5
  9. hestia_earth/models/cycle/animal/milkYield.py +8 -3
  10. hestia_earth/models/cycle/utils.py +6 -6
  11. hestia_earth/models/dammgen2009/noxToAirExcreta.py +11 -9
  12. hestia_earth/models/data/ecoinventV3/__init__.py +8 -26
  13. hestia_earth/models/ecoalimV9/cycle.py +51 -45
  14. hestia_earth/models/ecoalimV9/impact_assessment.py +63 -45
  15. hestia_earth/models/ecoalimV9/utils.py +21 -15
  16. hestia_earth/models/ecoinventV3/__init__.py +8 -140
  17. hestia_earth/models/ecoinventV3/cycle.py +140 -0
  18. hestia_earth/models/ecoinventV3/utils.py +28 -1
  19. hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +8 -137
  20. hestia_earth/models/ecoinventV3AndEmberClimate/cycle.py +144 -0
  21. hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py +2 -2
  22. hestia_earth/models/emepEea2019/utils.py +2 -3
  23. hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +5 -7
  24. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +41 -43
  25. hestia_earth/models/geospatialDatabase/awareWaterBasinId.py +2 -2
  26. hestia_earth/models/geospatialDatabase/awareWaterBasinId_v1.py +45 -0
  27. hestia_earth/models/hestia/default_emissions.py +7 -7
  28. hestia_earth/models/hestia/default_resourceUse.py +7 -6
  29. hestia_earth/models/hestia/landCover.py +110 -12
  30. hestia_earth/models/hestia/seed_emissions.py +7 -3
  31. hestia_earth/models/hestia/utils.py +1 -0
  32. hestia_earth/models/hestia/waterSalinity.py +2 -3
  33. hestia_earth/models/impact_assessment/emissions.py +3 -5
  34. hestia_earth/models/ipcc2019/biocharOrganicCarbonPerHa.py +9 -3
  35. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +1 -5
  36. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +1 -5
  37. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +1 -33
  38. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +1 -5
  39. hestia_earth/models/ipcc2019/n2OToAirAquacultureSystemsIndirect.py +44 -0
  40. hestia_earth/models/ipcc2019/n2OToAirCropResidueBurningIndirect.py +43 -0
  41. hestia_earth/models/ipcc2019/n2OToAirCropResidueDecompositionIndirect.py +13 -70
  42. hestia_earth/models/ipcc2019/n2OToAirExcretaIndirect.py +13 -70
  43. hestia_earth/models/ipcc2019/n2OToAirFuelCombustionIndirect.py +43 -0
  44. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +13 -70
  45. hestia_earth/models/ipcc2019/n2OToAirNaturalVegetationBurningIndirect.py +43 -0
  46. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +13 -70
  47. hestia_earth/models/ipcc2019/n2OToAirOrganicSoilBurningIndirect.py +43 -0
  48. hestia_earth/models/ipcc2019/n2OToAirOrganicSoilCultivationIndirect.py +43 -0
  49. hestia_earth/models/ipcc2019/n2OToAir_indirect_emissions_utils.py +112 -0
  50. hestia_earth/models/ipcc2019/utils.py +0 -25
  51. hestia_earth/models/jarvisAndPain1994/n2ToAirExcreta.py +11 -9
  52. hestia_earth/models/linkedImpactAssessment/emissions.py +25 -16
  53. hestia_earth/models/linkedImpactAssessment/utils.py +5 -1
  54. hestia_earth/models/log.py +8 -3
  55. hestia_earth/models/mocking/search-results.json +1670 -1666
  56. hestia_earth/models/utils/__init__.py +3 -0
  57. hestia_earth/models/utils/background_emissions.py +121 -14
  58. hestia_earth/models/utils/blank_node.py +1 -11
  59. hestia_earth/models/utils/emission.py +18 -8
  60. hestia_earth/models/utils/feedipedia.py +2 -2
  61. hestia_earth/models/utils/impact_assessment.py +4 -6
  62. hestia_earth/models/utils/indicator.py +8 -1
  63. hestia_earth/models/utils/lookup.py +30 -18
  64. hestia_earth/models/utils/productivity.py +1 -1
  65. hestia_earth/models/version.py +1 -1
  66. hestia_earth/orchestrator/log.py +8 -3
  67. hestia_earth/orchestrator/strategies/merge/merge_list.py +41 -54
  68. {hestia_earth_models-0.73.7.dist-info → hestia_earth_models-0.74.0.dist-info}/METADATA +3 -3
  69. {hestia_earth_models-0.73.7.dist-info → hestia_earth_models-0.74.0.dist-info}/RECORD +99 -75
  70. tests/models/aware2_0/__init__.py +0 -0
  71. tests/models/aware2_0/test_scarcityWeightedWaterUse.py +58 -0
  72. tests/models/dammgen2009/test_noxToAirExcreta.py +2 -2
  73. tests/models/ecoalimV9/test_cycle.py +1 -1
  74. tests/models/ecoalimV9/test_impact_assessment.py +1 -1
  75. tests/models/ecoinventV3/__init__.py +0 -0
  76. tests/models/{test_ecoinventV3.py → ecoinventV3/test_cycle.py} +5 -5
  77. tests/models/ecoinventV3AndEmberClimate/__init__.py +0 -0
  78. tests/models/{test_ecoinventV3AndEmberClimate.py → ecoinventV3AndEmberClimate/test_cycle.py} +6 -4
  79. tests/models/environmentalFootprintV3_1/test_environmentalFootprintSingleOverallScore.py +2 -2
  80. tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +18 -27
  81. tests/models/hestia/test_landCover.py +16 -6
  82. tests/models/ipcc2019/test_biocharOrganicCarbonPerHa.py +2 -1
  83. tests/models/ipcc2019/test_n2OToAirAquacultureSystemsIndirect.py +45 -0
  84. tests/models/ipcc2019/test_n2OToAirCropResidueBurningIndirect.py +45 -0
  85. tests/models/ipcc2019/test_n2OToAirCropResidueDecompositionIndirect.py +6 -32
  86. tests/models/ipcc2019/test_n2OToAirExcretaIndirect.py +6 -32
  87. tests/models/ipcc2019/test_n2OToAirFuelCombustionIndirect.py +45 -0
  88. tests/models/ipcc2019/test_n2OToAirInorganicFertiliserIndirect.py +6 -32
  89. tests/models/ipcc2019/test_n2OToAirNaturalVegetationBurningIndirect.py +45 -0
  90. tests/models/ipcc2019/test_n2OToAirOrganicFertiliserIndirect.py +6 -32
  91. tests/models/ipcc2019/test_n2OToAirOrganicSoilBurningIndirect.py +45 -0
  92. tests/models/ipcc2019/test_n2OToAirOrganicSoilCultivationIndirect.py +45 -0
  93. tests/models/ipcc2019/test_n2OToAir_indirect_emissions_utils.py +19 -0
  94. tests/models/site/pre_checks/test_cache_geospatialDatabase.py +4 -4
  95. tests/models/test_config.py +53 -7
  96. tests/models/utils/test_background_emissions.py +13 -0
  97. {hestia_earth_models-0.73.7.dist-info → hestia_earth_models-0.74.0.dist-info}/LICENSE +0 -0
  98. {hestia_earth_models-0.73.7.dist-info → hestia_earth_models-0.74.0.dist-info}/WHEEL +0 -0
  99. {hestia_earth_models-0.73.7.dist-info → hestia_earth_models-0.74.0.dist-info}/top_level.txt +0 -0
@@ -69,9 +69,7 @@ def _emission(
69
69
  min: list[float] = None,
70
70
  max: list[float] = None,
71
71
  statsDefinition: str = None,
72
- observations: list[int] = None,
73
- start_date: str,
74
- end_date: str
72
+ observations: list[int] = None
75
73
  ) -> dict:
76
74
  """
77
75
  Create an emission node based on the provided value and method tier.
@@ -99,8 +97,6 @@ def _emission(
99
97
  "max": max,
100
98
  "statsDefinition": statsDefinition,
101
99
  "observations": observations,
102
- "startDate": start_date,
103
- "endDate": end_date,
104
100
  "methodTier": method_tier.value,
105
101
  "depth": _DEPTH_LOWER
106
102
  }
@@ -2,7 +2,7 @@
2
2
  Utilities for calculating CO2 emissions based on changes in carbon stocks (e.g., `organicCarbonPerHa`,
3
3
  `aboveGroundBiomass` and `belowGroundBiomass`).
4
4
  """
5
- from datetime import datetime, timedelta
5
+ from datetime import datetime
6
6
  from enum import Enum
7
7
  from functools import reduce
8
8
  from itertools import product
@@ -1506,8 +1506,6 @@ def create_run_function(
1506
1506
  new_emission_func(
1507
1507
  term_id=emission_term_id,
1508
1508
  method_tier=_get_emission_method(total_emission),
1509
- start_date=_get_emission_start_date(total_emission, cycle_start_date),
1510
- end_date=_get_emission_end_date(total_emission, cycle_end_date),
1511
1509
  **calc_descriptive_stats(
1512
1510
  total_emission.value,
1513
1511
  EmissionStatsDefinition.SIMULATED,
@@ -1532,33 +1530,3 @@ def get_zero_emission(year):
1532
1530
  def _get_emission_method(emission: CarbonStockChangeEmission):
1533
1531
  method = emission.method
1534
1532
  return method if isinstance(method, EmissionMethodTier) else EmissionMethodTier.TIER_1
1535
-
1536
-
1537
- def _get_emission_start_date(emission: CarbonStockChangeEmission, cycle_start_date: str) -> str:
1538
- cycle_datetime = safe_parse_date(_gapfill_datestr(cycle_start_date))
1539
- emission_datetime = safe_parse_date(emission.start_date)
1540
-
1541
- should_run = (
1542
- cycle_datetime and emission_datetime
1543
- and cycle_datetime < emission_datetime # If the cycle starts before the emission, add a `startDate`
1544
- )
1545
-
1546
- return (
1547
- (emission_datetime + timedelta(seconds=1)).strftime(DatestrFormat.YEAR_MONTH_DAY.value) if should_run
1548
- else None
1549
- )
1550
-
1551
-
1552
- def _get_emission_end_date(emission: CarbonStockChangeEmission, cycle_end_date: str) -> str:
1553
- cycle_datetime = safe_parse_date(_gapfill_datestr(cycle_end_date, DatestrGapfillMode.END))
1554
- emission_datetime = safe_parse_date(emission.end_date)
1555
-
1556
- should_run = (
1557
- cycle_datetime and emission_datetime
1558
- and cycle_datetime > emission_datetime # If the cycle ends after the emission, add an `endDate`
1559
- )
1560
-
1561
- return (
1562
- emission_datetime.strftime(DatestrFormat.YEAR_MONTH_DAY.value) if should_run
1563
- else None
1564
- )
@@ -69,9 +69,7 @@ def _emission(
69
69
  min: list[float] = None,
70
70
  max: list[float] = None,
71
71
  statsDefinition: str = None,
72
- observations: list[int] = None,
73
- start_date: str,
74
- end_date: str
72
+ observations: list[int] = None
75
73
  ) -> dict:
76
74
  """
77
75
  Create an emission node based on the provided value and method tier.
@@ -99,8 +97,6 @@ def _emission(
99
97
  "max": max,
100
98
  "statsDefinition": statsDefinition,
101
99
  "observations": observations,
102
- "startDate": start_date,
103
- "endDate": end_date,
104
100
  "methodTier": method_tier.value,
105
101
  "depth": _DEPTH_LOWER
106
102
  }
@@ -0,0 +1,44 @@
1
+ from hestia_earth.schema import EmissionMethodTier
2
+
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
4
+
5
+ REQUIREMENTS = {
6
+ "Cycle": {
7
+ "completeness.cropResidue": "True",
8
+ "emissions": [
9
+ {"@type": "Emission", "value": "", "term.@id": "nh3ToSurfaceWaterAquacultureSystems"},
10
+ {"@type": "Emission", "value": "", "term.@id": "nh3ToAirAquacultureSystems"},
11
+ {"@type": "Emission", "value": "", "term.@id": "noxToAirAquacultureSystems"}
12
+ ],
13
+ "optional": {
14
+ "site": {
15
+ "@type": "Site",
16
+ "measurements": [
17
+ {"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
18
+ ]
19
+ }
20
+ }
21
+ }
22
+ }
23
+ LOOKUPS = {
24
+ "emission": [
25
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
26
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
27
+ ]
28
+ }
29
+ RETURNS = {
30
+ "Emission": [{
31
+ "value": "",
32
+ "methodTier": "tier 1"
33
+ }]
34
+ }
35
+ TERM_ID = 'n2OToAirAquacultureSystemsIndirect'
36
+ TIER = EmissionMethodTier.TIER_1.value
37
+ _NO3_TERM_ID = 'nh3ToSurfaceWaterAquacultureSystems'
38
+ _NH3_TERM_ID = 'nh3ToAirAquacultureSystems'
39
+ _NOX_TERM_ID = 'noxToAirAquacultureSystems'
40
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
41
+
42
+
43
+ def run(cycle: dict):
44
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)
@@ -0,0 +1,43 @@
1
+ from hestia_earth.schema import EmissionMethodTier
2
+
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
4
+
5
+ REQUIREMENTS = {
6
+ "Cycle": {
7
+ "completeness.cropResidue": "True",
8
+ "emissions": [
9
+ {"@type": "Emission", "value": "", "term.@id": "nh3ToAirCropResidueBurning"},
10
+ {"@type": "Emission", "value": "", "term.@id": "noxToAirCropResidueBurning"}
11
+ ],
12
+ "optional": {
13
+ "site": {
14
+ "@type": "Site",
15
+ "measurements": [
16
+ {"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
17
+ ]
18
+ }
19
+ }
20
+ }
21
+ }
22
+ LOOKUPS = {
23
+ "emission": [
24
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
25
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
26
+ ]
27
+ }
28
+ RETURNS = {
29
+ "Emission": [{
30
+ "value": "",
31
+ "methodTier": "tier 1"
32
+ }]
33
+ }
34
+ TERM_ID = 'n2OToAirCropResidueBurningIndirect'
35
+ TIER = EmissionMethodTier.TIER_1.value
36
+ _NO3_TERM_ID = None
37
+ _NH3_TERM_ID = 'nh3ToAirCropResidueBurning'
38
+ _NOX_TERM_ID = 'noxToAirCropResidueBurning'
39
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
40
+
41
+
42
+ def run(cycle: dict):
43
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)
@@ -1,16 +1,9 @@
1
- from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, TermTermType
1
+ from hestia_earth.schema import EmissionMethodTier
2
2
 
3
- from hestia_earth.models.log import debugValues, logRequirements, logShouldRun, log_as_table
4
- from hestia_earth.models.utils.constant import Units, get_atomic_conversion
5
- from hestia_earth.models.utils.completeness import _is_term_type_complete
6
- from hestia_earth.models.utils.emission import _new_emission, get_nh3_no3_nox_to_n
7
- from hestia_earth.models.utils.cycle import get_ecoClimateZone
8
- from .utils import ecoClimate_factors, EF4_FACTORS, EF5_FACTORS
9
- from . import MODEL
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
10
4
 
11
5
  REQUIREMENTS = {
12
6
  "Cycle": {
13
- "completeness.cropResidue": "True",
14
7
  "emissions": [
15
8
  {"@type": "Emission", "value": "", "term.@id": "no3ToGroundwaterCropResidueDecomposition"},
16
9
  {"@type": "Emission", "value": "", "term.@id": "nh3ToAirCropResidueDecomposition"},
@@ -26,6 +19,12 @@ REQUIREMENTS = {
26
19
  }
27
20
  }
28
21
  }
22
+ LOOKUPS = {
23
+ "emission": [
24
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
25
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
26
+ ]
27
+ }
29
28
  RETURNS = {
30
29
  "Emission": [{
31
30
  "value": "",
@@ -34,67 +33,11 @@ RETURNS = {
34
33
  }
35
34
  TERM_ID = 'n2OToAirCropResidueDecompositionIndirect'
36
35
  TIER = EmissionMethodTier.TIER_1.value
37
- NO3_TERM_ID = 'no3ToGroundwaterCropResidueDecomposition'
38
- NH3_TERM_ID = 'nh3ToAirCropResidueDecomposition'
39
- NOX_TERM_ID = 'noxToAirCropResidueDecomposition'
40
-
41
-
42
- def _emission(value: float, min: float, max: float, aggregated: bool = False):
43
- emission = _new_emission(TERM_ID, MODEL)
44
- emission['value'] = [value]
45
- emission['min'] = [min]
46
- emission['max'] = [max]
47
- emission['methodTier'] = TIER
48
- emission['statsDefinition'] = EmissionStatsDefinition.MODELLED.value
49
- emission['methodModelDescription'] = 'Aggregated version' if aggregated else 'Disaggregated version'
50
- return emission
51
-
52
-
53
- def _run(cycle: dict, no3: float, nh3: float, nox: float):
54
- ecoClimateZone = get_ecoClimateZone(cycle)
55
-
56
- ef4, aggregated = ecoClimate_factors(EF4_FACTORS, ecoClimateZone=ecoClimateZone)
57
- ef5 = EF5_FACTORS.get('default')
58
-
59
- debugValues(cycle, model=MODEL, term=TERM_ID,
60
- ecoClimateZone=ecoClimateZone,
61
- ef4_factors_used=log_as_table(ef4),
62
- ef5_factors_used=log_as_table(ef5),
63
- aggregated=aggregated)
64
-
65
- value = sum([
66
- no3 * ef5['value'],
67
- nh3 * ef4['value'],
68
- nox * ef4['value']
69
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
70
- min = sum([
71
- no3 * ef5['min'],
72
- nh3 * ef4['min'],
73
- nox * ef4['min']
74
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
75
- max = sum([
76
- no3 * ef5['max'],
77
- nh3 * ef4['max'],
78
- nox * ef4['max']
79
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
80
- return [_emission(value, min, max, aggregated=aggregated)]
81
-
82
-
83
- def _should_run(cycle: dict):
84
- nh3_n, no3_n, nox_n = get_nh3_no3_nox_to_n(cycle, NH3_TERM_ID, NO3_TERM_ID, NOX_TERM_ID)
85
- term_type_complete = _is_term_type_complete(cycle, TermTermType.CROPRESIDUE)
86
-
87
- logRequirements(cycle, model=MODEL, term=TERM_ID,
88
- no3_n=no3_n,
89
- nh3_n=nh3_n,
90
- nox_n=nox_n,
91
- term_type_cropResidue_complete=term_type_complete)
92
-
93
- should_run = all([no3_n is not None, nh3_n is not None, nox_n is not None, term_type_complete])
94
- logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
95
- return should_run, no3_n, nh3_n, nox_n
36
+ _NO3_TERM_ID = 'no3ToGroundwaterCropResidueDecomposition'
37
+ _NH3_TERM_ID = 'nh3ToAirCropResidueDecomposition'
38
+ _NOX_TERM_ID = 'noxToAirCropResidueDecomposition'
39
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
96
40
 
97
41
 
98
42
  def run(cycle: dict):
99
- should_run, no3, nh3, nox = _should_run(cycle)
100
- return _run(cycle, no3, nh3, nox) if should_run else []
43
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)
@@ -1,16 +1,9 @@
1
- from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, TermTermType
1
+ from hestia_earth.schema import EmissionMethodTier
2
2
 
3
- from hestia_earth.models.log import debugValues, logRequirements, logShouldRun, log_as_table
4
- from hestia_earth.models.utils.constant import Units, get_atomic_conversion
5
- from hestia_earth.models.utils.completeness import _is_term_type_complete
6
- from hestia_earth.models.utils.emission import _new_emission, get_nh3_no3_nox_to_n
7
- from hestia_earth.models.utils.cycle import get_ecoClimateZone
8
- from .utils import ecoClimate_factors, EF4_FACTORS, EF5_FACTORS
9
- from . import MODEL
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
10
4
 
11
5
  REQUIREMENTS = {
12
6
  "Cycle": {
13
- "completeness.excreta": "True",
14
7
  "emissions": [
15
8
  {"@type": "Emission", "value": "", "term.@id": "no3ToGroundwaterExcreta"},
16
9
  {"@type": "Emission", "value": "", "term.@id": "nh3ToAirExcreta"},
@@ -26,6 +19,12 @@ REQUIREMENTS = {
26
19
  }
27
20
  }
28
21
  }
22
+ LOOKUPS = {
23
+ "emission": [
24
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
25
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
26
+ ]
27
+ }
29
28
  RETURNS = {
30
29
  "Emission": [{
31
30
  "value": "",
@@ -34,67 +33,11 @@ RETURNS = {
34
33
  }
35
34
  TERM_ID = 'n2OToAirExcretaIndirect'
36
35
  TIER = EmissionMethodTier.TIER_1.value
37
- NO3_TERM_ID = 'no3ToGroundwaterExcreta'
38
- NH3_TERM_ID = 'nh3ToAirExcreta'
39
- NOX_TERM_ID = 'noxToAirExcreta'
40
-
41
-
42
- def _emission(value: float, min: float, max: float, aggregated: bool = False):
43
- emission = _new_emission(TERM_ID, MODEL)
44
- emission['value'] = [value]
45
- emission['min'] = [min]
46
- emission['max'] = [max]
47
- emission['methodTier'] = TIER
48
- emission['statsDefinition'] = EmissionStatsDefinition.MODELLED.value
49
- emission['methodModelDescription'] = 'Aggregated version' if aggregated else 'Disaggregated version'
50
- return emission
51
-
52
-
53
- def _run(cycle: dict, no3: float, nh3: float, nox: float):
54
- ecoClimateZone = get_ecoClimateZone(cycle)
55
-
56
- ef4, aggregated = ecoClimate_factors(EF4_FACTORS, ecoClimateZone=ecoClimateZone)
57
- ef5 = EF5_FACTORS.get('default')
58
-
59
- debugValues(cycle, model=MODEL, term=TERM_ID,
60
- ecoClimateZone=ecoClimateZone,
61
- ef4_factors_used=log_as_table(ef4),
62
- ef5_factors_used=log_as_table(ef5),
63
- aggregated=aggregated)
64
-
65
- value = sum([
66
- no3 * ef5['value'],
67
- nh3 * ef4['value'],
68
- nox * ef4['value']
69
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
70
- min = sum([
71
- no3 * ef5['min'],
72
- nh3 * ef4['min'],
73
- nox * ef4['min']
74
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
75
- max = sum([
76
- no3 * ef5['max'],
77
- nh3 * ef4['max'],
78
- nox * ef4['max']
79
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
80
- return [_emission(value, min, max, aggregated=aggregated)]
81
-
82
-
83
- def _should_run(cycle: dict):
84
- nh3_n, no3_n, nox_n = get_nh3_no3_nox_to_n(cycle, NH3_TERM_ID, NO3_TERM_ID, NOX_TERM_ID)
85
- term_type_complete = _is_term_type_complete(cycle, TermTermType.EXCRETA)
86
-
87
- logRequirements(cycle, model=MODEL, term=TERM_ID,
88
- no3_n=no3_n,
89
- nh3_n=nh3_n,
90
- nox_n=nox_n,
91
- term_type_excreta_complete=term_type_complete)
92
-
93
- should_run = all([no3_n is not None, nh3_n is not None, nox_n is not None, term_type_complete])
94
- logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
95
- return should_run, no3_n, nh3_n, nox_n
36
+ _NO3_TERM_ID = 'no3ToGroundwaterExcreta'
37
+ _NH3_TERM_ID = 'nh3ToAirExcreta'
38
+ _NOX_TERM_ID = 'noxToAirExcreta'
39
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
96
40
 
97
41
 
98
42
  def run(cycle: dict):
99
- should_run, no3, nh3, nox = _should_run(cycle)
100
- return _run(cycle, no3, nh3, nox) if should_run else []
43
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)
@@ -0,0 +1,43 @@
1
+ from hestia_earth.schema import EmissionMethodTier
2
+
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
4
+
5
+ REQUIREMENTS = {
6
+ "Cycle": {
7
+ "completeness.electricityFuel": "True",
8
+ "emissions": [
9
+ {"@type": "Emission", "value": "", "term.@id": "nh3ToAirFuelCombustion"},
10
+ {"@type": "Emission", "value": "", "term.@id": "noxToAirFuelCombustion"}
11
+ ],
12
+ "optional": {
13
+ "site": {
14
+ "@type": "Site",
15
+ "measurements": [
16
+ {"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
17
+ ]
18
+ }
19
+ }
20
+ }
21
+ }
22
+ LOOKUPS = {
23
+ "emission": [
24
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
25
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
26
+ ]
27
+ }
28
+ RETURNS = {
29
+ "Emission": [{
30
+ "value": "",
31
+ "methodTier": "tier 1"
32
+ }]
33
+ }
34
+ TERM_ID = 'n2OToAirFuelCombustionIndirect'
35
+ TIER = EmissionMethodTier.TIER_1.value
36
+ _NO3_TERM_ID = None
37
+ _NH3_TERM_ID = 'nh3ToAirFuelCombustion'
38
+ _NOX_TERM_ID = 'noxToAirFuelCombustion'
39
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
40
+
41
+
42
+ def run(cycle: dict):
43
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)
@@ -1,16 +1,9 @@
1
- from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition
1
+ from hestia_earth.schema import EmissionMethodTier
2
2
 
3
- from hestia_earth.models.log import debugValues, logRequirements, logShouldRun, log_as_table
4
- from hestia_earth.models.utils.constant import Units, get_atomic_conversion
5
- from hestia_earth.models.utils.completeness import _is_term_type_complete
6
- from hestia_earth.models.utils.emission import _new_emission, get_nh3_no3_nox_to_n
7
- from hestia_earth.models.utils.cycle import get_ecoClimateZone
8
- from .utils import ecoClimate_factors, EF4_FACTORS, EF5_FACTORS
9
- from . import MODEL
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
10
4
 
11
5
  REQUIREMENTS = {
12
6
  "Cycle": {
13
- "completeness.fertiliser": "True",
14
7
  "emissions": [
15
8
  {"@type": "Emission", "value": "", "term.@id": "no3ToGroundwaterInorganicFertiliser"},
16
9
  {"@type": "Emission", "value": "", "term.@id": "nh3ToAirInorganicFertiliser"},
@@ -26,6 +19,12 @@ REQUIREMENTS = {
26
19
  }
27
20
  }
28
21
  }
22
+ LOOKUPS = {
23
+ "emission": [
24
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
25
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
26
+ ]
27
+ }
29
28
  RETURNS = {
30
29
  "Emission": [{
31
30
  "value": "",
@@ -34,67 +33,11 @@ RETURNS = {
34
33
  }
35
34
  TERM_ID = 'n2OToAirInorganicFertiliserIndirect'
36
35
  TIER = EmissionMethodTier.TIER_1.value
37
- NO3_TERM_ID = 'no3ToGroundwaterInorganicFertiliser'
38
- NH3_TERM_ID = 'nh3ToAirInorganicFertiliser'
39
- NOX_TERM_ID = 'noxToAirInorganicFertiliser'
40
-
41
-
42
- def _emission(value: float, min: float, max: float, aggregated: bool = False):
43
- emission = _new_emission(TERM_ID, MODEL)
44
- emission['value'] = [value]
45
- emission['min'] = [min]
46
- emission['max'] = [max]
47
- emission['methodTier'] = TIER
48
- emission['statsDefinition'] = EmissionStatsDefinition.MODELLED.value
49
- emission['methodModelDescription'] = 'Aggregated version' if aggregated else 'Disaggregated version'
50
- return emission
51
-
52
-
53
- def _run(cycle: dict, no3: float, nh3: float, nox: float):
54
- ecoClimateZone = get_ecoClimateZone(cycle)
55
-
56
- ef4, aggregated = ecoClimate_factors(EF4_FACTORS, ecoClimateZone=ecoClimateZone)
57
- ef5 = EF5_FACTORS.get('default')
58
-
59
- debugValues(cycle, model=MODEL, term=TERM_ID,
60
- ecoClimateZone=ecoClimateZone,
61
- ef4_factors_used=log_as_table(ef4),
62
- ef5_factors_used=log_as_table(ef5),
63
- aggregated=aggregated)
64
-
65
- value = sum([
66
- no3 * ef5['value'],
67
- nh3 * ef4['value'],
68
- nox * ef4['value']
69
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
70
- min = sum([
71
- no3 * ef5['min'],
72
- nh3 * ef4['min'],
73
- nox * ef4['min']
74
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
75
- max = sum([
76
- no3 * ef5['max'],
77
- nh3 * ef4['max'],
78
- nox * ef4['max']
79
- ]) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
80
- return [_emission(value, min, max, aggregated=aggregated)]
81
-
82
-
83
- def _should_run(cycle: dict):
84
- nh3_n, no3_n, nox_n = get_nh3_no3_nox_to_n(cycle, NH3_TERM_ID, NO3_TERM_ID, NOX_TERM_ID)
85
- term_type_complete = _is_term_type_complete(cycle, 'fertiliser')
86
-
87
- logRequirements(cycle, model=MODEL, term=TERM_ID,
88
- no3_n=no3_n,
89
- nh3_n=nh3_n,
90
- nox_n=nox_n,
91
- term_type_fertiliser_complete=term_type_complete)
92
-
93
- should_run = all([no3_n is not None, nh3_n is not None, nox_n is not None, term_type_complete])
94
- logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
95
- return should_run, no3_n, nh3_n, nox_n
36
+ _NO3_TERM_ID = 'no3ToGroundwaterInorganicFertiliser'
37
+ _NH3_TERM_ID = 'nh3ToAirInorganicFertiliser'
38
+ _NOX_TERM_ID = 'noxToAirInorganicFertiliser'
39
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
96
40
 
97
41
 
98
42
  def run(cycle: dict):
99
- should_run, no3, nh3, nox = _should_run(cycle)
100
- return _run(cycle, no3, nh3, nox) if should_run else []
43
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)
@@ -0,0 +1,43 @@
1
+ from hestia_earth.schema import EmissionMethodTier
2
+
3
+ from .n2OToAir_indirect_emissions_utils import run as run_emission
4
+
5
+ REQUIREMENTS = {
6
+ "Cycle": {
7
+ "completeness.cropResidue": "True",
8
+ "emissions": [
9
+ {"@type": "Emission", "value": "", "term.@id": "nh3ToAirNaturalVegetationBurning"},
10
+ {"@type": "Emission", "value": "", "term.@id": "noxToAirNaturalVegetationBurning"}
11
+ ],
12
+ "optional": {
13
+ "site": {
14
+ "@type": "Site",
15
+ "measurements": [
16
+ {"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
17
+ ]
18
+ }
19
+ }
20
+ }
21
+ }
22
+ LOOKUPS = {
23
+ "emission": [
24
+ "IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
25
+ "IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
26
+ ]
27
+ }
28
+ RETURNS = {
29
+ "Emission": [{
30
+ "value": "",
31
+ "methodTier": "tier 1"
32
+ }]
33
+ }
34
+ TERM_ID = 'n2OToAirNaturalVegetationBurningIndirect'
35
+ TIER = EmissionMethodTier.TIER_1.value
36
+ _NO3_TERM_ID = None
37
+ _NH3_TERM_ID = 'nh3ToAirNaturalVegetationBurning'
38
+ _NOX_TERM_ID = 'noxToAirNaturalVegetationBurning'
39
+ _EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
40
+
41
+
42
+ def run(cycle: dict):
43
+ return run_emission(TERM_ID, _EMISSION_IDS, cycle)