fmaussion / salem

Add geolocalised subsetting, masking, and plotting operations to xarray
http://salem.readthedocs.io
Other
185 stars 43 forks source link

roi fails on [1,N] or [N,1] 2D masks #142

Open laurensstoop opened 5 years ago

laurensstoop commented 5 years ago

Hi @fmaussion,

The ds_country.salem.roi(shape=country_shape) fails if the mask is [1,N] or [N,1].

Specifically I have mask on very course data that makes from switzerland a set of 3 boxes on the same latitude.

The traceback made me realise that it fails in sio.py at the def _salem_grid_from_dataset(ds): function. The lines are

` # OK, get it x = ds.variables[x][:] y = ds.variables[y][:]

# Make the grid
dx = x[1]-x[0]  ### THIS DOESN'T WORK FOR 1D
dy = y[1]-y[0]  ### SAME
args = dict(nxny=(x.shape[0], y.shape[0]), proj=proj, dxdy=(dx, dy),
            x0y0=(x[0], y[0]))
return gis.Grid(**args)`

At the moment I bodged the info I needed from a different mask, so I can't help with a fool-proof solution.

~Laurens

enable7924 commented 3 months ago

I came across the same issue. If it doesn't hurt performance in your case you can call roi first then subset which worked for me.