From 23514333eca82e998c14b5199447b0638c14b235 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:29:28 -0400 Subject: [PATCH] address a few warnings --- clisops/core/regrid.py | 2 +- clisops/utils/dataset_utils.py | 8 ++++---- tests/test_core_regrid.py | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/clisops/core/regrid.py b/clisops/core/regrid.py index 2672cfce..54b2ac6e 100644 --- a/clisops/core/regrid.py +++ b/clisops/core/regrid.py @@ -637,7 +637,7 @@ def detect_type(self) -> str: ) and all( [ - self.ds.dims[dim] > 2 + self.ds.sizes[dim] > 2 for dim in [ self.ds[self.lon_bnds].dims[-1], self.ds[self.lat_bnds].dims[-1], diff --git a/clisops/utils/dataset_utils.py b/clisops/utils/dataset_utils.py index 0005b0c2..2301240e 100644 --- a/clisops/utils/dataset_utils.py +++ b/clisops/utils/dataset_utils.py @@ -498,14 +498,14 @@ def reformat_SCRIP_to_CF(ds, keep_attrs=False): ( ds.grid_dims.values[1], ds.grid_dims.values[0], - ds.dims["grid_corners"], + ds.sizes["grid_corners"], ) ).astype(np.float32) lon_b = ds.grid_corner_lon.values.reshape( ( ds.grid_dims.values[1], ds.grid_dims.values[0], - ds.dims["grid_corners"], + ds.sizes["grid_corners"], ) ).astype(np.float32) lat_bnds = np.zeros((ds.grid_dims.values[1], 2), dtype=np.float32) @@ -996,7 +996,7 @@ def detect_gridtype(ds, lon, lat, lon_bnds=None, lat_bnds=None): and all([ds[bnds].ndim == 2 for bnds in [lon_bnds, lat_bnds]]) and all( [ - ds.dims[dim] > 2 + ds.sizes[dim] > 2 for dim in [ ds[lon_bnds].dims[-1], ds[lat_bnds].dims[-1], @@ -1008,7 +1008,7 @@ def detect_gridtype(ds, lon, lat, lon_bnds=None, lat_bnds=None): # rectilinear: bounds [nlat/nlon, 2] elif ( all([ds[bnds].ndim == 2 for bnds in [lon_bnds, lat_bnds]]) - and ds.dims[ds.cf.get_bounds_dim_name(lon)] == 2 + and ds.sizes[ds.cf.get_bounds_dim_name(lon)] == 2 ): return "regular_lat_lon" else: diff --git a/tests/test_core_regrid.py b/tests/test_core_regrid.py index 04a51938..fbf4975a 100644 --- a/tests/test_core_regrid.py +++ b/tests/test_core_regrid.py @@ -126,7 +126,7 @@ def test_grid_init_ds_tas_cordex(mini_esgf_data): assert grid.nlon == 225 assert grid.ncells == 45225 - ds = ds.drop(["lat", "lon", "lat_vertices", "lon_vertices"]) + ds = ds.drop_vars(["lat", "lon", "lat_vertices", "lon_vertices"]) with pytest.raises( Exception, match="The grid format is not supported.", @@ -566,7 +566,9 @@ def test_detect_duplicated_cells(mini_esgf_data): def test_subsetted_grid(mini_esgf_data): - ds = xr.open_dataset(mini_esgf_data["CMIP6_TAS_ONE_TIME_STEP"], use_cftime=True) + ds = xr.open_dataset( + mini_esgf_data["CMIP6_TAS_ONE_TIME_STEP"], use_cftime=True + ).load() area = (0.0, 10.0, 175.0, 90.0)