diff --git a/docs/conf.py b/docs/conf.py index c74b5798bdb..fe66522f5bc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,7 +15,6 @@ import metpy - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. diff --git a/docs/override_check.py b/docs/override_check.py index 1b8fa125a87..580b5b195f7 100644 --- a/docs/override_check.py +++ b/docs/override_check.py @@ -9,7 +9,6 @@ import os import sys - modules_to_skip = ['metpy.xarray'] diff --git a/examples/Advanced_Sounding.py b/examples/Advanced_Sounding.py index e6774224486..5ea7232da0c 100644 --- a/examples/Advanced_Sounding.py +++ b/examples/Advanced_Sounding.py @@ -18,7 +18,7 @@ import metpy.calc as mpcalc from metpy.cbook import get_test_data -from metpy.plots import add_metpy_logo, SkewT +from metpy.plots import SkewT, add_metpy_logo from metpy.units import units ########################################### diff --git a/examples/gridding/Natural_Neighbor_Verification.py b/examples/gridding/Natural_Neighbor_Verification.py index 5bbb6b1e9a4..28e7f45b1fc 100644 --- a/examples/gridding/Natural_Neighbor_Verification.py +++ b/examples/gridding/Natural_Neighbor_Verification.py @@ -51,7 +51,7 @@ # 8. Repeat steps 4 through 7 for each grid cell. import matplotlib.pyplot as plt import numpy as np -from scipy.spatial import ConvexHull, Delaunay, delaunay_plot_2d, Voronoi, voronoi_plot_2d +from scipy.spatial import ConvexHull, Delaunay, Voronoi, delaunay_plot_2d, voronoi_plot_2d from scipy.spatial.distance import euclidean from metpy.interpolate import geometry diff --git a/examples/gridding/Point_Interpolation.py b/examples/gridding/Point_Interpolation.py index 86336945765..d0f300b9a7a 100644 --- a/examples/gridding/Point_Interpolation.py +++ b/examples/gridding/Point_Interpolation.py @@ -15,8 +15,11 @@ import numpy as np from metpy.cbook import get_test_data -from metpy.interpolate import (interpolate_to_grid, remove_nan_observations, - remove_repeat_coordinates) +from metpy.interpolate import ( + interpolate_to_grid, + remove_nan_observations, + remove_repeat_coordinates, +) from metpy.plots import add_metpy_logo diff --git a/examples/plots/Hodograph_Inset.py b/examples/plots/Hodograph_Inset.py index 76d4d26a388..c7f4421a6ba 100644 --- a/examples/plots/Hodograph_Inset.py +++ b/examples/plots/Hodograph_Inset.py @@ -14,7 +14,7 @@ import metpy.calc as mpcalc from metpy.cbook import get_test_data -from metpy.plots import add_metpy_logo, Hodograph, SkewT +from metpy.plots import Hodograph, SkewT, add_metpy_logo from metpy.units import units ########################################### diff --git a/examples/plots/Mesonet_Stationplot.py b/examples/plots/Mesonet_Stationplot.py index d505eb05dc1..02b281f101a 100644 --- a/examples/plots/Mesonet_Stationplot.py +++ b/examples/plots/Mesonet_Stationplot.py @@ -17,7 +17,7 @@ import metpy.calc as mpcalc from metpy.cbook import get_test_data -from metpy.plots import add_metpy_logo, StationPlot +from metpy.plots import StationPlot, add_metpy_logo from metpy.units import units ########################################### diff --git a/examples/plots/Simple_Sounding.py b/examples/plots/Simple_Sounding.py index 05a80776b27..fb859db68d6 100644 --- a/examples/plots/Simple_Sounding.py +++ b/examples/plots/Simple_Sounding.py @@ -14,10 +14,9 @@ import metpy.calc as mpcalc from metpy.cbook import get_test_data -from metpy.plots import add_metpy_logo, SkewT +from metpy.plots import SkewT, add_metpy_logo from metpy.units import units - ########################################### # Change default to be better for skew-T diff --git a/examples/plots/Skew-T_Layout.py b/examples/plots/Skew-T_Layout.py index 449d23b7756..47543fe9ff6 100644 --- a/examples/plots/Skew-T_Layout.py +++ b/examples/plots/Skew-T_Layout.py @@ -14,7 +14,7 @@ import metpy.calc as mpcalc from metpy.cbook import get_test_data -from metpy.plots import add_metpy_logo, Hodograph, SkewT +from metpy.plots import Hodograph, SkewT, add_metpy_logo from metpy.units import units ########################################### diff --git a/examples/plots/Station_Plot.py b/examples/plots/Station_Plot.py index e542cacec91..6143dcd03fd 100644 --- a/examples/plots/Station_Plot.py +++ b/examples/plots/Station_Plot.py @@ -18,7 +18,7 @@ from metpy.calc import reduce_point_density from metpy.cbook import get_test_data from metpy.io import metar -from metpy.plots import add_metpy_logo, current_weather, sky_cover, StationPlot +from metpy.plots import StationPlot, add_metpy_logo, current_weather, sky_cover ########################################### # The setup diff --git a/examples/plots/Station_Plot_with_Layout.py b/examples/plots/Station_Plot_with_Layout.py index 613dda51ccf..3545b6a31b9 100644 --- a/examples/plots/Station_Plot_with_Layout.py +++ b/examples/plots/Station_Plot_with_Layout.py @@ -24,8 +24,13 @@ from metpy.calc import wind_components from metpy.cbook import get_test_data -from metpy.plots import (add_metpy_logo, simple_layout, StationPlot, - StationPlotLayout, wx_code_map) +from metpy.plots import ( + StationPlot, + StationPlotLayout, + add_metpy_logo, + simple_layout, + wx_code_map, +) from metpy.units import units ########################################### diff --git a/examples/plots/upperair_declarative.py b/examples/plots/upperair_declarative.py index ffe0753a1ff..86a8a18697f 100644 --- a/examples/plots/upperair_declarative.py +++ b/examples/plots/upperair_declarative.py @@ -19,7 +19,6 @@ import metpy.plots as mpplots from metpy.units import units - ######################################## # **Getting the data** # diff --git a/setup.cfg b/setup.cfg index ecdec2cf20d..2622d88e19c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -105,3 +105,14 @@ max-line-length = 95 match = (?!(test_|setup)).*\.py match-dir = (?!(build|docs|examples|tutorials|_nexrad_msgs))[^.].* convention = numpy + +[isort] +multi_line_output = 3 +include_trailing_comma = True +force_grid_wrap = 0 +use_parentheses = True +ensure_newline_before_comments = True +line_length = 95 +known_first_party = ["metpy"] +force_sort_within_sections = true +src_paths=src,ci,docs,examples,tests,tools,tutorials diff --git a/src/metpy/__init__.py b/src/metpy/__init__.py index ee1199205ec..2817b2520f0 100644 --- a/src/metpy/__init__.py +++ b/src/metpy/__init__.py @@ -33,5 +33,6 @@ from ._version import get_version # noqa: E402 from .xarray import * # noqa: F401, F403, E402 + __version__ = get_version() del get_version diff --git a/src/metpy/_version.py b/src/metpy/_version.py index 73d7e36e0f5..f2636656633 100644 --- a/src/metpy/_version.py +++ b/src/metpy/_version.py @@ -16,9 +16,9 @@ def get_version(): version_scheme='post-release', local_scheme='dirty-tag') except (ImportError, LookupError): try: - from importlib.metadata import version, PackageNotFoundError + from importlib.metadata import PackageNotFoundError, version except ImportError: # Can remove when we require Python > 3.7 - from importlib_metadata import version, PackageNotFoundError + from importlib_metadata import PackageNotFoundError, version try: return version(__package__) diff --git a/src/metpy/calc/cross_sections.py b/src/metpy/calc/cross_sections.py index bbae1520762..f9e00b33e7e 100644 --- a/src/metpy/calc/cross_sections.py +++ b/src/metpy/calc/cross_sections.py @@ -10,11 +10,11 @@ import numpy as np import xarray as xr -from .basic import coriolis_parameter -from .tools import first_derivative from ..package_tools import Exporter from ..units import units from ..xarray import check_axis, check_matching_coordinates +from .basic import coriolis_parameter +from .tools import first_derivative exporter = Exporter(globals()) diff --git a/src/metpy/calc/indices.py b/src/metpy/calc/indices.py index 1fda8c50b36..b08deb4892a 100644 --- a/src/metpy/calc/indices.py +++ b/src/metpy/calc/indices.py @@ -4,12 +4,12 @@ """Contains calculation of various derived indices.""" import numpy as np -from .thermo import mixing_ratio, saturation_vapor_pressure -from .tools import _remove_nans, get_layer from .. import constants as mpconsts from ..package_tools import Exporter from ..units import check_units, concatenate, units from ..xarray import preprocess_and_wrap +from .thermo import mixing_ratio, saturation_vapor_pressure +from .tools import _remove_nans, get_layer exporter = Exporter(globals()) diff --git a/src/metpy/calc/kinematics.py b/src/metpy/calc/kinematics.py index 1ee602fe85f..aa772d32bd5 100644 --- a/src/metpy/calc/kinematics.py +++ b/src/metpy/calc/kinematics.py @@ -5,11 +5,11 @@ import numpy as np from . import coriolis_parameter -from .tools import first_derivative, get_layer_heights, gradient from .. import constants as mpconsts from ..package_tools import Exporter from ..units import check_units, units from ..xarray import add_grid_arguments_from_xarray, preprocess_and_wrap +from .tools import first_derivative, get_layer_heights, gradient exporter = Exporter(globals()) diff --git a/src/metpy/calc/thermo.py b/src/metpy/calc/thermo.py index 99b82295599..1f0bba91a94 100644 --- a/src/metpy/calc/thermo.py +++ b/src/metpy/calc/thermo.py @@ -9,14 +9,21 @@ import scipy.optimize as so import xarray as xr -from .tools import (_greater_or_close, _less_or_close, _remove_nans, find_bounding_indices, - find_intersections, first_derivative, get_layer) from .. import constants as mpconsts from ..cbook import broadcast_indices from ..interpolate.one_dimension import interpolate_1d from ..package_tools import Exporter from ..units import check_units, concatenate, units from ..xarray import add_vertical_dim_from_xarray, preprocess_and_wrap +from .tools import ( + _greater_or_close, + _less_or_close, + _remove_nans, + find_bounding_indices, + find_intersections, + first_derivative, + get_layer, +) exporter = Exporter(globals()) diff --git a/src/metpy/calc/tools.py b/src/metpy/calc/tools.py index 049316746cb..e86708861e5 100644 --- a/src/metpy/calc/tools.py +++ b/src/metpy/calc/tools.py @@ -337,6 +337,7 @@ def _get_bound_pressure_height(pressure, bound, height=None, interpolate=True): """ # avoid circular import if basic.py ever imports something from tools.py from .basic import height_to_pressure_std, pressure_to_height_std + # Make sure pressure is monotonically decreasing sort_inds = np.argsort(pressure)[::-1] pressure = pressure[sort_inds] diff --git a/src/metpy/calc/turbulence.py b/src/metpy/calc/turbulence.py index 461ba0eeba1..f598ed8ac65 100644 --- a/src/metpy/calc/turbulence.py +++ b/src/metpy/calc/turbulence.py @@ -5,9 +5,9 @@ import numpy as np -from .tools import make_take from ..package_tools import Exporter from ..xarray import preprocess_and_wrap +from .tools import make_take exporter = Exporter(globals()) diff --git a/src/metpy/interpolate/grid.py b/src/metpy/interpolate/grid.py index 1e1ed468893..4f80b29adf2 100644 --- a/src/metpy/interpolate/grid.py +++ b/src/metpy/interpolate/grid.py @@ -5,10 +5,13 @@ import numpy as np -from .points import (interpolate_to_points, inverse_distance_to_points, - natural_neighbor_to_points) from ..package_tools import Exporter from ..pandas import preprocess_pandas +from .points import ( + interpolate_to_points, + inverse_distance_to_points, + natural_neighbor_to_points, +) exporter = Exporter(globals()) @@ -342,6 +345,7 @@ def interpolate_to_isosurface(level_var, interp_var, level, bottom_up_search=Tru """ from ..calc import find_bounding_indices + # Find index values above and below desired interpolated surface value above, below, good = find_bounding_indices(level_var, [level], axis=0, from_below=bottom_up_search) diff --git a/src/metpy/interpolate/points.py b/src/metpy/interpolate/points.py index 086fc5ddf86..437cc77ec5d 100644 --- a/src/metpy/interpolate/points.py +++ b/src/metpy/interpolate/points.py @@ -6,8 +6,8 @@ import logging import numpy as np -from scipy.interpolate import griddata, Rbf -from scipy.spatial import cKDTree, ConvexHull, Delaunay, qhull +from scipy.interpolate import Rbf, griddata +from scipy.spatial import ConvexHull, Delaunay, cKDTree, qhull from . import geometry, tools from ..package_tools import Exporter diff --git a/src/metpy/io/gini.py b/src/metpy/io/gini.py index 2f7b43a0892..403d01300e3 100644 --- a/src/metpy/io/gini.py +++ b/src/metpy/io/gini.py @@ -16,8 +16,8 @@ from xarray.backends.common import AbstractDataStore from xarray.core.utils import FrozenDict -from ._tools import Bits, IOBuffer, NamedStruct, open_as_needed, zlib_decompress_all_frames from ..package_tools import Exporter +from ._tools import Bits, IOBuffer, NamedStruct, open_as_needed, zlib_decompress_all_frames exporter = Exporter(globals()) log = logging.getLogger(__name__) diff --git a/src/metpy/io/metar.py b/src/metpy/io/metar.py index 67a60069431..e4f8f87dea3 100644 --- a/src/metpy/io/metar.py +++ b/src/metpy/io/metar.py @@ -10,13 +10,13 @@ import numpy as np import pandas as pd -from ._tools import open_as_needed -from .metar_parser import parse, ParseError -from .station_data import station_info from ..calc import altimeter_to_sea_level_pressure, wind_components from ..package_tools import Exporter from ..plots.wx_symbols import wx_code_map from ..units import units +from ._tools import open_as_needed +from .metar_parser import ParseError, parse +from .station_data import station_info exporter = Exporter(globals()) diff --git a/src/metpy/io/nexrad.py b/src/metpy/io/nexrad.py index f142f6cc64f..2db784e8953 100644 --- a/src/metpy/io/nexrad.py +++ b/src/metpy/io/nexrad.py @@ -4,7 +4,7 @@ """Support reading information from various NEXRAD formats.""" import bz2 -from collections import defaultdict, namedtuple, OrderedDict +from collections import OrderedDict, defaultdict, namedtuple import contextlib import datetime import logging @@ -17,9 +17,18 @@ import numpy as np from scipy.constants import day, milli -from ._tools import (Array, BitField, Bits, DictStruct, Enum, IOBuffer, NamedStruct, - open_as_needed, zlib_decompress_all_frames) from ..package_tools import Exporter +from ._tools import ( + Array, + BitField, + Bits, + DictStruct, + Enum, + IOBuffer, + NamedStruct, + open_as_needed, + zlib_decompress_all_frames, +) exporter = Exporter(globals()) diff --git a/src/metpy/plots/__init__.py b/src/metpy/plots/__init__.py index 7058aa6aab0..06f69e46062 100644 --- a/src/metpy/plots/__init__.py +++ b/src/metpy/plots/__init__.py @@ -7,8 +7,12 @@ # Trigger matplotlib wrappers from . import _mpl # noqa: F401 -from ._util import (add_metpy_logo, add_timestamp, add_unidata_logo, # noqa: F401 - convert_gempak_color) +from ._util import ( # noqa: F401 + add_metpy_logo, + add_timestamp, + add_unidata_logo, + convert_gempak_color, +) from .ctables import * # noqa: F403 from .declarative import * # noqa: F403 from .skewt import * # noqa: F403 diff --git a/src/metpy/plots/_mpl.py b/src/metpy/plots/_mpl.py index 084055111aa..926df15485d 100644 --- a/src/metpy/plots/_mpl.py +++ b/src/metpy/plots/_mpl.py @@ -3,18 +3,19 @@ # SPDX-License-Identifier: BSD-3-Clause """Functionality that we have upstreamed or will upstream into matplotlib.""" +# See if we need to patch in our own scattertext implementation +from matplotlib.axes import Axes # noqa: E402, I100, I202 + # See if we should monkey-patch Barbs for better pivot import matplotlib.transforms as transforms import numpy as np -# See if we need to patch in our own scattertext implementation -from matplotlib.axes import Axes # noqa: E402, I100, I202 if not hasattr(Axes, 'scattertext'): - import matplotlib.cbook as cbook - import matplotlib.transforms as mtransforms from matplotlib import rcParams from matplotlib.artist import allow_rasterization + import matplotlib.cbook as cbook from matplotlib.text import Text + import matplotlib.transforms as mtransforms def scattertext(self, x, y, texts, loc=(0, 0), **kw): """Add text to the axes. diff --git a/src/metpy/plots/cartopy_utils.py b/src/metpy/plots/cartopy_utils.py index a1ac1dc7a82..d518c60767a 100644 --- a/src/metpy/plots/cartopy_utils.py +++ b/src/metpy/plots/cartopy_utils.py @@ -24,6 +24,7 @@ def __init__(self, name, scale, **kwargs): def geometries(self): """Return an iterator of (shapely) geometries for this feature.""" import cartopy.io.shapereader as shapereader + # Ensure that the associated files are in the cache fname = f'{self.name}_{self.scaler.scale}' for extension in ['.dbf', '.shx']: diff --git a/src/metpy/plots/declarative.py b/src/metpy/plots/declarative.py index 5e2ddca56fa..08d309fdc66 100644 --- a/src/metpy/plots/declarative.py +++ b/src/metpy/plots/declarative.py @@ -8,16 +8,26 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd -from traitlets import (Any, Bool, Float, HasTraits, Instance, Int, List, observe, Tuple, - Unicode, Union) - -from . import ctables -from . import wx_symbols -from .cartopy_utils import import_cartopy -from .station_plot import StationPlot +from traitlets import ( + Any, + Bool, + Float, + HasTraits, + Instance, + Int, + List, + Tuple, + Unicode, + Union, + observe, +) + +from . import ctables, wx_symbols from ..calc import reduce_point_density from ..package_tools import Exporter from ..units import units +from .cartopy_utils import import_cartopy +from .station_plot import StationPlot ccrs = import_cartopy() exporter = Exporter(globals()) @@ -480,6 +490,7 @@ def lookup_projection(projection_code): def lookup_map_feature(feature_name): """Get a Cartopy map feature based on a name.""" import cartopy.feature as cfeature + from . import cartopy_utils name = feature_name.upper() diff --git a/src/metpy/plots/skewt.py b/src/metpy/plots/skewt.py index 91e01f62c30..95750545c60 100644 --- a/src/metpy/plots/skewt.py +++ b/src/metpy/plots/skewt.py @@ -22,12 +22,12 @@ import matplotlib.transforms as transforms import numpy as np -from ._util import colored_line from ..calc import dewpoint, dry_lapse, el, lcl, moist_lapse, vapor_pressure from ..calc.tools import _delete_masked_points from ..interpolate import interpolate_1d from ..package_tools import Exporter from ..units import concatenate, units +from ._util import colored_line exporter = Exporter(globals()) diff --git a/src/metpy/plots/station_plot.py b/src/metpy/plots/station_plot.py index 70e83fa4c77..64c2a9d9ff6 100644 --- a/src/metpy/plots/station_plot.py +++ b/src/metpy/plots/station_plot.py @@ -7,9 +7,16 @@ import numpy as np -from .wx_symbols import (current_weather, high_clouds, low_clouds, mid_clouds, - pressure_tendency, sky_cover, wx_symbol_font) from ..package_tools import Exporter +from .wx_symbols import ( + current_weather, + high_clouds, + low_clouds, + mid_clouds, + pressure_tendency, + sky_cover, + wx_symbol_font, +) exporter = Exporter(globals()) diff --git a/src/metpy/plots/wx_symbols.py b/src/metpy/plots/wx_symbols.py index 99f9e981049..dafe5e9e1f5 100644 --- a/src/metpy/plots/wx_symbols.py +++ b/src/metpy/plots/wx_symbols.py @@ -7,8 +7,8 @@ """ try: - from importlib.resources import (files as importlib_resources_files, - as_file as importlib_resources_as_file) + from importlib.resources import as_file as importlib_resources_as_file + from importlib.resources import files as importlib_resources_files except ImportError: # Can remove when we require Python > 3.8 from importlib_resources import (files as importlib_resources_files, as_file as importlib_resources_as_file) diff --git a/src/metpy/testing.py b/src/metpy/testing.py index 103dc28febb..59e44263162 100644 --- a/src/metpy/testing.py +++ b/src/metpy/testing.py @@ -18,6 +18,7 @@ from metpy.calc import wind_components from metpy.cbook import get_test_data from metpy.deprecation import MetpyDeprecationWarning + from .units import units diff --git a/tests/calc/test_basic.py b/tests/calc/test_basic.py index 98ca54b43ba..8c15d9df21c 100644 --- a/tests/calc/test_basic.py +++ b/tests/calc/test_basic.py @@ -8,14 +8,30 @@ import pytest import xarray as xr -from metpy.calc import (add_height_to_pressure, add_pressure_to_height, - altimeter_to_sea_level_pressure, altimeter_to_station_pressure, - apparent_temperature, coriolis_parameter, geopotential_to_height, - heat_index, height_to_geopotential, height_to_pressure_std, - pressure_to_height_std, sigma_to_pressure, smooth_circular, - smooth_gaussian, smooth_n_point, smooth_rectangular, smooth_window, - wind_components, wind_direction, wind_speed, windchill) -from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal) +from metpy.calc import ( + add_height_to_pressure, + add_pressure_to_height, + altimeter_to_sea_level_pressure, + altimeter_to_station_pressure, + apparent_temperature, + coriolis_parameter, + geopotential_to_height, + heat_index, + height_to_geopotential, + height_to_pressure_std, + pressure_to_height_std, + sigma_to_pressure, + smooth_circular, + smooth_gaussian, + smooth_n_point, + smooth_rectangular, + smooth_window, + wind_components, + wind_direction, + wind_speed, + windchill, +) +from metpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal from metpy.units import units diff --git a/tests/calc/test_calc_tools.py b/tests/calc/test_calc_tools.py index 299ae865bcd..94e02435160 100644 --- a/tests/calc/test_calc_tools.py +++ b/tests/calc/test_calc_tools.py @@ -11,21 +11,44 @@ import pytest import xarray as xr -from metpy.calc import (angle_to_direction, find_bounding_indices, find_intersections, - first_derivative, get_layer, get_layer_heights, gradient, - laplacian, lat_lon_grid_deltas, nearest_intersection_idx, parse_angle, - pressure_to_height_std, reduce_point_density, resample_nn_1d, - second_derivative) -from metpy.calc.tools import (_delete_masked_points, _get_bound_pressure_height, - _greater_or_close, _less_or_close, _next_non_masked_element, - _remove_nans, azimuth_range_to_lat_lon, BASE_DEGREE_MULTIPLIER, - DIR_STRS, UND) -from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal, - needs_pyproj) +from metpy.calc import ( + angle_to_direction, + find_bounding_indices, + find_intersections, + first_derivative, + get_layer, + get_layer_heights, + gradient, + laplacian, + lat_lon_grid_deltas, + nearest_intersection_idx, + parse_angle, + pressure_to_height_std, + reduce_point_density, + resample_nn_1d, + second_derivative, +) +from metpy.calc.tools import ( + BASE_DEGREE_MULTIPLIER, + DIR_STRS, + UND, + _delete_masked_points, + _get_bound_pressure_height, + _greater_or_close, + _less_or_close, + _next_non_masked_element, + _remove_nans, + azimuth_range_to_lat_lon, +) +from metpy.testing import ( + assert_almost_equal, + assert_array_almost_equal, + assert_array_equal, + needs_pyproj, +) from metpy.units import units from metpy.xarray import grid_deltas_from_dataarray - FULL_CIRCLE_DEGREES = np.arange(0, 360, BASE_DEGREE_MULTIPLIER.m) * units.degree diff --git a/tests/calc/test_cross_sections.py b/tests/calc/test_cross_sections.py index 259a25d59d3..409f1c51bb3 100644 --- a/tests/calc/test_cross_sections.py +++ b/tests/calc/test_cross_sections.py @@ -7,10 +7,14 @@ import pytest import xarray as xr -from metpy.calc import (absolute_momentum, cross_section_components, normal_component, - tangential_component, unit_vectors_from_cross_section) -from metpy.calc.cross_sections import (distances_from_cross_section, - latitude_from_cross_section) +from metpy.calc import ( + absolute_momentum, + cross_section_components, + normal_component, + tangential_component, + unit_vectors_from_cross_section, +) +from metpy.calc.cross_sections import distances_from_cross_section, latitude_from_cross_section from metpy.interpolate import cross_section from metpy.testing import assert_array_almost_equal, assert_xarray_allclose, needs_cartopy from metpy.units import units diff --git a/tests/calc/test_indices.py b/tests/calc/test_indices.py index 568bd57a689..a6a3b56b59c 100644 --- a/tests/calc/test_indices.py +++ b/tests/calc/test_indices.py @@ -7,9 +7,15 @@ import numpy as np -from metpy.calc import (bulk_shear, bunkers_storm_motion, critical_angle, - mean_pressure_weighted, precipitable_water, - significant_tornado, supercell_composite) +from metpy.calc import ( + bulk_shear, + bunkers_storm_motion, + critical_angle, + mean_pressure_weighted, + precipitable_water, + significant_tornado, + supercell_composite, +) from metpy.testing import assert_almost_equal, assert_array_equal, get_upper_air_data from metpy.units import concatenate, units diff --git a/tests/calc/test_kinematics.py b/tests/calc/test_kinematics.py index 7ec51385da4..4c8702c8863 100644 --- a/tests/calc/test_kinematics.py +++ b/tests/calc/test_kinematics.py @@ -7,16 +7,37 @@ import pytest import xarray as xr -from metpy.calc import (absolute_vorticity, advection, ageostrophic_wind, - divergence, frontogenesis, geostrophic_wind, inertial_advective_wind, - lat_lon_grid_deltas, montgomery_streamfunction, - potential_temperature, potential_vorticity_baroclinic, - potential_vorticity_barotropic, q_vector, shearing_deformation, - static_stability, storm_relative_helicity, stretching_deformation, - total_deformation, vorticity, wind_components) -from metpy.constants import g, Re -from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal, - get_test_data, needs_cartopy, needs_pyproj) +from metpy.calc import ( + absolute_vorticity, + advection, + ageostrophic_wind, + divergence, + frontogenesis, + geostrophic_wind, + inertial_advective_wind, + lat_lon_grid_deltas, + montgomery_streamfunction, + potential_temperature, + potential_vorticity_baroclinic, + potential_vorticity_barotropic, + q_vector, + shearing_deformation, + static_stability, + storm_relative_helicity, + stretching_deformation, + total_deformation, + vorticity, + wind_components, +) +from metpy.constants import Re, g +from metpy.testing import ( + assert_almost_equal, + assert_array_almost_equal, + assert_array_equal, + get_test_data, + needs_cartopy, + needs_pyproj, +) from metpy.units import concatenate, units diff --git a/tests/calc/test_thermo.py b/tests/calc/test_thermo.py index 0d86574a20e..632079567bb 100644 --- a/tests/calc/test_thermo.py +++ b/tests/calc/test_thermo.py @@ -7,34 +7,62 @@ import pytest import xarray as xr -from metpy.calc import (brunt_vaisala_frequency, brunt_vaisala_frequency_squared, - brunt_vaisala_period, cape_cin, density, dewpoint, - dewpoint_from_relative_humidity, dewpoint_from_specific_humidity, - dry_lapse, dry_static_energy, el, equivalent_potential_temperature, - exner_function, gradient_richardson_number, isentropic_interpolation, - isentropic_interpolation_as_dataset, lcl, lfc, lifted_index, - mixed_layer, mixed_layer_cape_cin, mixed_parcel, mixing_ratio, - mixing_ratio_from_relative_humidity, - mixing_ratio_from_specific_humidity, moist_lapse, - moist_static_energy, most_unstable_cape_cin, most_unstable_parcel, - parcel_profile, parcel_profile_with_lcl, - parcel_profile_with_lcl_as_dataset, potential_temperature, - psychrometric_vapor_pressure_wet, - relative_humidity_from_dewpoint, - relative_humidity_from_mixing_ratio, - relative_humidity_from_specific_humidity, - relative_humidity_wet_psychrometric, - saturation_equivalent_potential_temperature, - saturation_mixing_ratio, - saturation_vapor_pressure, - specific_humidity_from_dewpoint, - specific_humidity_from_mixing_ratio, static_stability, - surface_based_cape_cin, temperature_from_potential_temperature, - thickness_hydrostatic, - thickness_hydrostatic_from_relative_humidity, vapor_pressure, - vertical_velocity, vertical_velocity_pressure, - virtual_potential_temperature, virtual_temperature, - wet_bulb_temperature) +from metpy.calc import ( + brunt_vaisala_frequency, + brunt_vaisala_frequency_squared, + brunt_vaisala_period, + cape_cin, + density, + dewpoint, + dewpoint_from_relative_humidity, + dewpoint_from_specific_humidity, + dry_lapse, + dry_static_energy, + el, + equivalent_potential_temperature, + exner_function, + gradient_richardson_number, + isentropic_interpolation, + isentropic_interpolation_as_dataset, + lcl, + lfc, + lifted_index, + mixed_layer, + mixed_layer_cape_cin, + mixed_parcel, + mixing_ratio, + mixing_ratio_from_relative_humidity, + mixing_ratio_from_specific_humidity, + moist_lapse, + moist_static_energy, + most_unstable_cape_cin, + most_unstable_parcel, + parcel_profile, + parcel_profile_with_lcl, + parcel_profile_with_lcl_as_dataset, + potential_temperature, + psychrometric_vapor_pressure_wet, + relative_humidity_from_dewpoint, + relative_humidity_from_mixing_ratio, + relative_humidity_from_specific_humidity, + relative_humidity_wet_psychrometric, + saturation_equivalent_potential_temperature, + saturation_mixing_ratio, + saturation_vapor_pressure, + specific_humidity_from_dewpoint, + specific_humidity_from_mixing_ratio, + static_stability, + surface_based_cape_cin, + temperature_from_potential_temperature, + thickness_hydrostatic, + thickness_hydrostatic_from_relative_humidity, + vapor_pressure, + vertical_velocity, + vertical_velocity_pressure, + virtual_potential_temperature, + virtual_temperature, + wet_bulb_temperature, +) from metpy.calc.thermo import _find_append_zero_crossings from metpy.testing import assert_almost_equal, assert_array_almost_equal, assert_nan from metpy.units import masked_array, units diff --git a/tests/interpolate/test_geometry.py b/tests/interpolate/test_geometry.py index 8dd4921107d..c9df2e9074a 100644 --- a/tests/interpolate/test_geometry.py +++ b/tests/interpolate/test_geometry.py @@ -10,10 +10,20 @@ from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal from scipy.spatial import Delaunay -from metpy.interpolate.geometry import (area, circumcenter, circumcircle_radius, dist_2, - distance, find_local_boundary, find_natural_neighbors, - find_nn_triangles_point, get_point_count_within_r, - get_points_within_r, order_edges, triangle_area) +from metpy.interpolate.geometry import ( + area, + circumcenter, + circumcircle_radius, + dist_2, + distance, + find_local_boundary, + find_natural_neighbors, + find_nn_triangles_point, + get_point_count_within_r, + get_points_within_r, + order_edges, + triangle_area, +) logging.getLogger('metpy.interpolate.geometry').setLevel(logging.ERROR) diff --git a/tests/interpolate/test_grid.py b/tests/interpolate/test_grid.py index 9eec547cbfb..b6778bd7622 100644 --- a/tests/interpolate/test_grid.py +++ b/tests/interpolate/test_grid.py @@ -12,10 +12,17 @@ import scipy from metpy.cbook import get_test_data -from metpy.interpolate.grid import (generate_grid, generate_grid_coords, get_boundary_coords, - get_xy_range, get_xy_steps, interpolate_to_grid, - interpolate_to_isosurface, inverse_distance_to_grid, - natural_neighbor_to_grid) +from metpy.interpolate.grid import ( + generate_grid, + generate_grid_coords, + get_boundary_coords, + get_xy_range, + get_xy_steps, + interpolate_to_grid, + interpolate_to_isosurface, + inverse_distance_to_grid, + natural_neighbor_to_grid, +) logging.getLogger('metpy.interpolate.grid').setLevel(logging.ERROR) diff --git a/tests/interpolate/test_interpolate_tools.py b/tests/interpolate/test_interpolate_tools.py index 51a97e7617e..5dfed766a0d 100644 --- a/tests/interpolate/test_interpolate_tools.py +++ b/tests/interpolate/test_interpolate_tools.py @@ -9,9 +9,12 @@ import pandas as pd import pytest -from metpy.interpolate import (interpolate_to_grid, remove_nan_observations, - remove_observations_below_value, - remove_repeat_coordinates) +from metpy.interpolate import ( + interpolate_to_grid, + remove_nan_observations, + remove_observations_below_value, + remove_repeat_coordinates, +) from metpy.interpolate.tools import barnes_weights, calc_kappa, cressman_weights diff --git a/tests/interpolate/test_points.py b/tests/interpolate/test_points.py index 9e2c6ee1c65..d327f32cd33 100644 --- a/tests/interpolate/test_points.py +++ b/tests/interpolate/test_points.py @@ -10,14 +10,16 @@ from numpy.testing import assert_almost_equal, assert_array_almost_equal import pytest import scipy -from scipy.spatial import cKDTree, Delaunay +from scipy.spatial import Delaunay, cKDTree from metpy.cbook import get_test_data -from metpy.interpolate import (interpolate_to_points, inverse_distance_to_points, - natural_neighbor_to_points) +from metpy.interpolate import ( + interpolate_to_points, + inverse_distance_to_points, + natural_neighbor_to_points, +) from metpy.interpolate.geometry import dist_2, find_natural_neighbors -from metpy.interpolate.points import (barnes_point, cressman_point, - natural_neighbor_point) +from metpy.interpolate.points import barnes_point, cressman_point, natural_neighbor_point logging.getLogger('metpy.interpolate.points').setLevel(logging.ERROR) diff --git a/tests/io/test_nexrad.py b/tests/io/test_nexrad.py index dc8bb3e34d7..7ef8b6a9e73 100644 --- a/tests/io/test_nexrad.py +++ b/tests/io/test_nexrad.py @@ -11,8 +11,8 @@ import numpy as np import pytest -from metpy.cbook import get_test_data, POOCH -from metpy.io import is_precip_mode, Level2File, Level3File +from metpy.cbook import POOCH, get_test_data +from metpy.io import Level2File, Level3File, is_precip_mode # Turn off the warnings for tests logging.getLogger('metpy.io.nexrad').setLevel(logging.CRITICAL) diff --git a/tests/plots/test_cartopy_utils.py b/tests/plots/test_cartopy_utils.py index 598361b9acd..735be753e01 100644 --- a/tests/plots/test_cartopy_utils.py +++ b/tests/plots/test_cartopy_utils.py @@ -12,6 +12,7 @@ except ImportError: pass # No CartoPy from metpy.plots.cartopy_utils import import_cartopy + # Fixture to make sure we have the right backend from metpy.testing import set_agg_backend # noqa: F401, I202 @@ -80,6 +81,7 @@ def test_us_states_scales(ccrs): def test_cartopy_stub(monkeypatch): """Test that the CartoPy stub will issue an error if CartoPy is not present.""" import sys + # This makes sure that cartopy is not found monkeypatch.setitem(sys.modules, 'cartopy.crs', None) diff --git a/tests/plots/test_declarative.py b/tests/plots/test_declarative.py index 3956ebf583a..118746cd267 100644 --- a/tests/plots/test_declarative.py +++ b/tests/plots/test_declarative.py @@ -17,13 +17,20 @@ from metpy.cbook import get_test_data from metpy.io import GiniFile from metpy.io.metar import parse_metar_file -from metpy.plots import (BarbPlot, ContourPlot, FilledContourPlot, ImagePlot, MapPanel, - PanelContainer, PlotObs) +from metpy.plots import ( + BarbPlot, + ContourPlot, + FilledContourPlot, + ImagePlot, + MapPanel, + PanelContainer, + PlotObs, +) + # Fixtures to make sure we have the right backend from metpy.testing import needs_cartopy, needs_pyproj, set_agg_backend # noqa: F401, I202 from metpy.units import units - MPL_VERSION = matplotlib.__version__[:3] diff --git a/tests/plots/test_mpl.py b/tests/plots/test_mpl.py index 601b7822f96..2f5e26cd9ba 100644 --- a/tests/plots/test_mpl.py +++ b/tests/plots/test_mpl.py @@ -11,6 +11,7 @@ # Needed to trigger scattertext monkey-patching import metpy.plots # noqa: F401, I202 + # Fixture to make sure we have the right backend from metpy.testing import set_agg_backend # noqa: F401, I202 diff --git a/tests/plots/test_skewt.py b/tests/plots/test_skewt.py index 3afb26219eb..ddd83ce1d3f 100644 --- a/tests/plots/test_skewt.py +++ b/tests/plots/test_skewt.py @@ -10,6 +10,7 @@ import pytest from metpy.plots import Hodograph, SkewT + # Fixtures to make sure we have the right backend and consistent round from metpy.testing import set_agg_backend # noqa: F401, I202 from metpy.units import units diff --git a/tests/plots/test_station_plot.py b/tests/plots/test_station_plot.py index f84088eb6fc..320dd293906 100644 --- a/tests/plots/test_station_plot.py +++ b/tests/plots/test_station_plot.py @@ -9,13 +9,20 @@ import pandas as pd import pytest -from metpy.plots import (current_weather, high_clouds, nws_layout, simple_layout, - sky_cover, StationPlot, StationPlotLayout) +from metpy.plots import ( + StationPlot, + StationPlotLayout, + current_weather, + high_clouds, + nws_layout, + simple_layout, + sky_cover, +) + # Fixtures to make sure we have the right backend and consistent round from metpy.testing import set_agg_backend # noqa: F401, I202 from metpy.units import units - MPL_VERSION = matplotlib.__version__[:3] diff --git a/tests/plots/test_util.py b/tests/plots/test_util.py index 4cfd172dca3..2ca2153ee77 100644 --- a/tests/plots/test_util.py +++ b/tests/plots/test_util.py @@ -11,6 +11,7 @@ import pytest from metpy.plots import add_metpy_logo, add_timestamp, add_unidata_logo, convert_gempak_color + # Fixture to make sure we have the right backend from metpy.testing import set_agg_backend # noqa: F401, I202 diff --git a/tests/test_testing.py b/tests/test_testing.py index 9efd83ab50f..e5edf5c94a8 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -9,8 +9,11 @@ import xarray as xr from metpy.deprecation import MetpyDeprecationWarning -from metpy.testing import (assert_array_almost_equal, check_and_drop_units, - check_and_silence_deprecation) +from metpy.testing import ( + assert_array_almost_equal, + check_and_drop_units, + check_and_silence_deprecation, +) # Test #1183: numpy.testing.assert_array* ignores any masked value, so work-around diff --git a/tests/test_xarray.py b/tests/test_xarray.py index 6fa1537364d..cee60d9aff0 100644 --- a/tests/test_xarray.py +++ b/tests/test_xarray.py @@ -9,8 +9,13 @@ import xarray as xr from metpy.plots.mapping import CFProjection -from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_array_equal, - get_test_data, needs_cartopy) +from metpy.testing import ( + assert_almost_equal, + assert_array_almost_equal, + assert_array_equal, + get_test_data, + needs_cartopy, +) from metpy.units import DimensionalityError, units from metpy.xarray import ( add_grid_arguments_from_xarray, @@ -18,7 +23,7 @@ check_axis, check_matching_coordinates, grid_deltas_from_dataarray, - preprocess_and_wrap + preprocess_and_wrap, ) diff --git a/tests/units/test_units.py b/tests/units/test_units.py index 3a7035c3bb0..9a306235363 100644 --- a/tests/units/test_units.py +++ b/tests/units/test_units.py @@ -8,8 +8,12 @@ import pandas as pd import pytest -from metpy.testing import assert_array_almost_equal, assert_array_equal -from metpy.testing import assert_nan, set_agg_backend # noqa: F401 +from metpy.testing import ( # noqa: F401 + assert_array_almost_equal, + assert_array_equal, + assert_nan, + set_agg_backend, +) from metpy.units import check_units, concatenate, pandas_dataframe_to_unit_arrays, units