Skip to content

Commit

Permalink
DAS-2232 - changed override to coordinates and dimension_file to dime…
Browse files Browse the repository at this point in the history
…nsion_datasets for clarity
  • Loading branch information
sudha-murthy committed Sep 26, 2024
1 parent f836ee6 commit c35c8ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
23 changes: 11 additions & 12 deletions hoss/dimension_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def get_coordinate_variables(
requested_variables: Set[str],
) -> list[str]:
"""This method returns coordinate variables that are referenced
in the variables requested.
in the variables requested. It returns it in a specific order
[latitude, longitude]
"""

try:
Expand All @@ -152,7 +153,7 @@ def get_coordinate_variables(

def update_dimension_variables(
prefetch_dataset: Dataset,
required_dimensions: Set[str],
coordinates: Set[str],
varinfo: VarInfoFromDmr,
) -> Dict[str, ndarray]:
"""Generate artificial 1D dimensions variable for each
Expand All @@ -166,16 +167,14 @@ def update_dimension_variables(
(5) Generate the x-y dimscale array and return to the calling method
"""
for dimension_name in required_dimensions:
dimension_variable = varinfo.get_variable(dimension_name)
if prefetch_dataset[dimension_variable.full_name_path][:].ndim > 1:
col_size = prefetch_dataset[dimension_variable.full_name_path][:].shape[0]
row_size = prefetch_dataset[dimension_variable.full_name_path][:].shape[1]
crs = get_variable_crs(dimension_name, varinfo)

geo_grid_corners = get_geo_grid_corners(
prefetch_dataset, required_dimensions, varinfo
)
for coordinate_name in coordinates:
coordinate_variable = varinfo.get_variable(coordinate_name)
if prefetch_dataset[coordinate_variable.full_name_path][:].ndim > 1:
col_size = prefetch_dataset[coordinate_variable.full_name_path][:].shape[0]
row_size = prefetch_dataset[coordinate_variable.full_name_path][:].shape[1]
crs = get_variable_crs(coordinate_name, varinfo)

geo_grid_corners = get_geo_grid_corners(prefetch_dataset, coordinates, varinfo)

x_y_extents = get_x_y_extents_from_geographic_points(geo_grid_corners, crs)

Expand Down
31 changes: 17 additions & 14 deletions hoss/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_spatial_index_ranges(
index_ranges,
bounding_box=bounding_box,
shape_file_path=shape_file_path,
override_dimensions=coordinate_variables,
coordinates=coordinate_variables,
)
)
return index_ranges
Expand All @@ -134,11 +134,11 @@ def get_spatial_index_ranges(
def get_projected_x_y_index_ranges(
non_spatial_variable: str,
varinfo: VarInfoFromDmr,
dimensions_file: Dataset,
dimension_datasets: Dataset,
index_ranges: IndexRanges,
bounding_box: BBox = None,
shape_file_path: str = None,
override_dimensions: Set[str] = set(),
coordinates: Set[str] = set(),
) -> IndexRanges:
"""This function returns a dictionary containing the minimum and maximum
index ranges for a pair of projection x and y coordinates, e.g.:
Expand All @@ -157,19 +157,21 @@ def get_projected_x_y_index_ranges(
projected coordinate points.
"""
if not override_dimensions:
if not coordinates:
projected_x, projected_y = get_projected_x_y_variables(
varinfo, non_spatial_variable
)

else:
projected_x = 'projected_x'
projected_y = 'projected_y'
override_dimensions_file = update_dimension_variables(
dimensions_file,
override_dimensions,
override_dimension_datasets = update_dimension_variables(
dimension_datasets,
coordinates,
varinfo,
)
dimensions_file = override_dimensions_file
dimension_datasets = override_dimension_datasets

if (
projected_x is not None
and projected_y is not None
Expand All @@ -178,23 +180,24 @@ def get_projected_x_y_index_ranges(
crs = get_variable_crs(non_spatial_variable, varinfo)

x_y_extents = get_projected_x_y_extents(
dimensions_file[projected_x][:],
dimensions_file[projected_y][:],
dimension_datasets[projected_x][:],
dimension_datasets[projected_y][:],
crs,
shape_file=shape_file_path,
bounding_box=bounding_box,
)

x_bounds = get_dimension_bounds(projected_x, varinfo, dimensions_file)
y_bounds = get_dimension_bounds(projected_y, varinfo, dimensions_file)
x_bounds = get_dimension_bounds(projected_x, varinfo, dimension_datasets)
y_bounds = get_dimension_bounds(projected_y, varinfo, dimension_datasets)

x_index_ranges = get_dimension_index_range(
dimensions_file[projected_x][:],
dimension_datasets[projected_x][:],
x_y_extents['x_min'],
x_y_extents['x_max'],
bounds_values=x_bounds,
)
y_index_ranges = get_dimension_index_range(
dimensions_file[projected_y][:],
dimension_datasets[projected_y][:],
x_y_extents['y_min'],
x_y_extents['y_max'],
bounds_values=y_bounds,
Expand Down

0 comments on commit c35c8ee

Please sign in to comment.