How to deal with NaN, PosInf, NegInf in the trend calculations?



Dear Toolbox team,


can you please guide me on how to deal the NaNs, PosInf, NegInf in the dataset? I'm using "cdstoolbox.stats.trend" to calculate the trend. Here is the error message:

error message Expand source
  File "/usr/local/lib64/python3.6/site-packages/scipy/optimize/minpack.py", line 708, in curve_fit
    ydata = np.asarray_chkfinite(ydata, float)
  File "/usr/local/lib64/python3.6/site-packages/numpy/lib/function_base.py", line 496, in asarray_chkfinite
    "array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

There is an input argument skipnan=True, but I can't manage to make it work.

skipnan error message Expand source
TypeError: trend() got an unexpected keyword argument 'skipna'

Here is the full code I use to retrieve the data, prepare the data, calculate the trend and plot it.

surface radiation trend Expand source
import cdstoolbox as ct

layout = ct.Layout(rows=1, debug=False, input_ncols=2, justify=‘flex-start’ )
layout.add_widget(row=0, content=‘output-0’, sm=9)

variables = {‘surface_downwelling_shortwave_flux’: ‘SIS’}

@ct.application()
@ct.output.figure()

def application():
request=[
‘satellite-surface-radiation-budget’, {
‘variable’: ‘surface_downwelling_shortwave_flux’,
‘product_family’: ‘clara’,
‘climate_data_record_type’: ‘thematic_climate_data_record’,
‘origin’: ‘eumetsat’,
‘sensor’: ‘avhrr’,
‘time_aggregation’: ‘monthly_mean’,
‘year’: [str(year) for year in range(2005, 2011)],
‘month’: [‘%02d’%(mnth) for mnth in range(1,13)]
}
]
data = ct.catalogue.retrieve(*request)

anom = ct.operator.sub(data, ct.cube.average(data, 'time'))

trend = ct.stats.trend(anom, dim='time')
trd = trend[1]
trd = ct.operator.mul(trd,3.156e8)
trd = ct.units.convert_units(trd, target_units="kg.s-4")

fig = ct.cdsplot.geomap(
        trd, 
        projection=ct.cdsplot.crs.PlateCarree(),
)

return fig</pre>


Kind regards,

Alex Bobryshev