Hello,
I would like to sequentially write pixel values (product.writePixels(…)) in netCDF4 (or other format).
To do this I need to construct the image structure beforehand with product.writeHeader(‘test.nc’).
But, the resulted image test.nc is unreadable (by snap or gdal…).
Here is a small piece of code to check the consistency of the different format within snappy:
import numpy as np
from esasnappy import Product, ProductIO, ProductData
formats = ([".dim", "BEAM-DIMAP"],
[".h5", "HDF5"],
[".img", "GDAL-HFA-WRITER"],
[".jp2", "JPEG2000"],
[".bin", "Generic Binary BSQ"],
[".tif", "GeoTIFF+XML"],
[".grd", "GDAL-GSBG-WRITER"],
[".nc", "NetCDF-CF"],
[".nc", "NetCDF-BEAM"],
[".nc", "NetCDF4-BEAM"],
[".tif", "GeoTIFF"],
["", "JP2"],
[".tif", "GDAL-GTiff-WRITER"],
[".tif", "GeoTIFF-BigTIFF"],
[".csv", "CSV"],
[".bmp", "GDAL-BMP-WRITER"],
[".rst", "GDAL-RST-WRITER"],
[".nc", "NetCDF4-CF"],
[".hdr", "ENVI"])
for format in formats:
print()
print('---------------')
print(format)
file = 'issues/test' + format[0]
product = Product('test', 'test', 100, 100)
band = product.addBand('SZA', ProductData.TYPE_FLOAT32)
band.setModified(True)
band.setNoDataValue(np.nan)
band.setNoDataValueUsed(True)
product.getBand('SZA').setDescription('Solar zenith angle in deg.')
writer = ProductIO.getProductWriter(format[1])
product.setProductWriter(writer)
try:
product.writeHeader(file)
p = ProductIO.readProduct(file)
try:
print(p.getBand('SZA').getDescription())
print('SUCCESS!!!!!!!')
except:
print('error for format ', format[1])
except:
print('no header allowed for', format[1])
print()
with the following results:
---------------
['.dim', 'BEAM-DIMAP']
WARNING: org.esa.snap.core.dataio.dimap.DimapProductReader: DimapProductReader: Unable to read file 'issues/test.data/SZA.img' referenced by 'SZA'.
WARNING: org.esa.snap.core.dataio.dimap.DimapProductReader: DimapProductReader: Removed band 'SZA' from product 'null'.
Solar zenith angle in deg.
SUCCESS!!!!!!!
---------------
['.h5', 'HDF5']
no header allowed for HDF5
---------------
['.img', 'GDAL-HFA-WRITER']
no header allowed for GDAL-HFA-WRITER
---------------
['.jp2', 'JPEG2000']
no header allowed for JPEG2000
---------------
['.bin', 'Generic Binary BSQ']
first_line_time metadata value is null
last_line_time metadata value is null
error for format Generic Binary BSQ
---------------
['.tif', 'GeoTIFF+XML']
first_line_time metadata value is null
last_line_time metadata value is null
Solar zenith angle in deg.
SUCCESS!!!!!!!
---------------
['.grd', 'GDAL-GSBG-WRITER']
no header allowed for GDAL-GSBG-WRITER
---------------
['.nc', 'NetCDF-CF']
error for format NetCDF-CF
---------------
['.nc', 'NetCDF-BEAM']
error for format NetCDF-BEAM
---------------
['.nc', 'NetCDF4-BEAM']
error for format NetCDF4-BEAM
---------------
['.tif', 'GeoTIFF']
Solar zenith angle in deg.
SUCCESS!!!!!!!
---------------
['', 'JP2']
first_line_time metadata value is null
last_line_time metadata value is null
error for format JP2
---------------
['.tif', 'GDAL-GTiff-WRITER']
no header allowed for GDAL-GTiff-WRITER
---------------
['.tif', 'GeoTIFF-BigTIFF']
no header allowed for GeoTIFF-BigTIFF
---------------
['.csv', 'CSV']
no header allowed for CSV
---------------
['.bmp', 'GDAL-BMP-WRITER']
no header allowed for GDAL-BMP-WRITER
---------------
['.rst', 'GDAL-RST-WRITER']
no header allowed for GDAL-RST-WRITER
---------------
['.nc', 'NetCDF4-CF']
error for format NetCDF4-CF
---------------
['.hdr', 'ENVI']
no header allowed for ENVI
Conclusion product.writeHeader() is efficient for GeoTIFF and Beam-dimap only.
Any misunderstanding from my part? or ideas for workaround?
Thanks
TRistan