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

Potentially problematic release.


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

Files changed (42) hide show
  1. hestia_earth/models/aware/scarcityWeightedWaterUse.py +2 -4
  2. hestia_earth/models/aware2_0/scarcityWeightedWaterUse.py +2 -5
  3. hestia_earth/models/chaudharyBrooks2018/utils.py +2 -2
  4. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +3 -2
  5. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +13 -6
  6. hestia_earth/models/ecoalimV9/utils.py +3 -3
  7. hestia_earth/models/ecoinventV3/utils.py +2 -2
  8. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +2 -2
  9. hestia_earth/models/emissionNotRelevant/__init__.py +2 -2
  10. hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +1 -2
  11. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +8 -5
  12. hestia_earth/models/faostat2018/utils.py +3 -3
  13. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +5 -4
  14. hestia_earth/models/geospatialDatabase/ecoClimateZone.py +2 -2
  15. hestia_earth/models/hestia/landCover_utils.py +8 -12
  16. hestia_earth/models/hestia/management.py +3 -3
  17. hestia_earth/models/hestia/seed_emissions.py +2 -2
  18. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +12 -9
  19. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +2 -2
  20. hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +2 -2
  21. hestia_earth/models/ipcc2019/pastureGrass_utils.py +6 -3
  22. hestia_earth/models/ipcc2019/utils.py +3 -2
  23. hestia_earth/models/linkedImpactAssessment/emissions.py +2 -2
  24. hestia_earth/models/mocking/search-results.json +1 -1
  25. hestia_earth/models/requirements.py +2 -2
  26. hestia_earth/models/utils/aggregated.py +2 -2
  27. hestia_earth/models/utils/background_emissions.py +6 -5
  28. hestia_earth/models/utils/ecoClimateZone.py +7 -8
  29. hestia_earth/models/utils/excretaManagement.py +3 -3
  30. hestia_earth/models/utils/feedipedia.py +7 -7
  31. hestia_earth/models/utils/input.py +2 -2
  32. hestia_earth/models/utils/liveAnimal.py +4 -4
  33. hestia_earth/models/utils/lookup.py +15 -20
  34. hestia_earth/models/utils/property.py +3 -3
  35. hestia_earth/models/utils/term.py +5 -5
  36. hestia_earth/models/version.py +1 -1
  37. hestia_earth/orchestrator/models/transformations.py +2 -2
  38. {hestia_earth_models-0.75.0.dist-info → hestia_earth_models-0.75.1.dist-info}/METADATA +2 -2
  39. {hestia_earth_models-0.75.0.dist-info → hestia_earth_models-0.75.1.dist-info}/RECORD +42 -42
  40. {hestia_earth_models-0.75.0.dist-info → hestia_earth_models-0.75.1.dist-info}/WHEEL +0 -0
  41. {hestia_earth_models-0.75.0.dist-info → hestia_earth_models-0.75.1.dist-info}/licenses/LICENSE +0 -0
  42. {hestia_earth_models-0.75.0.dist-info → hestia_earth_models-0.75.1.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  from hestia_earth.schema import SiteSiteType
2
2
  from hestia_earth.utils.model import find_term_match
3
- from hestia_earth.utils.lookup import download_lookup, _get_single_table_value, column_name
3
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
4
4
  from hestia_earth.utils.tools import safe_parse_float
5
5
 
6
6
  from hestia_earth.models.log import logRequirements, debugMissingLookup, logShouldRun
@@ -57,9 +57,7 @@ def _indicator(value: float): return _new_indicator(term=TERM_ID, model=MODEL, v
57
57
 
58
58
  def _get_factor_from_basinId(site: dict, aware_id: str):
59
59
  lookup_col = 'YR_IRRI' if site.get('siteType') in IRRIGATED_SITE_TYPES else 'YR_NONIRRI'
60
- value = _get_single_table_value(
61
- download_lookup(_AWARE_LOOKUP), column_name(AWARE_KEY), int(aware_id), column_name(lookup_col)
62
- )
60
+ value = get_table_value(download_lookup(_AWARE_LOOKUP), AWARE_KEY, int(aware_id), lookup_col)
63
61
  debugMissingLookup(_AWARE_LOOKUP, AWARE_KEY, aware_id, lookup_col, value, model=MODEL, term=TERM_ID)
64
62
  return safe_parse_float(value, default=None)
65
63
 
@@ -1,6 +1,6 @@
1
1
  from hestia_earth.schema import SiteSiteType
2
2
  from hestia_earth.utils.model import find_term_match
3
- from hestia_earth.utils.lookup import download_lookup, _get_single_table_value, column_name
3
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
4
4
  from hestia_earth.utils.tools import safe_parse_float
5
5
 
6
6
  from hestia_earth.models.log import logRequirements, debugMissingLookup, logShouldRun
@@ -67,10 +67,7 @@ def _lookup_column(site: dict):
67
67
  def _get_factor_from_basinId(site: dict, aware_id: str):
68
68
  lookup_col = _lookup_column(site)
69
69
  lookup = download_lookup(_AWARE_LOOKUP)
70
- try:
71
- value = _get_single_table_value(lookup, column_name(AWARE_KEY), int(aware_id), column_name(lookup_col))
72
- except Exception:
73
- value = None
70
+ value = get_table_value(lookup, AWARE_KEY, int(aware_id), lookup_col)
74
71
  debugMissingLookup(_AWARE_LOOKUP, AWARE_KEY, aware_id, lookup_col, value, model=MODEL, term=TERM_ID)
75
72
  return safe_parse_float(value, default=None)
76
73
 
@@ -1,4 +1,4 @@
1
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data
1
+ from hestia_earth.utils.lookup import download_lookup, get_table_value, extract_grouped_data
2
2
  from hestia_earth.utils.tools import safe_parse_float
3
3
 
4
4
  from hestia_earth.models.log import debugMissingLookup, logRequirements
@@ -8,7 +8,7 @@ from . import MODEL
8
8
 
9
9
 
10
10
  def _lookup_value(term_id: str, lookup_name: str, col_match: str, col_val: str, column: str):
11
- value = get_table_value(download_lookup(lookup_name), col_match, col_val, column_name(column))
11
+ value = get_table_value(download_lookup(lookup_name), col_match, col_val, column)
12
12
  debugMissingLookup(lookup_name, col_match, col_val, column, value, model=MODEL, term=term_id)
13
13
  return value
14
14
 
@@ -1,5 +1,5 @@
1
1
  from itertools import chain
2
- from hestia_earth.utils.lookup import download_lookup, column_name, find_term_ids_by
2
+ from hestia_earth.utils.lookup import download_lookup, find_term_ids_by
3
3
  from hestia_earth.utils.tools import list_sum, flatten
4
4
 
5
5
  from hestia_earth.models.log import logShouldRun, logRequirements, log_as_table
@@ -49,7 +49,8 @@ def get_all_non_renewable_terms(lookup_file_name: str, column: str) -> list:
49
49
  returns all non renewable term ids in lookup files like `electricity.csv` or `fuel.csv`
50
50
  """
51
51
  lookup = download_lookup(lookup_file_name)
52
- return find_term_ids_by(lookup, column_name(column), True)
52
+
53
+ return find_term_ids_by(lookup, column, True)
53
54
 
54
55
 
55
56
  def _valid_resource_indicator(resource: dict) -> bool:
@@ -1,7 +1,8 @@
1
1
  from hestia_earth.schema import TermTermType
2
- from hestia_earth.utils.lookup import get_table_value, download_lookup, column_name
2
+ from hestia_earth.utils.lookup import get_table_value, download_lookup
3
3
  from hestia_earth.utils.model import filter_list_term_type
4
4
  from hestia_earth.utils.tools import list_sum, flatten
5
+ from hestia_earth.utils.lookup import is_missing_value
5
6
 
6
7
  from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
7
8
  from . import MODEL
@@ -81,16 +82,22 @@ def _should_run(impact_assessment: dict) -> tuple[bool, list]:
81
82
  "value": _node_value(resource_indicator),
82
83
  "coefficient": get_table_value(
83
84
  lookup=download_lookup(filename=f"{input.get('termType')}.csv"),
84
- col_match='termid',
85
+ col_match='term.id',
85
86
  col_match_with=input.get('@id'),
86
- col_val=column_name(LOOKUPS.get(input.get('termType'), ''))) if input else None
87
+ col_val=LOOKUPS.get(input.get('termType', '')),
88
+ default_value=None
89
+ ) if input else None
87
90
  } for input in resource_indicator['inputs'] or [{}]]
88
91
  for resource_indicator in emissions_resource_use
89
92
  ]
90
93
  )
91
- valid_resources_with_cf = [em for em in resource_uses_unpacked if em['coefficient'] is not None
92
- and em['indicator-is-valid'] is True
93
- and em['indicator-input-is-valid'] is True]
94
+ valid_resources_with_cf = [
95
+ em for em in resource_uses_unpacked if all([
96
+ not is_missing_value(em['coefficient']),
97
+ em['indicator-is-valid'] is True,
98
+ em['indicator-input-is-valid'] is True,
99
+ ])
100
+ ]
94
101
 
95
102
  has_valid_input_requirements = all([
96
103
  all([
@@ -1,13 +1,13 @@
1
1
  import os
2
2
  from functools import lru_cache
3
3
  from hestia_earth.schema import TermTermType
4
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name
4
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
5
5
  from hestia_earth.utils.tools import non_empty_list, safe_parse_float, omit
6
6
 
7
7
  from hestia_earth.models.utils.term import get_lookup_value
8
8
  from hestia_earth.models.utils.background_emissions import convert_background_lookup
9
9
 
10
- _LOOKUP_INDEX_KEY = column_name('ecoalimMappingName')
10
+ _LOOKUP_INDEX_KEY = 'ecoalimMappingName'
11
11
 
12
12
 
13
13
  def get_input_mappings(model: str, input: dict):
@@ -58,7 +58,7 @@ def _cutoff_id(term_id: str, country_id: str = None, key_id: str = None):
58
58
  def cutoff_value(cutoff_lookup, term_id: str, country_id: str = None, key_id: str = None):
59
59
  cutoff_id = _cutoff_id(term_id=term_id, country_id=country_id, key_id=key_id)
60
60
  return None if cutoff_lookup is None else safe_parse_float(
61
- get_table_value(cutoff_lookup, 'termid', cutoff_id, 'percentage'),
61
+ get_table_value(cutoff_lookup, 'term.id', cutoff_id, 'percentage'),
62
62
  default=None
63
63
  )
64
64
 
@@ -1,13 +1,13 @@
1
1
  from functools import lru_cache
2
2
  from hestia_earth.schema import TermTermType
3
- from hestia_earth.utils.lookup import column_name, load_lookup
3
+ from hestia_earth.utils.lookup import load_lookup
4
4
  from hestia_earth.utils.tools import non_empty_list
5
5
 
6
6
  from hestia_earth.models.data.ecoinventV3 import get_filepath
7
7
  from hestia_earth.models.utils.term import get_lookup_value
8
8
  from hestia_earth.models.utils.background_emissions import convert_background_lookup
9
9
 
10
- _LOOKUP_INDEX_KEY = column_name('ecoinventName')
10
+ _LOOKUP_INDEX_KEY = 'ecoinventName'
11
11
 
12
12
 
13
13
  def get_input_mappings(model: str, input: dict):
@@ -1,4 +1,4 @@
1
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data
1
+ from hestia_earth.utils.lookup import download_lookup, get_table_value, extract_grouped_data
2
2
  from hestia_earth.utils.tools import safe_parse_float
3
3
 
4
4
  from hestia_earth.models.utils.cycle import cycle_end_year
@@ -14,7 +14,7 @@ def get_input_coefficient(model: str, cycle: dict, country_id: str, ecoinventNam
14
14
  # find the matching ember source with the ecoinventName.
15
15
  # example: "electricity, high voltage, electricity production, hard coal" > "Coal"
16
16
  ember_ecoinvent_lookup = download_lookup(EMBER_ECOINVENT_LOOKUP_NAME)
17
- source_name = get_table_value(ember_ecoinvent_lookup, column_name('ecoinventName'), ecoinventName, 'ember')
17
+ source_name = get_table_value(ember_ecoinvent_lookup, 'ecoinventName', ecoinventName, 'ember')
18
18
 
19
19
  # find the ratio for the country / year
20
20
  data = get_region_lookup_value(REGION_EMBER_SOURCES_LOOKUP_NAME, country_id, source_name, model=model)
@@ -1,5 +1,5 @@
1
1
  from hestia_earth.schema import NodeType, EmissionMethodTier, TermTermType
2
- from hestia_earth.utils.lookup import download_lookup, lookup_term_ids, lookup_columns, column_name
2
+ from hestia_earth.utils.lookup import download_lookup, lookup_term_ids, lookup_columns
3
3
  from hestia_earth.utils.lookup_utils import is_in_system_boundary
4
4
  from hestia_earth.utils.tools import flatten
5
5
 
@@ -49,7 +49,7 @@ def _emission_ids():
49
49
  def _model_ids(lookup_suffix: str):
50
50
  return [
51
51
  col for col in lookup_columns(download_lookup(f"emission-model-{lookup_suffix}.csv"))
52
- if col != column_name('term.id')
52
+ if col != 'term.id'
53
53
  ]
54
54
 
55
55
 
@@ -53,8 +53,7 @@ def _is_a_PEF_indicator(indicator: dict) -> bool:
53
53
 
54
54
 
55
55
  def _get_factor(term: dict, column: str) -> Optional[float]:
56
- factor = get_lookup_value(term, column, model=MODEL, term=TERM_ID)
57
- return float(factor) if factor is not None else None
56
+ return get_lookup_value(term, column, model=MODEL, term=TERM_ID)
58
57
 
59
58
 
60
59
  def _get_pef_method_model(term: dict) -> List[str]:
@@ -1,8 +1,8 @@
1
1
  from typing import Tuple
2
-
3
2
  from hestia_earth.schema import TermTermType
4
3
  from hestia_earth.utils.model import filter_list_term_type
5
4
  from hestia_earth.utils.tools import list_sum
5
+ from hestia_earth.utils.lookup import is_missing_value
6
6
 
7
7
  from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
8
8
  from hestia_earth.models.utils.indicator import _new_indicator
@@ -86,10 +86,13 @@ def _should_run(impact_assessment: dict) -> Tuple[bool, list]:
86
86
  for indicator in found_land_occupation_indicators
87
87
  ]) if found_land_occupation_indicators else False
88
88
 
89
- valid_indicator_with_coef = [indicator for indicator in found_indicators_with_coefficient if
90
- indicator['coefficient'] is not None and
91
- indicator['area-by-year-is-valid'] and
92
- indicator['area-unit-is-valid']]
89
+ valid_indicator_with_coef = [
90
+ indicator for indicator in found_indicators_with_coefficient if all([
91
+ not is_missing_value(indicator['coefficient']),
92
+ indicator['area-by-year-is-valid'],
93
+ indicator['area-unit-is-valid']
94
+ ])
95
+ ]
93
96
 
94
97
  has_land_occupation_indicators = bool(land_occupation_indicators)
95
98
 
@@ -1,6 +1,6 @@
1
1
  from hestia_earth.schema import TermTermType
2
2
  from hestia_earth.utils.api import download_hestia
3
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data_closest_date
3
+ from hestia_earth.utils.lookup import download_lookup, get_table_value, extract_grouped_data_closest_date
4
4
  from hestia_earth.utils.tools import safe_parse_float, flatten, non_empty_list
5
5
 
6
6
  from hestia_earth.models.log import logger, debugMissingLookup, logRequirements, logShouldRun, debugValues, log_as_table
@@ -20,8 +20,8 @@ FAOSTAT_AREA_LOOKUP = 'region-faostatArea.csv'
20
20
  def get_liveAnimal_to_animalProduct_id(product_term_id: str, column: str, **log_args):
21
21
  lookup_name = 'liveAnimal.csv'
22
22
  lookup = download_lookup(lookup_name)
23
- value = get_table_value(lookup, 'termid', product_term_id, column_name(column))
24
- debugMissingLookup(lookup_name, 'termid', product_term_id, column, value, model=MODEL, **log_args)
23
+ value = get_table_value(lookup, 'term.id', product_term_id, column)
24
+ debugMissingLookup(lookup_name, 'term.id', product_term_id, column, value, model=MODEL, **log_args)
25
25
  return value
26
26
 
27
27
 
@@ -1,5 +1,5 @@
1
1
  from hestia_earth.schema import TermTermType
2
- from hestia_earth.utils.lookup import get_table_value, download_lookup, column_name
2
+ from hestia_earth.utils.lookup import get_table_value, download_lookup, is_missing_value
3
3
  from hestia_earth.utils.model import filter_list_term_type
4
4
  from hestia_earth.utils.tools import flatten, list_sum, omit, pick, unique_values
5
5
  from hestia_earth.utils.blank_node import group_by_keys
@@ -82,9 +82,10 @@ def _should_run(impact_assessment: dict) -> tuple[bool, list]:
82
82
  "value": _node_value(emission),
83
83
  "coefficient": get_table_value(
84
84
  lookup=download_lookup(filename="waste.csv"),
85
- col_match='termid',
85
+ col_match='term.id',
86
86
  col_match_with=emission['key'].get('@id'),
87
- col_val=column_name(emission['term']['@id'])
87
+ col_val=emission['term']['@id'],
88
+ default_value=None
88
89
  )
89
90
  } | pick(emission, ['key', 'inputs'])
90
91
  for emission in emissions
@@ -93,7 +94,7 @@ def _should_run(impact_assessment: dict) -> tuple[bool, list]:
93
94
 
94
95
  valid_emission_with_cf = [
95
96
  em for em in emissions_unpacked if all([
96
- em['coefficient'] is not None,
97
+ not is_missing_value(em['coefficient']),
97
98
  em['key-is-valid'] is True
98
99
  ])
99
100
  ]
@@ -1,5 +1,5 @@
1
1
  from hestia_earth.schema import MeasurementMethodClassification
2
- from hestia_earth.utils.lookup import download_lookup, _get_single_table_value, column_name
2
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
3
3
 
4
4
  from hestia_earth.models.log import logRequirements, logShouldRun
5
5
  from hestia_earth.models.utils.measurement import _new_measurement
@@ -44,7 +44,7 @@ def _measurement(site: dict, value: int):
44
44
 
45
45
  def _name(value: int):
46
46
  lookup = download_lookup(f"{TERM_ID}.csv")
47
- return _get_single_table_value(lookup, column_name(TERM_ID), value, 'name')
47
+ return get_table_value(lookup, TERM_ID, value, 'name')
48
48
 
49
49
 
50
50
  def _run(site: dict):
@@ -3,7 +3,7 @@ from functools import lru_cache
3
3
  from collections import defaultdict
4
4
  from hestia_earth.schema import TermTermType
5
5
  from hestia_earth.utils.lookup import (
6
- download_lookup, get_table_value, column_name, _is_missing_value, extract_grouped_data, lookup_columns
6
+ download_lookup, get_table_value, is_missing_value, extract_grouped_data, lookup_columns, lookup_term_ids
7
7
  )
8
8
  from hestia_earth.utils.tools import safe_parse_float
9
9
 
@@ -57,10 +57,6 @@ def _get_lookup_with_cache(lookup_term: dict, column: str):
57
57
  def _get_faostat_name(term: dict) -> str: return _get_lookup_with_cache(term, "cropGroupingFaostatArea")
58
58
 
59
59
 
60
- def _is_missing_or_none(value) -> bool:
61
- return value is None or _is_missing_value(value)
62
-
63
-
64
60
  def _safe_divide(numerator, denominator, default=0) -> float:
65
61
  return default if not denominator else numerator / denominator
66
62
 
@@ -354,15 +350,15 @@ def _get_most_common_or_alphabetically_first(crop_terms: list) -> str:
354
350
  return sorted([term for term, freq in histogram.items() if freq == max_freq])[0]
355
351
 
356
352
 
353
+ @lru_cache()
357
354
  def _get_complete_faostat_to_crop_mapping() -> dict:
358
355
  """Returns mapping in the format: {faostat_name: IPCC_LAND_USE_CATEGORY, ...}"""
359
356
  term_type = TermTermType.CROP.value
360
357
  lookup = download_lookup(f"{term_type}.csv")
358
+ term_ids = lookup_term_ids(lookup)
361
359
  mappings = defaultdict(list)
362
- for crop_term_id in [row[0] for row in lookup]:
363
- key = column_name(
364
- get_table_value(lookup, 'termid', crop_term_id, column_name("cropGroupingFaostatArea"))
365
- )
360
+ for crop_term_id in term_ids:
361
+ key = get_table_value(lookup, 'term.id', crop_term_id, "cropGroupingFaostatArea")
366
362
  if key:
367
363
  mappings[key].append(crop_ipcc_land_use_category(crop_term_id=crop_term_id, lookup_term_type="crop"))
368
364
  return {
@@ -409,7 +405,7 @@ def _get_sum_for_land_category(
409
405
  return sum([
410
406
  safe_parse_float(value=extract_grouped_data(table_value, str(year)), default=None)
411
407
  for fao_name, table_value in values.items()
412
- if not _is_missing_or_none(extract_grouped_data(table_value, str(year))) and
408
+ if not is_missing_value(extract_grouped_data(table_value, str(year))) and
413
409
  fao_stat_to_ipcc_type[fao_name] == ipcc_land_use_category and
414
410
  (
415
411
  include_negatives or
@@ -426,8 +422,8 @@ def _get_sums_of_crop_expansion(country_id: str, year: int, include_negatives: b
426
422
  lookup = get_region_lookup(lookup_name=_LOOKUP_EXPANSION, term_id=country_id)
427
423
  columns = lookup_columns(lookup)
428
424
  values = {
429
- name: get_table_value(lookup, 'termid', country_id, column_name(name))
430
- for name in columns if name != "termid"
425
+ name: get_table_value(lookup, 'term.id', country_id, name)
426
+ for name in columns if name != 'term.id'
431
427
  }
432
428
 
433
429
  fao_stat_to_ipcc_type = _get_complete_faostat_to_crop_mapping()
@@ -1,7 +1,7 @@
1
1
  from typing import List
2
2
  from datetime import timedelta, datetime
3
3
  from hestia_earth.schema import SchemaType, TermTermType, COMPLETENESS_MAPPING
4
- from hestia_earth.utils.lookup import column_name, get_table_value, download_lookup
4
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
5
5
  from hestia_earth.utils.model import filter_list_term_type
6
6
  from hestia_earth.utils.tools import safe_parse_float, flatten, is_number, is_boolean, pick
7
7
  from hestia_earth.utils.blank_node import get_node_value
@@ -117,9 +117,9 @@ def _get_cycle_duration(cycle: dict, land_cover_id: str = None):
117
117
  cycle_duration = cycle.get('cycleDuration')
118
118
  lookup_value = None if cycle_duration or not land_cover_id else safe_parse_float(get_table_value(
119
119
  download_lookup("crop.csv"),
120
- column_name('landCoverTermId'),
120
+ 'landCoverTermId',
121
121
  land_cover_id,
122
- column_name('maximumCycleDuration')
122
+ 'maximumCycleDuration'
123
123
  ), default=None)
124
124
  return cycle_duration or lookup_value
125
125
 
@@ -1,7 +1,7 @@
1
1
  from functools import reduce
2
2
  from hestia_earth.schema import TermTermType, EmissionMethodTier, SiteSiteType
3
3
  from hestia_earth.utils.lookup import (
4
- download_lookup, column_name, extract_grouped_data_closest_date, find_term_ids_by
4
+ download_lookup, extract_grouped_data_closest_date, find_term_ids_by
5
5
  )
6
6
  from hestia_earth.utils.model import filter_list_term_type
7
7
  from hestia_earth.utils.tools import non_empty_list, flatten, list_sum, safe_parse_float, omit
@@ -103,7 +103,7 @@ def _map_group_emissions(group_id: str, required_emission_term_ids: list, emissi
103
103
  lookup = download_lookup('emission.csv')
104
104
  emissions = list(filter(
105
105
  lambda id: id in required_emission_term_ids,
106
- find_term_ids_by(lookup, column_name('inputProductionGroupId'), group_id)
106
+ find_term_ids_by(lookup, 'inputProductionGroupId', group_id)
107
107
  ))
108
108
  included_emissions = list(filter(lambda v: v in emission_ids, emissions))
109
109
  missing_emissions = list(filter(lambda v: v not in emission_ids, emissions))
@@ -1,5 +1,5 @@
1
1
  from hestia_earth.schema import EmissionMethodTier
2
- from hestia_earth.utils.lookup import column_name, download_lookup, get_table_value, extract_grouped_data
2
+ from hestia_earth.utils.lookup import download_lookup, get_table_value, extract_grouped_data
3
3
  from hestia_earth.utils.model import find_primary_product, find_term_match
4
4
  from hestia_earth.utils.tools import list_sum, safe_parse_float
5
5
 
@@ -168,9 +168,12 @@ def _extract_groupped_data(value: str, DE: float, NDF: float, ionophore: bool, m
168
168
 
169
169
  def _get_lookup_value(lookup, term: dict, lookup_col: str, DE: float, NDF: float, ionophore: bool, milk_yield: float):
170
170
  term_id = term.get('@id')
171
- value = get_table_value(lookup, 'termid', term_id, column_name(lookup_col)) if term_id else None
172
- debugMissingLookup(f"{term.get('termType')}.csv", 'termid', term_id, lookup_col, value, model=MODEL, term=TERM_ID)
173
- return value if value is None or ':' not in value else _extract_groupped_data(value, DE, NDF, ionophore, milk_yield)
171
+ value = get_table_value(lookup, 'term.id', term_id, lookup_col) if term_id else None
172
+ debugMissingLookup(f"{term.get('termType')}.csv", 'term.id', term_id, lookup_col, value, model=MODEL, term=TERM_ID)
173
+ return (
174
+ value if value is None or not isinstance(value, str) else
175
+ _extract_groupped_data(value, DE, NDF, ionophore, milk_yield)
176
+ )
174
177
 
175
178
 
176
179
  def _get_milk_yield(cycle: dict):
@@ -180,8 +183,8 @@ def _get_milk_yield(cycle: dict):
180
183
 
181
184
  def _get_DE_type(lookup, term_id: str, term_type: str):
182
185
  lookup_col = LOOKUPS.get(term_type, [None])[0]
183
- value = get_table_value(lookup, 'termid', term_id, column_name(lookup_col)) if lookup_col else None
184
- debugMissingLookup(f"{term_type}.csv", 'termid', term_id, lookup_col, value, model=MODEL, term=TERM_ID)
186
+ value = get_table_value(lookup, 'term.id', term_id, lookup_col) if lookup_col else None
187
+ debugMissingLookup(f"{term_type}.csv", 'term.id', term_id, lookup_col, value, model=MODEL, term=TERM_ID)
185
188
  return value
186
189
 
187
190
 
@@ -202,9 +205,9 @@ def _is_ionophore(cycle: dict, total_feed: float):
202
205
 
203
206
  def _get_default_values(lookup, term: dict):
204
207
  term_id = term.get('@id')
205
- value = get_table_value(lookup, 'termid', term_id, column_name(LOOKUPS['liveAnimal'][3])) if term_id else None
206
- min = get_table_value(lookup, 'termid', term_id, column_name(LOOKUPS['liveAnimal'][4])) if term_id else None
207
- max = get_table_value(lookup, 'termid', term_id, column_name(LOOKUPS['liveAnimal'][5])) if term_id else None
208
+ value = get_table_value(lookup, 'term.id', term_id, LOOKUPS['liveAnimal'][3]) if term_id else None
209
+ min = get_table_value(lookup, 'term.id', term_id, LOOKUPS['liveAnimal'][4]) if term_id else None
210
+ max = get_table_value(lookup, 'term.id', term_id, LOOKUPS['liveAnimal'][5]) if term_id else None
208
211
  return {
209
212
  'value': safe_parse_float(value, default=None),
210
213
  'min': safe_parse_float(min, default=None),
@@ -94,8 +94,8 @@ def _get_excreta_b0(country: dict, input: dict):
94
94
  def _get_excretaManagement_MCF_from_lookup(term_id: str, ecoClimateZone: int, duration_key: DURATION):
95
95
  lookup_name = 'excretaManagement-ecoClimateZone-CH4conv.csv'
96
96
  lookup = download_lookup(lookup_name)
97
- data_values = get_table_value(lookup, 'termid', term_id, str(ecoClimateZone))
98
- debugMissingLookup(lookup_name, 'termid', term_id, ecoClimateZone, data_values, model=MODEL, term=TERM_ID)
97
+ data_values = get_table_value(lookup, 'term.id', term_id, str(ecoClimateZone))
98
+ debugMissingLookup(lookup_name, 'term.id', term_id, ecoClimateZone, data_values, model=MODEL, term=TERM_ID)
99
99
  return safe_parse_float(
100
100
  extract_grouped_data(data_values, duration_key.value)
101
101
  or extract_grouped_data(data_values, DEFAULT_DURATION.value), # defaults to 12 months if no duration specified
@@ -5,7 +5,7 @@ import numpy as np
5
5
  import numpy.typing as npt
6
6
  from typing import Any, Callable, Literal, Optional, TypedDict, Union
7
7
  from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, SiteSiteType
8
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name
8
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
9
9
  from hestia_earth.utils.tools import safe_parse_float
10
10
  from hestia_earth.utils.stats import gen_seed, repeat_single, truncated_normal_1d
11
11
  from hestia_earth.utils.descriptive_stats import calc_descriptive_stats
@@ -289,7 +289,7 @@ def _get_fuel_factor(fuel_category: FuelCategory) -> dict:
289
289
  lookup = download_lookup(LOOKUP_FILENAME)
290
290
 
291
291
  data = {
292
- target: get_table_value(lookup, column_name("FuelCategory"), row, column_name(target))
292
+ target: get_table_value(lookup, "FuelCategory", row, target)
293
293
  for target in TARGET_DATA
294
294
  }
295
295
 
@@ -1,6 +1,6 @@
1
1
  from hestia_earth.schema import TermTermType
2
2
  from hestia_earth.utils.api import download_hestia
3
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data
3
+ from hestia_earth.utils.lookup import download_lookup, get_table_value, extract_grouped_data
4
4
  from hestia_earth.utils.tools import list_sum, safe_parse_float
5
5
 
6
6
  from hestia_earth.models.log import debugValues
@@ -33,7 +33,7 @@ def _get_activityCoefficient(animal: dict, systems: list) -> float:
33
33
 
34
34
  values = [(
35
35
  safe_parse_float(
36
- get_table_value(lookup, 'termid', system.get('term', {}).get('@id'), column_name(term_id)),
36
+ get_table_value(lookup, 'term.id', system.get('term', {}).get('@id'), term_id),
37
37
  default=0
38
38
  ),
39
39
  list_sum(system.get('value', [0]))
@@ -153,7 +153,10 @@ def _get_pregnancy_ratio_per_birth(animal: dict, value: str) -> float:
153
153
  def _get_pregnancy_ratio(animal: dict) -> float:
154
154
  term = animal.get('term', {})
155
155
  value = get_lookup_value(term, 'ratioCPregnancyNetEnergyPregnancyIpcc2019', model=MODEL, model_key=MODEL_KEY)
156
- return _get_pregnancy_ratio_per_birth(animal, value) if ';' in value else safe_parse_float(value, default=0)
156
+ return (
157
+ _get_pregnancy_ratio_per_birth(animal, value) if isinstance(value, str) and ';' in value else
158
+ safe_parse_float(value, default=0)
159
+ )
157
160
 
158
161
 
159
162
  def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
@@ -1,12 +1,12 @@
1
1
  from hestia_earth.schema import TermTermType
2
2
  from hestia_earth.utils.model import find_term_match, filter_list_term_type
3
3
  from hestia_earth.utils.tools import safe_parse_float
4
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
4
5
 
5
6
  from hestia_earth.models.log import debugValues
6
7
  from hestia_earth.models.utils.input import get_total_irrigation_m3
7
8
  from hestia_earth.models.utils.cycle import get_ecoClimateZone
8
9
  from hestia_earth.models.utils.term import get_lookup_value, get_milkYield_terms
9
- from hestia_earth.models.utils.ecoClimateZone import get_ecoClimateZone_lookup_value
10
10
  from . import MODEL
11
11
 
12
12
  # From IPCC2019 Indirect N2O emission factor, in N [avg, min, max, std]
@@ -129,7 +129,8 @@ def _get_waterRegime_lookup(model_term_id: str, practice: dict, col: str):
129
129
 
130
130
 
131
131
  def _is_wet(ecoClimateZone: str = None):
132
- return get_ecoClimateZone_lookup_value(ecoClimateZone, 'wet') == 1 if ecoClimateZone else None
132
+ lookup = download_lookup('ecoClimateZone.csv')
133
+ return None if ecoClimateZone is None else get_table_value(lookup, 'ecoClimateZone', int(ecoClimateZone), 'wet')
133
134
 
134
135
 
135
136
  def ecoClimate_factors(factors: dict, input_term_type: TermTermType = None, ecoClimateZone: str = None):
@@ -1,6 +1,6 @@
1
1
  from functools import reduce
2
2
  from hestia_earth.schema import EmissionMethodTier
3
- from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name
3
+ from hestia_earth.utils.lookup import download_lookup, get_table_value
4
4
  from hestia_earth.utils.tools import flatten, list_sum, pick
5
5
  from hestia_earth.utils.blank_node import group_by_keys
6
6
 
@@ -100,7 +100,7 @@ def _run_emission(cycle: dict, emission_term_id: str, data: dict):
100
100
 
101
101
  def _emission_group(term_id: str):
102
102
  lookup = download_lookup('emission.csv', True)
103
- return get_table_value(lookup, 'termid', term_id, column_name('inputProductionGroupId'))
103
+ return get_table_value(lookup, 'term.id', term_id, 'inputProductionGroupId')
104
104
 
105
105
 
106
106
  def _group_emissions(impact: dict):