From 502672f3cb4451b669bf7fc712974163a8215143 Mon Sep 17 00:00:00 2001 From: Fabien Maussion Date: Wed, 31 Jan 2024 20:43:05 +0000 Subject: [PATCH] Update CI and solve some deprecation warnings --- .github/workflows/run-tests.yml | 10 +++---- ...y37-all.yml => requirements-py311-all.yml} | 2 +- ...y38-min.yml => requirements-py311-min.yml} | 2 +- ...-py38-xr.yml => requirements-py311-xr.yml} | 2 +- ...y39-all.yml => requirements-py312-all.yml} | 2 +- ci/requirements-py38-all-rc.yml | 28 ------------------- ci/requirements-py38-all.yml | 27 ------------------ ci/requirements-py38-xarray-dev.yml | 27 ------------------ salem/gis.py | 10 +++---- salem/sio.py | 4 +-- salem/tests/test_datasets.py | 1 - salem/tests/test_gis.py | 5 ++-- salem/tests/test_graphics.py | 3 +- salem/tests/test_misc.py | 2 +- 14 files changed, 19 insertions(+), 106 deletions(-) rename ci/{requirements-py37-all.yml => requirements-py311-all.yml} (95%) rename ci/{requirements-py38-min.yml => requirements-py311-min.yml} (92%) rename ci/{requirements-py38-xr.yml => requirements-py311-xr.yml} (92%) rename ci/{requirements-py39-all.yml => requirements-py312-all.yml} (95%) delete mode 100644 ci/requirements-py38-all-rc.yml delete mode 100644 ci/requirements-py38-all.yml delete mode 100644 ci/requirements-py38-xarray-dev.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0f72b7b..35c6f34 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,17 +15,15 @@ jobs: fail-fast: false matrix: test-env: - - py38-all - - py38-xarray-dev - - py38-all-rc - - py39-all - py310-all + - py311-all + - py312-all use-mpl: - "--mpl" include: - - test-env: py38-min + - test-env: py311-min use-mpl: "" - - test-env: py38-xr + - test-env: py311-xr use-mpl: "" runs-on: ubuntu-latest defaults: diff --git a/ci/requirements-py37-all.yml b/ci/requirements-py311-all.yml similarity index 95% rename from ci/requirements-py37-all.yml rename to ci/requirements-py311-all.yml index 6f39c54..22a9e6e 100644 --- a/ci/requirements-py37-all.yml +++ b/ci/requirements-py311-all.yml @@ -2,7 +2,7 @@ name: test_env channels: - conda-forge dependencies: - - python=3.7 + - python=3.11 - six - numpy - scipy diff --git a/ci/requirements-py38-min.yml b/ci/requirements-py311-min.yml similarity index 92% rename from ci/requirements-py38-min.yml rename to ci/requirements-py311-min.yml index 02c641f..9232777 100644 --- a/ci/requirements-py38-min.yml +++ b/ci/requirements-py311-min.yml @@ -2,7 +2,7 @@ name: test_env channels: - conda-forge dependencies: - - python=3.8 + - python=3.11 - six - numpy - scipy diff --git a/ci/requirements-py38-xr.yml b/ci/requirements-py311-xr.yml similarity index 92% rename from ci/requirements-py38-xr.yml rename to ci/requirements-py311-xr.yml index 9e6d1fc..95b8be5 100644 --- a/ci/requirements-py38-xr.yml +++ b/ci/requirements-py311-xr.yml @@ -2,7 +2,7 @@ name: test_env channels: - conda-forge dependencies: - - python=3.8 + - python=3.11 - six - numpy - scipy diff --git a/ci/requirements-py39-all.yml b/ci/requirements-py312-all.yml similarity index 95% rename from ci/requirements-py39-all.yml rename to ci/requirements-py312-all.yml index ac29638..dddab56 100644 --- a/ci/requirements-py39-all.yml +++ b/ci/requirements-py312-all.yml @@ -2,7 +2,7 @@ name: test_env channels: - conda-forge dependencies: - - python=3.9 + - python=3.12 - six - numpy - scipy diff --git a/ci/requirements-py38-all-rc.yml b/ci/requirements-py38-all-rc.yml deleted file mode 100644 index 5646988..0000000 --- a/ci/requirements-py38-all-rc.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: test_env -channels: - - conda-forge/label/rc - - conda-forge -dependencies: - - python=3.8 - - six - - numpy - - scipy - - pyproj - - joblib - - netCDF4 - - shapely - - geopandas>=0.8 - - rasterio - - pandas>=1.2 - - xarray - - dask - - matplotlib - - Pillow - - scikit-image - - cartopy - - pip - - pip: - - coveralls==3.2.0 - - pytest-cov - - pytest-mpl - - motionless diff --git a/ci/requirements-py38-all.yml b/ci/requirements-py38-all.yml deleted file mode 100644 index 1cd9fae..0000000 --- a/ci/requirements-py38-all.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: test_env -channels: - - conda-forge -dependencies: - - python=3.8 - - six - - numpy - - scipy - - pyproj - - joblib - - netCDF4 - - shapely - - geopandas - - rasterio - - pandas - - xarray - - dask - - matplotlib - - scikit-image - - Pillow - - cartopy - - pip - - pip: - - coveralls==3.2.0 - - pytest-cov - - pytest-mpl - - motionless diff --git a/ci/requirements-py38-xarray-dev.yml b/ci/requirements-py38-xarray-dev.yml deleted file mode 100644 index 604cf58..0000000 --- a/ci/requirements-py38-xarray-dev.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: test_env -channels: - - conda-forge -dependencies: - - python=3.8 - - six - - numpy - - scipy - - pyproj - - joblib - - netCDF4 - - shapely - - geopandas - - rasterio - - pandas - - dask - - matplotlib - - Pillow - - scikit-image - - cartopy - - pip - - pip: - - git+https://github.com/pydata/xarray.git - - coveralls==3.2.0 - - pytest-cov - - pytest-mpl - - motionless diff --git a/salem/gis.py b/salem/gis.py index 95297fb..b554bb7 100644 --- a/salem/gis.py +++ b/salem/gis.py @@ -32,6 +32,7 @@ class Dummy(): pass crs_type = Dummy + def check_crs(crs, raise_on_error=False): """Checks if the crs represents a valid grid, projection or ESPG string. @@ -1123,7 +1124,7 @@ def region_of_interest(self, shape=None, geometry=None, grid=None, x0, y0 = cgrid.transform(*xy0, crs=crs, nearest=True) x1, y1 = cgrid.transform(*xy1, crs=crs, nearest=True) mask[np.min([y0, y1]):np.max([y0, y1]) + 1, - np.min([x0, x1]):np.max([x0, x1]) + 1] = 1 + np.min([x0, x1]):np.max([x0, x1]) + 1] = 1 return mask @@ -1138,7 +1139,6 @@ def to_dict(self): -------- from_dict : create a Grid from a dict """ - srs = self.proj.srs return dict(proj=self.proj.srs, x0y0=(self.x0, self.y0), nxny=(self.nx, self.ny), dxdy=(self.dx, self.dy), pixel_ref=self.pixel_ref) @@ -1242,8 +1242,7 @@ def to_geometry(self, to_crs=None): ii.append(i) out['j'] = jj out['i'] = ii - out['geometry'] = geoms - out.crs = self.proj.srs + out.set_geometry(geoms, crs=self.proj.srs, inplace=True) if check_crs(to_crs): transform_geopandas(out, to_crs=to_crs, inplace=True) @@ -1264,6 +1263,7 @@ def proj_is_same(p1, p2): """ if has_gdal: # this is more robust, but gdal is a pain + osr.UseExceptions() s1 = osr.SpatialReference() s1.ImportFromProj4(p1.srs) s2 = osr.SpatialReference() @@ -1577,7 +1577,7 @@ def mercator_grid(center_ll=None, extent=None, ny=600, nx=None, e, n = transform_proj(wgs84, projloc, lon, lat) - if origin== 'upper-left': + if origin == 'upper-left': corner = (-xx / 2. + e, yy / 2. + n) dxdy = (xx / nx, - yy / ny) else: diff --git a/salem/sio.py b/salem/sio.py index dd3e82a..4064c18 100644 --- a/salem/sio.py +++ b/salem/sio.py @@ -231,7 +231,7 @@ def _wrf_grid_from_dataset(ds): atol = 5e-3 if proj_id == 2 else 1e-3 check = np.isclose(reflon, mylon, atol=atol) - if not np.alltrue(check): + if not np.all(check): n_pix = np.sum(~check) maxe = np.max(np.abs(reflon - mylon)) if maxe < (360 - atol): @@ -239,7 +239,7 @@ def _wrf_grid_from_dataset(ds): 'of our lons did not match those of the WRF ' 'file. Max error: {}'.format(n_pix, atol, maxe)) check = np.isclose(reflat, mylat, atol=atol) - if not np.alltrue(check): + if not np.all(check): n_pix = np.sum(~check) maxe = np.max(np.abs(reflat - mylat)) warnings.warn('For {} grid points, the expected accuracy ({}) ' diff --git a/salem/tests/test_datasets.py b/salem/tests/test_datasets.py index 7e9a376..156edca 100644 --- a/salem/tests/test_datasets.py +++ b/salem/tests/test_datasets.py @@ -220,7 +220,6 @@ def test_xarray(self): class TestGeoNetcdf(unittest.TestCase): def test_eraint(self): - f = get_demo_file('era_interim_tibet.nc') d = GeoNetcdf(f) assert d.grid.origin == 'upper-left' diff --git a/salem/tests/test_gis.py b/salem/tests/test_gis.py index 6cc9a0b..5f7eb25 100644 --- a/salem/tests/test_gis.py +++ b/salem/tests/test_gis.py @@ -114,7 +114,7 @@ def test_constructor(self): g.corner_grid.xy_coordinates) ex = g.corner_grid.extent - assert_allclose([-0.5, 2.5, -0.5, 2.5], ex) + assert_allclose([-0.5, 2.5, -0.5, 2.5], ex) assert_allclose(g.center_grid.extent, g.corner_grid.extent) @@ -157,7 +157,7 @@ def test_constructor(self): g.corner_grid.xy_coordinates) ex = g.corner_grid.extent - assert_allclose([-0.5, 2.5, -2.5, 0.5], ex) + assert_allclose([-0.5, 2.5, -2.5, 0.5], ex) assert_allclose(g.center_grid.extent, g.corner_grid.extent) @@ -180,7 +180,6 @@ def test_constructor(self): def test_comparisons(self): """See if the grids can compare themselves""" - args = dict(nxny=(3, 3), dxdy=(1, 1), x0y0=(0, 0), proj=wgs84) g1 = Grid(**args) self.assertEqual(g1.center_grid, g1.corner_grid) diff --git a/salem/tests/test_graphics.py b/salem/tests/test_graphics.py index 5ed18df..03cb193 100644 --- a/salem/tests/test_graphics.py +++ b/salem/tests/test_graphics.py @@ -63,9 +63,8 @@ def _create_dummy_shp(fname): p4 = shpg.Point(1, 1) df = gpd.GeoDataFrame() df['name'] = ['Polygon', 'Line'] - df['geometry'] = gpd.GeoSeries([p1, p2]) + df.set_geometry(gpd.GeoSeries([p1, p2]), crs='epsg:4326', inplace=True) of = os.path.join(testdir, fname) - df.crs = 'epsg:4326' df.to_file(of) return of diff --git a/salem/tests/test_misc.py b/salem/tests/test_misc.py index 5479198..7edd27e 100644 --- a/salem/tests/test_misc.py +++ b/salem/tests/test_misc.py @@ -59,7 +59,7 @@ def create_dummy_shp(fname): p4 = shpg.Point(1, 1) df = gpd.GeoDataFrame() df['name'] = ['Polygon', 'Line'] - df['geometry'] = gpd.GeoSeries([p1, p2]) + df.set_geometry(gpd.GeoSeries([p1, p2]), inplace=True) of = os.path.join(testdir, fname) df.to_file(of) return of