Skip to content

Commit 6dea224

Browse files
authored
Merge pull request #1649 from knutfrode/dev
[run-ex] Switching land and ocean colors if inverted shapefile (i.e. …
2 parents 1dd1995 + 4eff37d commit 6dea224

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

opendrift/models/basemodel/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,14 +896,15 @@ def closest_ocean_points(self, lon, lat):
896896
o.env.finalize() # This is not env of the main simulation
897897
land_reader = reader_landmask
898898
else:
899-
logger.info('Using existing reader for land_binary_mask')
899+
logger.info('Using existing reader for land_binary_mask to move elements to ocean')
900900
land_reader_name = self.env.priority_list['land_binary_mask'][0]
901901
land_reader = self.env.readers[land_reader_name]
902902
o = self
903903

904904
if isinstance(land_reader, ShapeReader):
905905
# can do this better
906906
land_indices = land_reader.__on_land__(lon, lat)
907+
land_indices = np.where(land_indices==1)[0]
907908
lon[land_indices], lat[land_indices], _ = land_reader.get_nearest_outside(
908909
lon[land_indices],
909910
lat[land_indices],
@@ -2484,9 +2485,15 @@ def set_up_map(self,
24842485
if 'land_binary_mask' in self.env.priority_list and self.env.priority_list[
24852486
'land_binary_mask'][0] == 'shape':
24862487
logger.debug('Using custom shapes for plotting land..')
2488+
if self.env.readers['shape'].invert is True: # Switching land and ocean colors
2489+
facecolor = ocean_color
2490+
ax.patch.set_facecolor(land_color)
2491+
else:
2492+
facecolor = land_color
2493+
24872494
ax.add_geometries(self.env.readers['shape'].polys,
24882495
self.crs_lonlat,
2489-
facecolor=land_color,
2496+
facecolor=facecolor,
24902497
edgecolor='black')
24912498
else:
24922499
reader_global_landmask.plot_land(ax, lonmin, latmin, lonmax,

0 commit comments

Comments
 (0)