Skip to content

Commit 5d83875

Browse files
committed
Update required for newer version of numpy
1 parent 80340a5 commit 5d83875

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

aodntools/timeseries_products/common.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime, timezone
33

44
import numpy as np
5+
import xarray as xr
56

67
# Common date/time format strings
78
TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
@@ -179,7 +180,7 @@ def in_water_index(nc):
179180
"""
180181
time_deployment_start = np.datetime64(nc.attrs['time_deployment_start'][:-1])
181182
time_deployment_end = np.datetime64(nc.attrs['time_deployment_end'][:-1])
182-
TIME = nc['TIME'][:]
183+
TIME = nc['TIME'].values
183184
return (TIME >= time_deployment_start) & (TIME <= time_deployment_end)
184185

185186
def in_water(nc):
@@ -189,7 +190,11 @@ def in_water(nc):
189190
:param nc: xarray dataset
190191
:return: xarray dataset
191192
"""
192-
return nc.where(in_water_index(nc), drop=True)
193+
194+
condition = in_water_index(nc) # This returns a numpy array
195+
# Wrap the condition in a DataArray so that it aligns with the TIME coordinate.
196+
cond_da = xr.DataArray(condition, dims=["TIME"], coords={"TIME": nc["TIME"].values})
197+
return nc.where(cond_da, drop=True)
193198

194199

195200
def current_utc_timestamp(format=TIMESTAMP_FORMAT):

0 commit comments

Comments
 (0)