Skip to content

Commit

Permalink
DAS-2232 - added method to check for variables with no dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sudha-murthy committed Oct 3, 2024
1 parent 802fe0e commit 60fb22a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
14 changes: 14 additions & 0 deletions hoss/dimension_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ def get_override_projected_dimensions(
return override_dimensions


def get_variables_with_anonymous_dims(
varinfo: VarInfoFromDmr, required_variables: set[str]
) -> bool:
"""
returns the list of required variables without any
dimensions
"""
return set(
required_variable
for required_variable in required_variables
if len(varinfo.get_variable(required_variable).dimensions) == 0
)


def get_coordinate_variables(
varinfo: VarInfoFromDmr,
requested_variables: Set[str],
Expand Down
38 changes: 20 additions & 18 deletions hoss/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
get_dimension_bounds,
get_dimension_extents,
get_dimension_index_range,
get_variables_with_anonymous_dims,
update_dimension_variables,
)
from hoss.projection_utilities import (
Expand Down Expand Up @@ -121,25 +122,26 @@ def get_spatial_index_ranges(
shape_file_path=shape_file_path,
)
)

if (not geographic_dimensions) and (not projected_dimensions):
for non_spatial_variable in non_spatial_variables:
latitude_coordinates, longitude_coordinates = get_coordinate_variables(
varinfo, [non_spatial_variable]
)
if latitude_coordinates and longitude_coordinates:
index_ranges.update(
get_x_y_index_ranges_from_coordinates(
non_spatial_variable,
varinfo,
dimensions_file,
varinfo.get_variable(latitude_coordinates[0]),
varinfo.get_variable(longitude_coordinates[0]),
index_ranges,
bounding_box=bounding_box,
shape_file_path=shape_file_path,
)
variables_with_anonymous_dims = get_variables_with_anonymous_dims(
varinfo, required_variables
)
for variable_with_anonymous_dims in variables_with_anonymous_dims:
latitude_coordinates, longitude_coordinates = get_coordinate_variables(
varinfo, [variable_with_anonymous_dims]
)
if latitude_coordinates and longitude_coordinates:
index_ranges.update(
get_x_y_index_ranges_from_coordinates(
variable_with_anonymous_dims,
varinfo,
dimensions_file,
varinfo.get_variable(latitude_coordinates[0]),
varinfo.get_variable(longitude_coordinates[0]),
index_ranges,
bounding_box=bounding_box,
shape_file_path=shape_file_path,
)
)

return index_ranges

Expand Down

0 comments on commit 60fb22a

Please sign in to comment.