hestia-earth-models 0.64.4__py3-none-any.whl → 0.64.5__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 (62) hide show
  1. hestia_earth/models/blonkConsultants2016/ch4ToAirNaturalVegetationBurning.py +5 -9
  2. hestia_earth/models/blonkConsultants2016/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +5 -9
  3. hestia_earth/models/blonkConsultants2016/n2OToAirNaturalVegetationBurningDirect.py +6 -13
  4. hestia_earth/models/cycle/animal/input/properties.py +6 -0
  5. hestia_earth/models/cycle/completeness/soilAmendment.py +3 -2
  6. hestia_earth/models/cycle/concentrateFeed.py +10 -4
  7. hestia_earth/models/cycle/input/properties.py +6 -0
  8. hestia_earth/models/cycle/liveAnimal.py +2 -2
  9. hestia_earth/models/cycle/milkYield.py +3 -3
  10. hestia_earth/models/cycle/otherSitesArea.py +59 -0
  11. hestia_earth/models/cycle/otherSitesUnusedDuration.py +9 -8
  12. hestia_earth/models/cycle/pastureSystem.py +3 -2
  13. hestia_earth/models/cycle/product/properties.py +6 -0
  14. hestia_earth/models/cycle/siteArea.py +83 -0
  15. hestia_earth/models/cycle/stockingDensityAnimalHousingAverage.py +28 -16
  16. hestia_earth/models/cycle/utils.py +1 -1
  17. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +128 -0
  18. hestia_earth/models/environmentalFootprintV3/utils.py +17 -0
  19. hestia_earth/models/ipcc2006/co2ToAirOrganicSoilCultivation.py +17 -6
  20. hestia_earth/models/ipcc2006/n2OToAirOrganicSoilCultivationDirect.py +17 -6
  21. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +904 -0
  22. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +70 -618
  23. hestia_earth/models/mocking/search-results.json +395 -323
  24. hestia_earth/models/pooreNemecek2018/saplings.py +10 -7
  25. hestia_earth/models/site/management.py +18 -14
  26. hestia_earth/models/utils/__init__.py +38 -0
  27. hestia_earth/models/utils/array_builders.py +63 -52
  28. hestia_earth/models/utils/blank_node.py +137 -82
  29. hestia_earth/models/utils/descriptive_stats.py +3 -239
  30. hestia_earth/models/utils/feedipedia.py +15 -2
  31. hestia_earth/models/utils/landCover.py +9 -0
  32. hestia_earth/models/utils/lookup.py +13 -2
  33. hestia_earth/models/utils/measurement.py +3 -28
  34. hestia_earth/models/utils/stats.py +429 -0
  35. hestia_earth/models/utils/term.py +15 -3
  36. hestia_earth/models/utils/time_series.py +90 -0
  37. hestia_earth/models/version.py +1 -1
  38. {hestia_earth_models-0.64.4.dist-info → hestia_earth_models-0.64.5.dist-info}/METADATA +1 -1
  39. {hestia_earth_models-0.64.4.dist-info → hestia_earth_models-0.64.5.dist-info}/RECORD +62 -48
  40. tests/models/blonkConsultants2016/test_ch4ToAirNaturalVegetationBurning.py +2 -2
  41. tests/models/blonkConsultants2016/test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +2 -2
  42. tests/models/blonkConsultants2016/test_n2OToAirNaturalVegetationBurningDirect.py +2 -2
  43. tests/models/cycle/completeness/test_soilAmendment.py +1 -1
  44. tests/models/cycle/test_liveAnimal.py +1 -1
  45. tests/models/cycle/test_milkYield.py +1 -1
  46. tests/models/cycle/test_otherSitesArea.py +68 -0
  47. tests/models/cycle/test_siteArea.py +51 -0
  48. tests/models/cycle/test_stockingDensityAnimalHousingAverage.py +2 -2
  49. tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +136 -0
  50. tests/models/ipcc2019/test_co2ToAirCarbonStockChange_utils.py +50 -0
  51. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +1 -39
  52. tests/models/pooreNemecek2018/test_saplings.py +1 -1
  53. tests/models/site/test_management.py +3 -153
  54. tests/models/utils/test_array_builders.py +67 -6
  55. tests/models/utils/test_blank_node.py +191 -7
  56. tests/models/utils/test_descriptive_stats.py +2 -86
  57. tests/models/utils/test_measurement.py +1 -22
  58. tests/models/utils/test_stats.py +186 -0
  59. tests/models/utils/test_time_series.py +88 -0
  60. {hestia_earth_models-0.64.4.dist-info → hestia_earth_models-0.64.5.dist-info}/LICENSE +0 -0
  61. {hestia_earth_models-0.64.4.dist-info → hestia_earth_models-0.64.5.dist-info}/WHEEL +0 -0
  62. {hestia_earth_models-0.64.4.dist-info → hestia_earth_models-0.64.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,128 @@
1
+ from hestia_earth.schema import TermTermType
2
+ from hestia_earth.utils.lookup import download_lookup
3
+ from hestia_earth.utils.tools import list_sum, non_empty_list
4
+
5
+ from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
6
+ from hestia_earth.models.utils import hectar_to_square_meter, days_to_years
7
+ from hestia_earth.models.utils.blank_node import most_relevant_blank_node_by_type
8
+ from hestia_earth.models.utils.indicator import _new_indicator
9
+ from hestia_earth.models.utils.landCover import get_pef_grouping
10
+ from hestia_earth.models.utils.lookup import fallback_country
11
+ from . import MODEL
12
+ from .utils import get_coefficient_factor
13
+
14
+ REQUIREMENTS = {
15
+ "Cycle": {
16
+ "siteDuration": "> 0",
17
+ "siteArea": "> 0",
18
+ "site": {"siteType": "",
19
+ "@type": "Site",
20
+ "management": [{"@type": "Management", "value": "", "term.termType": "landCover"}],
21
+ "country": {"@type": "Term", "termType": "region"}
22
+ },
23
+ "optional": {
24
+ "otherSitesDuration": "> 0",
25
+ "otherSitesArea": "> 0",
26
+ "otherSites": [
27
+ {
28
+ "siteType": "",
29
+ "@type": "Site",
30
+ "management": [{"@type": "Management", "value": "", "term.termType": "landCover"}],
31
+ "country": {"@type": "Term", "termType": "region"}
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ }
37
+ LOOKUPS = {
38
+ "@doc": "Performs lookup on landCover.csv for column headers and region-pefTermGrouping-landOccupation.csv for CFs",
39
+ "region-pefTermGrouping-landOccupation": "",
40
+ "landCover": [
41
+ "pefTermGrouping"
42
+ ]
43
+ }
44
+
45
+ RETURNS = {
46
+ "Indicator": {
47
+ "value": ""
48
+ }
49
+ }
50
+ TERM_ID = 'soilQualityIndexLandOccupation'
51
+ LOOKUP = f"{list(LOOKUPS.keys())[1]}.csv"
52
+
53
+
54
+ def _indicator(value: float):
55
+ indicator = _new_indicator(TERM_ID, MODEL)
56
+ indicator['value'] = value
57
+ return indicator
58
+
59
+
60
+ def _run(sites: list):
61
+ values = [site['coeff'] * hectar_to_square_meter(site['area']) * days_to_years(site['duration']) for site in sites]
62
+ return _indicator(list_sum(values)) if values else None
63
+
64
+
65
+ def _should_run(cycle: dict):
66
+ end_date = cycle.get('endDate')
67
+
68
+ has_site = bool(cycle.get('site', False))
69
+ has_other_sites = bool(cycle.get('otherSites', []))
70
+
71
+ all_sites = non_empty_list([cycle.get('site')] + cycle.get('otherSites', []))
72
+ site_areas = [cycle.get('siteArea')] + cycle.get('otherSitesArea', [])
73
+ site_durations = [cycle.get('siteDuration')] + cycle.get('otherSitesDuration', [])
74
+
75
+ sites = [
76
+ {
77
+ 'site-type': site.get('siteType'),
78
+ 'country-id': site.get('country', {}).get('@id'),
79
+ 'area': site_areas[index],
80
+ 'duration': site_durations[index],
81
+ 'landCover-id': (most_relevant_blank_node_by_type(
82
+ site.get("management", []),
83
+ term_type=TermTermType.LANDCOVER.value,
84
+ date=end_date
85
+ ) or {}).get('term', {}).get('@id'),
86
+ }
87
+ for index, site in enumerate(all_sites)
88
+ ]
89
+
90
+ sites = [
91
+ site for site in sites
92
+ if all([
93
+ site.get('area', 0) > 0,
94
+ site.get('duration', 0) > 0,
95
+ site.get('landCover-id'),
96
+ ])
97
+ ]
98
+
99
+ sites = [
100
+ site |
101
+ {
102
+ 'coeff': get_coefficient_factor(
103
+ LOOKUP,
104
+ fallback_country(site.get('country-id'), [download_lookup(LOOKUP)]),
105
+ get_pef_grouping(site.get('landCover-id')),
106
+ term_id=TERM_ID
107
+ )
108
+ } for site in sites
109
+ ]
110
+ valid_sites = [site for site in sites if site.get('coeff') is not None]
111
+
112
+ has_valid_sites = bool(valid_sites)
113
+
114
+ logRequirements(cycle, model=MODEL, term=TERM_ID,
115
+ has_valid_sites=has_valid_sites,
116
+ has_site=has_site,
117
+ has_other_sites=has_other_sites,
118
+ valid_sites=log_as_table(valid_sites),
119
+ )
120
+
121
+ should_run = all([has_valid_sites])
122
+ logShouldRun(cycle, MODEL, TERM_ID, should_run)
123
+ return should_run, valid_sites
124
+
125
+
126
+ def run(cycle: dict):
127
+ should_run, sites = _should_run(cycle)
128
+ return _run(sites) if should_run else None
@@ -0,0 +1,17 @@
1
+ from typing import Optional
2
+ from hestia_earth.utils.lookup import download_lookup
3
+ from hestia_earth.utils.lookup import get_table_value, column_name
4
+
5
+ from hestia_earth.models.log import debugMissingLookup
6
+ from . import MODEL
7
+
8
+
9
+ def get_coefficient_factor(lookup_name: str, country_id: str, occupation_type: Optional[str], term_id: str):
10
+ """
11
+ Gets the EU PEF Characteristic factor for a given eu site type and country
12
+ """
13
+ coefficient = get_table_value(download_lookup(lookup_name), 'termid', country_id, column_name(occupation_type))
14
+ debugMissingLookup(
15
+ lookup_name, 'termid', country_id, column_name(occupation_type), coefficient, model=MODEL, term=term_id
16
+ )
17
+ return coefficient
@@ -10,12 +10,23 @@ from . import MODEL
10
10
 
11
11
  REQUIREMENTS = {
12
12
  "Cycle": {
13
- "products": [{
14
- "@type": "Product",
15
- "primary": "True",
16
- "value": "> 0",
17
- "economicValueShare": "> 0"
18
- }],
13
+ "or": [
14
+ {
15
+ "cycleDuration": "",
16
+ "practices": [{"@type": "Practice", "value": "", "term.@id": "longFallowRatio"}]
17
+ },
18
+ {
19
+ "@doc": "for plantations, additional properties are required",
20
+ "practices": [
21
+ {"@type": "Practice", "value": "", "term.@id": "nurseryDensity"},
22
+ {"@type": "Practice", "value": "", "term.@id": "nurseryDuration"},
23
+ {"@type": "Practice", "value": "", "term.@id": "plantationProductiveLifespan"},
24
+ {"@type": "Practice", "value": "", "term.@id": "plantationDensity"},
25
+ {"@type": "Practice", "value": "", "term.@id": "plantationLifespan"},
26
+ {"@type": "Practice", "value": "", "term.@id": "rotationDuration"}
27
+ ]
28
+ }
29
+ ],
19
30
  "site": {
20
31
  "@type": "Site",
21
32
  "measurements": [
@@ -10,12 +10,23 @@ from . import MODEL
10
10
 
11
11
  REQUIREMENTS = {
12
12
  "Cycle": {
13
- "products": [{
14
- "@type": "Product",
15
- "primary": "True",
16
- "value": "> 0",
17
- "economicValueShare": "> 0"
18
- }],
13
+ "or": [
14
+ {
15
+ "cycleDuration": "",
16
+ "practices": [{"@type": "Practice", "value": "", "term.@id": "longFallowRatio"}]
17
+ },
18
+ {
19
+ "@doc": "for plantations, additional properties are required",
20
+ "practices": [
21
+ {"@type": "Practice", "value": "", "term.@id": "nurseryDensity"},
22
+ {"@type": "Practice", "value": "", "term.@id": "nurseryDuration"},
23
+ {"@type": "Practice", "value": "", "term.@id": "plantationProductiveLifespan"},
24
+ {"@type": "Practice", "value": "", "term.@id": "plantationDensity"},
25
+ {"@type": "Practice", "value": "", "term.@id": "plantationLifespan"},
26
+ {"@type": "Practice", "value": "", "term.@id": "rotationDuration"}
27
+ ]
28
+ }
29
+ ],
19
30
  "site": {
20
31
  "@type": "Site",
21
32
  "measurements": [