Skip to content

Commit 950aeec

Browse files
authored
Merge pull request #1616 from knutfrode/dev
[run-ex] Further cleaning, and removing obsolete methods sea_floor_de…
2 parents 3a27486 + 862c68e commit 950aeec

File tree

3 files changed

+33
-70
lines changed

3 files changed

+33
-70
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: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,18 @@ def store_previous_variables(self):
621621

622622
def interact_with_coastline(self, final=False):
623623
"""Coastline interaction according to configuration setting"""
624+
624625
if self.num_elements_active() == 0:
625626
return
626-
i = self.get_config('general:coastline_action')
627-
coastline_approximation_precision = self.get_config('general:coastline_approximation_precision')
628-
if not hasattr(self, 'environment') or not hasattr(
629-
self.environment, 'land_binary_mask'):
627+
if not hasattr(self, 'environment') or not hasattr(self.environment, 'land_binary_mask'):
630628
return
629+
630+
i = self.get_config('general:coastline_action')
631631
if i == 'none': # Do nothing
632632
return
633+
634+
coastline_approximation_precision = self.get_config('general:coastline_approximation_precision')
635+
633636
if final is True: # Get land_binary_mask for final location
634637
en, en_prof, missing = \
635638
self.env.get_environment(['land_binary_mask'],
@@ -706,15 +709,17 @@ def interact_with_coastline(self, final=False):
706709

707710
def interact_with_seafloor(self):
708711
"""Seafloor interaction according to configuration setting"""
712+
709713
if self.num_elements_active() == 0:
710714
return
711715
if 'sea_floor_depth_below_sea_level' not in self.env.priority_list:
712716
return
713717

714-
# The shape of these is different than the original arrays
715-
# because it is for active drifters
716-
sea_floor_depth = self.sea_floor_depth()
717-
sea_surface_height = self.sea_surface_height()
718+
sea_floor_depth = self.environment.sea_floor_depth_below_sea_level
719+
if 'sea_surface_height' in self.required_variables:
720+
sea_surface_height = self.environment.sea_surface_height
721+
else:
722+
sea_surface_height = 0
718723

719724
# Check if any elements are below sea floor
720725
# But remember that the water column is the sea floor depth + sea surface height
@@ -2756,9 +2761,9 @@ def plot_timestep(i):
27562761

27572762
if drifter is not None:
27582763
for drnum, dr in enumerate(drifter):
2759-
drifter_pos[drnum].set_offsets(np.c_[dr['x'][i],
2760-
dr['y'][i]])
2761-
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])
27622767
ret.append(drifter_line[drnum])
27632768
ret.append(drifter_pos[drnum])
27642769

@@ -2982,12 +2987,12 @@ def plot_timestep(i):
29822987
sts = (self.result.time - self.result.time[0]) / np.timedelta64(1, 's')
29832988
dr_times = np.array(dr['time'], dtype=self.result.time.dtype)
29842989
dts = (dr_times-dr_times[0]) / np.timedelta64(1, 's')
2985-
dr['x'] = np.interp(sts, dts, dr['lon'])
2986-
dr['y'] = np.interp(sts, dts, dr['lat'])
2987-
dr['x'][sts < dts[0]] = np.nan
2988-
dr['x'][sts > dts[-1]] = np.nan
2989-
dr['y'][sts < dts[0]] = np.nan
2990-
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
29912996
dlabel = dr['label'] if 'label' in dr else 'Drifter'
29922997
dcolor = dr['color'] if 'color' in dr else 'r'
29932998
dlinewidth = dr['linewidth'] if 'linewidth' in dr else 2
@@ -3764,22 +3769,22 @@ def _plot_drifter(self, ax, gcrs, drifter):
37643769
'''Plot provided trajectory along with simulated'''
37653770
time = np.array(drifter['time'], dtype=self.result.time.dtype)
37663771
i = np.where((time >= self.result.time[0].values) & (time <= self.result.time[-1].values))[0]
3767-
x, y = (np.atleast_1d(drifter['lon'])[i],
3772+
lon, lat = (np.atleast_1d(drifter['lon'])[i],
37683773
np.atleast_1d(drifter['lat'])[i])
37693774
dlabel = drifter['label'] if 'label' in drifter else 'Drifter'
37703775
dcolor = drifter['color'] if 'color' in drifter else 'r'
37713776
dlinewidth = drifter['linewidth'] if 'linewidth' in drifter else 2
37723777
dzorder = drifter['zorder'] if 'zorder' in drifter else 10
37733778

3774-
ax.plot(x,
3775-
y,
3779+
ax.plot(lon,
3780+
lat,
37763781
linewidth=dlinewidth,
37773782
color=dcolor,
37783783
transform=self.crs_lonlat,
37793784
label=dlabel,
37803785
zorder=dzorder)
3781-
ax.plot(x[0], y[0], 'ok', transform=self.crs_lonlat)
3782-
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)
37833788

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

opendrift/models/physics_methods.py

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -954,47 +954,6 @@ def solar_elevation(self):
954954
'''Solar elevation at present time and position of active elements.'''
955955
return solar_elevation(self.time, self.elements.lon, self.elements.lat)
956956

957-
def sea_floor_depth(self):
958-
'''Sea floor depth (positive) for presently active elements'''
959-
960-
if hasattr(self, 'environment') and \
961-
hasattr(self.environment, 'sea_floor_depth_below_sea_level'):
962-
if len(self.environment.sea_floor_depth_below_sea_level) == \
963-
self.num_elements_active():
964-
sea_floor_depth = \
965-
self.environment.sea_floor_depth_below_sea_level
966-
if 'sea_floor_depth' not in locals():
967-
env, env_profiles, missing = \
968-
self.env.get_environment(['sea_floor_depth_below_sea_level'],
969-
time=self.time, lon=self.elements.lon,
970-
lat=self.elements.lat,
971-
z=self.elements.z, profiles=None)
972-
sea_floor_depth = \
973-
env['sea_floor_depth_below_sea_level'].astype('float32')
974-
return sea_floor_depth
975-
976-
def sea_surface_height(self):
977-
'''Sea surface height (positive/negative) for presently active elements'''
978-
979-
if 'sea_surface_height' not in self.required_variables:
980-
return 0
981-
if hasattr(self, 'environment') and \
982-
hasattr(self.environment, 'sea_surface_height'):
983-
if len(self.environment.sea_surface_height) == \
984-
self.num_elements_active():
985-
sea_surface_height = \
986-
self.environment.sea_surface_height
987-
if 'sea_surface_height' not in locals():
988-
env, env_profiles, missing = \
989-
self.env.get_environment(['sea_surface_height'],
990-
time=self.time, lon=self.elements.lon,
991-
lat=self.elements.lat,
992-
z=self.elements.z, profiles=None)
993-
sea_surface_height = \
994-
env['sea_surface_height'].astype('float32')
995-
return sea_surface_height
996-
997-
998957
def wind_drag_coefficient(windspeed):
999958
'''Large and Pond (1981), J. Phys. Oceanog., 11, 324-336.'''
1000959
Cd = 0.0012*np.ones(len(windspeed))
@@ -1011,7 +970,7 @@ def windspeed_from_stress_polyfit(wind_stress):
1011970
return p(wind_stress)
1012971

1013972

1014-
def declination(time):
973+
def solar_declination(time):
1015974
'''Solar declination in degrees.'''
1016975
try:
1017976
day_of_year = time.timetuple().tm_yday
@@ -1052,7 +1011,7 @@ def hour_angle(time, longitude):
10521011

10531012
def solar_elevation(time, longitude, latitude):
10541013
'''Solar elevation in degrees.'''
1055-
d_rad = np.deg2rad(declination(time))
1014+
d_rad = np.deg2rad(solar_declination(time))
10561015
h = hour_angle(time, longitude)
10571016
solar_elevation = np.rad2deg(np.arcsin(
10581017
np.sin(np.deg2rad(latitude))*np.sin(d_rad) +

0 commit comments

Comments
 (0)