Hello there,
I have to create a Stack of some S-1 products and, since I cannot solve the sorting issue related to the “CreateStackOp” presented in this thread (Call ProductSet-Reader and Create Stack in Snap) I’m trying to get the stack by myself.
I wrote a code but when I try to write the final product to file I get the error 'java.lang.IllegalStateException: no product reader for band ‘Sigma0_VV_20170103’.
This is my code:
...
files_list=glob.glob(InputFold+'\*.dim')
#Initialize snappy
HashMap = jpy.get_type('java.util.HashMap')
#Get snappy operators
GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
ind= [m.start() for m in re.finditer('_',os.path.split(files_list[0])[1])]
date_start = os.path.split(files_list[0])[1][ind[3]+1:ind[3]+9]
ind= [m.start() for m in re.finditer('_',os.path.split(files_list[-1])[1])]
date_end = os.path.split(files_list[-1])[1][ind[3]+1:ind[3]+9]
#==============================================================================
# CREATE 2 PRODUCTS, ONE FOR SIGMA_VV AND ONE FOR SIGMA_VH
#==============================================================================
source = ProductIO.readProduct(os.path.join(InputFold,files_list[0]))
width=source.getSceneRasterWidth()
height=source.getSceneRasterHeight()
writer = ProductIO.getProductWriter('BEAM-DIMAP')
product1 = Product('Sigma0_VV_Stack_'+date_start+'_'+date_end, source.getProductType(), width, height)
product2 = Product('Sigma0_VH_Stack_'+date_start+'_'+date_end, source.getProductType(), width, height)
snappy.ProductUtils.copyGeoCoding(source, product1)
snappy.ProductUtils.copyGeoCoding(source, product1)
product1.setProductWriter(writer)
product2.setProductWriter(writer)
#==============================================================================
# LOOP OVER THE FILES
#==============================================================================
for file in files_list:
ind= [m.start() for m in re.finditer('_',os.path.split(file)[1])]
date = os.path.split(file)[1][ind[3]+1:ind[3]+9]
# OPEN FILES
source = ProductIO.readProduct(file)
# SELECT BANDS WE WANT TO STACK
band1 = source.getBand('Sigma0_VV')
band2 = source.getBand('Sigma0_VH')
# RENAME BANDS ADDING THE DATE
band1.setName(band1.getName()+'_'+date)
band2.setName(band2.getName()+'_'+date)
# ADD THE SELECTED BANDS TO THE PRODUCTS CREATED
product1.addBand(band1)
product2.addBand(band2)
#==============================================================================
# ADD 2 BANDS TO THE PRODUCTS, ONE WITH THE LAT, THE OTHER WITH THE LON OF EACH PIXEL
#==============================================================================
BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
#Latitude Band
lat = BandDescriptor()
lat.name = 'Latitude'
lat.type = 'float64'
lat.expression = 'LAT'
#Longitude Band
lon = BandDescriptor()
lon.name = 'Longitude'
lon.type = 'float64'
lon.expression = 'LON'
newBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 2)
newBands[0] = lat
newBands[1] = lon
#Compute BANDMATHS Operator
parameters = HashMap()
parameters.put('targetBands', newBands)
prod1 = GPF.createProduct('BandMaths', parameters, source)
#Get new bands and add to the Products created
ProductUtils.copyBand('Latitude',prod1,product1,True)
ProductUtils.copyBand('Longitude',prod1,product1,True)
ProductUtils.copyBand('Latitude',prod1,product2,True)
ProductUtils.copyBand('Longitude',prod1,product2,True)
#==============================================================================
# WRITE PRODUCTS TO FILE
#==============================================================================
ProductIO.writeProduct(product1,os.path.join(OutputFold,os.path.split(files_list[-1])[1][1:ind[3]]+'_Sigma0_VV_Stack_'+date_start+'_'+date_end), 'BEAM-DIMAP')
ProductIO.writeProduct(product2,os.path.join(OutputFold,os.path.split(files_list[-1])[1][1:ind[3]]+'_Sigma0_VH_Stack_'+date_start+'_'+date_end), 'BEAM-DIMAP')
Anyone has any suggestion to solve this issue?
Thank you in advance!
Davide