@marpet hello again, and sorry for disturbing
I’m trying another approach, that seems to partially work. It consists on the usage of .tif files of the datasets “ascending_subset” and “descending_subset” in order to build an array in which insert my bands. When I run the code, a serie of errors starts to run in the terminal (“SEVERE: org.esa.snap.core.util.SystemUtils$SnapImagingListener: JAI error occurred: ‘Problem occurs when computing a tile by the owner.’ at com.sun.media.jai.util.SunTileScheduler@3d2202d0
java.lang.NullPointerException”), but then the product is created anway. When I open it on SNAP, in fact, the two band in the single product appear but it’s impossible to open the product because of the error “Unable to read the file”.
Here’s the code (I precise that the two input products have got the same dimensions of height and width)
ascending_subset = snappy.ProductIO.readProduct(path_file)
descending_subset = snappy.ProductIO.readProduct(path_file)
ascending_tif = file.tif
descending_tif = file.tif
ascending = gdal.Open(ascending_tif)
descending = gdal.Open(descending_tif)
band_ascending = ascending.GetRasterBand(1)
band_descending = descending.GetRasterBand(1)
ascending_array = np.array(ascending.ReadAsArray())
descending_array = np.array(descending.ReadAsArray())
product = snappy.Product(“title”, “subtitle”, width1, height1)
writer = snappy.ProductIO.getProductWriter(‘BEAM-DIMAP’)
product.setProductWriter(writer)
ProductUtils.copyMetadata(ascending_subset, product)
ProductUtils.copyTiePointGrids(ascending_subset, product)
ProductUtils.copyBand(“displacement_as”, ascending_subset, product, True)
band1 = product.addBand(“displacement_ascending”, snappy.ProductData.TYPE_FLOAT64)
product.setProductReader(ProductIO.getProductReader(“BEAM-DIMAP”))
product.setProductWriter(writer)
ProductUtils.copyMetadata(descending_subset,product)
ProductUtils.copyTiePointGrids(descending_subset, product) #copia dei dati del discendente
ProductUtils.copyBand(“displacement_des”, descending_subset, product, True)
band2 = product.addBand(“displacement_descending”, snappy.ProductData.TYPE_FLOAT64)
product.setProductReader(ProductIO.getProductReader(“BEAM-DIMAP”))
writer = snappy.ProductIO.getProductWriter(‘BEAM-DIMAP’)
product.setProductWriter(writer)
product.writeHeader(“displacement.dim”)
#band1.setPixels(0, 0, width, height, ascending_array) – set as a comment because when I run it the error “RuntimeError: no matching Java method overloads found”
band1.writePixels(0, 0, width, height, ascending_array)
#band2.setPixels(0, 0, width, height, descending_array)
band2.writePixels(0, 0, width, height, descending_array)
output = output_path
snappy.ProductIO.writeProduct(product, output, “BEAM-DIMAP”)
I don’t know why the final product exists, with the new bands, but they can’t be read.
Thank you in advance!