diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fb284a1..6e18044c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +### Changed +### Deprecated +### Removed +### Fixed +### Security + + +## [2.11.0] +### 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. +- Add a function to test ghrsst dataset ability to access variables when mask_and_scale is true. ### Changed ### Deprecated ### Removed diff --git a/podaac/subsetter/subset.py b/podaac/subsetter/subset.py index 2cc66381..d1b9e461 100644 --- a/podaac/subsetter/subset.py +++ b/podaac/subsetter/subset.py @@ -1134,6 +1134,38 @@ def decode_cf_datetime(num_dates, units, calendar=None, use_cftime=None): xarray.coding.times.decode_cf_datetime = decode_cf_datetime +def test_access_sst_dtime_values(datafile): + """ + Test accessing values of 'sst_dtime' variable in a NetCDF file. + + Parameters + ---------- + datafile (str): Path to the NetCDF file. + + Returns + ------- + access_successful (bool): True if 'sst_dtime' values are accessible, False otherwise. + """ + + nc_dataset, _, _ = open_as_nc_dataset(datafile) + args = { + 'decode_coords': False, + 'mask_and_scale': True, + 'decode_times': True + } + try: + with xr.open_dataset( + xr.backends.NetCDF4DataStore(nc_dataset), + **args + ) as dataset: + # pylint: disable=pointless-statement + for var_name in dataset.variables: + dataset[var_name].values + except (TypeError, ValueError, KeyError): + return False + return True + + def subset(file_to_subset: str, bbox: np.ndarray, output_file: str, variables: Union[List[str], str, None] = (), # pylint: disable=too-many-branches, disable=too-many-statements @@ -1239,14 +1271,10 @@ def subset(file_to_subset: str, bbox: np.ndarray, output_file: str, 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 + if getattr(time_var, 'long_name', None) == "reference time of sst file": + args['mask_and_scale'] = test_access_sst_dtime_values(file_to_subset) break - try: - if nc_dataset[time_variable].long_name == "reference time of sst file": - args['mask_and_scale'] = True - except AttributeError: - pass - if hdf_type == 'GPM': args['decode_times'] = False diff --git a/pyproject.toml b/pyproject.toml index e8cccef2..314290d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ [tool.poetry] name = "l2ss-py" -version = "2.12.0a0" +version = "2.11.0rc7" description = "L2 Subsetter Service" authors = ["podaac-tva "] license = "Apache-2.0"