Skip to content

Commit

Permalink
DAS-2232 - fixed get_variable_crs and a few minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
sudha-murthy committed Sep 26, 2024
1 parent 756f7c0 commit 53f1660
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions hoss/dimension_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ def get_prefetch_variables(
required_dimensions = varinfo.get_required_dimensions(required_variables)
if not required_dimensions:
coordinate_variables = get_coordinate_variables(varinfo, required_variables)
logger.info('coordinates: ' f'{coordinate_variables}')
required_dimensions = set(coordinate_variables)
logger.info('required_dimensions: ' f'{required_dimensions}')

bounds = varinfo.get_references_for_attribute(required_dimensions, 'bounds')
required_dimensions.update(bounds)

Expand Down
12 changes: 7 additions & 5 deletions hoss/projection_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ def get_variable_crs(variable: str, varinfo: VarInfoFromDmr) -> CRS:
if grid_mapping is not None:
try:
grid_mapping_variable = varinfo.get_variable(grid_mapping)
if grid_mapping_variable is None:
if grid_mapping_variable is not None:
cf_attributes = grid_mapping_variable.attributes
else:
# check for any overrides
cf_attributes = varinfo.get_missing_variable_attributes(grid_mapping)
if cf_attributes:
crs = CRS.from_cf(cf_attributes)
return crs

crs = CRS.from_cf(varinfo.get_variable(grid_mapping).attributes)
if cf_attributes:
crs = CRS.from_cf(cf_attributes)
else:
raise MissingGridMappingVariable(grid_mapping, variable)

except AttributeError as exception:
raise MissingGridMappingVariable(grid_mapping, variable) from exception
Expand Down
6 changes: 3 additions & 3 deletions hoss/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_spatial_index_ranges(
)

with Dataset(dimensions_path, 'r') as dimensions_file:
if len(geographic_dimensions) > 0:
if geographic_dimensions:
# If there is no bounding box, but there is a shape file, calculate
# a bounding box to encapsulate the GeoJSON shape:
if bounding_box is None and shape_file_path is not None:
Expand All @@ -104,7 +104,7 @@ def get_spatial_index_ranges(
index_ranges[dimension] = get_geographic_index_range(
dimension, varinfo, dimensions_file, bounding_box
)
if len(projected_dimensions) > 0:
if projected_dimensions:
for non_spatial_variable in non_spatial_variables:
index_ranges.update(
get_projected_x_y_index_ranges(
Expand All @@ -116,7 +116,7 @@ def get_spatial_index_ranges(
shape_file_path=shape_file_path,
)
)
if len(geographic_dimensions) == 0 and len(projected_dimensions) == 0:
if (not geographic_dimensions) and (not projected_dimensions):
coordinate_variables = get_coordinate_variables(varinfo, required_variables)
if coordinate_variables:
for non_spatial_variable in non_spatial_variables:
Expand Down

0 comments on commit 53f1660

Please sign in to comment.