From bcb8f62e927b03513b71d3ffa7e1e4e1e9128c7d Mon Sep 17 00:00:00 2001 From: Ken Kehoe Date: Tue, 7 Nov 2023 11:28:47 -0700 Subject: [PATCH] Pint update to stop warning (#747) * Fixing declaring new units with Pint. * Commenting out return to stop warning * PEP8 * Rolling back as this causes errors? --- act/qc/bsrn_tests.py | 24 ++++++++++++------------ act/qc/clean.py | 2 +- act/utils/data_utils.py | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/act/qc/bsrn_tests.py b/act/qc/bsrn_tests.py index a135a8d31d..431fefdcf3 100644 --- a/act/qc/bsrn_tests.py +++ b/act/qc/bsrn_tests.py @@ -433,8 +433,8 @@ def bsrn_comparison_tests( with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=RuntimeWarning) if use_dask and isinstance(self._ds[glb_diffuse_SW_dn_name].data, da.Array): - sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].data + - self._ds[direct_normal_SW_dn_name].data * np.cos(np.radians(sza))) + sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].data + + self._ds[direct_normal_SW_dn_name].data * np.cos(np.radians(sza))) sum_sw_down[sum_sw_down < 50] = np.nan ratio = self._ds[gbl_SW_dn_name].data / sum_sw_down index_a = sza < 75 @@ -445,8 +445,8 @@ def bsrn_comparison_tests( index_4 = da.where((ratio < 0.85) & index_b, True, False) index = (index_1 | index_2 | index_3 | index_4).compute() else: - sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].values + - self._ds[direct_normal_SW_dn_name].values * np.cos(np.radians(sza))) + sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].values + + self._ds[direct_normal_SW_dn_name].values * np.cos(np.radians(sza))) sum_sw_down[sum_sw_down < 50] = np.nan ratio = self._ds[gbl_SW_dn_name].values / sum_sw_down index_a = sza < 75 @@ -505,14 +505,14 @@ def bsrn_comparison_tests( with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=RuntimeWarning) if use_dask and isinstance(self._ds[glb_diffuse_SW_dn_name].data, da.Array): - sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].data + - self._ds[direct_normal_SW_dn_name].data * np.cos(np.radians(sza))) + sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].data + + self._ds[direct_normal_SW_dn_name].data * np.cos(np.radians(sza))) sum_sw_down[sum_sw_down < 50] = np.nan index = da.where(self._ds[glb_SW_up_name].data > sum_sw_down, True, False).compute() else: - sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].values + - self._ds[direct_normal_SW_dn_name].values * np.cos(np.radians(sza))) + sum_sw_down = (self._ds[glb_diffuse_SW_dn_name].values + + self._ds[direct_normal_SW_dn_name].values * np.cos(np.radians(sza))) sum_sw_down[sum_sw_down < 50] = np.nan index = self._ds[glb_SW_up_name].values > sum_sw_down @@ -577,10 +577,10 @@ def bsrn_comparison_tests( f'for {test_options[3]} test.') if use_dask and isinstance(self._ds[glb_LW_dn_name].data, da.Array): - index_1 = da.where(self._ds[glb_LW_dn_name].data > - (self._ds[glb_LW_up_name].data + LWdn_lt_LWup_component), True, False) - index_2 = da.where(self._ds[glb_LW_dn_name].data < - (self._ds[glb_LW_up_name].data - LWdn_gt_LWup_component), True, False) + index_1 = da.where(self._ds[glb_LW_dn_name].data + > (self._ds[glb_LW_up_name].data + LWdn_lt_LWup_component), True, False) + index_2 = da.where(self._ds[glb_LW_dn_name].data + < (self._ds[glb_LW_up_name].data - LWdn_gt_LWup_component), True, False) index = (index_1 | index_2).compute() else: index_1 = self._ds[glb_LW_dn_name].values > (self._ds[glb_LW_up_name].values + LWdn_lt_LWup_component) diff --git a/act/qc/clean.py b/act/qc/clean.py index 224198094a..e1a7813e58 100644 --- a/act/qc/clean.py +++ b/act/qc/clean.py @@ -703,7 +703,7 @@ def clean_arm_qc( continue remove_test = True - test_number = int(parse_bit(flag_masks[ii])) + test_number = parse_bit(flag_masks[ii])[0] for attr_name in self._ds[qc_var_name].attrs: if test_attribute_limit_name == attr_name: remove_test = False diff --git a/act/utils/data_utils.py b/act/utils/data_utils.py index 29005f25fa..66242897f7 100644 --- a/act/utils/data_utils.py +++ b/act/utils/data_utils.py @@ -581,8 +581,8 @@ def convert_units(data, in_units, out_units): convert_dict = { 'C': 'degC', 'F': 'degF', - '%': 'percent', # seems like pint does not like this symbol? - '1': 'unitless', # seems like pint does not like this number? + '%': 'percent', # Pint does not like this symbol with .to('%') + '1': 'unitless', # Pint does not like a number } if in_units in convert_dict: @@ -597,9 +597,9 @@ def convert_units(data, in_units, out_units): # Instantiate the registry ureg = pint.UnitRegistry(autoconvert_offset_to_baseunit=True) - # Add missing units - ureg.define('percent = 0.01*count = %') - ureg.define('unitless = count = 1') + # Add missing units and conversions + ureg.define('fraction = []') + ureg.define('unitless = []') if not isinstance(data, np.ndarray): data = np.array(data)