Skip to content

Commit

Permalink
Merge pull request Unidata#1267 from kgoebber/update_declarative_options
Browse files Browse the repository at this point in the history
adds functionality to obs declarative
  • Loading branch information
dopplershift committed Jan 12, 2020
2 parents ce72871 + 45be805 commit 2bc6af1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/metpy/plots/declarative.py
Expand Up @@ -1284,6 +1284,7 @@ class PlotObs(HasTraits):
* colors (optional)
* vector_field (optional)
* vector_field_color (optional)
* vector_field_length (optional)
* reduce_points (optional)
"""

Expand Down Expand Up @@ -1356,6 +1357,11 @@ class PlotObs(HasTraits):
vector_field_color = Unicode('black', allow_none=True)
vector_field_color.__doc__ = """String color name to plot the vector. (optional)"""

vector_field_length = Int(default_value=None, allow_none=True)
vector_field_length.__doc__ = """Integer value to set the length of the plotted vector.
(optional)
"""

reduce_points = Float(default_value=0)
reduce_points.__doc__ = """Float to reduce number of points plotted. (optional)"""

Expand Down Expand Up @@ -1493,8 +1499,12 @@ def _build(self):
color = self.colors[i]
else:
color = self.colors[0]
if self.formats[i] is not None:
mapper = getattr(wx_symbols, str(self.formats[i]), None)
if len(self.formats) > 1:
formats = self.formats[i]
else:
formats = self.formats[0]
if formats is not None:
mapper = getattr(wx_symbols, str(formats), None)
if mapper is not None:
self.handle.plot_symbol(location, data[ob_type][subset],
mapper, color=color)
Expand All @@ -1504,5 +1514,7 @@ def _build(self):
else:
self.handle.plot_parameter(location, data[ob_type][subset], color=color)
if self.vector_field[0] is not None:
kwargs = ({'length': self.vector_field_length}
if self.vector_field_length is not None else {})
self.handle.plot_barb(data[self.vector_field[0]][subset],
data[self.vector_field[1]][subset])
data[self.vector_field[1]][subset], **kwargs)
Binary file modified tests/plots/baseline/test_declarative_upa_obs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/plots/test_declarative.py
Expand Up @@ -536,6 +536,7 @@ def test_declarative_upa_obs():
obs.locations = ['NW', 'SW', 'NE']
obs.formats = [None, None, lambda v: format(v, '.0f')[:3]]
obs.vector_field = ('u_wind', 'v_wind')
obs.vector_field_length = 7
obs.reduce_points = 0

# Panel for plot with Map features
Expand Down

0 comments on commit 2bc6af1

Please sign in to comment.