Skip to content

Commit

Permalink
DAS-2232 - updated notebook version due to Synk vulnerability. Also r…
Browse files Browse the repository at this point in the history
…emoved duplicate method
  • Loading branch information
sudha-murthy committed Sep 10, 2024
1 parent 2c93a4b commit dfb1e15
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 66 deletions.
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
#
harmony-py~=0.4.10
netCDF4~=1.6.4
notebook~=7.0.4
notebook~=7.2.2
xarray~=2023.9.0
7 changes: 5 additions & 2 deletions hoss/dimension_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_override_dimensions(
required_variables, 'coordinates'
)
return override_dimensions
except AttributeError as exception:
except AttributeError:
return set()


Expand Down Expand Up @@ -682,7 +682,10 @@ def get_dimension_bounds(
be returned.
"""
bounds = varinfo.get_variable(dimension_name).references.get('bounds')
try:
bounds = varinfo.get_variable(dimension_name).references.get('bounds')
except AttributeError:
bounds = None

if bounds is not None:
try:
Expand Down
79 changes: 16 additions & 63 deletions hoss/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ def get_spatial_index_ranges(
if len(override_dimensions) > 0:
for non_spatial_variable in non_spatial_variables:
index_ranges.update(
get_required_x_y_index_ranges(
get_projected_x_y_index_ranges(
non_spatial_variable,
varinfo,
dimensions_file,
override_dimensions,
index_ranges,
bounding_box=bounding_box,
shape_file_path=shape_file_path,
override_dimensions=override_dimensions,
)
)
return index_ranges
Expand All @@ -141,6 +141,7 @@ def get_projected_x_y_index_ranges(
index_ranges: IndexRanges,
bounding_box: BBox = None,
shape_file_path: str = None,
override_dimensions: 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 @@ -159,10 +160,19 @@ def get_projected_x_y_index_ranges(
projected coordinate points.
"""
projected_x, projected_y = get_projected_x_y_variables(
varinfo, non_spatial_variable
)

if len(override_dimensions) == 0:
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,
varinfo,
)
dimensions_file = override_dimensions_file
if (
projected_x is not None
and projected_y is not None
Expand Down Expand Up @@ -198,63 +208,6 @@ def get_projected_x_y_index_ranges(
return x_y_index_ranges


def get_required_x_y_index_ranges(
non_spatial_variable: str,
varinfo: VarInfoFromDmr,
coordinates_file: Dataset,
override_dimensions: Set[str],
index_ranges: IndexRanges,
bounding_box: BBox = None,
shape_file_path: str = None,
) -> IndexRanges:
"""This function returns a dictionary containing the minimum and maximum
index ranges for a pair of projection x and y coordinates, e.g.:
index_ranges = {'/x': (20, 42), '/y': (31, 53)}
First, the dimensions of the input, non-spatial variable are checked
for associated projection x and y coordinates. If these are present,
and they have not already been added to the `index_ranges` cache, the
extents of the input spatial subset are determined in these projected
coordinates. This requires the derivation of a minimum resolution of
the target grid in geographic coordinates. Points must be placed along
the exterior of the spatial subset shape. All points are then projected
from a geographic Coordinate Reference System (CRS) to the target grid
CRS. The minimum and maximum values are then derived from these
projected coordinate points.
"""
projected_x = 'projected_x'
projected_y = 'projected_y'
dimensions_file = update_dimension_variables(
coordinates_file,
override_dimensions,
varinfo,
)
crs = get_variable_crs(non_spatial_variable, varinfo)

x_y_extents = get_projected_x_y_extents(
dimensions_file[projected_x][:],
dimensions_file[projected_y][:],
crs,
shape_file=shape_file_path,
bounding_box=bounding_box,
)
x_index_ranges = get_dimension_index_range(
dimensions_file[projected_x][:],
x_y_extents['x_min'],
x_y_extents['x_max'],
)
y_index_ranges = get_dimension_index_range(
dimensions_file[projected_y][:],
x_y_extents['y_min'],
x_y_extents['y_max'],
)

x_y_index_ranges = {projected_y: y_index_ranges, projected_x: x_index_ranges}
return x_y_index_ranges


def get_geographic_index_range(
dimension: str,
varinfo: VarInfoFromDmr,
Expand Down

0 comments on commit dfb1e15

Please sign in to comment.