Skip to content

Commit

Permalink
Make extend a parameter of clim. map plots
Browse files Browse the repository at this point in the history
Previously, all global and projection plots extended indexed
colormaps in both the min and max direction.  We don't necessarily
want that, for sea-ice variables in particular.  With this merge,
the `extend` parameter is available for modification and is set
to `"neither"` for sea-ice fields.
  • Loading branch information
xylar committed Oct 6, 2022
1 parent b41229d commit 3ee7152
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
6 changes: 4 additions & 2 deletions mpas_analysis/sea_ice/climatology_map_sea_ice_conc.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def _add_obs_tasks(self, seasons, comparisonGridNames, hemisphere,
groupLink='{}_conc'.format(hemisphere.lower()),
galleryName='Observations: SSM/I {}'.format(
prefix),
maskMinThreshold=minConcentration)
maskMinThreshold=minConcentration,
extend='neither')

self.add_subtask(subtask)

Expand Down Expand Up @@ -228,7 +229,8 @@ def _add_ref_tasks(self, seasons, comparisonGridNames, hemisphere,
groupSubtitle=None,
groupLink='{}_conc'.format(hemisphere.lower()),
galleryName=galleryName,
maskMinThreshold=minConcentration)
maskMinThreshold=minConcentration,
extend='neither')

self.add_subtask(subtask)

Expand Down
3 changes: 2 additions & 1 deletion mpas_analysis/sea_ice/climatology_map_sea_ice_thick.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def __init__(self, config, mpasClimatologyTask, hemisphere,
groupSubtitle=None,
groupLink=f'{hemisphere.lower()}_thick',
galleryName=galleryName,
maskMinThreshold=0)
maskMinThreshold=0,
extend='neither')

self.add_subtask(subtask)

Expand Down
18 changes: 14 additions & 4 deletions mpas_analysis/shared/plot/climatology_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def plot_global_comparison(
dpi=None,
lineWidth=1,
lineColor='black',
maxTitleLength=None):
maxTitleLength=None,
extend='both'):
"""
Plots a data set as a longitude/latitude map.
Expand Down Expand Up @@ -333,6 +334,10 @@ def plot_global_comparison(
the maximum number of characters in the title, beyond which it is
truncated with a trailing ellipsis. The default is from the
``maxTitleLength`` config option.
extend : {'neither', 'both', 'min', 'max'}, optional
Determines the ``contourf``-coloring of values that are outside the
range of the levels provided if using an indexed colormap.
"""
# Authors
# -------
Expand Down Expand Up @@ -361,7 +366,7 @@ def plot_panel(ax, title, array, colormap, norm, levels, ticks, contours,
zorder=1, rasterized=True)
else:
plotHandle = ax.contourf(Lons, Lats, array, cmap=colormap,
norm=norm, levels=levels, extend='both',
norm=norm, levels=levels, extend=extend,
transform=projection, zorder=1)

_add_land_lakes_coastline(ax)
Expand Down Expand Up @@ -463,7 +468,8 @@ def plot_projection_comparison(
cartopyGridFontSize=None,
defaultFontSize=None,
vertical=False,
maxTitleLength=None):
maxTitleLength=None,
extend='both'):
"""
Plots a data set as a projection map.
Expand Down Expand Up @@ -528,6 +534,10 @@ def plot_projection_comparison(
the maximum number of characters in the title, beyond which it is
truncated with a trailing ellipsis. The default is from the
``maxTitleLength`` config option.
extend : {'neither', 'both', 'min', 'max'}, optional
Determines the ``contourf``-coloring of values that are outside the
range of the levels provided if using an indexed colormap.
"""
# Authors
# -------
Expand Down Expand Up @@ -580,7 +590,7 @@ def plot_panel(ax, title, array, colormap, norm, levels, ticks, contours,
rasterized=True)
else:
plotHandle = ax.contourf(xCenter, yCenter, array, cmap=colormap,
norm=norm, levels=levels, extend='both')
norm=norm, levels=levels, extend=extend)

if useCartopyCoastline:
_add_land_lakes_coastline(ax, ice_shelves=False)
Expand Down
20 changes: 17 additions & 3 deletions mpas_analysis/shared/plot/plot_climatology_map_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class PlotClimatologyMapSubtask(AnalysisTask):
maskMaxThreshold : float or None
a value above which the field is mask out in plots
extend : {'neither', 'both', 'min', 'max'}
Determines the ``contourf``-coloring of values that are outside the
range of the levels provided if using an indexed colormap.
"""

def __init__(self, parentTask, season, comparisonGridName,
Expand Down Expand Up @@ -214,13 +218,14 @@ def __init__(self, parentTask, season, comparisonGridName,
self.filePrefix = None
self.maskMinThreshold = None
self.maskMaxThreshold = None
self.extend = 'both'

def set_plot_info(self, outFileLabel, fieldNameInTitle, mpasFieldName,
refFieldName, refTitleLabel, unitsLabel,
imageCaption, galleryGroup, groupSubtitle, groupLink,
galleryName, diffTitleLabel='Model - Observations',
configSectionName=None, maskMinThreshold=None,
maskMaxThreshold=None):
maskMaxThreshold=None, extend=None):
"""
Store attributes related to plots, plot file names and HTML output.
Expand Down Expand Up @@ -274,6 +279,10 @@ def set_plot_info(self, outFileLabel, fieldNameInTitle, mpasFieldName,
maskMaxThreshold : float or None, optional
a value above which the field is mask out in plots
extend : {'neither', 'both', 'min', 'max'}, optional
Determines the ``contourf``-coloring of values that are outside the
range of the levels provided if using an indexed colormap.
"""

self.outFileLabel = outFileLabel
Expand Down Expand Up @@ -313,6 +322,9 @@ def set_plot_info(self, outFileLabel, fieldNameInTitle, mpasFieldName,
self.fieldNameInTitle = f'{fieldNameInTitle} at z={depth} m'
self.thumbnailDescription = f'{season} z={depth} m'

if extend is not None:
self.extend = extend

def setup_and_check(self):
"""
Perform steps to set up the analysis and check for errors in the setup.
Expand Down Expand Up @@ -529,7 +541,8 @@ def _plot_latlon(self, remappedModelClimatology, remappedRefClimatology,
diffTitle=self.diffTitleLabel,
cbarlabel=self.unitsLabel,
titleFontSize=titleFontSize,
defaultFontSize=defaultFontSize)
defaultFontSize=defaultFontSize,
extend=self.extend)

caption = f'{season} {self.imageCaption}'
write_image_xml(
Expand Down Expand Up @@ -631,7 +644,8 @@ def _plot_projection(self, remappedModelClimatology,
titleFontSize=titleFontSize,
cartopyGridFontSize=cartopyGridFontSize,
defaultFontSize=defaultFontSize,
vertical=vertical)
vertical=vertical,
extend=self.extend)

upperGridName = capwords(comparisonGridName.replace('_', ' '))
caption = f'{season} {self.imageCaption}'
Expand Down

0 comments on commit 3ee7152

Please sign in to comment.