mrayson / sfoda

Stuff for Ocean Data Analysis (time-series, ocean model IO, mapping, etc)
Other
4 stars 1 forks source link

othertime with xarray #8

Open williamedge opened 1 year ago

williamedge commented 1 year ago

othertime.SecondsSince returns bad values when an xarray timeseries is input, and does not throw any warning.

e.g. time = np.arange(np.datetime64('2000-01-01'), np.datetime64('2000-01-02'), np.timedelta64(1,'h')) time = time.astype('datetime64[ns]') time_xr = xr.DataArray(data=time)

print(othertime.SecondsSince(time, basetime=datetime(2000,1,1))) print(othertime.SecondsSince(time_xr, basetime=datetime(2000,1,1)))

[ 0. 3600. 7200. 10800. 14400. 18000. 21600. 25200. 28800. 32400.

                  1. 68400.
      1. 82800.] <xarray.DataArray (dim_0: 24)> array([ 0., 3600000., 7200000., 10800000., 14400000., 18000000., 21600000., 25200000., 28800000., 32400000., 36000000., 39600000., 43200000., 46800000., 50400000., 54000000., 57600000., 61200000., 64800000., 68400000., 72000000., 75600000., 79200000., 82800000.]) Dimensions without coordinates: dim_0