mdelgadoblasco / snap2stamps

Using SNAP as InSAR processor for StaMPS
Other
109 stars 52 forks source link

Problem with coregistration and interferogram generation - slave image always the same #15

Closed tamsima closed 10 months ago

tamsima commented 1 year ago

Hi

I have a problem with the python script that would generate the coregistered data and interferograms. In my case, somehow the slave image file is never overwritten, so it generates interferograms always for the same master-slave pair. I tried removing the default files from the graphs in SNAP, but then I get an error message: [NodeId: Read] The 'file' parameter is not set\r\n" . But if I set some random file that should then be exchanged in the loop in pyhton, that does not do the expected exchange..

So, I figured that the following code always replaces the file that is taken as slave (and all of the other python codes work for me), but it's not the case with this one and I don't understand why, or how to make it work when there is not an initial file already in the graph.

` k = 0
for dimfile in glob.iglob(slavesplittedfolder + '/*/'+IW+'.dim', recursive = True): message = ('Processing slave file') print(message) print(dimfile) k=k+1 dimfile_master = (r'Z:/Tamara/InSAR/Golubin/2021/asc/stamps/split_master/20210819/20210819_IW2.dim')

head, tail = os.path.split(os.path.join(slavesplittedfolder, dimfile))

subdirectory= os.path.join(outputifgfolder, dimfile_master[62:70] + '_' +tail[0:8])
if not os.path.exists(subdirectory):
    os.mkdir(subdirectory)

subdirectory1 = os.path.join(outputfiltnotcfolder, dimfile_master[62:70] + '_' +tail[0:8])
if not os.path.exists(subdirectory1):
    os.mkdir(subdirectory1)

outputname = dimfile_master[62:70] + '_' +tail[0:8] +'_' + 'filt_int_sub_tc'
print(outputname)
outputname1 = dimfile_master[62:70] + '_' +tail[0:8] +'_' + 'filt_notc'
print(outputname1)

with open(graphxml, 'r') as file :
    filedata = file.read()
# Replace the target string

filedata = filedata.replace('MASTER', dimfile_master)
filedata = filedata.replace('SLAVE', dimfile)
filedata = filedata.replace('OUTPUTCOREGFOLDER', outputcoregfolder)
filedata = filedata.replace('OUTPUTIFGFOLDER', os.path.join(outputifgfolder,subdirectory))
filedata = filedata.replace('OUTPUTFILTNOTCFOLDER', os.path.join(outputfiltnotcfolder, subdirectory1))
filedata = filedata.replace('OUTPUTFILE', outputname)
filedata = filedata.replace('OUTPUTFILE1', outputname1)
# filedata = filedata.replace('POLYGON',polygon)
# Write the file out again
with open(graph2run, 'w') as file:
    file.write(filedata)

args = [ GPT, graph2run, '-c', CACHE, '-q', CPU]

# Launch the processing
process = subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
timeStarted = time.time()

stdout = process.communicate()[0]
print('SNAP STDOUT:{}'.format(stdout))
timeDelta = time.time() - timeStarted                     # Get execution time.
print('['+str(k)+'] Finished process in '+str(timeDelta)+' seconds.')
out_file.write('['+str(k)+'] Finished process in '+str(timeDelta)+' seconds.\n')

if process.returncode != 0 :
    message='Error computing with coregistration and interferogram generation of splitted slave '+str(dimfile)
    err_file.write(message+'\n')
else:
    message='Coregistration and Interferogram computation for data '+str(tail)+' successfully completed.\n'
    print(message)
    out_file.write(message)
print(bar_message)

out_file.write(bar_message)

out_file.close() ` By the way, I'm using python 3, so I adapted the files a bit but all other files are working..

Cheers Tamara