Skip to content

Commit

Permalink
Merge branch 'master' into i210_pyproj_future_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp authored and philipp committed Mar 20, 2023
2 parents 723b9b7 + 3085126 commit f651790
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pysheds/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def to_raster(data, file_name, target_view=None, profile=None, blockxsize=256,
Value indicating no data in output Raster (overrides target_view.nodata)
dtype : numpy datatype
Desired datatype of the output array.
kwargs : Keyword arguments passed to rasterio.open together with the profile, eg. compress='lzw'
"""
if target_view is None:
target_view = data.viewfinder
Expand Down Expand Up @@ -290,6 +291,7 @@ def to_raster(data, file_name, target_view=None, profile=None, blockxsize=256,
'width' : width
}
profile.update(profile_updates)
profile.update(kwargs)
with rasterio.open(file_name, 'w', **profile) as dst:
dst.write(np.asarray(data), 1)

12 changes: 12 additions & 0 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ def test_to_raster():
fdir_out = grid.read_raster('test_dir.tif')
assert((fdir_out == grid.view(fdir)).all())

def test_to_raster_kwargs():
"""
Test if kwargs of the "to_raster" method are passed to rasterio
"""
import rasterio as rio
catch = d.catch
grid.clip_to(catch)
grid.to_raster(fdir, 'test_dir.tif', target_view=fdir.viewfinder,
blockxsize=16, blockysize=16, compress='LZW')
with rio.open('test_dir.tif') as ds:
assert ds.profile['compress'] == 'lzw'

# def test_from_raster():
# grid.clip_to('catch')
# grid.to_raster('dir', 'test_dir.tif', view=False, apply_mask=False, blockxsize=16, blockysize=16)
Expand Down

0 comments on commit f651790

Please sign in to comment.