Skip to content

Commit

Permalink
optimize mask and scale code
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Jul 8, 2024
1 parent 52dc007 commit 9b1d9c1
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions podaac/subsetter/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,9 @@ def build_cond(str_timestamp, compare):
timestamp = np.datetime64(timestamp) - epoch_datetime

time_data = dataset[time_var_name]
try:
if dataset[time_var_name].long_name == "reference time of sst file":
timedelta_seconds = dataset['sst_dtime'].astype('timedelta64[s]')
time_data = dataset[time_var_name] + timedelta_seconds
except AttributeError:
pass
if getattr(time_data, 'long_name', None) == "reference time of sst file":
timedelta_seconds = dataset['sst_dtime'].astype('timedelta64[s]')
time_data = time_data + timedelta_seconds

return compare(time_data, timestamp)

Expand Down Expand Up @@ -1235,20 +1232,16 @@ def subset(file_to_subset: str, bbox: np.ndarray, output_file: str,

if min_time or max_time:
args['decode_times'] = True
# check fill value and dtype; we know that this will cause an integer Overflow with xarray
for time_variable in [v for v in nc_dataset.variables.keys() if 'time' in v]:
try:
if nc_dataset[time_variable].getncattr('_FillValue') == nc.default_fillvals.get('f8') and \
(nc_dataset[time_variable].dtype == 'float64') or (nc_dataset[time_variable].dtype == 'float32'):
args['mask_and_scale'] = True
except AttributeError:
pass
float_dtypes = ['float64', 'float32']
fill_value_f8 = nc.default_fillvals.get('f8')

try:
if nc_dataset[time_variable].long_name == "reference time of sst file":
args['mask_and_scale'] = True
except AttributeError:
pass
for time_variable in (v for v in nc_dataset.variables.keys() if 'time' in v):
time_var = nc_dataset[time_variable]

if (getattr(time_var, '_FillValue', None) == fill_value_f8 and time_var.dtype in float_dtypes) or \
(getattr(time_var, 'long_name', None) == "reference time of sst file"):
args['mask_and_scale'] = True
break

if hdf_type == 'GPM':
args['decode_times'] = False
Expand Down

0 comments on commit 9b1d9c1

Please sign in to comment.