Skip to content

Commit 0b9a783

Browse files
authored
Merge pull request #195 from knutfrode/dev
gridtime: making sure we have same dtype for initial and target datet…
2 parents 169d00d + b6ef9f3 commit 0b9a783

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

examples/example_model_along_trajectory.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
print(ta.versions())
1414

15-
import logging
16-
logging.basicConfig(level=logging.DEBUG)
17-
1815
#%%
1916
# Open drifter dataset from a CSV file
2017
ds = ta.read_csv('bug05_pos.csv.xz',
@@ -38,11 +35,8 @@
3835
#%%
3936
# Grid the drifter dataset to the timesteps of the model.
4037
times = nk.sel(time=slice('2022-05-10', '2022-05-20')).time.values
41-
print(times, 'Drifter times')
4238
ds = ds.traj.gridtime(times)
43-
print('Dropping na')
4439
ds = ds.dropna('time', how='all')
45-
print('Dropped na')
4640

4741
print(ds)
4842

@@ -62,9 +56,6 @@
6256
#%%
6357
# Notice that the `lat` and `lon` variables from Norkyst match the original `lat` and `lon` from the dataset.
6458

65-
try:
66-
plt.figure()
67-
temp.plot()
68-
plt.show()
69-
except:
70-
print('Could not plot data')
59+
plt.figure()
60+
temp.plot()
61+
plt.show()

trajan/traj1d.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,10 @@ def gridtime(self, times, time_varname=None, round=True):
322322
times = times.to_numpy()
323323

324324
time_varname = self.time_varname if time_varname is None else time_varname
325+
times = times.astype(self.ds[time_varname].dtype) # Make sure we have same dtype for ds and times array
325326

326327
ds = self.ds.copy()
328+
327329
# We fill NaN-values in time coordinate to be able to interpolate
328330
ds[time_varname] = ds[time_varname].interpolate_na(
329331
dim=time_varname, method='linear', fill_value='extrapolate', use_coordinate=False)

0 commit comments

Comments
 (0)