Closed GiuliaIsNotAvailable closed 1 year ago
It does not make any difference if i use bic: climate water balance or prec: precipitation series in the compute.pearson_parameters. Here is the code:
prec_E5L_rsum = prec_E5L.rolling("30D", min_periods=30).sum().dropna() evap_E5L_rsum = evap_E5L.rolling("30D", min_periods=30).sum().dropna() bic_rsum = bic_E5L_daily.rolling("30D", min_periods=30).sum().dropna()
initial_year = bic_rsum.index[0].year calibration_year_initial = bic_rsum.index[0].year calibration_year_final = bic_rsum.index[-1].year period_times = 366 scale = 1 periodicity = compute.Periodicity.daily
values = bic_rsum.values
scaled_values = compute.scale_values( values, scale=scale, periodicity=periodicity, )
prob_zeros, locs, scales, skews = compute.pearson_parameters( scaled_values, data_start_year=initial_year, calibration_start_year=calibration_year_initial, calibration_end_year=calibration_year_final, periodicity=periodicity, ) pearson_params = {"prob_zero":prob_zeros, "loc":locs, "scale":scales, "skew":skews}
speival = indices.spei( precips_mm= prec_E5L_rsum, pet_mm= evap_E5L_rsum, scale=scale, distribution=indices.Distribution.pearson, data_start_year=initial_year, calibration_year_initial=calibration_year_initial, calibration_year_final=calibration_year_final, periodicity=compute.Periodicity.monthly, fitting_params=pearson_params, ) I adapted the code following this example for the SPI calculation: https://github.com/martinvonk/SPEI/blob/main/doc/examples/example04_package_comparison.ipynb
I'm sorry you've run into issues with this package, Giulia. I have an impending update that will maybe solve this issue for you. In the next version, we drop the usage of numba. If you know how to install via a non-master branch and can give that a try then I recommend that, as it may solve the issue for you in the meantime. Here's my PR with the latest refactored code: https://github.com/monocongo/climate_indices/pull/526
Thank you for your quick response. When do you think the update will be ready? I wish you good work!
Follow these steps to install and test your code against the development branch I mentioned above:
git clone -b issue_522_pyproject_poetry https://github.com/monocongo/climate_indices.git
cd climate_indices
If you don't have Poetry installed, you can install it with:
python -m pip install poetry
poetry shell
poetry install
Now you are in a virtual environment provided by poetry
, so you can run your code there to see if the changes on that branch will affect your result. Once you've completed your work there and want to exit the virtual environment you can get out with a single exit
command:
exit
The PR for the changes is ready to go I've just been reticent to pull the trigger. This issue may be the impetus I needed!
It worked! Thank you very much for the detailed explanation!
Thanks for following up, @GiuliaIsNotAvailable. I'm happy we've fixed your issue!
Hello, I'm using your package (Python 3.11 on Windows) for calculating SPI and SPEI indices, starting from timeseries of precipitation and evapotranspiration derived from ERA5 Land. As for SPI, the package worked. Unfortunately, when I try to compute SPEI, I encounter a problem in applying the compute.pearson_parameter function on the climate water balance timeseries (daily precipitation - evapotranspiration). The error message is the following:
I tested the same function (pearson_parameters) on the precipitation timeseries used for the SPI and it did not work either. Any suggestions?
Thank you in advance
Giulia