Skip to main content

Hestia Data Utils

Utils library to manipulate distributions on the Hestia platform

Install

  1. pip install hestia_earth.distribution
  2. Optional: to generate posterior distribution files, install the sampler:
pip install hestia_earth.distribution[stats]
./install-cmdstan.sh

cmdstanpy drives CmdStan, which is compiled on the machine rather than installed from pip — hence the second step. It needs a C++ toolchain (build-essential on Debian/Ubuntu, Xcode command line tools on macOS) and takes a few minutes the first time. Reading existing distribution files needs neither.

Usage

By default, all output files will be stored under ./data folder. You can set the env variable DISTRIBUTION_DATA_FOLDER to store in a different folder.

To get univariate posterior distribution:

from hestia_earth.distribution.posterior_yield import get_post_ensemble, get_post

# get a single posterior distribution, run:
mu_ensemble, sd_ensemble = get_post_ensemble('GADM-GBR', 'wheatGrain')

# Or, if only instrested in the mean of the mu and sd values, run:
mu, sd = get_post('GADM-GBR', 'wheatGrain')

To calculate the probability of a set of values using bivariate distribution:

from hestia_earth.distribution.utils.MCMC_bivariate import calculate_fit_2d

# get the likelihood of a candidate based on the bivariate distribution between Grain
# yield and Nitrogen fertiliser usage of a given country and a given product, run:
yield_value = 8500
n_use = 200
likelihood = calculate_fit_2d([n_use, yield_value], 'GADM-GBR', 'wheatGrain')

Advance Usage

You can clone this repository to use the commands below.

Generate prior distribution

To generate yield prior file for all products:

python generate_prior_yield.py --overwrite

For more information, run python generate_prior_yield.py --help.

Generate likelihood data

In order to generate likelihood data (a spreadsheet of crop yield and fertiliser data) for a specific product and a specific country, run:

python generate_likelihood.py --product-id="wheatGrain" --country-id="GADM-GBR" --limit=1000

For more information, run python generate_likelihood.py --help.

Generate posterior distribution

  • In order to generate posterior distribution (for Bayesian statistics) for a specific country, run:
python generate_posterior_yield.py --country-id="GADM-GBR"

or to generate the fertiliser usage:

python generate_posterior_fert.py --country-id="GADM-GBR"

or to generate the pesticide usage:

python generate_posterior_pest.py --country-id="GADM-GBR"

Note: all commands above will update the same CSV file so they must not be run at the same time.

Generate multivariate distribution

  • In order to generate multivariate distribution (between yield and N, P, K fetiliser inputs) for a specific country and product, run:
python generate_MCMC_mv.py --country-id="GADM-GBR" --product-id="wheatGrain" --sample-size=10

Plotting

Prior Yield

To plot prior distribution by product by country:

python plot_prior_yield.py --country-id='GADM-GBR' --product-id='wheatGrain' --output-file='prior.png'

To plot FAO annual yield data, change --type parameter to one of the four options: fao_per_country, fao_per_product, fao_per_country_per_product, world_mu_signma. Example:

python plot_prior_yield.py --country-id='GADM-GBR' --output-file='fao-yield-gbr-allProducts.png' --type='fao_per_country'

For more information, run python plot_prior_yield.py --help.

Cycle Yield

To plot the bivariate distribution of yield data for Wheat, grain in United Kingdom:

python plot_cycle_yield.py --product-id=wheatGrain" --country-id="GADM-GBR" --limit=100

This will take a sample size of 100 and create a result.png file with the distribution.

For more information, run python plot_cycle_yield.py --help.

Posterior Yield

In order to plot the posterior distribution for a specific product and a specific country, run:

python plot_posterior_yield.py --country-id="GADM-GBR" --product-id="wheatGrain" --output-file="post.png"

For more information, run python plot_posterior_yield.py --help.

Plot bivariate distribution between Yield and fetiliser use

In order to plot the bivariate distribution between Yield and N, P or K fetiliser use for a specific product and a specific country, run:

python plot_MCMC_bivariate.py --y=8500 --n=200 --country-id='GADM-GBR' --product-id='wheatGrain' --output='gbr-yield-vs-nitrogen.png'

Or

python plot_MCMC_mv.py --y=8500 --n=200 --p=50 --k=50  --pest=5  --country-id='GADM-GBR' --product-id='wheatGrain' --output='gbr-yield-vs-nitrogen-on-demand.png'

Or

python plot_MCMC_mv.py --y=8500 --n=200 --p=50 --k=50  --country-id='GADM-GBR' --product-id='wheatGrain' --output='gbr-yield-vs-nitrogen-static.png'

For more information, run python plot_MCMC_bivariate.py --help.

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_distribution-0.4.0.tar.gz (25.8 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_distribution-0.4.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file hestia_earth_distribution-0.4.0.tar.gz.

File metadata

File hashes

Hashes for hestia_earth_distribution-0.4.0.tar.gz
Algorithm Hash digest
SHA256 763a23733fc506f6af0ab1b596aefa7805a194b1b44b69b7effd0d694cce8b8d
MD5 7d379bcc3812dd6052364e6d9d88546c
BLAKE2b-256 3951d4cb02aa37c304887c56180d02b1da1b08532c15e976bd21dd9ad5528d9e

See more details on using hashes here.

File details

Details for the file hestia_earth_distribution-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hestia_earth_distribution-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 600fb9d89d22117b3e4c2c4237b3407c9d19ee496120fd4d3eb1ac359855fc7b
MD5 9937bc175752f2d33915c5c4ee74c7a4
BLAKE2b-256 20c1d45505c402849fd779e3b0cb2dcc8c149221c51e75e2c521f2722f4a4bf1

See more details on using hashes here.

Release history Release notifications | RSS feed

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page