Skip to content

Commit 0f1b710

Browse files
committed
DAS-2326 Update comments
1 parent 7a3b9e9 commit 0f1b710

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
### Changed
44

55
- Change HOSS behavior to return NoDataException warning instead of a failed
6-
exception when the variable, spatial, temporal request does not return any data.
6+
exception when the variable, spatial, temporal request does not return any
7+
data. Also fix a bug where the out of range subset requests were reported
8+
with a default output.
79

810
## [v1.1.16] - 2025-11-17
911

hoss/dimension_utilities.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,12 @@ def get_dimension_indices_from_values(
347347
dimension_values = np.flip(dimension)
348348
dimension_indices = np.flip(dimension_indices)
349349

350-
# np.interp does not throw an exception if the extents are outside dimension range
351-
# It just returns the lowest index or highest index
352-
if (minimum_extent < dimension_values[0]) and (
353-
maximum_extent < dimension_values[0]
354-
):
355-
raise InvalidRequestedRange()
356-
if (minimum_extent > dimension_values[-1]) and (
357-
maximum_extent > dimension_values[-1]
358-
):
350+
# Check if the minimum and maximum extents are out of range of the dimension values.
351+
if minimum_extent < dimension_values[0] or maximum_extent > dimension_values[-1]:
359352
raise InvalidRequestedRange()
360353

354+
# np.interp does not throw an exception if the extents are outside dimension range
355+
# It just returns the lowest index or highest index.
361356
raw_indices = np.interp(dimension_range, dimension_values, dimension_indices)
362357

363358
if (raw_indices[0] == raw_indices[1]) and (raw_indices[0] % 1 == 0.5):
@@ -558,7 +553,7 @@ def get_requested_index_ranges(
558553
required_dimensions = varinfo.get_required_dimensions(required_variables)
559554

560555
dim_index_ranges = {}
561-
failed_dim_variables = set()
556+
out_of_range_dim_variables = set()
562557
with Dataset(dimensions_path, 'r') as dimensions_file:
563558
for dim in harmony_message.subset.dimensions:
564559
try:
@@ -589,11 +584,11 @@ def get_requested_index_ranges(
589584
# processing the other dimensions and raise exception for all the
590585
# dimensions that are invalid.
591586
except InvalidRequestedRange:
592-
failed_dim_variables.add(dim.name)
587+
out_of_range_dim_variables.add(dim.name)
593588

594-
if failed_dim_variables:
589+
if out_of_range_dim_variables:
595590
raise NoDataException(
596-
f'Input request outside supported dimension range for {failed_dim_variables}'
591+
f'Input request outside supported dimension range for {out_of_range_dim_variables}'
597592
)
598593

599594
return dim_index_ranges

hoss/subset.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def get_required_variables(
221221
# If request includes variable subsetting, check that all requested
222222
# variables exist in the granule.
223223
if requested_variables:
224-
# check if the requested variables are in the granule.
225224
check_requested_variables_in_granule(varinfo, requested_variables)
226225

227226
# Otherwise, if request is an index subset and no variables are requested,
@@ -245,7 +244,6 @@ def check_requested_variables_in_granule(
245244
if any of the requested variables are not in the granule.
246245
247246
"""
248-
249247
invalid_requested_variables = {
250248
variable_name
251249
for variable_name in requested_variables

tests/unit/test_spatial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_get_spatial_index_ranges_projected(self):
5959
{'/x': (37, 56), '/y': (7, 26)},
6060
)
6161
with self.subTest('Spatial request outside granule'):
62-
harmony_message = Message({'subset': {'bbox': [120, -68, 140, -70]}})
62+
harmony_message = Message({'subset': {'bbox': [120, -70, 140, -68]}})
6363
with self.assertRaises(NoDataException) as context:
6464
get_spatial_index_ranges(
6565
{'/NEE', '/x', '/y', '/time'},
@@ -150,6 +150,7 @@ def test_get_spatial_index_ranges_projected_from_coordinates(self):
150150
),
151151
expected_index_ranges,
152152
)
153+
153154
with self.subTest('projection gridded with coordinates NoDataException'):
154155
harmony_message = Message(
155156
{'subset': {'bbox': [-179.9, -89.8, -179.8, -89.5]}}
@@ -363,7 +364,7 @@ def test_get_spatial_index_ranges_geographic(self):
363364
)
364365
self.assertEqual(
365366
context.exception.message,
366-
"Spatial subset request outside supported dimension range for {'/latitude'}",
367+
"Spatial subset request outside supported dimension range for {'/latitude', '/longitude'}",
367368
)
368369

369370
@patch('hoss.spatial.get_dimension_index_range')

0 commit comments

Comments
 (0)