Skip to content

Commit

Permalink
Update CI and solve some deprecation warnings (#235)
Browse files Browse the repository at this point in the history
* Update CI and solve some deprecation warnings

* Better ducking

* further deprecations
  • Loading branch information
fmaussion authored Feb 11, 2024
1 parent f5e7e09 commit 69d725f
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 177 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test_env
channels:
- conda-forge
dependencies:
- python=3.7
- python=3.11
- six
- numpy
- scipy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test_env
channels:
- conda-forge
dependencies:
- python=3.8
- python=3.11
- six
- numpy
- scipy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test_env
channels:
- conda-forge
dependencies:
- python=3.8
- python=3.11
- six
- numpy
- scipy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test_env
channels:
- conda-forge
dependencies:
- python=3.9
- python=3.12
- six
- numpy
- scipy
Expand Down
28 changes: 0 additions & 28 deletions ci/requirements-py38-all-rc.yml

This file was deleted.

27 changes: 0 additions & 27 deletions ci/requirements-py38-all.yml

This file was deleted.

27 changes: 0 additions & 27 deletions ci/requirements-py38-xarray-dev.yml

This file was deleted.

30 changes: 14 additions & 16 deletions salem/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io
import os
import warnings
from six.moves.urllib.request import urlopen
from urllib.request import urlopen

# External libs
import pyproj
Expand All @@ -34,14 +34,6 @@
API_KEY = None


def _to_scalar(x):
"""If a list then scalar"""
try:
return x[0]
except IndexError:
return x


class GeoDataset(object):
"""Interface for georeferenced datasets.
Expand Down Expand Up @@ -102,7 +94,7 @@ def time(self):
return None
return self._time[self.t0:self.t1].index

def set_period(self, t0=[0], t1=[-1]):
def set_period(self, t0=0, t1=-1):
"""Set a period of interest for the dataset.
This will be remembered at later calls to time() or GeoDataset's
getvardata implementations.
Expand All @@ -114,10 +106,16 @@ def set_period(self, t0=[0], t1=[-1]):
"""

if self._time is not None:
self.sub_t = [0, -1]
# we dont check for what t0 or t1 is, we let Pandas do the job
# TODO quick and dirty solution for test_longtime, TBR
self.sub_t = [_to_scalar(self._time[t0]),
_to_scalar(self._time[t1])]
try:
self.sub_t[0] = self._time.loc[t0]
except KeyError:
self.sub_t[0] = self._time.iloc[t0]
try:
self.sub_t[1] = self._time.loc[t1]
except KeyError:
self.sub_t[1] = self._time.iloc[t1]
self.t0 = self._time.index[self.sub_t[0]]
self.t1 = self._time.index[self.sub_t[1]]

Expand Down Expand Up @@ -487,7 +485,7 @@ class GoogleCenterMap(GeoDataset):
"""

def __init__(self, center_ll=(11.38, 47.26), size_x=640, size_y=640,
scale=1, zoom=12, maptype='satellite', use_cache=True,
scale=1, zoom=12, maptype='satellite', use_cache=True,
**kwargs):
"""Initialize
Expand All @@ -500,7 +498,7 @@ def __init__(self, center_ll=(11.38, 47.26), size_x=640, size_y=640,
size_y : int
image size
scale : int
image scaling factor. 1, 2. 2 is higher resolution but takes
image scaling factor. 1, 2. 2 is higher resolution but takes
longer to download
zoom : int
google zoom level (https://developers.google.com/maps/documentation/
Expand Down Expand Up @@ -530,7 +528,7 @@ def __init__(self, center_ll=(11.38, 47.26), size_x=640, size_y=640,
import motionless
googleurl = motionless.CenterMap(lon=center_ll[0], lat=center_ll[1],
size_x=size_x, size_y=size_y,
maptype=maptype, zoom=zoom, scale=scale,
maptype=maptype, zoom=zoom, scale=scale,
**kwargs)

# done
Expand Down
10 changes: 5 additions & 5 deletions salem/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion salem/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'ne_50m_lakes.shp')

# Be sure we have the directory
if ~ os.path.exists(shapefiles['world_borders']):
if not os.path.exists(shapefiles['world_borders']):
from salem.utils import get_demo_file
_ = get_demo_file('world_borders.shp')

Expand Down
Loading

0 comments on commit 69d725f

Please sign in to comment.