ProductIO.writeProduct() function takes longer to run when called in Python

I can’t understand why the ProductIO.writeProduct() function takes at least a few minutes to execute for a collocation between two images of around 3000 x 4000 px in the following code (the collocate() function is implemented in another script):

collocated_products = collocate(product1, product2, ‘${ORIGINAL_NAME}’, ‘${ORIGINAL_NAME}’)
path_collocated = os.path.join(PARENT, FOLDER, ‘collocation.tif’)
ProductIO.writeProduct(collocated_products, path_collocated, ‘GeoTIFF’)

While when its called from the command-line with gpt it’s very quick.
Is there any other way to write the resulting collocated product to the disk quickly?

One reason could be a different memory setting. However, maybe it helps if you use the Write operator.
Please have a look at this and the following posts:

2 Likes

Thanks a lot, indeed the code below takes roughly the same time to run as gpt when it’s called from the command-line:

WriteOp = jpy.get_type('org.esa.snap.core.gpf.common.WriteOp')
writeOp = WriteOp(product, File(path), format)
writeOp.writeProduct(ProgressMonitor.NULL)