Skip to content

Commit

Permalink
update for rasterio deprec
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Oct 26, 2016
1 parent 2ea3f71 commit 9c5321c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions salem/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ def set_roi(self, shape=None, geometry=None, crs=wgs84, grid=None,
if shape is not None:
gdf = sio.read_shapefile(shape)
gis.transform_geopandas(gdf, to_crs=ogrid.corner_grid)
with rasterio.drivers():
with rasterio.Env():
mask = features.rasterize(gdf.geometry, out=mask)
if geometry is not None:
geom = gis.transform_geometry(geometry, crs=crs,
to_crs=ogrid.corner_grid)
with rasterio.drivers():
with rasterio.Env():
mask = features.rasterize(np.atleast_1d(geom), out=mask)
if grid is not None:
_tmp = np.ones((grid.ny, grid.nx), dtype=np.int16)
Expand Down Expand Up @@ -276,7 +276,7 @@ def __init__(self, file):
"""

# brutally efficient
with rasterio.drivers():
with rasterio.Env():
with rasterio.open(file) as src:
nxny = (src.width, src.height)
ul_corner = (src.bounds.left, src.bounds.top)
Expand All @@ -297,7 +297,7 @@ def get_vardata(self, var_id=1):
"""
wx = (self.sub_x[0], self.sub_x[1]+1)
wy = (self.sub_y[0], self.sub_y[1]+1)
with rasterio.drivers():
with rasterio.Env():
with rasterio.open(self.file) as src:
band = src.read(var_id, window=(wy, wx))
return band
Expand Down Expand Up @@ -327,7 +327,7 @@ def __init__(self, file):
south=south)

# brutally efficient
with rasterio.drivers():
with rasterio.Env():
with rasterio.open(file) as src:
nxny = (src.width, src.height)
ul_corner = (src.bounds.left, src.bounds.top)
Expand All @@ -347,7 +347,7 @@ def get_vardata(self, var_id=1):
"""
wx = (self.sub_x[0], self.sub_x[1]+1)
wy = (self.sub_y[0], self.sub_y[1]+1)
with rasterio.drivers():
with rasterio.Env():
with rasterio.open(self.file) as src:
band = src.read(var_id, window=(wy, wx))
return band
Expand Down
4 changes: 2 additions & 2 deletions salem/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,14 @@ def region_of_interest(self, shape=None, geometry=None, grid=None,
# corner grid is needed for rasterio
transform_geopandas(shape, to_crs=self.corner_grid)
import rasterio
with rasterio.drivers():
with rasterio.Env():
mask = rasterio.features.rasterize(shape.geometry, out=mask)
if geometry is not None:
import rasterio
# corner grid is needed for rasterio
geom = transform_geometry(geometry, crs=crs,
to_crs=self.corner_grid)
with rasterio.drivers():
with rasterio.Env():
mask = rasterio.features.rasterize(np.atleast_1d(geom),
out=mask)
if grid is not None:
Expand Down

0 comments on commit 9c5321c

Please sign in to comment.