diff --git a/docs/requirements.txt b/docs/requirements.txt index dd7a29c..700910c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -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 diff --git a/hoss/dimension_utilities.py b/hoss/dimension_utilities.py index ae1b287..758c37b 100644 --- a/hoss/dimension_utilities.py +++ b/hoss/dimension_utilities.py @@ -74,7 +74,7 @@ def get_override_dimensions( required_variables, 'coordinates' ) return override_dimensions - except AttributeError as exception: + except AttributeError: return set() @@ -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: diff --git a/hoss/spatial.py b/hoss/spatial.py index 69a02a3..8a88dfe 100644 --- a/hoss/spatial.py +++ b/hoss/spatial.py @@ -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 @@ -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.: @@ -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 @@ -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,