Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing handling of level in PlotObs #1524

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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