Skip to content

Commit

Permalink
Merge pull request #14 from lucduron/fix-time
Browse files Browse the repository at this point in the history
Avoid arbitrary time 0.0 if single frame
  • Loading branch information
tomsail authored Mar 1, 2024
2 parents d5c6a31 + 32a6601 commit d9d3c5e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions xarray_selafin_backend/xarray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from xarray_selafin_backend import Serafin


def compute_duration_between_datetime(t0, time_serie):
return (time_serie - t0).astype("timedelta64[s]").astype(float)


def read_serafin(f):
resin = Serafin.Read(f, "en")
resin.__enter__()
Expand Down Expand Up @@ -78,12 +82,9 @@ def write_serafin(fout, ds, file_format):

t0 = np.datetime64(datetime(*slf_header.date))

if slf_header.nb_frames == 1:
time_serie = [float(0.0)]
else:
time_serie = [
(t.values - t0).astype("timedelta64[s]").astype(int) for t in ds.time
]
time_serie = compute_duration_between_datetime(t0, ds.time.values)
if isinstance(time_serie, float):
time_serie = [time_serie]
for it, t_ in enumerate(time_serie):
temp = np.empty(shape, dtype=slf_header.np_float_type)
for iv, var in enumerate(vars):
Expand Down

0 comments on commit d9d3c5e

Please sign in to comment.