Skip to content

Commit

Permalink
Adds a scale attribute for declarative syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Mar 2, 2020
1 parent 235b248 commit a88e240
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 it by ten to 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.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 @@ -419,6 +419,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.346)
def test_declarative_barb_gfs():
"""Test making a contour plot."""
Expand Down

0 comments on commit a88e240

Please sign in to comment.