Skip to content

Commit

Permalink
DAS-2293: rename dropped_variables -> ExcludedScienceVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
flamingbear committed Feb 5, 2025
1 parent 58254ba commit 6acc701
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
14 changes: 7 additions & 7 deletions smap_l2_gridder/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
'Soil_Moisture_Retrieval_Data': {
**STANDARD_LOCATIONS,
**GRIDS['M09km'],
'dropped_variables': ['tb_time_utc'],
'ExcludedScienceVariables': ['tb_time_utc'],
},
'Soil_Moisture_Retrieval_Data_Polar': {
'row': 'Soil_Moisture_Retrieval_Data_Polar/EASE_row_index',
'col': 'Soil_Moisture_Retrieval_Data_Polar/EASE_column_index',
**GRIDS['N09km'],
'dropped_variables': ['tb_time_utc'],
'ExcludedScienceVariables': ['tb_time_utc'],
},
},
},
Expand All @@ -52,13 +52,13 @@
'Soil_Moisture_Retrieval_Data': {
**STANDARD_LOCATIONS,
**GRIDS['M09km'],
'dropped_variables': ['spacecraft_overpass_time_utc'],
'ExcludedScienceVariables': ['spacecraft_overpass_time_utc'],
},
'Soil_Moisture_Retrieval_Data_3km': {
'row': 'Soil_Moisture_Retrieval_Data_3km/EASE_row_index_3km',
'col': 'Soil_Moisture_Retrieval_Data_3km/EASE_column_index_3km',
**GRIDS['M03km'],
'dropped_variables': ['spacecraft_overpass_time_utc'],
'ExcludedScienceVariables': ['spacecraft_overpass_time_utc'],
},
},
},
Expand All @@ -70,7 +70,7 @@
'Soil_Moisture_Retrieval_Data': {
**STANDARD_LOCATIONS,
**GRIDS['M03km'],
'dropped_variables': ['spacecraft_overpass_time_utc'],
'ExcludedScienceVariables': ['spacecraft_overpass_time_utc'],
},
},
},
Expand Down Expand Up @@ -120,11 +120,11 @@ def get_collection_group_info(short_name: str, group: str) -> dict:
return group_info


def get_dropped_variables(short_name: str, group: str) -> set[str]:
def get_excluded_science_variables(short_name: str, group: str) -> set[str]:
"""Return a set of variables to be excluded from the processed file."""
try:
info = get_collection_group_info(short_name, group)
dropped_vars = info['dropped_variables']
dropped_vars = info['ExcludedScienceVariables']
return set(dropped_vars)
except KeyError:
return set()
6 changes: 3 additions & 3 deletions smap_l2_gridder/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .collections import (
get_collection_group_info,
get_collection_info,
get_dropped_variables,
get_excluded_science_variables,
)
from .crs import compute_dims, create_crs, parse_gpd_file

Expand Down Expand Up @@ -143,8 +143,8 @@ def get_target_variables(
in_data: DataTree, group: str, short_name: str
) -> Iterable[str]:
"""Get variables to be regridded in the output file."""
dropped_variables = get_dropped_variables(short_name, group)
return set(in_data[group].data_vars) - set(dropped_variables)
excluded_science_variables = get_excluded_science_variables(short_name, group)
return set(in_data[group].data_vars) - set(excluded_science_variables)


def get_grid_information(in_dt: DataTree, group: str, short_name: str) -> dict:
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
InvalidCollectionError,
get_collection_group_info,
get_collection_info,
get_dropped_variables,
get_excluded_science_variables,
)


Expand Down Expand Up @@ -39,7 +39,7 @@ def mock_collection_info():
'col': 'path/to/col',
'gpd': 'test.gpd',
'epsg': 'EPSG:test',
'dropped_variables': ['hot-variable1', 'hot-variable2'],
'ExcludedScienceVariables': ['hot-variable1', 'hot-variable2'],
}
},
},
Expand Down Expand Up @@ -89,21 +89,27 @@ def test_get_collection_group_info(mocker, mock_collection_info):
get_collection_group_info('invalid_sample_collection', 'invalid_sample_group')


def test_get_dropped_variables(mocker, mock_collection_info):
def test_get_excluded_science_variables(mocker, mock_collection_info):
"""Test dropped variable functionality."""
mocker.patch(
'smap_l2_gridder.collections.get_all_information',
return_value=mock_collection_info,
)

expected = set(['hot-variable1', 'hot-variable2'])
assert get_dropped_variables('sample2_collection', 'dropped_group_name') == expected
assert (
get_excluded_science_variables('sample2_collection', 'dropped_group_name')
== expected
)

expected = set()
assert get_dropped_variables('sample_collection', 'sample_group_name') == expected
assert (
get_excluded_science_variables('sample_collection', 'sample_group_name')
== expected
)

with pytest.raises(
InvalidCollectionError,
match='No collection information for invalid_collection_name',
):
get_dropped_variables('invalid_collection_name', 'group')
get_excluded_science_variables('invalid_collection_name', 'group')

0 comments on commit 6acc701

Please sign in to comment.