Skip to content

Commit

Permalink
Merge pull request #1182 from ocefpaf/plotting_bug
Browse files Browse the repository at this point in the history
Projection is never None at this point of the code and the if-clause is ill defined
  • Loading branch information
erikvansebille authored Jun 17, 2022
2 parents edb1dd5 + df6872c commit 31f81d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion parcels/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ class CField(Structure):
pointer(self.grid.ctypes_struct))
return cstruct

def show(self, animation=False, show_time=None, domain=None, depth_level=0, projection=None, land=True,
def show(self, animation=False, show_time=None, domain=None, depth_level=0, projection='PlateCarree', land=True,
vmin=None, vmax=None, savefile=None, **kwargs):
"""Method to 'show' a Parcels Field
Expand Down
2 changes: 1 addition & 1 deletion parcels/particleset/baseparticleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
if verbose_progress:
pbar.close()

def show(self, with_particles=True, show_time=None, field=None, domain=None, projection=None,
def show(self, with_particles=True, show_time=None, field=None, domain=None, projection='PlateCarree',
land=True, vmin=None, vmax=None, savefile=None, animation=False, **kwargs):
"""Method to 'show' a Parcels ParticleSet
Expand Down
20 changes: 9 additions & 11 deletions parcels/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from parcels.tools.loggers import logger


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


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


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

if projection is not None and not spherical:
raise RuntimeError('projection not accepted when Field doesn''t have geographic coordinates')

if spherical:
if spherical and projection:
try:
import cartopy
except:
logger.info("Visualisation of field with geographic coordinates is not possible. Cartopy not found.")
return None, None, None, None # creating axes was not possible

projection = cartopy.crs.PlateCarree(central_longitude) if projection is None else projection
projection = cartopy.crs.PlateCarree(central_longitude) if projection == 'PlateCarree' else projection
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': projection})
try: # gridlines not supported for all projections
if isinstance(projection, cartopy.crs.PlateCarree) and central_longitude != 0:
Expand All @@ -299,7 +297,7 @@ def create_parcelsfig_axis(spherical, land=True, projection=None, central_longit
if isinstance(land, str):
ax.coastlines(land)
elif land:
ax.coastlines()
ax.coastlines(zorder=10)
else:
cartopy = None
fig, ax = plt.subplots(1, 1)
Expand Down

0 comments on commit 31f81d5

Please sign in to comment.