Skip to content

Commit

Permalink
MNT: Change some top-level imports to function-level (Fixes Unidata#1901
Browse files Browse the repository at this point in the history
)

This avoids importing metpy.calc and metpy.plots in the metar parsing
code, which improves import times for code that's only doing unrelated
I/O, as well as eliminates a warning when CartoPy is not installed.

The wx_code_map and wx_code_to_numeric function should eventually be
moved to metar.py, but that's an API change.
  • Loading branch information
dopplershift committed Jun 22, 2021
1 parent f56bdd2 commit acd279b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/metpy/io/metar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
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

exporter = Exporter(globals())
Expand Down Expand Up @@ -122,6 +120,8 @@ def parse_metar_to_dataframe(metar_text, *, year=None, month=None):
* 'northward_wind': Northward component (v-compoment) of the wind vector, measured in knots
"""
from ..calc import altimeter_to_sea_level_pressure, wind_components

# Defaults year and/or month to present reported date if not provided
if year is None or month is None:
now = datetime.now()
Expand Down Expand Up @@ -242,6 +242,8 @@ def parse_metar_to_named_tuple(metar_text, station_metadata, year, month):
Attachment IV
"""
from ..plots.wx_symbols import wx_code_map

# Decode the data using the parser (built using Canopy) the parser utilizes a grammar
# file which follows the format structure dictated by the WMO Handbook, but has the
# flexibility to decode the METAR text when there are missing or incorrectly
Expand Down Expand Up @@ -498,6 +500,8 @@ def parse_metar_file(filename, *, year=None, month=None):
* 'northward_wind': Northward component (v-compoment) of the wind vector, measured in knots
"""
from ..calc import altimeter_to_sea_level_pressure, wind_components

# Defaults year and/or month to present reported date if not provided
if year is None or month is None:
now = datetime.now()
Expand Down

0 comments on commit acd279b

Please sign in to comment.