Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Jul 8, 2024
2 parents e0917a4 + 9b1d9c1 commit 89c9d0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- [issue/267](https://github.com/podaac/l2ss-py/pull/261): Add xtrack and atrack dimension options for get_nd_indexers when bounding box subsetting is performed on SNDR.
- Fix temporal subsetting ghrsst dataset by adding time delta to time variable.
### Changed
### Deprecated
### Removed
Expand All @@ -18,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [issue/260](https://github.com/podaac/l2ss-py/pull/261): Add gpm cleanup function to add a timeMidScan variable if the timeMidScan variable isn't present. Function takes the years, months, days etc ScanTime variables and creates a single time variable using datetime.datetime library.
### Changed
- Update code to determin lat lon time variables
- Update code to determine lat lon time variables
- Update xarray version
- [pull/248](https://github.com/podaac/l2ss-py/pull/248): add Harmony extra_args.cut parameter to subset_params in service adapter
### Deprecated
Expand Down
22 changes: 12 additions & 10 deletions podaac/subsetter/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,9 @@ def build_cond(str_timestamp, compare):
timestamp = np.datetime64(timestamp) - epoch_datetime

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

return compare(time_data, timestamp)

Expand Down Expand Up @@ -1230,14 +1230,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')

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

try:
if nc_dataset[time_variable].long_name == "reference time of sst file":
Expand Down

0 comments on commit 89c9d0c

Please sign in to comment.