pankajkarman / bias_correction

python library for bias correction
MIT License
30 stars 8 forks source link

Problem with Example #2

Open dragonburn1991 opened 3 years ago

dragonburn1991 commented 3 years ago

Hello, Thank you for sharing your bias correction programs

I am following the example from https://github.com/pankajkarman/bias_correction/blob/master/example.ipynb. However, when I get some error when I try to bias correction by using this command: df2 = bc.correct(method='basic_quantile').

The error as followed: ValueError Traceback (most recent call last)

in () ----> 1 df1 = bc.correct(method='basic_quantile') ~/anaconda3/lib/python3.7/site-packages/bias_correction.py in correct(self, method, lower_limit, cdf_threshold) 136 cdf_threshold=cdf_threshold) 137 elif method == 'basic_quantile': --> 138 corrected = quantile_correction(self.obs_data, self.mod_data, self.sce_data, modified = False) 139 else: 140 corrected = quantile_correction(self.obs_data, self.mod_data, self.sce_data, modified = True) ~/anaconda3/lib/python3.7/site-packages/bias_correction.py in quantile_correction(obs_data, mod_data, sce_data, modified) 15 16 def quantile_correction(obs_data, mod_data, sce_data, modified = True): ---> 17 cdf = ECDF(mod_data) 18 p = cdf(sce_data) 19 cor = np.subtract(*[np.nanpercentile(x, p) for x in [obs_data, mod_data]]) ~/anaconda3/lib/python3.7/site-packages/statsmodels/distributions/empirical_distribution.py in __init__(self, x, side) 139 nobs = len(x) 140 y = np.linspace(1./nobs,1,nobs) --> 141 super(ECDF, self).__init__(x, y, side=side, sorted=True) 142 else: 143 return interp1d(x,y,drop_errors=False,fill_values=ival) ~/anaconda3/lib/python3.7/site-packages/statsmodels/distributions/empirical_distribution.py in __init__(self, x, y, ival, sorted, side) 87 if _x.shape != _y.shape: 88 msg = "x and y do not have the same shape" ---> 89 raise ValueError(msg) 90 if len(_x.shape) != 1: 91 msg = 'x and y must be 1-dimensional' ValueError: x and y do not have the same shape I was wondering how can I fix this issue. Thank you in advance
pankajkarman commented 3 years ago

It seems you are using the pip version of the code. Please use the latest code on github. Pip code has a few issues which have been resolved. However, I have not pushed the latest version to pip as the normal correction for multi-dimensional data is still not working. Will push the code to pip once this issue is resolved.

Thanks

drmshaltout commented 3 years ago

Hello I would like to test the following command for only one station Could I use an excel file for the model, and data_to_be_corrected? and also for reference? and what are the format of this excel file bc = BiasCorrection(reference, model, data_to_be_corrected)

pankajkarman commented 3 years ago

You could have a single excel file for model, reference and data_to_be_corrected or separate files for all these three. However, model and reference should have some overlap time period. In short, model and reference are datasets which you use to find bias and then this bias is used to correct the data_to_be_corrected.

pankajkarman commented 3 years ago

ex Take a look at the attached image for an example.

drmshaltout commented 3 years ago

Thanks for your answer Could you please send me a sample for the following: MODEL_HISTORIQUE.txt; OBSERVED.txt; Model.txt; To prepare my files to be like them. All the best and Thank you in advance Mohamed

pankajkarman commented 3 years ago

MODEL.txt MODEL_HISTORIQUE.txt OBSERVED.txt

Here are the requested files. Hope it's useful.

Thanks

drmshaltout commented 3 years ago

Thank you for your prompt answer.

Please find the attached script that I used to bias-corrected the data that you send to me.

I get one simple error

ax.legand () Traceback (most recent call last): File "", line 1, in AttributeError: 'AxesSubplot' object has no attribute 'legand'

and I get this error also, could you tell me how to fix it. bc = BiasCorrection(ref, mod, sce)

corrected = bc.correct(method='gamma_mapping') Traceback (most recent call last): File "", line 1, in File "C:\Python36-32\lib\site-packages\bias_correction.py", line 133, in correct cdf_threshold=cdf_threshold) File "C:\Python36-32\lib\site-packages\bias_correction.py", line 35, in gamma_correction obs_gamma, mod_gamma, sce_gamma = [gamma.fit(x) for x in [obs_raindays, mod_raindays, sce_raindays]] File "C:\Python36-32\lib\site-packages\bias_correction.py", line 35, in obs_gamma, mod_gamma, sce_gamma = [gamma.fit(x) for x in [obs_raindays, mod_raindays, sce_raindays]] File "C:\Python36-32\lib\site-packages\scipy\stats_continuous_distns.py", line 2860, in fit return super(gamma_gen, self).fit(data, *args, **kwds) File "C:\Python36-32\lib\site-packages\scipy\stats_distn_infrastructure.py", line 2302, in fit if not np.isfinite(data).all(): File "C:\Python36-32\lib\site-packages\pandas\core\generic.py", line 1330, in nonzero f"The truth value of a {type(self).name} is ambiguous. " ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). ERROR

Levin000 commented 3 years ago

Thank you for your prompt answer.

Please find the attached script that I used to bias-corrected the data that you send to me.

I get one simple error

ax.legand () Traceback (most recent call last): File "", line 1, in AttributeError: 'AxesSubplot' object has no attribute 'legand'

and I get this error also, could you tell me how to fix it. bc = BiasCorrection(ref, mod, sce)

corrected = bc.correct(method='gamma_mapping') Traceback (most recent call last): File "", line 1, in File "C:\Python36-32\lib\site-packages\bias_correction.py", line 133, in correct cdf_threshold=cdf_threshold) File "C:\Python36-32\lib\site-packages\bias_correction.py", line 35, in gamma_correction obs_gamma, mod_gamma, sce_gamma = [gamma.fit(x) for x in [obs_raindays, mod_raindays, sce_raindays]] File "C:\Python36-32\lib\site-packages\bias_correction.py", line 35, in obs_gamma, mod_gamma, sce_gamma = [gamma.fit(x) for x in [obs_raindays, mod_raindays, sce_raindays]] File "C:\Python36-32\lib\site-packages\scipy\stats_continuous_distns.py", line 2860, in fit return super(gamma_gen, self).fit(data, *args, kwds) File "C:\Python36-32\lib\site-packages\scipy\stats_distn_infrastructure.py", line 2302, in fit if not np.isfinite(data).all(): File "C:\Python36-32\lib\site-packages\pandas\core\generic.py", line 1330, in nonzero f"The truth value of a {type(self).name**} is ambiguous. " ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). ERROR

Are you mean ax.legend()?

drmshaltout commented 3 years ago

Yes this is one error about ax.legend() and ther are another error related to ; corrected = bc.correct(method='gamma_mapping')