From 033a8997dd77f61fc36fd4a9ce6a4cef15b6a654 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Thu, 14 Nov 2024 17:57:02 +0100 Subject: [PATCH] refactor --- compliance_checker/cf/cf_1_6.py | 17 ++++++++--------- compliance_checker/cf/util.py | 3 ++- compliance_checker/ioos.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compliance_checker/cf/cf_1_6.py b/compliance_checker/cf/cf_1_6.py index b2b96d8c..1a39171e 100644 --- a/compliance_checker/cf/cf_1_6.py +++ b/compliance_checker/cf/cf_1_6.py @@ -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__) @@ -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', @@ -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}"', @@ -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}", ) @@ -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}", ) @@ -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) @@ -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( diff --git a/compliance_checker/cf/util.py b/compliance_checker/cf/util.py index a8949d26..33290264 100644 --- a/compliance_checker/cf/util.py +++ b/compliance_checker/cf/util.py @@ -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 diff --git a/compliance_checker/ioos.py b/compliance_checker/ioos.py index cb70594b..c7d79e2d 100644 --- a/compliance_checker/ioos.py +++ b/compliance_checker/ioos.py @@ -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,