Skip to content

Commit 31f81d5

Browse files
Merge pull request #1182 from ocefpaf/plotting_bug
Projection is never None at this point of the code and the if-clause is ill defined
2 parents edb1dd5 + df6872c commit 31f81d5

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

parcels/field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ class CField(Structure):
12301230
pointer(self.grid.ctypes_struct))
12311231
return cstruct
12321232

1233-
def show(self, animation=False, show_time=None, domain=None, depth_level=0, projection=None, land=True,
1233+
def show(self, animation=False, show_time=None, domain=None, depth_level=0, projection='PlateCarree', land=True,
12341234
vmin=None, vmax=None, savefile=None, **kwargs):
12351235
"""Method to 'show' a Parcels Field
12361236

parcels/particleset/baseparticleset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
516516
if verbose_progress:
517517
pbar.close()
518518

519-
def show(self, with_particles=True, show_time=None, field=None, domain=None, projection=None,
519+
def show(self, with_particles=True, show_time=None, field=None, domain=None, projection='PlateCarree',
520520
land=True, vmin=None, vmax=None, savefile=None, animation=False, **kwargs):
521521
"""Method to 'show' a Parcels ParticleSet
522522

parcels/plotting.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from parcels.tools.loggers import logger
1313

1414

15-
def plotparticles(particles, with_particles=True, show_time=None, field=None, domain=None, projection=None,
16-
land=True, vmin=None, vmax=None, savefile=None, animation=False, **kwargs):
15+
def plotparticles(particles, with_particles=True, show_time=None, field=None, domain=None,
16+
projection='PlateCarree', land=True, vmin=None, vmax=None, savefile=None,
17+
animation=False, **kwargs):
1718
"""Function to plot a Parcels ParticleSet
1819
1920
:param show_time: Time at which to show the ParticleSet
@@ -48,7 +49,7 @@ def plotparticles(particles, with_particles=True, show_time=None, field=None, do
4849
return # creating axes was not possible
4950
ax.set_title('Particles' + parsetimestr(particles.fieldset.U.grid.time_origin, show_time))
5051
latN, latS, lonE, lonW = parsedomain(domain, particles.fieldset.U)
51-
if cartopy is None or projection is None:
52+
if (cartopy is None) or (projection is None):
5253
if domain is not None:
5354
if isinstance(particles.fieldset.U.grid, CurvilinearGrid):
5455
ax.set_xlim(particles.fieldset.U.grid.lon[latS, lonW], particles.fieldset.U.grid.lon[latN, lonE])
@@ -99,7 +100,7 @@ def plotparticles(particles, with_particles=True, show_time=None, field=None, do
99100
plt.close()
100101

101102

102-
def plotfield(field, show_time=None, domain=None, depth_level=0, projection=None, land=True,
103+
def plotfield(field, show_time=None, domain=None, depth_level=0, projection='PlateCarree', land=True,
103104
vmin=None, vmax=None, savefile=None, **kwargs):
104105
"""Function to plot a Parcels Field
105106
@@ -263,24 +264,21 @@ def plotfield(field, show_time=None, domain=None, depth_level=0, projection=None
263264
return plt, fig, ax, cartopy
264265

265266

266-
def create_parcelsfig_axis(spherical, land=True, projection=None, central_longitude=0, cartopy_features=[]):
267+
def create_parcelsfig_axis(spherical, land=True, projection='PlateCarree', central_longitude=0, cartopy_features=[]):
267268
try:
268269
import matplotlib.pyplot as plt
269270
except:
270271
logger.info("Visualisation is not possible. Matplotlib not found.")
271272
return None, None, None, None # creating axes was not possible
272273

273-
if projection is not None and not spherical:
274-
raise RuntimeError('projection not accepted when Field doesn''t have geographic coordinates')
275-
276-
if spherical:
274+
if spherical and projection:
277275
try:
278276
import cartopy
279277
except:
280278
logger.info("Visualisation of field with geographic coordinates is not possible. Cartopy not found.")
281279
return None, None, None, None # creating axes was not possible
282280

283-
projection = cartopy.crs.PlateCarree(central_longitude) if projection is None else projection
281+
projection = cartopy.crs.PlateCarree(central_longitude) if projection == 'PlateCarree' else projection
284282
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': projection})
285283
try: # gridlines not supported for all projections
286284
if isinstance(projection, cartopy.crs.PlateCarree) and central_longitude != 0:
@@ -299,7 +297,7 @@ def create_parcelsfig_axis(spherical, land=True, projection=None, central_longit
299297
if isinstance(land, str):
300298
ax.coastlines(land)
301299
elif land:
302-
ax.coastlines()
300+
ax.coastlines(zorder=10)
303301
else:
304302
cartopy = None
305303
fig, ax = plt.subplots(1, 1)

0 commit comments

Comments
 (0)