Skip to content

Commit

Permalink
add test for coverage and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Aug 8, 2020
1 parent 3a568bb commit e03c05f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/metpy/plots/declarative.py
Expand Up @@ -1305,12 +1305,14 @@ class PlotObs(HasTraits):
* time
* fields
* locations (optional)
* time_range (optional)
* time_window (optional)
* formats (optional)
* colors (optional)
* plot_units (optional)
* vector_field (optional)
* vector_field_color (optional)
* vector_field_length (optional)
* vector_plot_units (optional)
* reduce_points (optional)
"""

Expand Down Expand Up @@ -1397,14 +1399,14 @@ class PlotObs(HasTraits):
plot_units.__doc__ = """A list of the desired units to plot the fields in.
Setting this attribute will convert the units of the field variable to the given units for
plotting using the MetPy Units module, provided that units are attached to the DateFrame.
plotting using the MetPy Units module, provided that units are attached to the DataFrame.
"""

vector_plot_units = Unicode(default_value=None, allow_none=True)
vector_plot_units.__doc__ = """The desired units to plot the vector field in.
Setting this attribute will convert the units of the field variable to the given units for
plotting using the MetPy Units module, provided that units are attached to the DateFrame.
plotting using the MetPy Units module, provided that units are attached to the DataFrame.
"""

def clear(self):
Expand Down Expand Up @@ -1574,14 +1576,14 @@ def _build(self):
if self.vector_field[0] is not None:
vector_kwargs = {}
vector_kwargs['color'] = self.vector_field_color
if self.vector_plot_units is not None:
vector_kwargs['plot_units'] = self.vector_plot_units
vector_kwargs['plot_units'] = self.vector_plot_units
if hasattr(self.data, 'units') and (vector_kwargs['plot_units'] is not None):
u = (data[self.vector_field[0]][subset].values
* units(self.data.units[self.vector_field[0]]))
v = (data[self.vector_field[1]][subset].values
* units(self.data.units[self.vector_field[1]]))
else:
vector_kwargs.pop('plot_units')
u = data[self.vector_field[0]][subset]
v = data[self.vector_field[1]][subset]
if self.vector_field_length is not None:
Expand Down
5 changes: 2 additions & 3 deletions src/metpy/plots/station_plot.py
Expand Up @@ -185,6 +185,8 @@ def plot_parameter(self, location, parameter, formatter='.0f', **kwargs):
How to format the data as a string for plotting. If a string, it should be
compatible with the :func:`format` builtin. If a callable, this should take a
value and return a string. Defaults to '0.f'.
plot_units: `pint.unit`
Units to plot in (performing conversion if necessary). Defaults to given units.
kwargs
Additional keyword arguments to use for matplotlib's plotting functions.
Expand Down Expand Up @@ -348,9 +350,6 @@ def _scalar_plotting_units(scalar_value, plotting_units):
else:
raise ValueError('To convert to plotting units, units must be attached to '
'scalar value being converted.')

# Strip units, CartoPy transform doesn't like
scalar_value = np.array(scalar_value)
return scalar_value

def _make_kwargs(self, kwargs):
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 38 additions & 1 deletion tests/plots/test_declarative.py
Expand Up @@ -841,7 +841,8 @@ def test_attribute_error_station():
pc.draw()


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.022)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance={'2.1': 0.407}.get(MPL_VERSION, 0.022))
def test_declarative_sfc_obs_change_units():
"""Test making a surface observation plot."""
data = parse_metar_file(get_test_data('metar_20190701_1200.txt', as_file_obj=False),
Expand Down Expand Up @@ -874,6 +875,42 @@ def test_declarative_sfc_obs_change_units():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True,
tolerance={'2.1': 0.09}.get(MPL_VERSION, 0.022))
def test_declarative_multiple_sfc_obs_change_units():
"""Test making a surface observation plot."""
data = parse_metar_file(get_test_data('metar_20190701_1200.txt', as_file_obj=False),
year=2019, month=7)

obs = PlotObs()
obs.data = data
obs.time = datetime(2019, 7, 1, 12)
obs.time_window = timedelta(minutes=15)
obs.level = None
obs.fields = ['air_temperature', 'dew_point_temperature', 'air_pressure_at_sea_level']
obs.locations = ['NW', 'W', 'NE']
obs.colors = ['red', 'green', 'black']
obs.reduce_points = 0.75
obs.plot_units = ['degF', 'degF', None]

# Panel for plot with Map features
panel = MapPanel()
panel.layout = (1, 1, 1)
panel.projection = ccrs.PlateCarree()
panel.area = 'in'
panel.layers = ['states']
panel.plots = [obs]

# Bringing it all together
pc = PanelContainer()
pc.size = (12, 12)
pc.panels = [panel]

pc.draw()

return pc.figure


def test_save():
"""Test that our saving function works."""
pc = PanelContainer()
Expand Down

0 comments on commit e03c05f

Please sign in to comment.