hestia-earth-models 0.68.1__py3-none-any.whl → 0.69.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.
- hestia_earth/models/agribalyse2016/fuelElectricity.py +0 -5
- hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py +0 -11
- hestia_earth/models/aware/scarcityWeightedWaterUse.py +0 -4
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +0 -18
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +0 -12
- hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionDuringCycle.py +0 -5
- hestia_earth/models/cml2001Baseline/resourceUseMineralsAndMetalsDuringCycle.py +0 -4
- hestia_earth/models/config/Cycle.json +23 -30
- hestia_earth/models/cycle/aboveGroundCropResidueTotal.py +0 -6
- hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +0 -8
- hestia_earth/models/cycle/animal/input/properties.py +0 -9
- hestia_earth/models/cycle/animal/milkYield.py +0 -6
- hestia_earth/models/cycle/animal/properties.py +0 -6
- hestia_earth/models/cycle/completeness/animalFeed.py +0 -6
- hestia_earth/models/cycle/completeness/cropResidue.py +0 -6
- hestia_earth/models/cycle/completeness/electricityFuel.py +0 -6
- hestia_earth/models/cycle/completeness/excreta.py +0 -6
- hestia_earth/models/cycle/completeness/freshForage.py +0 -6
- hestia_earth/models/cycle/completeness/material.py +0 -6
- hestia_earth/models/cycle/completeness/seed.py +0 -6
- hestia_earth/models/cycle/completeness/soilAmendment.py +0 -6
- hestia_earth/models/cycle/concentrateFeed.py +0 -6
- hestia_earth/models/cycle/cropResidueManagement.py +0 -5
- hestia_earth/models/cycle/cycleDuration.py +0 -8
- hestia_earth/models/cycle/endDate.py +0 -7
- hestia_earth/models/cycle/excretaKgMass.py +0 -5
- hestia_earth/models/cycle/excretaKgN.py +0 -5
- hestia_earth/models/cycle/excretaKgVs.py +0 -5
- hestia_earth/models/cycle/inorganicFertiliser.py +0 -6
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +0 -13
- hestia_earth/models/cycle/input/properties.py +0 -9
- hestia_earth/models/cycle/input/value.py +0 -6
- hestia_earth/models/cycle/liveAnimal.py +0 -5
- hestia_earth/models/cycle/materialAndSubstrate.py +1 -6
- hestia_earth/models/cycle/milkYield.py +0 -10
- hestia_earth/models/cycle/otherSitesArea.py +0 -6
- hestia_earth/models/cycle/otherSitesUnusedDuration.py +0 -6
- hestia_earth/models/cycle/pastureSystem.py +0 -6
- hestia_earth/models/cycle/post_checks/cache.py +0 -5
- hestia_earth/models/cycle/post_checks/otherSites.py +0 -7
- hestia_earth/models/cycle/post_checks/site.py +0 -7
- hestia_earth/models/cycle/practice/value.py +0 -7
- hestia_earth/models/cycle/pre_checks/cache_sources.py +0 -5
- hestia_earth/models/cycle/pre_checks/otherSites.py +0 -7
- hestia_earth/models/cycle/pre_checks/site.py +0 -6
- hestia_earth/models/cycle/product/currency.py +0 -5
- hestia_earth/models/cycle/product/economicValueShare.py +0 -14
- hestia_earth/models/cycle/product/price.py +0 -5
- hestia_earth/models/cycle/product/primary.py +0 -5
- hestia_earth/models/cycle/product/properties.py +0 -7
- hestia_earth/models/cycle/product/revenue.py +0 -9
- hestia_earth/models/cycle/product/value.py +0 -6
- hestia_earth/models/cycle/siteArea.py +0 -6
- hestia_earth/models/cycle/siteDuration.py +0 -10
- hestia_earth/models/cycle/siteUnusedDuration.py +0 -6
- hestia_earth/models/cycle/startDate.py +0 -8
- hestia_earth/models/cycle/startDateDefinition.py +0 -6
- hestia_earth/models/cycle/transformation.py +0 -5
- hestia_earth/models/dammgen2009/noxToAirExcreta.py +2 -2
- hestia_earth/models/ecoinventV3/__init__.py +0 -15
- hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +0 -11
- hestia_earth/models/emepEea2019/nh3ToAirExcreta.py +14 -40
- hestia_earth/models/emepEea2019/pm10ToAirAnimalHousing.py +0 -4
- hestia_earth/models/emepEea2019/pm25ToAirAnimalHousing.py +0 -4
- hestia_earth/models/emepEea2019/tspToAirAnimalHousing.py +0 -4
- hestia_earth/models/emissionNotRelevant/__init__.py +0 -5
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +0 -9
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +0 -6
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +0 -6
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexTotalLandUseEffects.py +0 -6
- hestia_earth/models/epa2014/no3ToGroundwaterExcreta.py +2 -2
- hestia_earth/models/faostat2018/product/price.py +0 -5
- hestia_earth/models/geospatialDatabase/awareWaterBasinId.py +0 -5
- hestia_earth/models/geospatialDatabase/ecoClimateZone.py +1 -20
- hestia_earth/models/geospatialDatabase/ecoregion.py +0 -7
- hestia_earth/models/geospatialDatabase/potentialEvapotranspirationAnnual.py +0 -4
- hestia_earth/models/geospatialDatabase/potentialEvapotranspirationMonthly.py +0 -4
- hestia_earth/models/geospatialDatabase/precipitationAnnual.py +0 -4
- hestia_earth/models/geospatialDatabase/precipitationMonthly.py +0 -4
- hestia_earth/models/geospatialDatabase/region.py +0 -5
- hestia_earth/models/geospatialDatabase/temperatureAnnual.py +0 -4
- hestia_earth/models/geospatialDatabase/temperatureMonthly.py +0 -4
- hestia_earth/models/haversineFormula/transport/distance.py +0 -7
- hestia_earth/models/hestia/landCover.py +31 -18
- hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +0 -11
- hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +0 -11
- hestia_earth/models/hestia/nh3ToSurfaceWaterAquacultureSystems.py +64 -0
- hestia_earth/models/hestia/residueRemoved.py +0 -4
- hestia_earth/models/hestia/resourceUse_utils.py +0 -5
- hestia_earth/models/hestia/seed_emissions.py +0 -13
- hestia_earth/models/impact_assessment/allocationMethod.py +0 -6
- hestia_earth/models/impact_assessment/emissions.py +0 -9
- hestia_earth/models/impact_assessment/irrigated.py +0 -5
- hestia_earth/models/impact_assessment/organic.py +0 -5
- hestia_earth/models/impact_assessment/post_checks/cycle.py +0 -7
- hestia_earth/models/impact_assessment/post_checks/site.py +0 -7
- hestia_earth/models/impact_assessment/pre_checks/cycle.py +0 -6
- hestia_earth/models/impact_assessment/pre_checks/site.py +0 -6
- hestia_earth/models/impact_assessment/product/economicValueShare.py +0 -6
- hestia_earth/models/impact_assessment/product/value.py +0 -5
- hestia_earth/models/ipcc2019/aboveGroundBiomass.py +9 -2
- hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +0 -6
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +0 -10
- hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +0 -4
- hestia_earth/models/ipcc2019/belowGroundBiomass.py +9 -2
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +1 -1
- hestia_earth/models/ipcc2019/croppingDuration.py +0 -5
- hestia_earth/models/ipcc2019/n2OToAirExcretaDirect.py +1 -1
- hestia_earth/models/ipcc2019/no3ToGroundwaterExcreta.py +51 -15
- hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +0 -12
- hestia_earth/models/ipcc2019/organicCarbonPerHa.py +2 -15
- hestia_earth/models/ipcc2019/{organicCarbonPerHa_tier_1_utils.py → organicCarbonPerHa_tier_1.py} +3 -15
- hestia_earth/models/ipcc2019/{organicCarbonPerHa_tier_2_utils.py → organicCarbonPerHa_tier_2.py} +3 -13
- hestia_earth/models/ipcc2019/pastureGrass.py +0 -10
- hestia_earth/models/koble2014/aboveGroundCropResidue.py +0 -9
- hestia_earth/models/koble2014/cropResidueManagement.py +0 -6
- hestia_earth/models/linkedImpactAssessment/emissions.py +0 -5
- hestia_earth/models/mocking/search-results.json +1202 -1146
- hestia_earth/models/pooreNemecek2018/ch4ToAirAquacultureSystems.py +14 -15
- hestia_earth/models/pooreNemecek2018/excretaKgN.py +12 -17
- hestia_earth/models/pooreNemecek2018/excretaKgVs.py +22 -23
- hestia_earth/models/pooreNemecek2018/n2OToAirAquacultureSystemsDirect.py +6 -9
- hestia_earth/models/pooreNemecek2018/n2ToAirAquacultureSystems.py +6 -9
- hestia_earth/models/pooreNemecek2018/nh3ToAirAquacultureSystems.py +11 -15
- hestia_earth/models/pooreNemecek2018/noxToAirAquacultureSystems.py +6 -9
- hestia_earth/models/pooreNemecek2018/utils.py +2 -2
- hestia_earth/models/site/defaultMethodClassification.py +0 -7
- hestia_earth/models/site/defaultMethodClassificationDescription.py +0 -7
- hestia_earth/models/site/flowingWater.py +0 -5
- hestia_earth/models/site/management.py +0 -21
- hestia_earth/models/site/measurement/value.py +0 -6
- hestia_earth/models/site/post_checks/country.py +0 -5
- hestia_earth/models/site/potentialEvapotranspirationAnnual.py +0 -3
- hestia_earth/models/site/potentialEvapotranspirationMonthly.py +0 -3
- hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +0 -5
- hestia_earth/models/site/pre_checks/cache_sources.py +0 -5
- hestia_earth/models/site/pre_checks/cache_years.py +0 -5
- hestia_earth/models/site/pre_checks/country.py +0 -5
- hestia_earth/models/site/precipitationAnnual.py +0 -3
- hestia_earth/models/site/precipitationMonthly.py +0 -3
- hestia_earth/models/site/rainfallAnnual.py +0 -3
- hestia_earth/models/site/rainfallMonthly.py +0 -3
- hestia_earth/models/site/soilMeasurement.py +0 -5
- hestia_earth/models/site/temperatureAnnual.py +0 -3
- hestia_earth/models/site/temperatureMonthly.py +0 -3
- hestia_earth/models/transformation/input/excreta.py +0 -5
- hestia_earth/models/transformation/input/max.py +0 -8
- hestia_earth/models/transformation/input/min.py +0 -8
- hestia_earth/models/transformation/input/properties.py +0 -6
- hestia_earth/models/transformation/input/sd.py +0 -8
- hestia_earth/models/transformation/input/value.py +0 -8
- hestia_earth/models/transformation/product/excreta.py +0 -7
- hestia_earth/models/utils/excretaManagement.py +37 -0
- hestia_earth/models/utils/lookup.py +2 -0
- hestia_earth/models/utils/practice.py +1 -27
- hestia_earth/models/utils/source.py +29 -9
- hestia_earth/models/version.py +1 -1
- hestia_earth/orchestrator/strategies/run/add_blank_node_if_missing.py +12 -8
- {hestia_earth_models-0.68.1.dist-info → hestia_earth_models-0.69.1.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.68.1.dist-info → hestia_earth_models-0.69.1.dist-info}/RECORD +179 -187
- tests/models/emepEea2019/test_nh3ToAirExcreta.py +6 -17
- tests/models/hestia/test_nh3ToSurfaceWaterAquacultureSystems.py +51 -0
- tests/models/ipcc2019/test_aboveGroundBiomass.py +4 -0
- tests/models/ipcc2019/test_belowGroundBiomass.py +4 -0
- tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChange.py +1 -1
- tests/models/ipcc2019/test_no3ToGroundwaterExcreta.py +24 -9
- tests/models/ipcc2019/test_organicCarbonPerHa.py +2 -2
- tests/models/ipcc2019/{test_organicCarbonPerHa_tier_1_utils.py → test_organicCarbonPerHa_tier_1.py} +2 -2
- tests/models/ipcc2019/{test_organicCarbonPerHa_tier_2_utils.py → test_organicCarbonPerHa_tier_2.py} +2 -2
- tests/models/pooreNemecek2018/test_ch4ToAirAquacultureSystems.py +1 -7
- tests/models/pooreNemecek2018/test_n2OToAirAquacultureSystemsDirect.py +1 -7
- tests/models/pooreNemecek2018/test_n2ToAirAquacultureSystems.py +1 -7
- tests/models/pooreNemecek2018/test_nh3ToAirAquacultureSystems.py +1 -7
- tests/models/pooreNemecek2018/test_noxToAirAquacultureSystems.py +1 -7
- tests/models/utils/test_source.py +6 -1
- tests/orchestrator/strategies/run/test_add_blank_node_if_missing.py +1 -1
- hestia_earth/models/blonkConsultants2016/__init__.py +0 -13
- hestia_earth/models/blonkConsultants2016/ch4ToAirNaturalVegetationBurning.py +0 -78
- hestia_earth/models/blonkConsultants2016/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +0 -78
- hestia_earth/models/blonkConsultants2016/n2OToAirNaturalVegetationBurningDirect.py +0 -78
- hestia_earth/models/blonkConsultants2016/utils.py +0 -30
- tests/models/blonkConsultants2016/__init__.py +0 -0
- tests/models/blonkConsultants2016/test_ch4ToAirNaturalVegetationBurning.py +0 -34
- tests/models/blonkConsultants2016/test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +0 -36
- tests/models/blonkConsultants2016/test_n2OToAirNaturalVegetationBurningDirect.py +0 -34
- tests/models/blonkConsultants2016/test_utils.py +0 -9
- {hestia_earth_models-0.68.1.dist-info → hestia_earth_models-0.69.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.68.1.dist-info → hestia_earth_models-0.69.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.68.1.dist-info → hestia_earth_models-0.69.1.dist-info}/top_level.txt +0 -0
@@ -1,11 +1,3 @@
|
|
1
|
-
"""
|
2
|
-
Input Value
|
3
|
-
|
4
|
-
This model calculates the [Input min](https://hestia.earth/schema/Input#min)
|
5
|
-
by taking the min of the same [Product](https://hestia.earth/schema/Product) of the
|
6
|
-
previous Transformation (or Cycle if first Transformation) and applying the
|
7
|
-
[share](https://hestia.earth/schema/Transformation/transformedShare).
|
8
|
-
"""
|
9
1
|
from functools import reduce
|
10
2
|
from hestia_earth.schema import NodeType
|
11
3
|
|
@@ -1,9 +1,3 @@
|
|
1
|
-
"""
|
2
|
-
Input Properties
|
3
|
-
|
4
|
-
This model copies the [Product properties](https://hestia.earth/schema/Product#properties) of the Cycle
|
5
|
-
to the first transformations [inputs](https://hestia.earth/schema/Transformation#inputs).
|
6
|
-
"""
|
7
1
|
from hestia_earth.schema import NodeType
|
8
2
|
from hestia_earth.utils.tools import non_empty_list
|
9
3
|
|
@@ -1,11 +1,3 @@
|
|
1
|
-
"""
|
2
|
-
Input Value
|
3
|
-
|
4
|
-
This model calculates the [Input sd](https://hestia.earth/schema/Input#sd)
|
5
|
-
by taking the sd of the same [Product](https://hestia.earth/schema/Product) of the
|
6
|
-
previous Transformation (or Cycle if first Transformation) and applying the
|
7
|
-
[share](https://hestia.earth/schema/Transformation/transformedShare).
|
8
|
-
"""
|
9
1
|
from functools import reduce
|
10
2
|
from hestia_earth.schema import NodeType
|
11
3
|
|
@@ -1,11 +1,3 @@
|
|
1
|
-
"""
|
2
|
-
Input Value
|
3
|
-
|
4
|
-
This model calculates the [Input value](https://hestia.earth/schema/Input#value)
|
5
|
-
by taking the value of the same [Product](https://hestia.earth/schema/Product) of the
|
6
|
-
previous Transformation (or Cycle if first Transformation) and applying the
|
7
|
-
[share](https://hestia.earth/schema/Transformation/transformedShare).
|
8
|
-
"""
|
9
1
|
from functools import reduce
|
10
2
|
from hestia_earth.schema import NodeType
|
11
3
|
|
@@ -1,10 +1,3 @@
|
|
1
|
-
"""
|
2
|
-
Product Excreta
|
3
|
-
|
4
|
-
This model calculates the value of every `Product` by taking the value of the `Input` with the same `term`.
|
5
|
-
It also adds other variants of the same `Product` in different `units` (e.g. `kg N`, `kg VS` and `kg`).
|
6
|
-
Note: this model also substract `Emissions` for `Input` with `units` = `kg N`.
|
7
|
-
"""
|
8
1
|
from hestia_earth.schema import SchemaType, TermTermType
|
9
2
|
from hestia_earth.utils.tools import list_sum, non_empty_list
|
10
3
|
from hestia_earth.utils.model import filter_list_term_type
|
@@ -1,6 +1,11 @@
|
|
1
1
|
from hestia_earth.schema import TermTermType
|
2
2
|
from hestia_earth.utils.model import filter_list_term_type
|
3
|
+
from hestia_earth.utils.lookup import column_name, download_lookup, get_table_value
|
4
|
+
from hestia_earth.utils.tools import safe_parse_float, list_sum
|
3
5
|
|
6
|
+
from hestia_earth.models.log import debugValues, debugMissingLookup, log_as_table
|
7
|
+
from . import _filter_list_term_unit
|
8
|
+
from .constant import Units
|
4
9
|
from .term import get_lookup_value
|
5
10
|
|
6
11
|
|
@@ -8,3 +13,35 @@ def get_lookup_factor(practices: list, lookup_col: str):
|
|
8
13
|
practices = filter_list_term_type(practices, TermTermType.EXCRETAMANAGEMENT)
|
9
14
|
practice = practices[0].get('term', {}) if len(practices) > 0 else None
|
10
15
|
return get_lookup_value(practice, lookup_col) if practice else None
|
16
|
+
|
17
|
+
|
18
|
+
def _get_nh3_factor(lookup_name: str, term_id: str, input: dict, **log_args):
|
19
|
+
input_term_id = input.get('term', {}).get('@id')
|
20
|
+
value = get_table_value(download_lookup(lookup_name), 'termid', term_id, column_name(input_term_id))
|
21
|
+
debugMissingLookup(lookup_name, 'termid', term_id, input_term_id, value, **log_args)
|
22
|
+
return safe_parse_float(value, None)
|
23
|
+
|
24
|
+
|
25
|
+
def get_excreta_inputs_with_factor(cycle: dict, lookup_name: str, excreta_convertion_func, **log_args):
|
26
|
+
practices = filter_list_term_type(cycle.get('practices', []), TermTermType.EXCRETAMANAGEMENT)
|
27
|
+
practice_id = practices[0].get('term', {}).get('@id') if len(practices) > 0 else None
|
28
|
+
|
29
|
+
# total of excreta including the factor
|
30
|
+
excreta_inputs = filter_list_term_type(cycle.get('inputs', []), TermTermType.EXCRETA)
|
31
|
+
excreta_inputs = _filter_list_term_unit(excreta_inputs, Units.KG_N)
|
32
|
+
excreta_values = [
|
33
|
+
(
|
34
|
+
i.get('term', {}).get('@id'),
|
35
|
+
excreta_convertion_func([i]),
|
36
|
+
_get_nh3_factor(lookup_name, practice_id, i, **log_args)
|
37
|
+
) for i in excreta_inputs
|
38
|
+
]
|
39
|
+
excreta_logs = log_as_table([
|
40
|
+
{'id': id, 'value': v, 'EF': ef} for id, v, ef in excreta_values
|
41
|
+
])
|
42
|
+
has_excreta_EF_inputs = len(excreta_values) > 0
|
43
|
+
debugValues(cycle, **log_args,
|
44
|
+
practice_id=practice_id,
|
45
|
+
has_excreta_EF_inputs=has_excreta_EF_inputs,
|
46
|
+
excreta=excreta_logs)
|
47
|
+
return list_sum([v * f for id, v, f in excreta_values if v is not None and f is not None], 0)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import functools
|
1
2
|
from typing import Optional, List
|
2
3
|
from hestia_earth.utils.lookup import (
|
3
4
|
download_lookup,
|
@@ -125,6 +126,7 @@ def fallback_country(country_id: str, lookups: List[str]) -> str:
|
|
125
126
|
return country_id if country_id and is_in_lookup(country_id) else fallback_id if is_in_lookup(fallback_id) else None
|
126
127
|
|
127
128
|
|
129
|
+
@functools.cache
|
128
130
|
def get_region_lookup_value(lookup_name: str, term_id: str, column: str, **log_args):
|
129
131
|
# for performance, try to load the region specific lookup if exists
|
130
132
|
lookup = (
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from hestia_earth.schema import SchemaType
|
2
2
|
from hestia_earth.utils.model import linked_node
|
3
3
|
|
4
|
-
from .term import
|
4
|
+
from .term import download_term
|
5
5
|
from .method import include_model
|
6
6
|
|
7
7
|
|
@@ -9,29 +9,3 @@ def _new_practice(term, model=None):
|
|
9
9
|
node = {'@type': SchemaType.PRACTICE.value}
|
10
10
|
node['term'] = linked_node(term if isinstance(term, dict) else download_term(term))
|
11
11
|
return include_model(node, model)
|
12
|
-
|
13
|
-
|
14
|
-
def is_model_enabled(model: str, term_id: str, practice: dict = None):
|
15
|
-
"""
|
16
|
-
Verify if the model + term_id group is allowed for that practice.
|
17
|
-
|
18
|
-
Parameters
|
19
|
-
----------
|
20
|
-
model : str
|
21
|
-
The name of the `methodModel`.
|
22
|
-
term_id : str
|
23
|
-
The name of the `term`.
|
24
|
-
practice : dict
|
25
|
-
The `Practice`.
|
26
|
-
|
27
|
-
Returns
|
28
|
-
-------
|
29
|
-
bool
|
30
|
-
If the model is allowed for that particular model and term_id.
|
31
|
-
"""
|
32
|
-
def get_value():
|
33
|
-
term = practice.get('term', {})
|
34
|
-
value = get_lookup_value(term, term_id) or ''
|
35
|
-
return model in value.split(';')
|
36
|
-
|
37
|
-
return get_value() if practice else False
|
@@ -4,7 +4,7 @@ import re
|
|
4
4
|
from hestia_earth.schema import SchemaType
|
5
5
|
from hestia_earth.utils.api import find_node_exact, search
|
6
6
|
from hestia_earth.utils.model import linked_node
|
7
|
-
from hestia_earth.utils.tools import flatten
|
7
|
+
from hestia_earth.utils.tools import flatten, non_empty_list
|
8
8
|
|
9
9
|
from . import cached_value
|
10
10
|
|
@@ -17,23 +17,43 @@ def _find_source(biblio_title: str = None):
|
|
17
17
|
return None if source is None else linked_node({'@type': SchemaType.SOURCE.value, **source})
|
18
18
|
|
19
19
|
|
20
|
-
def get_source(node: dict, biblio_title: str = None):
|
20
|
+
def get_source(node: dict, biblio_title: str = None, other_biblio_titles: list = []):
|
21
21
|
source = cached_value(node, CACHE_SOURCES_KEY, {}).get(biblio_title) or _find_source(biblio_title)
|
22
|
-
|
22
|
+
other_sources = non_empty_list([
|
23
|
+
(cached_value(node, CACHE_SOURCES_KEY, {}).get(title) or _find_source(title))
|
24
|
+
for title in other_biblio_titles
|
25
|
+
])
|
26
|
+
return (
|
27
|
+
{'source': source} if source else {}
|
28
|
+
) | (
|
29
|
+
{'otherSources': other_sources} if other_sources else {}
|
30
|
+
)
|
23
31
|
|
24
32
|
|
25
33
|
def _extract(content: str):
|
26
|
-
return [
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
return [
|
35
|
+
str(m).replace("BIBLIO_TITLE = ", '').replace("'", '')
|
36
|
+
for m in re.findall(r'BIBLIO_TITLE = \'[^\']*\'', content)
|
37
|
+
] + flatten([
|
38
|
+
str(m).replace(
|
39
|
+
"OTHER_BIBLIO_TITLES = [", ''
|
40
|
+
).replace(
|
41
|
+
' ', ''
|
42
|
+
).replace(
|
43
|
+
"'", ''
|
44
|
+
).replace(
|
45
|
+
"]", ''
|
46
|
+
).replace(
|
47
|
+
'# noqa: E501', ''
|
48
|
+
).split(',')
|
49
|
+
for m in re.findall(r'OTHER_BIBLIO_TITLES = \[[^[]*\]', content)
|
50
|
+
])
|
30
51
|
|
31
52
|
|
32
53
|
def _list_sources():
|
33
54
|
dir = pathlib.Path(ROOT_DIR)
|
34
55
|
files = list(dir.rglob('**/*.py'))
|
35
|
-
|
36
|
-
return list(map(_clean, sources))
|
56
|
+
return list(set(flatten([_extract(open(f, 'r').read().replace('\n', '')) for f in files])))
|
37
57
|
|
38
58
|
|
39
59
|
def find_sources():
|
hestia_earth/models/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = '0.
|
1
|
+
VERSION = '0.69.1'
|
@@ -1,4 +1,6 @@
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier
|
1
2
|
from hestia_earth.utils.lookup_utils import is_node_type_allowed
|
3
|
+
from hestia_earth.utils.tools import list_sum
|
2
4
|
|
3
5
|
from hestia_earth.orchestrator.log import debugValues, logShouldRun
|
4
6
|
from hestia_earth.orchestrator.utils import get_required_model_param, find_term_match
|
@@ -16,7 +18,7 @@ def _run_required(data: dict, model: str, term_id: str):
|
|
16
18
|
|
17
19
|
_RUN_FROM_ARGS = {
|
18
20
|
'runNonAddedTerm': lambda node: 'term' not in node.get('added', []),
|
19
|
-
'runNonMeasured': lambda node: node.get('methodTier') !=
|
21
|
+
'runNonMeasured': lambda node: node.get('methodTier') != EmissionMethodTier.MEASURED.value
|
20
22
|
}
|
21
23
|
|
22
24
|
|
@@ -31,12 +33,14 @@ def _run_aggregated(data: dict, skip_aggregated: bool = False):
|
|
31
33
|
return not data.get('aggregated', False) or not skip_aggregated
|
32
34
|
|
33
35
|
|
34
|
-
def
|
35
|
-
# emissions are set to 0 when not
|
36
|
+
def _is_0_not_relevant_emission(node: dict):
|
37
|
+
# emissions are set to 0 when not relevant, but we should still run for subsequent models
|
36
38
|
return node is not None and all([
|
37
39
|
node.get('@type', node.get('type')) == 'Emission',
|
38
|
-
'value' in node.get('added', [])
|
39
|
-
|
40
|
+
'value' in node.get('added', []),
|
41
|
+
list_sum(node.get('value') or [], -1) == 0,
|
42
|
+
node.get('methodTier') == EmissionMethodTier.NOT_RELEVANT.value
|
43
|
+
])
|
40
44
|
|
41
45
|
|
42
46
|
def should_run(data: dict, model: dict):
|
@@ -47,20 +51,20 @@ def should_run(data: dict, model: dict):
|
|
47
51
|
|
48
52
|
# run if: value is empty or force run from args
|
49
53
|
is_empty = _is_empty(node, args.get('skipEmptyValue', False))
|
50
|
-
|
54
|
+
is_0_not_relevant_emission = _is_0_not_relevant_emission(node)
|
51
55
|
run_is_aggregated = _run_aggregated(data, args.get('skipAggregated', False))
|
52
56
|
run_args = {
|
53
57
|
key: func(node) for key, func in _RUN_FROM_ARGS.items() if node and args.get(key, False) is True
|
54
58
|
}
|
55
59
|
run = any([
|
56
60
|
is_empty,
|
57
|
-
|
61
|
+
is_0_not_relevant_emission,
|
58
62
|
(len(run_args.keys()) > 0 and all([v for _k, v in run_args.items()]))
|
59
63
|
]) and _run_required(data, model.get('model'), term_id) and run_is_aggregated
|
60
64
|
|
61
65
|
logShouldRun(data, model.get('model'), term_id, run, key=key, value=term_id,
|
62
66
|
is_empty=is_empty,
|
63
|
-
|
67
|
+
is_0_not_relevant_emission=is_0_not_relevant_emission,
|
64
68
|
run_is_aggregated=run_is_aggregated,
|
65
69
|
**run_args)
|
66
70
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: hestia-earth-models
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.69.1
|
4
4
|
Summary: HESTIA's set of modules for filling gaps in the activity data using external datasets (e.g. populating soil properties with a geospatial dataset using provided coordinates) and internal lookups (e.g. populating machinery use from fuel use). Includes rules for when gaps should be filled versus not (e.g. never gap fill yield, gap fill crop residue if yield provided etc.).
|
5
5
|
Home-page: https://gitlab.com/hestia-earth/hestia-engine-models
|
6
6
|
Author: HESTIA Team
|
@@ -11,7 +11,7 @@ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.6
|
12
12
|
Description-Content-Type: text/markdown
|
13
13
|
License-File: LICENSE
|
14
|
-
Requires-Dist: hestia-earth-schema==
|
14
|
+
Requires-Dist: hestia-earth-schema==31.*
|
15
15
|
Requires-Dist: hestia-earth-utils>=0.14.0
|
16
16
|
Requires-Dist: python-dateutil>=2.8.1
|
17
17
|
Requires-Dist: CurrencyConverter==0.16.8
|