Skip to content

Commit

Permalink
Fix numpy deprecation warnings (#195)
Browse files Browse the repository at this point in the history
* Fix coveralls upload

* Fix use of removed xarray functions

* Fix numpy deprecation warnings

* Force up-to-date versions in rc ci environment
  • Loading branch information
TimoRoth committed Feb 23, 2021
1 parent 3e8b770 commit 7255ce0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- name: Upload Coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
COVERALLS_PARALLEL: true
run: coveralls
finish-coveralls:
Expand All @@ -67,6 +68,7 @@ jobs:
- name: Coveralls Finished
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
run: |
pip3 install --upgrade coveralls &&
coveralls --finish
4 changes: 2 additions & 2 deletions ci/requirements-py38-all-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ dependencies:
- joblib
- netCDF4
- shapely
- geopandas
- geopandas>=0.8
- rasterio
- pandas
- pandas>=1.2
- xarray
- dask
- matplotlib
Expand Down
22 changes: 11 additions & 11 deletions salem/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ def _check_input(self, **kwargs):
else:
raise ValueError('Input params not compatible')

self._nx = np.int(nx)
self._ny = np.int(ny)
self._nx = int(nx)
self._ny = int(ny)
if (self._nx <= 0) or (self._ny <= 0):
raise ValueError('nxny not valid')
self._dx = np.float(dx)
self._dy = np.float(dy)
self._x0 = np.float(x0)
self._y0 = np.float(y0)
self._dx = float(dx)
self._dy = float(dy)
self._x0 = float(x0)
self._y0 = float(y0)
self._origin = origin

# Check for pixel ref
Expand Down Expand Up @@ -712,8 +712,8 @@ def transform(self, x, y, z=None, crs=wgs84, nearest=False, maskout=False):
# See if we need to round
if nearest:
f = np.rint if self.pixel_ref == 'center' else np.floor
x = f(x).astype(np.int)
y = f(y).astype(np.int)
x = f(x).astype(int)
y = f(y).astype(int)

# Mask?
if maskout:
Expand Down Expand Up @@ -840,7 +840,7 @@ def lookup_transform(self, data, grid=None, method=np.mean, lut=None,
out_shape[-2:] = [self.ny, self.nx]

if data.dtype.kind == 'i':
out_data = np.zeros(out_shape, dtype=np.float) * np.NaN
out_data = np.zeros(out_shape, dtype=float) * np.NaN
else:
out_data = np.zeros(out_shape, dtype=data.dtype) * np.NaN

Expand All @@ -863,7 +863,7 @@ def _2d_trafo(ind, outd):
# prepare output
if method is len:
out_data[~np.isfinite(out_data)] = 0
out_data = out_data.astype(np.int)
out_data = out_data.astype(int)
else:
out_data = np.ma.masked_invalid(out_data)

Expand Down Expand Up @@ -958,7 +958,7 @@ def map_gridded_data(self, data, grid=None, interp='nearest',
# We dont do integer arithmetics other than nearest
out_data = np.ma.masked_all(out_shape, dtype=data.dtype)
elif data.dtype.kind == 'i':
out_data = np.ma.masked_all(out_shape, dtype=np.float)
out_data = np.ma.masked_all(out_shape, dtype=float)
else:
out_data = np.ma.masked_all(out_shape, dtype=data.dtype)

Expand Down
16 changes: 13 additions & 3 deletions salem/sio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import xarray as xr
from xarray.backends.netCDF4_ import NetCDF4DataStore
from xarray.backends.api import _MultiFileCloser
from xarray.core import dtypes
try:
from xarray.backends.locks import (NETCDFC_LOCK, HDF5_LOCK, combine_locks)
Expand Down Expand Up @@ -1176,18 +1175,29 @@ def open_mf_wrf_dataset(paths, chunks=None, compat='no_conflicts', lock=None,
lock = NETCDF4_PYTHON_LOCK
datasets = [open_wrf_dataset(p, chunks=chunks or {}, lock=lock)
for p in paths]
file_objs = [ds._file_obj for ds in datasets]
orig_datasets = datasets

def ds_closer():
for ods in orig_datasets:
ods.close()

if preprocess is not None:
datasets = [preprocess(ds) for ds in datasets]

try:
combined = xr.combine_nested(datasets, concat_dim='time',
compat=compat)
except AttributeError:
combined = xr.auto_combine(datasets, concat_dim='time', compat=compat)
combined._file_obj = _MultiFileCloser(file_objs)
combined.attrs = datasets[0].attrs

try:
combined.set_close(ds_closer)
except AttributeError:
from xarray.backends.api import _MultiFileCloser
mfc = _MultiFileCloser([ods._file_obj for ods in orig_datasets])
combined._file_obj = mfc

# drop accumulated vars if needed (TODO: make this not hard coded)
vns = ['PRCP', 'PRCP_C', 'PRCP_NC']
vns = [vn for vn in vns if vn in combined.variables]
Expand Down
2 changes: 1 addition & 1 deletion salem/tests/test_gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def test_map_gridded_data_over(self):

for proj in projs:
nx, ny = (4, 5)
data = np.arange(nx * ny).reshape((ny, nx)).astype(np.float)
data = np.arange(nx * ny).reshape((ny, nx)).astype(float)

in_data = data * np.NaN
in_data[0, :] = 78
Expand Down
2 changes: 1 addition & 1 deletion salem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def read_colormap(name):
line = line.split('(')[-1].split(')')[0]
out.append([float(n) for n in line.split(',')])

return np.asarray(out).astype(np.float) / 256.
return np.asarray(out).astype(float) / 256.


@memory.cache
Expand Down
6 changes: 3 additions & 3 deletions salem/wrftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def _ncl_slp(z, t, p, q):

p0 = p[0, ...]

level = np.zeros((ny, nx), dtype=np.int) - 1
level = np.zeros((ny, nx), dtype=int) - 1
for k in np.arange(nz):
pok = np.nonzero((p[k, ...] < (p0 - pconst)) & (level == -1))
level[pok] = k
Expand All @@ -604,8 +604,8 @@ def _ncl_slp(z, t, p, q):
if np.any((klo - khi) == 0):
raise RuntimeError('Trapping levels are weird.') # pragma: no cover

x, y = np.meshgrid(np.arange(nx, dtype=np.int),
np.arange(ny, dtype=np.int))
x, y = np.meshgrid(np.arange(nx, dtype=int),
np.arange(ny, dtype=int))

plo = p[klo, y, x]
phi = p[khi, y, x]
Expand Down

0 comments on commit 7255ce0

Please sign in to comment.