Skip to content

Commit

Permalink
Merge pull request #1331 from kgoebber/new_add_scale
Browse files Browse the repository at this point in the history
Adds a scale attribute for declarative syntax
  • Loading branch information
dopplershift committed Jul 28, 2020
2 parents e420468 + c19ad48 commit c1ad2ac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,14 @@ class Plots2D(HasTraits):
plotting using the MetPy Units module.
"""

scale = Float(default_value=1e0)
scale.__doc__ = """Scale the field to be plotted by the value given.
This attribute will scale the field by multiplying by the scale. For example, to
scale vorticity to be whole values for contouring you could set the scale to 1e5, such that
the data values will be scaled by 10^5.
"""

@property
def _cmap_obj(self):
"""Return the colormap object.
Expand Down Expand Up @@ -929,7 +937,7 @@ def griddata(self):

if self.plot_units is not None:
data_subset = data_subset.metpy.convert_units(self.plot_units)
self._griddata = data_subset
self._griddata = data_subset * self.scale

return self._griddata

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,35 @@ def test_declarative_barb_earth_relative():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.612)
def test_declarative_gridded_scale():
"""Test making a contour plot."""
import numpy as np
data = xr.open_dataset(get_test_data('NAM_test.nc', as_file_obj=False))

contour = ContourPlot()
contour.data = data
contour.field = 'Geopotential_height_isobaric'
contour.level = 300 * units.hPa
contour.linewidth = 2
contour.contours = np.arange(0, 2000, 12).tolist()
contour.scale = 1e-1
contour.clabels = True

panel = MapPanel()
panel.area = (-124, -72, 20, 53)
panel.projection = 'lcc'
panel.layers = ['coastline', 'borders', 'usstates']
panel.plots = [contour]

pc = PanelContainer()
pc.size = (8, 8)
pc.panels = [panel]
pc.draw()

return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.347)
def test_declarative_barb_gfs():
"""Test making a contour plot."""
Expand Down

0 comments on commit c1ad2ac

Please sign in to comment.