Skip to content

Commit

Permalink
Several fixes for upstream package updates (#126)
Browse files Browse the repository at this point in the history
* Several fixes for upstream package updates

* Update ci requirements

* typo

* a test more
  • Loading branch information
fmaussion committed Oct 31, 2018
1 parent ec097d7 commit c3a4ef0
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 16 deletions.
1 change: 1 addition & 0 deletions ci/requirements-py27-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- dask
- matplotlib
- Pillow
- scikit-image
- descartes
- cartopy
- pip:
Expand Down
1 change: 1 addition & 0 deletions ci/requirements-py36-all-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- dask
- matplotlib
- Pillow
- scikit-image
- descartes
- cartopy
- pip:
Expand Down
1 change: 1 addition & 0 deletions ci/requirements-py36-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- xarray
- dask
- matplotlib<3.0.0
- scikit-image
- Pillow
- descartes
- cartopy
Expand Down
1 change: 1 addition & 0 deletions ci/requirements-py36-xarray-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- dask
- matplotlib
- Pillow
- scikit-image
- descartes
- cartopy
- pip:
Expand Down
9 changes: 8 additions & 1 deletion salem/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

API_KEY = None


def _to_scalar(x):
"""If a list then scalar"""
try:
Expand Down Expand Up @@ -92,7 +93,13 @@ def __init__(self, grid, time=None):
if isinstance(time, pd.Series):
time = pd.Series(np.arange(len(time)), index=time.index)
else:
time = pd.Series(np.arange(len(time)), index=time)
try:
time = pd.Series(np.arange(len(time)), index=time)
except AttributeError:
# https://github.com/pandas-dev/pandas/issues/23419
for t in time:
setattr(t, 'nanosecond', 0)
time = pd.Series(np.arange(len(time)), index=time)
self._time = time

# set_period() will set those
Expand Down
28 changes: 19 additions & 9 deletions salem/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np

try:
from scipy.misc import imresize
from skimage.transform import resize as imresize
except ImportError:
pass

Expand Down Expand Up @@ -466,14 +466,24 @@ def _check_data(self, data=None, crs=None, interp='nearest',

# need to resize if not same
if not ((shp[0] == self.grid.ny) and (shp[1] == self.grid.nx)):
if interp.lower() == 'linear':
interp = 'bilinear'
if interp.lower() == 'spline':
interp = 'cubic'
# TODO: this does not work well with masked arrays
data = imresize(data.filled(np.NaN),
(self.grid.ny, self.grid.nx),
interp=interp, mode='F')
if interp.lower() == 'nearest':
interp = 0
elif interp.lower() == 'linear':
interp = 1
elif interp.lower() == 'spline':
interp = 3
try:
data = imresize(data.filled(np.NaN),
(self.grid.ny, self.grid.nx),
order=interp, mode='edge',
anti_aliasing=True)
except RuntimeError:
# For some order anti_aliasing doesnt work with 'edge'
data = imresize(data.filled(np.NaN),
(self.grid.ny, self.grid.nx),
order=interp, mode='edge',
anti_aliasing=False)

elif isinstance(crs, Grid):
# Remap
if overplot:
Expand Down
2 changes: 1 addition & 1 deletion salem/sio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ def open_mf_wrf_dataset(paths, chunks=None, compat='no_conflicts', lock=None,
raise IOError('no files to open')

# TODO: current workaround to dask thread problems
dask.set_options(get=dask.get)
dask.config.set(scheduler='single-threaded')

if lock is None:
lock = _default_lock(paths[0], 'netcdf4')
Expand Down
11 changes: 7 additions & 4 deletions salem/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,13 @@ def test_map(self):
# The interpolation is conservative with the grid...
srgb = np.sum(rgb2[..., 0:3], axis=2)
pok = np.nonzero(srgb != srgb[0, 0])
rgb1 = rgb1[np.min(pok[0]):np.max(pok[0]),
np.min(pok[1]):np.max(pok[1]),...]
rgb2 = rgb2[np.min(pok[0]):np.max(pok[0]),
np.min(pok[1]):np.max(pok[1]),...]
rgb1 = rgb1[np.min(pok[0])+1:np.max(pok[0]-1),
np.min(pok[1])+1:np.max(pok[1]-1),
...]
rgb2 = rgb2[np.min(pok[0])+1:np.max(pok[0]-1),
np.min(pok[1])+1:np.max(pok[1]-1),
...]

assert_array_equal(rgb1, rgb2)

cmap.set_bad('pink')
Expand Down
2 changes: 1 addition & 1 deletion salem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _hash_cache_dir():


hash_cache_dir = _hash_cache_dir()
memory = Memory(cachedir=hash_cache_dir + '_joblib', verbose=0)
memory = Memory(location=hash_cache_dir + '_joblib', verbose=0)

# A series of variables and dimension names that Salem will understand
valid_names = dict()
Expand Down

0 comments on commit c3a4ef0

Please sign in to comment.