Ignore 'NaN' values for calculation GEV

28 views
Skip to first unread message

Imran Hosen

unread,
Oct 10, 2024, 5:26:14 AM10/10/24
to xarray
Dear All,
I am working with 3D precipitation daily data (time: 10950 lat: 172 lon: 221) and attempting to calculate Generalized Extreme Value (GEV) parameters using the scipy package. Below is the code I am using for this purpose:

# annual maximum precip
precip_annmax = precip.resample(time='Y').max()
precip_annmax = precip_annmax.chunk(dict(time = -1))
fit_GEV_numpy = lambda x: np.array(stats.genextreme.fit(x))
# fit the GEV distribution at each grid cell individually and in parallel
gev_params = xr.apply_ufunc(fit_GEV_numpy,
                            precip_annmax,
                            input_core_dims = [['time']],
                            output_core_dims  = [['param']],
                            output_sizes = {'param': 3},
                            dask = 'parallelized',
                            output_dtypes = [float],
                            vectorize = True)
Then, I'm trying to calculate the return period precipitation as follows:
precip_return50 = stats.genextreme.ppf(1 - (1/50),
                                       gev_params.isel(param = 0),
                                       gev_params.isel(param = 1),
                                       gev_params.isel(param = 2))

I am facing an issue with my dataset, which contains a significant number of NaN values. These NaN values seem to be causing problems, particularly when calculating the "return precipitation." I have already tried using the skipna=True option, but it hasn't resolved the issue.

Note: I also tested another dataset without NaN values and this code works fine. Only creates a problem when the dataset contains NaN values. 

Could you please suggest a way to properly ignore or handle NaN values during the calculation of the return levels?

Thank you for your time and suggestions.

Kind regards,
Imran 

Reply all
Reply to author
Forward
0 new messages