Skip to content

Commit

Permalink
Pint update to stop warning (#747)
Browse files Browse the repository at this point in the history
* Fixing declaring new units with Pint.

* Commenting out return to stop warning

* PEP8

* Rolling back as this causes errors?
  • Loading branch information
kenkehoe committed Nov 7, 2023
1 parent cbfe7fd commit bcb8f62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions act/qc/bsrn_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion act/qc/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions act/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit bcb8f62

Please sign in to comment.