Hestia's Distribution library
Project description
Hestia Data Utils
Utils library to manipulate distributions on the Hestia platform
Install
pip install hestia_earth.distribution
- Optional: to generate distribution files, please install pymc 4.
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.
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'
For more information, run python plot_MCMC_bivariate.py --help
.
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
Built Distribution
Hashes for hestia-earth-distribution-0.0.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ccd7e2f744a64cc294b264567d8b1f1d4083a074adfefb9fd4e25afcc06a462 |
|
MD5 | f04232c2269e10e010f7d4247a892561 |
|
BLAKE2b-256 | 2158310f4291859ab73d3a802c77da6950a8ade055df02adfab80a6bfc42f32c |
Hashes for hestia_earth_distribution-0.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b36b4197cae75429062045b09edab5a16c4d4b6c21202d084d11848c486a0edf |
|
MD5 | 23c794190f8dbb519b279c9a48e8057a |
|
BLAKE2b-256 | 765ccc7f82694518e226a77186a2dd4a8768e0ad6f6f43c4b5cefc70de96e071 |