Skip to content

Commit

Permalink
adding tests and fixed some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anacmontoya committed Jul 30, 2024
1 parent 0388f76 commit 927bba5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from . import ctables, wx_symbols
from ._mpl import TextCollection
from .patheffects import (ColdFront, OccludedFront, WarmFront, StationaryFront)
from .patheffects import ColdFront, OccludedFront, WarmFront, StationaryFront

Check failure on line 23 in src/metpy/plots/declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I001 isort found an import in the wrong position Raw Output: ./src/metpy/plots/declarative.py:23:1: I001 isort found an import in the wrong position
from .cartopy_utils import import_cartopy
from .station_plot import StationPlot

Check failure on line 25 in src/metpy/plots/declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I005 isort found an unexpected missing import Raw Output: ./src/metpy/plots/declarative.py:25:1: I005 isort found an unexpected missing import
from ..calc import reduce_point_density, smooth_n_point, zoom_xarray
Expand Down Expand Up @@ -2183,7 +2183,6 @@ def _draw_strengths(self, text, lon, lat, color, offset=None):
offset : tuple (default: (0, 0))
A tuple containing the x- and y-offset of the label, respectively
"""
import math
if offset is None:
offset = tuple(x * self.label_fontsize * 0.8 for x in self.strength_offset)

Expand All @@ -2193,7 +2192,7 @@ def _draw_strengths(self, text, lon, lat, color, offset=None):
color=color,
offset=offset,
weight='demi',
size=math.floor(self.label_fontsize * 0.7),
size=int(self.label_fontsize * 0.7),
transform=ccrs.PlateCarree()))

def _draw_labels(self, text, lon, lat, color, offset=(0, 0)):
Expand Down
77 changes: 75 additions & 2 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

from metpy.calc import wind_speed
from metpy.cbook import get_test_data
from metpy.io import GiniFile
from metpy.io import (GiniFile, parse_wpc_surface_bulletin)

Check failure on line 20 in tests/plots/test_declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I001 isort found an import in the wrong position Raw Output: ./tests/plots/test_declarative.py:20:1: I001 isort found an import in the wrong position
from metpy.io.metar import parse_metar_file

Check failure on line 21 in tests/plots/test_declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I005 isort found an unexpected missing import Raw Output: ./tests/plots/test_declarative.py:21:1: I005 isort found an unexpected missing import
from metpy.plots import (ArrowPlot, BarbPlot, ContourPlot, FilledContourPlot, ImagePlot,
MapPanel, PanelContainer, PlotGeometry, PlotObs, RasterPlot)
MapPanel, PanelContainer, PlotGeometry, PlotObs, RasterPlot,

Check failure on line 23 in tests/plots/test_declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I001 isort found an import in the wrong position Raw Output: ./tests/plots/test_declarative.py:23:1: I001 isort found an import in the wrong position
PlotSurfaceAnalysis)

Check failure on line 24 in tests/plots/test_declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I001 isort found an import in the wrong position Raw Output: ./tests/plots/test_declarative.py:24:1: I001 isort found an import in the wrong position
from metpy.testing import needs_cartopy, version_check

Check failure on line 25 in tests/plots/test_declarative.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 I005 isort found an unexpected missing import Raw Output: ./tests/plots/test_declarative.py:25:1: I005 isort found an unexpected missing import
from metpy.units import units

Expand Down Expand Up @@ -2245,3 +2246,75 @@ def test_attribute_error_no_suggest():
panel = MapPanel()
panel.galaxy = 'Andromeda'
assert 'Perhaps you meant' not in str(excinfo.value)


@pytest.mark.mpl_image_compare(remove_text=False)
@needs_cartopy
def test_declarative_plot_surface_analysis_default():
"""Test that `PlotSurfaceAnalysis` correctly plots features and strengths."""
# WPC Surface Analysis Bulletin to plot
df = parse_wpc_surface_bulletin(get_test_data('WPC_sfc_fronts_20210628_1800.txt'))

# Plot geometries and strengths
ps = PlotSurfaceAnalysis()
ps.geometry = df['geometry']
ps.feature = df['feature']
ps.strength = df['strength']

# Place plot in a panel and container
panel = MapPanel()
panel.area = [-120, -80, 30, 70]
panel.projection = 'lcc'
panel.layers = ['lakes', 'land', 'ocean',
'states', 'coastline', 'borders']
panel.plots = [ps]

pc = PanelContainer()
pc.size = (12,8)
pc.panels = [panel]
pc.draw()

return pc.figure

Check warning

Code scanning / CodeQL

File is not always closed Warning test

File is opened but is not closed.

@pytest.mark.mpl_image_compare(remove_text=False)
@needs_cartopy
def test_declarative_plot_surface_analysis_custom():
"""Test customization traits of `PlotSurfaceAnalysis`."""
# WPC Surface Analysis Bulletin to plot
df = parse_wpc_surface_bulletin(get_test_data('WPC_sfc_fronts_20210628_1800.txt'))

# Plot geometries and strengths
ps = PlotSurfaceAnalysis()
ps.geometry = df['geometry']
ps.feature = df['feature']
ps.strength = df['strength']
#customize
ps.HIGH_color = '#377eb8'
ps.COLD_color = '#ff7f00'
ps.TROF_color = '#4daf4a'
ps.OCFNT_color = '#f781bf'
ps.WARM_color = '#a65628'
ps.LOW_color = '#984ea3'
ps.FRONT_markersize = 4
ps.FRONT_linewidth = 3
ps.HIGH_label = 'HIGH'
ps.LOW_label = 'LOW'
ps.TROF_linestyle = 'dotted'
ps.label_fontsize = 15
ps.TROF_linewidth = 5
ps.strength_offset = (0,1)

Check warning

Code scanning / CodeQL

File is not always closed Warning test

File is opened but is not closed.

# Place plot in a panel and container
panel = MapPanel()
panel.area = [-120, -80, 30, 70]
panel.projection = 'lcc'
panel.layers = ['lakes', 'land', 'ocean',
'states', 'coastline', 'borders']
panel.plots = [ps]

pc = PanelContainer()
pc.size = (12,8)
pc.panels = [panel]
pc.draw()

return pc.figure

0 comments on commit 927bba5

Please sign in to comment.