Skip to main content

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.).

Project description

HESTIA Engine Models

Pipeline Status Coverage Report

HESTIA's set of models for running calculations or retrieving data using external datasets and internal lookups.

Documentation

Documentation for every model can be found in the HESTIA Guide.

Install

  1. Install python 3.12 minimum
  2. Install the module:
pip install hestia_earth.models

Usage

from hestia_earth.models.pooreNemecek2018 import run

cycle_data = {"@type": "Cycle", ...}
# cycle is a JSONLD node Cycle
result = run('no3ToGroundwaterSoilFlux', cycle_data)
print(result)

This will display only the result of the no3ToGroundwaterSoilFlux model (Emission).

Additionally, to reduce the number of queries to the HESTIA API and run the models faster, prefetching can be enabled:

from hestia_earth.models.preload_requests import enable_preload

enable_preload()

Using the orchestrator

The models come with an "orchestrator", which allows you to run a pre-configured set of models instead of a single one.

The configuration for each Node (Cycle, Site or ImpactAssessment) can be found in the config folder.

Usage:

from hestia_earth.orchestrator import run
from hestia_earth.models.config import load_config

cycle = {"@type": "Cycle", ...}
result = run(cycle, load_config(cycle))
print(result)

This will display the Cycle recalculated with all HESTIA default models running.

Using Spatial Models

We have models that can gap-fill geographical information on a Site. If you want to use these models:

  1. Install the library: pip install hestia-earth-earth-engine
  2. Follow the Getting Started instructions.

Collecting logs in JSON format

:info: This is an experimental feature and is not yet integrated in all the HESTIA tools.

To collect logs in JSON format:

  1. Set the env variable LOG_JSON_ENABLED to true
  2. Use the following code to collect contribution logs:
from hestia_earth.orchestrator import run
from hestia_earth.models.config import load_config
from hestia_earth.models.jlog import reset_collected_logs, get_collected_logs

# make sure the logs are reset before each run
reset_collected_logs()

# run the models as usual
impact = {"@type": "ImpactAssessment", ...}
result = run(impact, load_config(impact))
print(result)

# write the logs to a JSON file
logs = get_collected_logs()
with open("logs.json", "w") as f:
    f.write(to_string(logs, indent=2))

When a node is recalculated in separate passes (e.g. stage 1 then stage 2 in different processes), seed the later pass with the earlier one's logs so stage-1-only placements are not lost:

from hestia_earth.models.jlog import load_collected_logs, get_collected_logs

# stage 2: load the logs collected during stage 1, then run stage 2 as usual
load_collected_logs(stage1_logs)
result = run(impact, load_config(impact), stage=2)
logs = get_collected_logs()  # contains both stage 1 and stage 2

Collecting contribution data

:info: This is an experimental feature and is not yet integrated in all the HESTIA tools.

To collect contribution data of impacts/endpoints on ImpactAssessment:

  1. Set the env variable LOG_CONTRIBUTION_ENABLED to true
  2. Use the following code to collect contribution logs:
from hestia_earth.orchestrator import run
from hestia_earth.models.config import load_config
from hestia_earth.models.log_contribution import reset_contributions, get_contributions

# make sure the contributions are reset before each run
reset_contributions()

# run the models as usual
impact = {"@type": "ImpactAssessment", ...}
result = run(impact, load_config(impact))
print(result)

# write the contributions to a JSON file
contributions = get_contributions()
with open("contributions.json", "w") as f:
    f.write(to_string(contributions, indent=2))

The contribution data will store the factors used for each emissionsResourceUse that contributes to specific impacts, and likewise impacts that contribute to endpoints. The index in the data represents the index of the blank node in the list of contributing blank nodes.

Using the ecoinventV3 model

:warning: This model has been deprecated and no further support will be provided.

ecoinvent is a consistent, transparent, and well validated life cycle inventory database. We use ecoinvent data to ascertain the environmental impacts of activities that occur outside of our system boundary, for example data on the environmental impacts of extracting oil and producing diesel, or the impacts of manufacturing plastics.

The ecoinventV3 model requires a valid license to run. We are currently working on a way to enable users of this code with a valid ecoinvent licence to run these models themselves, but for now, these models are only available on the public platform.

Amortising Land Use Change Emissions Using Linear Discounting

:info: This is an experimental feature and is not yet integrated in all the HESTIA tools. All carbon stock change models (ipcc2019.aboveGroundBiomass, etc.) and their associated emission models (ipcc2019.co2ToAirAboveGroundBiomassStockChange, etc.) have been updated; however, changes to hestia.landCover are required to make linear discounting fully functional (see work item #1623 for further information).

To amortise the impacts of land use change using linear discounting across IPCC (2019) models:

  1. Set the env variable USE_LINEAR_DISCOUNTING to true

TypeScript / JavaScript package

The model metadata is also published to npm as @hestia-earth/engine-models:

npm install @hestia-earth/engine-models

It exposes the links between models, terms and their documentation (model-links.json), and the KaTeX formulas extracted from each model, with bindings that map every symbol to a value logged at runtime (the "jlog"):

import { getFormulas } from '@hestia-earth/engine-models';

getFormulas({ model: 'ipcc2019', term: 'ch4ToAirEntericFermentation' });
// => [ { formula: 'E_{CH4} = (GE \\times Y_m) / 55.65', bindings: [...] } ]

See formulas/README.md for the full guide on getting a model's formulas, rendering them with KaTeX, and substituting the symbols with the values from a given execution.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hestia_earth_models-0.82.1.tar.gz (470.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hestia_earth_models-0.82.1-py3-none-any.whl (892.1 kB view details)

Uploaded Python 3

File details

Details for the file hestia_earth_models-0.82.1.tar.gz.

File metadata

  • Download URL: hestia_earth_models-0.82.1.tar.gz
  • Upload date:
  • Size: 470.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for hestia_earth_models-0.82.1.tar.gz
Algorithm Hash digest
SHA256 e8ef468bf8c961fd9e734cfeed85c9dd1c1f708d0750beb79f59ac20e53be94f
MD5 ec4621225c7a72d10fb4e7e25ddbf755
BLAKE2b-256 ed756d07eadef1477073cdcc1c7cf6c0a64a3c0e2286f62cb9554848ce3212a4

See more details on using hashes here.

File details

Details for the file hestia_earth_models-0.82.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hestia_earth_models-0.82.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7e8463f2aaa46a5c55ed09edf98b4486586d8957b9542d2353cf2d00b1463e8
MD5 f4e849016427071f71b1e28feb70fd63
BLAKE2b-256 37191b57518f725c934f3d45fffda6ab0aca336d5603e92ae32ffc5287fd8ec0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page