Package: hestia-earth-distribution
Hestia Data UtilsUtils library to manipulate distributions on the Hestia platformInstallpip install hestia_earth.distributionOptional: to generate distribution files, please installpymc 4.UsageBy default, all output files will be stored under./datafolder.
You can set the env variableDISTRIBUTION_DATA_FOLDERto store in a different folder.To get univariate posterior distribution:fromhestia_earth.distribution.posterior_yieldimportget_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:fromhestia_earth.distribution.utils.MCMC_bivariateimportcalculate_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=8500n_use=200likelihood=calculate_fit_2d([n_use,yield_value],'GADM-GBR','wheatGrain')Advance UsageYou can clone this repository to use the commands below.Generate prior distributionTo generate yield prior file for all products:python generate_prior_yield.py --overwriteFor more information, runpython generate_prior_yield.py --help.Generate likelihood dataIn 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=1000For more information, runpython generate_likelihood.py --help.Generate posterior distributionIn 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 runat the same time.PlottingPrior YieldTo 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--typeparameter 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, runpython plot_prior_yield.py --help.Cycle YieldTo plot the bivariate distribution of yield data forWheat, graininUnited Kingdom:python plot_cycle_yield.py --product-id=wheatGrain" --country-id="GADM-GBR" --limit=100This will take a sample size of100and create aresult.pngfile with the distribution.For more information, runpython plot_cycle_yield.py --help.Posterior YieldIn 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, runpython plot_posterior_yield.py --help.Plot bivariate distribution between Yield and fetiliser useIn 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'Orpython 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.png'For more information, runpython plot_MCMC_bivariate.py --help.