Created
April 5, 2016 18:13
-
-
Save gidden/4193a0ffb425f2c2afb0d2a7d4740467 to your computer and use it in GitHub Desktop.
Reading in custom-written raster bands causes seg fault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://www.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rasterio as rio | |
with rio.drivers(): | |
with rio.open('tos_O1_2001-2002.nc', 'r') as src: | |
raster = src.read()[0] | |
profile = src.profile | |
profile['count'] = 2 | |
with rio.open('test.nc', 'w', **profile) as dst: | |
dst.write_band(1, raster) | |
dst.write_band(2, raster) | |
with rio.open('test.nc') as src: | |
rasters = src.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two quick comments:
src.read(1)
rather than reading the entire dataset into a 3D arraydst.write(raster, 1)
which is preferred over thewrite_band
method.