Skip to content

Commit

Permalink
remove last bit of cf_units
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Nov 6, 2024
1 parent 4b8ab7e commit 191502d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions compliance_checker/cf/cf_1_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cftime
import numpy as np
import regex
from cf_units import Unit
from pyudunits2 import UnresolvableUnitException

from compliance_checker import cfutil
from compliance_checker.base import BaseCheck, Result, TestCtx
Expand Down Expand Up @@ -812,8 +812,8 @@ def _check_valid_cf_units(self, ds, variable_name):
)

try:
units_conv = Unit(units)
except ValueError:
units_conv = util._units(units)
except (ValueError, UnresolvableUnitException):
valid_units.messages.append(
f'Unit string "{units}" is not recognized by UDUnits',
)
Expand All @@ -828,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(Unit(reference)),
units_conv.is_convertible_to(util._units(reference)),
f'Units "{units}" for variable '
f"{variable_name} must be convertible to "
f'canonical units "{reference}"',
Expand Down Expand Up @@ -1494,7 +1494,8 @@ 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 Unit(units) == Unit("degree"),
units not in e_n_units
and util._units(units) == util._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,7 +1604,8 @@ 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 Unit(units) == Unit("degree"),
units not in e_n_units
and cfutil._units(units) == cfutil._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 @@ -1864,8 +1866,7 @@ def check_time_coordinate(self, ds):
ret_val.append(result)
# IMPLEMENTATION CONFORMANCE 4.4 RECOMMENDED 2/2
# catch non-recommended months or years time interval
unit = Unit(variable.units)
if unit.is_long_time_interval():
if any(unit in variable.units for unit in ("months", "years")):
message = f"Using relative time interval of months or years is not recommended for coordinate variable {variable.name}"
result = Result(
BaseCheck.MEDIUM,
Expand Down Expand Up @@ -2844,12 +2845,14 @@ 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 = Unit(cell_measure_var.units)
cell_measure_units = cfutil._units(cell_measure_var.units)
except ValueError:
valid = False
reasoning.append(conversion_failure_msg)
else:
if not cell_measure_units.is_convertible(Unit(f"m{exponent}")):
if not cell_measure_units.is_convertible_to(
cfutil._units(f"m{exponent}"),
):
valid = False
reasoning.append(conversion_failure_msg)
if not set(cell_measure_var.dimensions).issubset(var.dimensions):
Expand Down Expand Up @@ -3042,7 +3045,7 @@ def _check_cell_methods_paren_info(self, paren_contents, var):

# then the units
try:
Unit(interval_matches.group("interval_units"))
cfutil._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

0 comments on commit 191502d

Please sign in to comment.