I want to run tests with different COG compressions, but I am not finding a way to configure it in Snappy. I locate the Java class, but I don’t know how to instruct it to change the compression from ‘LZW’ to ‘JPEG,’ for example.
Additionally, I’m getting a warning that I’m not sure how to handle.
Any ideas?
Thank you in advance.
def export_single_band(source, band_name, output_path, math=False, data_type='uint16', data_unit='db',
expression=None, output_format='GDAL-COG-WRITER'):
"""
Exports a single band from the source product to a specified format.
Parameters:
source (Product): Source SNAP product.
band_name (str): Name of the band to export.
output_path (str): Path to the output file.
math (bool): Flag to indicate if band math operation is applied (default is False).
data_type (str): Data type for the exported band (default is 'uint16').
data_unit (str): Data unit for the exported band (default is 'db').
expression (str): Band math expression (required if math is True).
output_format (str): Output format for the exported file (default is 'GDAL-COG-WRITER').
Returns:
None
"""
output_extension = get_extension(output_format)
output_name = f'{output_path}{output_extension}'
if math is True:
band_descriptor = snappy.jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
target_band = band_descriptor()
target_band.name = band_name
target_band.type = data_type
target_band.unit = data_unit
target_band.expression = expression
target_bands = snappy.jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1)
target_bands[0] = target_band
parameters = HashMap()
parameters.put('targetBands', target_bands)
first_out = GPF.createProduct('BandMaths', parameters, source)
else:
first_out = source
name = source.getName()
width = source.getSceneRasterWidth()
height = source.getSceneRasterHeight()
out_product = Product(name, output_format, width, height)
writer = ProductIO.getProductWriter(output_format)
print(writer)
print(writer.getWriterPlugIn())
out_product.setProductWriter(writer)
ProductUtils.copyGeoCoding(first_out, out_product)
ProductUtils.copyBand(band_name, first_out, out_product, True)
ProductIO.writeProduct(out_product, output_name, output_format, pm)
org.esa.s2tbx.dataio.gdal.writer.GDALProductWriter@28b523a
org.esa.s2tbx.dataio.gdal.writer.plugins.COGDriverProductWriterPlugIn@6af65f29
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV_oil_spill_bit_msk', started
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 10% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 20% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 30% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 40% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 50% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 60% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 70% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 80% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 90% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', 100% worked
Writing bands of product 'st_1_0_S1A_IW_GRDH_1SDV_20190731T055824_20190731T055849_028357_03344B_EA5E_Cal_TC'... - Writing band 'Sigma0_VV', done
Warning 6: driver COG does not support creation option TILED