Skip to content

Commit

Permalink
add more changes so that we can temporally subset ghrsst dataset coll…
Browse files Browse the repository at this point in the history
…ections
  • Loading branch information
sliu008 committed Jul 15, 2024
1 parent 219a141 commit 2b7b68c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion podaac/subsetter/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,37 @@ 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
dataset['sst_dtime'].values
return True
except (TypeError, ValueError):
return False


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
Expand Down Expand Up @@ -1240,7 +1271,7 @@ 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
args['mask_and_scale'] = test_access_sst_dtime_values(file_to_subset)
break

if hdf_type == 'GPM':
Expand Down

0 comments on commit 2b7b68c

Please sign in to comment.