Skip to content

Commit 862c68e

Browse files
committed
Renamed x,y to lon,lat internally for drifter dictionary for plots and animations
1 parent cb8cfa5 commit 862c68e

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

examples/example_current_from_drifter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@
4141
# Finally running simulation
4242
o.run(end_time=r.end_time, time_step=r.time_step)
4343

44-
o.animation(buffer=.01, fast=True, drifter={'time': driftertimes, 'lon': drifterlons, 'lat': drifterlats,
45-
'label': 'CODE Drifter', 'color': 'b', 'linewidth': 2, 'markersize': 40})
44+
drifter={'time': driftertimes, 'lon': drifterlons, 'lat': drifterlats,
45+
'label': 'CODE Drifter', 'color': 'b', 'linewidth': 2, 'markersize': 40}
46+
o.animation(buffer=.01, fast=True, drifter=drifter)
4647

4748
#%%
4849
# .. image:: /gallery/animations/example_current_from_drifter_0.gif
4950

5051
#%%
5152
# Drifter track is shown in red, and simulated trajectories are shown in gray. Oil spill is displaced relative to drifter, but drifter current is assumed to be spatially homogeneous.
52-
o.plot(buffer=.01, fast=True, drifter={
53-
'lon': drifterlons, 'lat': drifterlats,
54-
'time': driftertimes, 'linewidth': 2, 'color': 'r'})
53+
o.plot(buffer=.01, fast=True, drifter=drifter)
5554

opendrift/models/basemodel/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,9 +2761,9 @@ def plot_timestep(i):
27612761

27622762
if drifter is not None:
27632763
for drnum, dr in enumerate(drifter):
2764-
drifter_pos[drnum].set_offsets(np.c_[dr['x'][i],
2765-
dr['y'][i]])
2766-
drifter_line[drnum].set_data(dr['x'][0:i+1], dr['y'][0:i+1])
2764+
drifter_pos[drnum].set_offsets(np.c_[dr['lon'][i],
2765+
dr['lat'][i]])
2766+
drifter_line[drnum].set_data(dr['lon'][0:i+1], dr['lat'][0:i+1])
27672767
ret.append(drifter_line[drnum])
27682768
ret.append(drifter_pos[drnum])
27692769

@@ -2987,12 +2987,12 @@ def plot_timestep(i):
29872987
sts = (self.result.time - self.result.time[0]) / np.timedelta64(1, 's')
29882988
dr_times = np.array(dr['time'], dtype=self.result.time.dtype)
29892989
dts = (dr_times-dr_times[0]) / np.timedelta64(1, 's')
2990-
dr['x'] = np.interp(sts, dts, dr['lon'])
2991-
dr['y'] = np.interp(sts, dts, dr['lat'])
2992-
dr['x'][sts < dts[0]] = np.nan
2993-
dr['x'][sts > dts[-1]] = np.nan
2994-
dr['y'][sts < dts[0]] = np.nan
2995-
dr['y'][sts > dts[-1]] = np.nan
2990+
dr['lon'] = np.interp(sts, dts, dr['lon'])
2991+
dr['lat'] = np.interp(sts, dts, dr['lat'])
2992+
dr['lon'][sts < dts[0]] = np.nan
2993+
dr['lon'][sts > dts[-1]] = np.nan
2994+
dr['lat'][sts < dts[0]] = np.nan
2995+
dr['lat'][sts > dts[-1]] = np.nan
29962996
dlabel = dr['label'] if 'label' in dr else 'Drifter'
29972997
dcolor = dr['color'] if 'color' in dr else 'r'
29982998
dlinewidth = dr['linewidth'] if 'linewidth' in dr else 2
@@ -3769,22 +3769,22 @@ def _plot_drifter(self, ax, gcrs, drifter):
37693769
'''Plot provided trajectory along with simulated'''
37703770
time = np.array(drifter['time'], dtype=self.result.time.dtype)
37713771
i = np.where((time >= self.result.time[0].values) & (time <= self.result.time[-1].values))[0]
3772-
x, y = (np.atleast_1d(drifter['lon'])[i],
3772+
lon, lat = (np.atleast_1d(drifter['lon'])[i],
37733773
np.atleast_1d(drifter['lat'])[i])
37743774
dlabel = drifter['label'] if 'label' in drifter else 'Drifter'
37753775
dcolor = drifter['color'] if 'color' in drifter else 'r'
37763776
dlinewidth = drifter['linewidth'] if 'linewidth' in drifter else 2
37773777
dzorder = drifter['zorder'] if 'zorder' in drifter else 10
37783778

3779-
ax.plot(x,
3780-
y,
3779+
ax.plot(lon,
3780+
lat,
37813781
linewidth=dlinewidth,
37823782
color=dcolor,
37833783
transform=self.crs_lonlat,
37843784
label=dlabel,
37853785
zorder=dzorder)
3786-
ax.plot(x[0], y[0], 'ok', transform=self.crs_lonlat)
3787-
ax.plot(x[-1], y[-1], 'xk', transform=self.crs_lonlat)
3786+
ax.plot(lon[0], lat[0], 'ok', transform=self.crs_lonlat)
3787+
ax.plot(lon[-1], lat[-1], 'xk', transform=self.crs_lonlat)
37883788

37893789
def get_map_background(self, ax, background, crs, time=None):
37903790
# Get background field for plotting on map or animation

0 commit comments

Comments
 (0)