Snappy ProductIO option

Hello, Could someone tell me some option similar to ProductIO.writeProduct() in python. I need a option similar to export in Snap desktop.

You find the export options in the menu at File / Export

Thank you for your answer.
I have another question. In python, is there other command line similar to ProductIO.writeProduct () to export products??

You can use the Write operator.
By calling GPF.createProduct(ā€œWriteā€, parameters, product)

Parameter names are: file, formatName

I think my question fits also here, to avoid opening new topic. Is there also a way to read geotiff files in python, without having to read the whole product (safe file)? Just plain geotiff.

1 Like

If you donā€™t want to use any Snappy Functionality, then Rasterio is a good Python lib for it. Havenā€™t tried opening a geotiff as a product, maybe itā€™l work?

@pakoun I just opened one of my subsetted GeoTIFFs within SNAP and it worked fine, I would assume then that ProductIO.readProduct() would accept a .tif as input.

def do_write(source):
parameters = HashMap()
parameters.put(ā€˜fileā€™, sentinel_1.getName()+ā€˜finaX.dimā€™)
parameters.put(ā€˜formatNameā€™, ā€˜BEAM-DIMAPā€™)

  output=GPF.createProduct("Write",  parameters,source)
  return output

but after this ,how to write to harddisk?

@sxau2013 If you want then to write that to you disk:

ProductIO.writeProduct(target_file, <path+Name>,  'GeoTIFF')

@CiaranEvans Usually I am using gdal to open and edit geotiff files. I though though to do that with snappy if possible for the following reason: I am having some problems with data around 180 deg and I need to edit the GCPs and save them in a new geotiff. Then I open the safe file with snappy which is needed to perform all the SAR related corrections. Somehow though I need to read only the GCP corrected geotiff data file. I am thinking to put this band either to original esa geotiff file, or to use it somehow in the readProduct operator.

From what I see the ProductIO.readProduct() works only if you provide the safe file, not with just the tiff. But if it would, the interesting part is how to create a product which reads the safe file (so it gets all the metadata info and LUTs), but the actual data comes from another geotiff file and not the original from ESA. I am dieing to know that! :smiley:

There is the easy approach to substitute the origina ESA geotiff with the corrected one but I dont want to mess with the safe fileā€¦

@sxau2013 sorry for suggesting this. You would need to iterate manually over the data tiles in the product in order to let it write. not a good way to do.
Anyway, you should use ProductIO. Thatā€™s the intended way to write data.

@pakoun
ProductIO.readProduct() reads all formats SNAP supports. like SAFE or NetCDF or GeoTiff.
Maybe the Merge operator gives you the functionality you need. With this operator you can merge the content of one or more products.

1 Like

Thank you! I will try it out!

I tried the merge operator as followin but I have an error.

slave_prod = ProductIO.readProduct(<geotiff file>)
master_prod = ProductIO.readProduct(<safe file>)
sourceProducts = HashMap()
sourceProducts.put('masterProduct', master_prod)
sourceProducts.put('slaveProduct', slave_prod) 
parameters = HashMap()
parameters.put('geographicError', '1.0E-5f') 
merged = GPF.createProduct('Merge', parameters, sourceProducts)

RuntimeError: org.esa.snap.core.gpf.OperatorException: Product [slaveProduct] is not compatible to master product.

The arrays for both products have identical dimensions. The slave_prod is just a tiff file which I load with the ProductIO.readProduct. Any idea what might be wrong here?

If the dimensions are identical but one is for example not geo-referenced then you should set geographicError parameter to ā€˜NaNā€™. If they donā€™t have the same size it will not work at all.