Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix temporal ghrsst #279

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 16 additions & 9 deletions podaac/subsetter/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@ def build_cond(str_timestamp, compare):
epoch_datetime = dataset[epoch_time_var_name].values[0]
timestamp = np.datetime64(timestamp) - epoch_datetime

return compare(dataset[time_var_name], timestamp)
time_data = dataset[time_var_name]
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)

temporal_conds = []
if min_time:
Expand Down Expand Up @@ -1227,14 +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')

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
Loading