0

I am willing to calculate trend of a netcdf file using scipy.stats. Everytime I run this code snippet:

    import scipy.stats
    slope0      =  np.zeros(GDI[0, :, :].shape)
    intercept0  =  np.zeros(GDI[0, :, :].shape)
    r_value0    =  np.zeros(GDI[0, :, :].shape)
    p_value0    =  np.zeros(GDI[0, :, :].shape)
    std_err0    =  np.zeros(GDI[0, :, :].shape)
    nlon=len(lon)
    nlat=len(lat)
    ntime=len(time)
    for ilat in range(nlat):
    for jlon in range(nlon): 
    slope0[jlon, ilat], intercept0[jlon, ilat], r_value0[jlon, ilat], p_value0[jlon, ilat], std_err0[jlon, ilat], std_err = scipy.stats.linregress(time, GDI[:, jlon, ilat])
 

I encounter the following error:

numpy.core._exceptions._UFuncBinaryResolutionError: ufunc 'add' cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]')` 

My data follows the following structure:

<xarray.DataArray (time: 2184, latitude: 67, longitude: 74)>
array([[[ -78.82753935, -63.61520502, -75.04746738, ..., -91.40400582,  -93.52223331, -99.73324103....]]]),
Coordinates:
time       (time) datetime64[ns] 2014-09-01 ... 2014-11-30T23:00:00
longitude  (longitude) float32 -10.0 -9.25 -8.5 -7.75 ... 43.25 44.0 44.75
latitude   (latitude) float32 24.5 23.75 23.0 22.25 ... -23.5 -24.25 -25.0
level      float64 700.0

I have tried using some solutions proposed in the forum but to no avail. Please can anyone have an idea to help me tackle this problem???

hpaulj
  • 221,503
  • 14
  • 230
  • 353
Stephny
  • 1
  • 1
  • The error says you are trying to add two datetime64 arrays. They can be subtracted to produce a time difference, but they can't be added. e,g, `June 1, 1920 + Aug 2, 2020` doesn't make sense! – hpaulj Apr 02 '21 at 19:38
  • Vague allusions to other things you tried doesn't help us (help you)! What attempts have to made to debug this? Have you paid attention to the full traceback (which you forgot to show!)? – hpaulj Apr 02 '21 at 19:42

0 Answers0