Skip to main content

HESTIA's utils library

Project description

HESTIA Utils

Install

  1. Install the module:
pip install hestia_earth.utils
  1. Add this to your environment variables:
API_URL=https://api.hestia.earth
WEB_URL=https://www.hestia.earth

Usage

  1. To download a file from the HESTIA API:
from hestia_earth.schema import SchemaType
from hestia_earth.utils.api import download_hestia

cycle = download_hestia('cycleId', SchemaType.CYCLE)
sandContent = download_hestia('sandContent', SchemaType.TERM)
  1. To search for a specific Node on HESTIA:
from hestia_earth.schema import SchemaType
from hestia_earth.utils.api import find_node_exact

source = find_node_exact(SchemaType.SOURCE, {'bibliography.title': 'My Bibliography'})
  1. To get a lookup table from local file system:
from hestia_earth.schema import SchemaType
from hestia_earth.utils.lookup import load_lookup

df = load_lookup('path/to/my/lookup.csv')
  1. To get a lookup table from HESTIA:
from hestia_earth.schema import SchemaType
from hestia_earth.utils.lookup import download_lookup

df = download_lookup('crop.csv')

LSRS Format

You can use this library to convert HESTIA data into the LSRS format.

convert() accepts Impact Assessment, Cycle, Site and Source nodes and returns one simplified dict per node:

  • Impact Assessment → the 88 LSRS indicator columns plus metadata (including land transformation and deforestation read from its indicators).
  • Cycle → yield, EVS, seed, pesticide, diesel, electricity, crop residues, and (using the nutrient/unit helpers in lsrs/models_utils.py) fertiliser kg N / kg P2O5 / kg K2O, lime kg CaCO3 and irrigation m3.
  • Site → site type, country, region and current land cover.
  • Source → bibliography title and year.

These JSON outputs can be rendered to Excel or stored elsewhere. lsrs/models_utils.py holds nutrient/unit/land-cover helpers copied from hestia-earth-models so this library has no dependency on it.

For example, this will let you download all verified aggregation on HESTIA:

  1. Add the env variable API_ACCESS_TOKEN and use the API Key from your account.
  2. Create a file to store the search query:
{
  "bool": {
    "must": [
      { "match": { "@type": "ImpactAssessment" } },
      { "match": { "aggregatedDataValidated": true } }
    ]
  }
}
  1. Run python3 convert_to_lsrs.py --query-path test.json --data-state recalculated

This will create 2 files:

  • query-results-lsrs.json: contains the raw JSON data needed to generate the Excel file
  • query-results-lsrs.xlsx: cotains the LSRS data in Excel format.

Note: if you make some changes to the Excel generation, you can run this to use the json data and re-generate the Excel file quicker: python3 render_lsrs.py --filepath query-results-lsrs.json

Converting multiple files and rendering into a single Excel

You can use the convert script to create all the JSON files containing the raw data, then render everything together at once:

  1. Run all your conversion, using --skip-rendering parameter:
python3 convert_to_lsrs.py --query-path test1.json --data-state recalculated --skip-rendering
python3 convert_to_lsrs.py --query-path test1.json --data-state recalculated --skip-rendering
  1. This will write multiple JSON files in the samples folder. Once done, render all together: python3 render_lsrs.py --folder samples. This will create the final samples.xlsx file.

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_utils-0.17.23.tar.gz (89.7 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_utils-0.17.23-py3-none-any.whl (85.1 kB view details)

Uploaded Python 3

File details

Details for the file hestia_earth_utils-0.17.23.tar.gz.

File metadata

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

File hashes

Hashes for hestia_earth_utils-0.17.23.tar.gz
Algorithm Hash digest
SHA256 8ba78883ebe4378da4dc0d5ac55c1dd6b89e23603bc06185fa5bf86da8a4097b
MD5 bc0b9ef75d99ba180f0ca25ec3811284
BLAKE2b-256 ad053d860c5cf390a08e3ee1ea218d4b0f60c3da2c133165a5a23ff02976fab7

See more details on using hashes here.

File details

Details for the file hestia_earth_utils-0.17.23-py3-none-any.whl.

File metadata

File hashes

Hashes for hestia_earth_utils-0.17.23-py3-none-any.whl
Algorithm Hash digest
SHA256 5805420ef89579686dcf9b1bf19f6fdb0a8ea7bad2cbab7e6d174f1e73154c6b
MD5 b5caa87d4e2308d828917b3f33b7a7d5
BLAKE2b-256 474af35612754ce38cfdbf787809e9b968eac6a67ee671299265e844796fccb8

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