Open EHdr raster with hdr header file from memory
fkluibenschaedl@...
Hi All, I am curious if there is a way to load the raster from memory though. Since each eraster within the archive aforementioned archive is compressed using gzip, The goal is to download the dataset, unpack the .bil file, open it with the matching header information, and store it as e.g. GeoTIFF for further processing. Below is some code that (obviously) fails when it passes a tuple to the rasterio.open fp argument. Looking forward to your thoughts on this. Thanks in advance,
|
|
Luke
You could use a raw raster VRT combined with the /vsitar and /vsigzip virtual filesystems (you could probably use /vsicurl as well to replace your FTP code, but I couldn't get that to work immediately so gave up). import rasterio vrt = ''' <VRTDataset rasterXSize="6935" rasterYSize="3351"> <SRS>EPSG:4326</SRS> <GeoTransform>-124.729583333333,0.00833333333333333,0,52.8704166666666,0,-0.00833333333333333</GeoTransform> <VRTRasterBand dataType="Int16" band="1" subClass="VRTRawRasterBand"> <SourceFilename relativetoVRT="0">/vsigzip//vsitar/{}</SourceFilename> <NoDataValue>-9999</NoDataValue> <ImageOffset>0</ImageOffset> <PixelOffset>2</PixelOffset> <LineOffset>13870</LineOffset> <ByteOrder>MSB</ByteOrder> </VRTRasterBand> </VRTDataset> ''' file_path = '/path/to/SNODAS_20210101.tar/us_ssmv11050lL00T0024TTNATS2021010105DP000.dat.gz' with rasterio.open(vrt.format(file_path)) as src: print(src.profile)
On Tue., 29 Jun. 2021, 08:27 , <fkluibenschaedl@...> wrote:
|
|
Luke
Replacing your FTP code with direct access using the /vsicurl/ virtual filesystem:
import rasterio
vrt = '''
<VRTDataset rasterXSize="6935" rasterYSize="3351">
<SRS>EPSG:4326</SRS>
<GeoTransform>-124.729583333333,0.00833333333333333,0,52.8704166666666,0,-0.00833333333333333</GeoTransform>
<VRTRasterBand dataType="Int16" band="1" subClass="VRTRawRasterBand">
<SourceFilename relativetoVRT="0">{}/{}/{}</SourceFilename>
<NoDataValue>-9999</NoDataValue>
<ImageOffset>0</ImageOffset>
<PixelOffset>2</PixelOffset>
<LineOffset>13870</LineOffset>
<ByteOrder>MSB</ByteOrder>
</VRTRasterBand>
</VRTDataset>
'''
""
vsi_path = '/vsigzip//vsitar//vsicurl'
ftp_path = 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02158/masked/2021/01_Jan/SNODAS_20210101.tar'
file_path = 'us_ssmv11050lL00T0024TTNATS2021010105DP000.dat.gz'
with rasterio.open(vrt.format(vsi_path, ftp_path, file_path)) as src:
print(src.profile)
|
|
fkluibenschaedl@...
On Fri, Jul 2, 2021 at 01:12 AM, Luke wrote:
Replacing your FTP code with direct access using the /vsicurl/ virtual filesystem: This is a very elegant solution, thanks for pointing it out and thanks for the sample code! The only drawback I see is that it is not possible to access multiple products (files within the archive) while at the same time downloading the archive only once. Thanks again,
|
|