Skip to content

Commit

Permalink
Merge pull request #1524 from dopplershift/plot-obs-level
Browse files Browse the repository at this point in the history
Fixing handling of level in PlotObs
  • Loading branch information
dopplershift authored Oct 2, 2020
2 parents db2a433 + ae2aee0 commit 89fd4c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ class PlotObs(HasTraits):
parent = Instance(Panel)
_need_redraw = Bool(default_value=True)

level = Union([Int(allow_none=True), Instance(units.Quantity)])
level = Union([Int(allow_none=True), Instance(units.Quantity)], default_value=None)
level.__doc__ = """The level of the field to be plotted.
This is a value with units to choose the desired plot level. For example, selecting the
Expand Down Expand Up @@ -1463,7 +1463,8 @@ def obsdata(self):

# Subset for a particular level if given
if self.level is not None:
data = data[data.pressure == self.level.m]
mag = getattr(self.level, 'magnitude', self.level)
data = data[data.pressure == mag]

# Subset for our particular time
if self.time is not None:
Expand Down
14 changes: 13 additions & 1 deletion tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ def test_plotobs_subset_default_nolevel(sample_obs):
"""Test PlotObs subsetting with minimal config."""
obs = PlotObs()
obs.data = sample_obs
obs.level = None

truth = pd.DataFrame([('2020-08-06 13:00', 'KDEN', 500, 7, 15),
('2020-08-06 12:59', 'KOKC', 500, 8, 16)],
Expand All @@ -575,6 +574,19 @@ def test_plotobs_subset_level(sample_obs):
pd.testing.assert_frame_equal(obs.obsdata, truth)


def test_plotobs_subset_level_no_units(sample_obs):
"""Test PlotObs subsetting based on unitless level."""
obs = PlotObs()
obs.data = sample_obs
obs.level = 1000

truth = pd.DataFrame([('2020-08-06 13:00', 'KDEN', 1000, 5, 13),
('2020-08-06 12:59', 'KOKC', 1000, 6, 14)],
columns=['time', 'stid', 'pressure', 'temperature', 'dewpoint'],
index=[4, 5])
pd.testing.assert_frame_equal(obs.obsdata, truth)


def test_plotobs_subset_time(sample_obs):
"""Test PlotObs subsetting for a particular time."""
obs = PlotObs()
Expand Down

0 comments on commit 89fd4c0

Please sign in to comment.