CNES / pangeo-pytide

Tidal constituents analysis in Python.
BSD 3-Clause "New" or "Revised" License
31 stars 10 forks source link

tidal prediction date format issues #10

Closed apatlpo closed 1 year ago

apatlpo commented 2 years ago

I've add issues predicting tides and this seems to be related to date format: The tidal analysis looks like:

wt = pytide.WaveTable(["M2", "S2", "N2", "K2", "K1", "O1", "P1", "Q1", "S1", "M4"]) # to restrict
time = ds.time.values.astype("datetime64[us]")
f, vu = wt.compute_nodal_modulations(time)
w = wt.harmonic_analysis(ds.XE.values, f, vu)

The following prediction does not work and produce a result that is very wrong:

ds["XE_harmonic"] = ("time", wt.tide_from_tide_series(time, w))

Manually changing the date into seconds works however:

_time = [(pd.Timestamp(t)-pd.Timestamp(1970,1,1)).total_seconds() for t in time]
ds["XE_harmonic"] = ("time", wt.tide_from_tide_series(_time, w))
fbriol commented 2 years ago

I modified the library to handle numpy dates directly in the compiled code. This should solve the problem.