Skip to content
Snippets Groups Projects
Commit ee901b56 authored by Nils-Arne Dreier's avatar Nils-Arne Dreier Committed by Siddhant Tibrewal
Browse files

fix: first timestep is not startdate but startdate + dt

parent 66591896
No related branches found
No related tags found
1 merge request!50fix: first timestep is not startdate but startdate + dt
Pipeline #101238 passed
......@@ -9,10 +9,10 @@ def add_time(dataset, startdate, enddate, dt, name="time"):
startdate = np.datetime64(startdate)
if type(enddate) is str:
enddate = np.datetime64(enddate)
if type(dt) is int:
dt = np.timedelta64(dt, "s")
time_data = (
np.arange(startdate, enddate, np.timedelta64(dt, "s")) - startdate
) // np.timedelta64(1, "s")
time_data = (np.arange(startdate + dt, enddate + dt, dt) - startdate) // np.timedelta64(1, "s")
for g in _collect_groups(dataset):
time = g.create_dataset(name, data=time_data, fill_value=None, shape=time_data.shape)
......
......@@ -135,16 +135,16 @@ def main():
"seconds since " in time_coordinate.attrs["units"]
), "Currently the time must be given in seconds"
dt = time_coordinate[1] - time_coordinate[0]
# compute time start index
t0 = (
np.datetime64(start_datetime())
- np.datetime64(v.group.time.attrs["units"][len("seconds since ") :])
) / np.timedelta64(1, "s")
) / np.timedelta64(1, "s") + dt
t0_idx = np.searchsorted(v.group.time, t0)
print(t0_idx, t0)
assert v.group.time[t0_idx] == t0, "start_datetime not found in time axis"
dt = time_coordinate[t0_idx + 1] - time_coordinate[t0_idx]
# see YAC_REDUCTION_TIME_NONE etc. (TODO: pass constants through coyote)
time_methods2yac = {"point": 0, "sum": 1, "mean": 2, "min": 3, "max": 4}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment