Add option/ability to use Rasterio MemoryFiles as outputs/destinations #204
Replies: 4 comments 12 replies
-
Neat idea. I'd love to see this as well! |
Beta Was this translation helpful? Give feedback.
-
Curious what you need to do in Way to do it in current stateThis seems to work: from rasterio.io import MemoryFile
import xarray
xds = xarray.open("my-dataset.nc4")
with MemoryFile() as memfile:
xds.rio.to_raster(memfile.name)
with memfile.open() as dataset:
.... Potential future implementationI think the logic in
|
Beta Was this translation helpful? Give feedback.
-
As far as rasterio goes, not something I have tried - writing out many band rasters. E.g. I have plenty of 20+ band geotiffs lying around and working on a 27 band one today, the example I think just mention the output of one band? |
Beta Was this translation helpful? Give feedback.
-
Odd one here, I get ---------------------------------------------------------------------------
InvalidDimensionOrder Traceback (most recent call last)
<ipython-input-236-49a27e007153> in <module>
2 rds = result
3 with MemoryFile() as memfile:
----> 4 with memfile.open(driver='GTiff',count=int(rds.rio.count),width=int(rds.rio.width),height=int(rds.rio.height),dtype=str(rds.dtype),crs=rds.rio.crs, transform=rds.rio.transform(recalc=True), nodata=rds.rio.nodata
5 ) as dataset:
6 data = rds.values
/env/lib/python3.8/site-packages/rioxarray/rioxarray.py in count(self)
797 if self._count is not None:
798 return self._count
--> 799 extra_dim = self._check_dimensions()
800 self._count = 1
801 if extra_dim is not None:
/env/lib/python3.8/site-packages/rioxarray/rioxarray.py in _check_dimensions(self)
784 )
785 if not extra_dims and self._obj.dims != (self.y_dim, self.x_dim):
--> 786 raise InvalidDimensionOrder(
787 "Invalid dimension order. Expected order: {0}"
788 "You can use `DataArray.transpose{0}` "
InvalidDimensionOrder: Invalid dimension order. Expected order: ('y', 'x')You can use `DataArray.transpose('y', 'x')` to reorder your dimensions. |
Beta Was this translation helpful? Give feedback.
-
Hey folks,
I've been a heavy
rasterio
user for a while, working on a project currently that is going to be taking NetCDF4 files and converting them to COGs (with some other stuff in between).I found
rioxarray
really handy for getting my NetCDF4 files into Rasters, what would be really awesome is integration/the ability to userasterio
MemoryFiles.The use case being that really I'd rather not have to write to disk and clean up intermediate files (I do a lot of serverless based workloads).
For example I could see my code looking something like:
This would then allow me to work on the resultant raster within Rasterio without worrying about writing to disk and cleaning up intermediate files
Hopefully I've explained myself well, happy to try and flesh it out if needed :D
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions