Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Nov 14, 2024
1 parent 9991912 commit 033a899
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
17 changes: 8 additions & 9 deletions compliance_checker/cf/cf_1_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
grid_mapping_dict16,
)
from compliance_checker.cf.cf_base import CFNCCheck, appendix_a_base
from compliance_checker.cfunits import _units

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -811,7 +812,7 @@ def _check_valid_cf_units(self, ds, variable_name):
)

try:
units_conv = cfutil._units(units)
units_conv = _units(units)
except ValueError:
valid_units.messages.append(
f'Unit string "{units}" is not recognized by UDUnits',
Expand All @@ -827,7 +828,7 @@ def _check_valid_cf_units(self, ds, variable_name):
# being expressed as "s"/seconds
if standard_name not in {"time", "forecast_reference_time"}:
valid_units.assert_true(
units_conv.is_convertible(cfutil._units(reference)),
units_conv.is_convertible(_units(reference)),
f'Units "{units}" for variable '
f"{variable_name} must be convertible to "
f'canonical units "{reference}"',
Expand Down Expand Up @@ -1493,8 +1494,7 @@ def check_latitude(self, ds):
# check that the units aren't in east and north degrees units,
# but are convertible to angular units
allowed_units.assert_true(
units not in e_n_units
and cfutil._units(units) == cfutil._units("degree"),
units not in e_n_units and _units(units) == _units("degree"),
f"Grid latitude variable '{latitude}' should use degree equivalent units without east or north components. "
f"Current units are {units}",
)
Expand Down Expand Up @@ -1603,8 +1603,7 @@ def check_longitude(self, ds):
# check that the units aren't in east and north degrees units,
# but are convertible to angular units
allowed_units.assert_true(
units not in e_n_units
and cfutil._units(units) == cfutil._units("degree"),
units not in e_n_units and _units(units) == _units("degree"),
f"Grid longitude variable '{longitude}' should use degree equivalent units without east or north components. "
f"Current units are {units}",
)
Expand Down Expand Up @@ -2844,13 +2843,13 @@ def _cell_measures_core(self, ds, var, external_set, variable_template):
f'cell_methods attribute with a measure type of "{cell_measure_type}".'
)
try:
cell_measure_units = cfutil._units(cell_measure_var.units)
cell_measure_units = _units(cell_measure_var.units)
except ValueError:
valid = False
reasoning.append(conversion_failure_msg)
else:
if not cell_measure_units.is_convertible(
cfutil._units(f"m{exponent}"),
_units(f"m{exponent}"),
):
valid = False
reasoning.append(conversion_failure_msg)
Expand Down Expand Up @@ -3044,7 +3043,7 @@ def _check_cell_methods_paren_info(self, paren_contents, var):

# then the units
try:
cfutil._units(interval_matches.group("interval_units"))
_units(interval_matches.group("interval_units"))
except ValueError:
valid_info.messages.append(
'§7.3.3 {}:cell_methods interval units "{}" is not parsable by UDUNITS.'.format(
Expand Down
3 changes: 2 additions & 1 deletion compliance_checker/cf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from lxml import etree
from netCDF4 import Dataset

from compliance_checker.cfutil import _units, units_convertible
from compliance_checker.cfunits import _units
from compliance_checker.cfutil import units_convertible

# copied from paegan
# paegan may depend on these later
Expand Down
2 changes: 1 addition & 1 deletion compliance_checker/ioos.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
)
from compliance_checker.cf import util as cf_util # not to be confused with cfutil.py
from compliance_checker.cf.cf import CF1_6Check, CF1_7Check
from compliance_checker.cfunits import _units
from compliance_checker.cfutil import (
_units,
get_geophysical_variables,
get_instrument_variables,
get_z_variables,
Expand Down

0 comments on commit 033a899

Please sign in to comment.