Skip to content

Commit

Permalink
DAS-2232 - removed accidental checkin of an incomplete unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sudha-murthy committed Oct 4, 2024
1 parent 36e15c7 commit 5c5eb85
Showing 1 changed file with 0 additions and 148 deletions.
148 changes: 0 additions & 148 deletions tests/unit/test_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,154 +183,6 @@ def test_get_spatial_index_ranges_geographic(self):
{'/latitude': (5, 44), '/longitude': (160, 199)},
)

@patch('hoss.spatial.get_dimension_index_range')
@patch('hoss.spatial.get_projected_x_y_extents')
def test_get_x_y_index_ranges_from_coordinates(
self, mock_get_x_y_extents, mock_get_dimension_index_range
):
"""Ensure that x and y index ranges are only requested only when there are
no projected dimensions and when there are coordinate datasets,
and the values have not already been calculated.
The example used in this test is for the SMAP SPL3SMP collection,
(SMAP L3 Radiometer Global Daily 36 km EASE-Grid Soil Moisture)
which has a Equal-Area Scalable Earth Grid (EASE-Grid 2.0) CRS for
a projected grid which is lambert_cylindrical_equal_area projection
"""
smap_varinfo = VarInfoFromDmr(
'tests/data/SC_SPL3SMP_009.dmr',
'SPL3SMP',
'hoss/hoss_config.json',
)
smap_file_path = 'tests/data/SC_SPL3SMP_009_prefetch.nc4'
expected_index_ranges = {'projected_x': (487, 595), 'projected_y': (9, 38)}
bbox = BBox(2, 54, 42, 72)

latitude_coordinate = smap_varinfo.get_variable(
'/Soil_Moisture_Retrieval_Data_AM/latitude'
)
longitude_coordinate = smap_varinfo.get_variable(
'/Soil_Moisture_Retrieval_Data_AM/longitude'
)

crs = CRS.from_cf(
{
'false_easting': 0.0,
'false_northing': 0.0,
'longitude_of_central_meridian': 0.0,
'standard_parallel': 30.0,
'grid_mapping_name': 'lambert_cylindrical_equal_area',
}
)

x_y_extents = {
'x_min': 192972.56050179302,
'x_max': 4052423.7705376535,
'y_min': 5930779.396449475,
'y_max': 6979878.9118312765,
}

mock_get_x_y_extents.return_value = x_y_extents

# When ranges are derived, they are first calculated for x, then y:
mock_get_dimension_index_range.side_effect = [(487, 595), (9, 38)]

with self.subTest(
'Projected grid from coordinates gets expected dimension ranges'
):
with Dataset(smap_file_path, 'r') as smap_prefetch:
self.assertDictEqual(
get_x_y_index_ranges_from_coordinates(
'/Soil_Moisture_Retrieval_Data_AM/surface_flag',
smap_varinfo,
smap_prefetch,
latitude_coordinate,
longitude_coordinate,
{},
bounding_box=bbox,
shape_file_path=None,
),
expected_index_ranges,
)

# Assertions don't like direct comparisons of numpy arrays, so
# have to extract the call arguments and compare those
mock_get_x_y_extents.assert_called_once_with(
ANY, ANY, crs, shape_file=None, bounding_box=bbox
)

actual_x_values = mock_get_x_y_extents.call_args_list[0][0][0]
actual_y_values = mock_get_x_y_extents.call_args_list[0][0][1]

assert_array_equal(actual_x_values, smap_prefetch['projected_x'][:])
assert_array_equal(actual_y_values, smap_prefetch['projected_y'][:])

self.assertEqual(mock_get_dimension_index_range.call_count, 2)
mock_get_dimension_index_range.assert_has_calls(
[
call(
ANY,
x_y_extents['x_min'],
x_y_extents['x_max'],
bounds_values=None,
),
call(
ANY,
x_y_extents['y_min'],
x_y_extents['y_max'],
bounds_values=None,
),
]
)
assert_array_equal(
mock_get_dimension_index_range.call_args_list[0][0][0],
smap_prefetch['projected_x'][:],
)
assert_array_equal(
mock_get_dimension_index_range.call_args_list[1][0][0],
smap_prefetch['projected_y'][:],
)

mock_get_x_y_extents.reset_mock()
mock_get_dimension_index_range.reset_mock()

with self.subTest(
'Non projected grid with no coordinates not try to get index ranges'
):
with Dataset(smap_file_path, 'r') as smap_prefetch:
self.assertDictEqual(
get_x_y_index_ranges_from_coordinates(
'projected_x',
smap_varinfo,
smap_prefetch,
latitude_coordinate,
longitude_coordinate,
{},
bounding_box=bbox,
),
{},
)

mock_get_x_y_extents.assert_not_called()
mock_get_dimension_index_range.assert_not_called()

with self.subTest('Function does not rederive known index ranges'):
with Dataset(smap_file_path, 'r') as smap_prefetch:
self.assertDictEqual(
get_projected_x_y_index_ranges(
'Soil_Moisture_Retrieval_Data_AM/surface_flag',
smap_varinfo,
smap_prefetch,
expected_index_ranges,
bounding_box=bbox,
),
{},
)

mock_get_x_y_extents.assert_not_called()
mock_get_dimension_index_range.assert_not_called()

@patch('hoss.spatial.get_dimension_index_range')
@patch('hoss.spatial.get_projected_x_y_extents')
def test_get_projected_x_y_index_ranges(
Expand Down

0 comments on commit 5c5eb85

Please sign in to comment.