Exemple #1
0
def get_common_burst(Mslc_dir,Sslc_dir,common_burst_txt):
    Mpar_list = sorted(glob.glob(Mslc_dir+'/*.IW*.burst.par'))
    Spar_list = sorted(glob.glob(Sslc_dir+'/*.IW*.burst.par'))
    if os.path.isfile(common_burst_txt):
        os.remove(common_burst_txt)
    for kk in range(len(Mpar_list)):
        MBURST = Mpar_list[kk]
        SBURST = Spar_list[kk]
        
        Mtt = Sslc_dir + '/' + os.path.basename(MBURST.replace('burst.par','tt0'))
        Stt = SBURST.replace('burst.par','tt0')
        call_str = "grep 'Burst:' " + MBURST + ' >' + Mtt
        os.system(call_str)
        
        call_str = "grep 'Burst:' " + SBURST + ' >' + Stt
        os.system(call_str)
        
        MM = ut.read_txt2array(Mtt)
        SM = ut.read_txt2array(Stt)
        La_M = MM[:,2]
        La_S = SM[:,2]
        
        PP = common_burst_Ref(La_M,La_S)
        
        print('Common bursts of swath' + str(kk+1) + ' : (master) ' + str(PP[0]) + ' ' + str(PP[1]) + ' (slave) ' + str(PP[2]) + ' ' + str(PP[3]))
        call_str = 'echo ' + str(PP[0]) + ' ' + str(PP[1]) + ' ' + str(PP[2]) + ' ' + str(PP[3]) + ' >>' +  common_burst_txt
        os.system(call_str)
                  
    return   
Exemple #2
0
def main(argv):
    start_time = time.time()
    inps = cmdLineParse()
    projectName = inps.projectName
    scratchDir = os.getenv('SCRATCHDIR')
    templateDir = os.getenv('TEMPLATEDIR')
    templateFile = templateDir + "/" + projectName + ".template"
    projectDir = scratchDir + '/' + projectName
    ifgDir = scratchDir + '/' + projectName + '/ifgrams'
    templateDict = ut.update_template(templateFile)
    rlks = templateDict['range_looks']
    azlks = templateDict['azimuth_looks']

    if inps.ifgarmListTxt: ifgramList_txt = inps.ifgarmListTxt
    else: ifgramList_txt = scratchDir + '/' + projectName + '/ifgram_list.txt'
    ifgList0 = ut.read_txt2array(ifgramList_txt)
    ifgList = ifgList0[:, 0]

    err_txt = scratchDir + '/' + projectName + '/geocode_gamma_all.err'
    if os.path.isfile(err_txt): os.remove(err_txt)

    data_para = []
    for i in range(len(ifgList)):
        #m0 = ut.yyyymmdd(ifgList[i].split('-')[0])
        #s0 = ut.yyyymmdd(ifgList[i].split('-')[1])
        cmd0 = ['geocode_gamma.py', projectName, ifgList[i]]
        data0 = [cmd0, err_txt]
        geo_file0 = ifgDir + '/' + ifgList[i] + '/geo_' + ifgList[
            i] + '_' + rlks + 'rlks.diff_filt.unw.bmp'

        k00 = 0
        if os.path.isfile(geo_file0):
            if os.path.getsize(geo_file0) > 0:
                k00 = 1
        if k00 == 0:
            data_para.append(data0)

        data_para.append(data0)

    ut.parallel_process(data_para,
                        work,
                        n_jobs=inps.parallelNumb,
                        use_kwargs=False)
    print("Geocode interferograms for project %s is done! " % projectName)
    ut.print_process_time(start_time, time.time())

    sys.exit(1)
Exemple #3
0
def main(argv):

    inps = cmdLineParse()
    projectName = inps.projectName
    Sdate = inps.sdate

    scratchDir = os.getenv('SCRATCHDIR')
    templateDir = os.getenv('TEMPLATEDIR')
    templateFile = templateDir + "/" + projectName + ".template"

    slcDir = scratchDir + '/' + projectName + "/SLC"
    rslcDir = scratchDir + '/' + projectName + "/RSLC"
    if not os.path.isdir(rslcDir): os.mkdir(rslcDir)
    #workDir    = processDir + '/' + igramDir
    workDir = rslcDir + '/' + Sdate
    if not os.path.isdir(workDir): os.mkdir(workDir)

    templateDict = ut.update_template(templateFile)
    rlks = templateDict['range_looks']
    azlks = templateDict['azimuth_looks']
    Mdate = templateDict['masterDate']

    demDir = scratchDir + '/' + projectName + '/DEM'

    #  Definition of file
    MslcDir = slcDir + '/' + Mdate
    SslcDir = slcDir + '/' + Sdate
    Samp = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp'
    SampPar = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp.par'
    Sampbmp = rslcDir + '/' + Sdate + '/' + Sdate + '_' + rlks + 'rlks.amp.bmp'

    Mslc = slcDir + '/' + Mdate + '/' + Mdate + '.slc'
    Mslcpar = slcDir + '/' + Mdate + '/' + Mdate + '.slc.par'
    Mamp = slcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp'
    MampPar = slcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp.par'
    Mampbmp = slcDir + '/' + Mdate + '/' + Mdate + '_' + rlks + 'rlks.amp.bmp'

    SLC1_INF_tab0 = MslcDir + '/' + Mdate + '_SLC_Tab'
    SLC2_INF_tab = SslcDir + '/' + Sdate + '_SLC_Tab'
    RSLC_tab = SslcDir + '/' + Sdate + '_RSLC_Tab'
    SLC1_INF_tab = SslcDir + '/' + Mdate + '_SLC_Tab_coreg'

    HGTSIM = demDir + '/' + Mdate + '_' + rlks + 'rlks.rdc.dem'
    if not os.path.isfile(HGTSIM):
        call_str = 'generate_rdc_dem.py ' + projectName
        os.system(call_str)

    ############## copy master files into slave folder for parallel process ###########

    #if not templateDict['coreg_all_parallel'] == '1':
    #    Mslc = slcDir  + '/' + Sdate + '/' + Mdate + '.slc'
    #    Mslcpar = slcDir  + '/' + Sdate + '/' + Mdate + '.slc.par'
    #    Mamp = slcDir  + '/' + Sdate + '/' + Mdate + '_' + rlks + 'rlks.amp'
    #    MampPar = slcDir  + '/' + Sdate + '/' + Mdate + '_' + rlks + 'rlks.amp.par'
    #    HGTSIM      = slcDir  + '/' + Sdate + '/' + Mdate + '_' + rlks + 'rlks.rdc.dem'

    #else:

    #    Mslc = Mslc0
    #    Mslcpar = Mslcpar0
    #    Mamp = Mamp0
    #    MampPar = MampPar0
    #    HGTSIM  = HGTSIM0

    #Mslc = slcDir  + '/' + Sdate + '/' + Mdate + '.slc'
    #Mslcpar = slcDir  + '/' + Sdate + '/' + Mdate + '.slc.par'
    #Mamp = slcDir  + '/' + Sdate + '/' + Mdate + '_' + rlks + 'rlks.amp'
    #MampPar = slcDir  + '/' + Sdate + '/' + Mdate + '_' + rlks + 'rlks.amp.par'
    #HGTSIM      = slcDir  + '/' + Sdate + '/' + Mdate + '_' + rlks + 'rlks.rdc.dem'
    SLC1_INF_tab1 = SslcDir + '/' + Mdate + '_SLC_Tab'
    ut.copy_file(SLC1_INF_tab0, SLC1_INF_tab1)
    ##############################################################################
    with open(SLC1_INF_tab1, "r") as f:
        lines = f.readlines()

    with open(SLC1_INF_tab, "w") as fw:
        lines_coreg = []
        for k0 in lines:
            k00 = k0.replace(MslcDir, SslcDir)
            lines_coreg.append(k00)
            fw.write(k00)

    S_IW = ut.read_txt2array(SLC1_INF_tab1)
    S_IW = S_IW.flatten()
    #M_IW = ut.read_txt2array(SLC1_INF_tab1)
    #M_IW = M_IW.flatten()
    #S_IW = ut.read_txt2array(SLC1_INF_tab)
    #S_IW = S_IW.flatten()

    #RSLC_tab = workDir + '/' + Sdate + '_RSLC_tab'
    #if os.path.isfile(RSLC_tab):
    #    os.remove(RSLC_tab)

    #BURST = SslcDir + '/' + Sdate + '_Burst_Tab'
    #AA = np.loadtxt(BURST)
    #if EW==SW:
    #    AA = AA.reshape([1,2])
    #
    #for kk in range(int(EW)-int(SW)+1):
    #    ii = int(int(kk) + 1)
    #    SB2=AA[ii-1,0]
    #    EB2=AA[ii-1,1]
    #    call_str = 'echo ' + workDir + '/'+ Sdate+ '_'+ str(int(SB2)) + str(int(EB2)) +'.IW'+str(int(SW)+kk)+ '.rslc' + ' ' + workDir + '/' + Sdate + '_'+ str(int(SB2)) + str(int(EB2)) +'.IW'+ str(int(SW)+kk)+ '.rslc.par' + ' ' + workDir + '/'+ Sdate+'_'+ str(int(SB2)) + str(int(EB2)) + '.IW'+str(int(SW)+kk)+ '.rslc.TOPS_par >>' + RSLC_tab
    #   os.system(call_str)

    os.chdir(workDir)
    #TEST = workDir + '/' + Sdate +'_' + rlks + 'rlks.amp.par'
    TEST = workDir + '/' + Sdate + '.rslc.par'

    k0 = 0
    if os.path.isfile(TEST):
        if os.path.getsize(TEST) > 0:
            k0 = 1

    if k0 == 0:
        if not Mdate == Sdate:
            call_str = 'S1_coreg_TOPS ' + SLC1_INF_tab1 + ' ' + Mdate + ' ' + SLC2_INF_tab + ' ' + Sdate + ' ' + RSLC_tab + ' ' + HGTSIM + ' ' + rlks + ' ' + azlks + ' - - 0.6 0.01 1.2 1'
            os.system(call_str)

            #### clean large file ####
            mslc = workDir + '/' + Mdate + '.slc'
            mrslc = workDir + '/' + Mdate + '.rslc'
            sslc = workDir + '/' + Sdate + '.slc'
            srslc = workDir + '/' + Sdate + '.rslc'
            srslcPar = workDir + '/' + Sdate + '.rslc.par'

            call_str = 'multi_look ' + srslc + ' ' + srslcPar + ' ' + Samp + ' ' + SampPar + ' ' + rlks + ' ' + azlks
            os.system(call_str)
            nWIDTH = ut.read_gamma_par(SampPar, 'read', 'range_samples')
            if os.path.isfile(mslc): os.remove(mslc)
            if os.path.isfile(mrslc): os.remove(mrslc)
            if os.path.isfile(sslc): os.remove(sslc)

            call_str = 'raspwr ' + Samp + ' ' + nWIDTH
            os.system(call_str)

            #call_str = 'rm *mli*'
            #os.system(call_str)

            #call_str = 'rm *IW*'
            #os.system(call_str)

            #call_str = 'rm *off*'
            #os.system(call_str)

            #call_str = 'rm *diff'
            #os.system(call_str)

            #call_str = 'rm *diff_par*'
            #os.system(call_str)

            #call_str = 'rm ' + Mdate + '.*'
            #os.system(call_str)

        else:
            call_str = 'cp ' + Mslc + ' ' + workDir + '/' + Mdate + '.rslc'
            os.system(call_str)

            call_str = 'cp ' + Mslcpar + ' ' + workDir + '/' + Mdate + '.rslc.par'
            os.system(call_str)

            call_str = 'cp ' + Mamp + ' ' + workDir + '/' + Mdate + '_' + rlks + 'rlks.amp'
            os.system(call_str)

            call_str = 'cp ' + MampPar + ' ' + workDir + '/' + Mdate + '_' + rlks + 'rlks.amp.par'
            os.system(call_str)

            ut.copy_file(Mampbmp, Sampbmp)

    ################   clean redundant files #############

    #if not Mdate ==Sdate:

    #    if not templateDict['diff_all_parallel'] == '1':
    #        for i in range(len(S_IW)):
    #            if os.path.isfile(S_IW[i]):
    #                os.remove(S_IW[i])
    #        if os.path.isfile(Mslc): os.remove(Mslc)
    #        if os.path.isfile(Mslcpar): os.remove(Mslcpar)
    #        if os.path.isfile(Mamp): os.remove(Mamp)
    #        if os.path.isfile(HGTSIM): os.remove(HGTSIM)

    print("Coregister TOP SLC image to the reference TOPS image is done !!")
    sys.exit(1)
Exemple #4
0
def main(argv):
    
    inps = cmdLineParse()     
    projectName = inps.projectName
    scratchDir = os.getenv('SCRATCHDIR')
    templateDir = os.getenv('TEMPLATEDIR')
    templateFile = templateDir + "/" + projectName + ".template"
    templateDict=ut.update_template(templateFile)
    templateDict['network_method'] = inps.method
    templateDict['conNumb'] = inps.conNumb
    
    processDir = scratchDir + '/' + projectName
    slcDir     = scratchDir + '/' + projectName + "/SLC"
    rslcDir    = scratchDir + '/' + projectName + '/RSLC'
    
    #slc_list = ut.get_project_slcList(projectName)    
    masterDate = templateDict['masterDate']
    
    if inps.coreg: 
        slcDir  = rslcDir
        slc0    = '.rslc'
        slcpar0 = '.rslc.par'
    else:
        slc0    = '.slc'
        slcpar0 = '.slc.par'
        
    slc_list0 = [os.path.basename(fname) for fname in sorted(glob.glob(slcDir + '/*'))]
    slc_list = []
    for k0 in slc_list0:
        if ut.is_number(k0):
            slc_list.append(k0)
    slc_list = sorted(slc_list)    
    
    SLCfile = []
    SLCParfile = []
    for kk in range(len(slc_list)):
        str_slc = slcDir + "/" + slc_list[kk] +"/" + slc_list[kk] + slc0
        str_slc_par = slcDir + "/" + slc_list[kk] +"/" + slc_list[kk] + slcpar0
        SLCfile.append(str_slc)
        SLCParfile.append(str_slc_par)       

    RefPar = slcDir + "/" + masterDate +"/" + masterDate + slcpar0
    SLC_Tab = scratchDir + '/' + projectName  + "/SLC_Tab"
    
    SLC_Tab_all = processDir + "/SLC_Tab_all"
    TS_Berp_all = processDir + "/TS_Berp_all"
    TS_Itab_all = processDir + "/TS_Itab_all"
    itab_type = '1'
    pltflg = '0'
    
    if os.path.isfile(SLC_Tab): os.remove(SLC_Tab)
    with open(SLC_Tab, 'a') as f:
        for kk in range(len(SLCfile)):
            f.write(str(SLCfile[kk])+ ' '+str(SLCParfile[kk])+'\n')

    ## Get all of the pairs using GAMMA
    call_str = "base_calc " + SLC_Tab + " " + RefPar + " " + TS_Berp_all + " " + TS_Itab_all + " " + '1 0 ' + '- - - -  >/dev/null'
    os.system(call_str)
      
    with open(TS_Berp_all, 'r') as f:
        lines = f.readlines()  
        
    TS_Net_all = ut.read_txt2array(TS_Berp_all)
    if len(lines) ==1:
        TS_Net_all = TS_Net_all.reshape(1,9)

    TS_Net = TS_Net_all[0:(len(SLCfile)-1),:]
    date_list, tbase_list, pbase_list =  get_datelist_bperplist(TS_Net)
    bl_list_txt =  scratchDir + '/' + projectName + '/bl_list.txt'
    with open(bl_list_txt, 'w') as f:
        for kk in range(len(SLCfile)):
            f.write(str(date_list[kk])+ ' '+str(pbase_list[kk])+'\n')
       
    exclude_list = []
    if 'exclude_date' in templateDict: 
        exclude_list = templateDict['exclude_date'].split(',')[:]
    if inps.excludeDate:
        exclude_list0 = inps.excludeDate
        for k0 in exclude_list0:
            exclude_list.append(k0)
    templateDict['exclude_list'] = exclude_list
    
    if inps.startDate: templateDict['startDate'] = inps.startDate
    if inps.endDate: templateDict['endDate'] = inps.endDate
    if inps.maxTB: templateDict['max_tb'] = inps.maxTB
    if inps.maxSB: templateDict['max_sb'] = inps.maxSB
        
    date_list, tbase_list, pbase_list = prune_datelist(date_list, tbase_list, pbase_list, templateDict)
    date12_list, ifgram_tbase_list, ifgram_pbase_list = select_network_candidate(date_list,tbase_list,pbase_list,templateDict)
    date12_list_final, ifgram_tbase_list_final, ifgram_pbase_list_final =  prune_network(date12_list, ifgram_tbase_list, ifgram_pbase_list, templateDict)
    
    if inps.outfile: out_file = inps.outfile
    else: out_file = scratchDir + '/' + projectName  + "/ifgram_list.txt"
        
    write_ifgram_list(date12_list_final,ifgram_tbase_list_final,ifgram_pbase_list_final, out_file)
    sys.exit(1)
Exemple #5
0
def main(argv):
    
    inps = cmdLineParse() 
    projectName = inps.projectName
    Sdate = inps.Sdate

    scratchDir = os.getenv('SCRATCHDIR')
    templateDir = os.getenv('TEMPLATEDIR')
    templateFile = templateDir + "/" + projectName + ".template"
    templateDict=ut.update_template(templateFile)
           
    rlks = templateDict['range_looks']
    azlks = templateDict['azimuth_looks']
    Mdate =  templateDict['masterDate']
    
    processDir = scratchDir + '/' + projectName + "/PROCESS"
    slcDir     = scratchDir + '/' + projectName + "/SLC"
    rslcDir     = scratchDir + '/' + projectName + "/RSLC"
    
    workDir0 = rslcDir + '/' + Sdate
    #if not os.path.isdir(rslcDir):
    #    os.mkdir(rslcDir)
        
    MslcDir    = slcDir + '/' + Mdate
    SslcDir    = slcDir + '/' + Sdate
    #MBurst_Par = slcDir + '/' + Mdate + '/' + 
    workDir = slcDir + '/' + Sdate
    
    BURST = workDir + '/' + Mdate + '_' + Sdate + '.common_burst_ref'
    
    MslcImg = workDir + '/'+Mdate + '.slc'
    MslcPar = workDir + '/'+Mdate + '.slc.par'    
    
    MamprlksImg = workDir + '/'+Mdate +   '_' + rlks + 'rlks' + '.amp'
    MamprlksPar = workDir + '/'+Mdate +   '_' + rlks +'rlks' + '.amp.par' 
    
    SslcImg = workDir + '/'+ Sdate + '.slc'
    SslcPar = workDir + '/'+ Sdate + '.slc.par'    
    
    SamprlksImg = workDir + '/'+ Sdate +  '_' + rlks + 'rlks' + '.amp'
    SamprlksPar = workDir + '/'+ Sdate +  '_' + rlks + 'rlks' + '.amp.par' 
    
    if not os.path.isdir(workDir):
        os.mkdir(workDir)
    
    get_common_burst(MslcDir,SslcDir,BURST)
    AA = ut.read_txt2array(BURST)
    NL = ut.get_txt_lines(BURST)
    
    if NL ==1:
        AA = AA.reshape(1,len(AA))
    
    
    SW = templateDict['start_swath']
    EW = templateDict['end_swath']             
                  
    SB = templateDict['start_burst']
    EB = templateDict['end_burst'] 
    
        
    SLC2_tab = workDir + '/' + Sdate + '_SLC_Tab0'
        

    SLC2_INF_tab = workDir + '/' + Sdate + '_SLC_Tab'
    SLC2_RSLC_tab = workDir + '/' + Sdate + '_RSLC_Tab'
    
    BURST2_tab = workDir + '/' + Sdate + '_Burst_Tab'
    
    if os.path.isfile(SLC2_tab):
        os.remove(SLC2_tab)
        
    if os.path.isfile(SLC2_INF_tab):
        os.remove(SLC2_INF_tab)
        
    if os.path.isfile(SLC2_RSLC_tab):
        os.remove(SLC2_RSLC_tab)
    
    if os.path.isfile(BURST2_tab):
        os.remove(BURST2_tab)
    
    for kk in range(int(EW)-int(SW)+1):
        
        call_str = 'echo ' + SslcDir + '/' + Sdate+'.IW'+str(int(SW)+kk) + '.slc' + ' ' + SslcDir + '/'+ Sdate + '.IW'+str(int(SW)+kk) +'.slc.par' + ' ' + SslcDir + '/'+ Sdate+'.IW'+str(int(SW)+kk) + '.slc.TOPS_par >>' + SLC2_tab
        os.system(call_str)
        
        ii = int(SW) + kk
        SB1=int(AA[ii-1,0])
        EB1=int(AA[ii-1,1])
        
        SB2=int(AA[ii-1,2])
        EB2=int(AA[ii-1,3])
        
        if not int(SB)==1:
            SB2 = SB2 + int(SB) - int(SB1)
        if not int(EB)==100:
            EB2 = SB2 + int(EB) - int(SB)
        
        call_str = 'echo ' + workDir + '/'+ Sdate+ '_'+ str(int(SB2)) + str(int(EB2)) +'.IW'+str(int(SW)+kk)+ '.slc' + ' ' + workDir + '/' + Sdate + '_'+ str(int(SB2)) + str(int(EB2)) +'.IW'+ str(int(SW)+kk)+ '.slc.par' + ' ' + workDir + '/'+ Sdate+'_'+ str(int(SB2)) + str(int(EB2)) + '.IW'+str(int(SW)+kk)+ '.slc.TOPS_par >>' + SLC2_INF_tab
        os.system(call_str)
        
        call_str = 'echo ' + workDir0 + '/'+ Sdate+ '_'+ str(int(SB2)) + str(int(EB2)) +'.IW'+str(int(SW)+kk)+ '.rslc' + ' ' + workDir + '/' + Sdate + '_'+ str(int(SB2)) + str(int(EB2)) +'.IW'+ str(int(SW)+kk)+ '.rslc.par' + ' ' + workDir + '/'+ Sdate+'_'+ str(int(SB2)) + str(int(EB2)) + '.IW'+str(int(SW)+kk)+ '.rslc.TOPS_par >>' + SLC2_RSLC_tab
        os.system(call_str)
        
        call_str = 'echo ' + str(int(SB2)) + ' ' + str(int(EB2)) + ' >>' + BURST2_tab
        os.system(call_str)

      
    TEST = SamprlksPar
    k0 = 0
    if os.path.isfile(TEST):
        if os.path.getsize(TEST) > 0:
            k0 = 1
    
    if k0==0:
    
        call_str = 'SLC_copy_ScanSAR ' + SLC2_tab + ' ' + SLC2_INF_tab  + ' ' + BURST2_tab 
        os.system(call_str)
    
        call_str = 'SLC_mosaic_S1_TOPS ' + SLC2_INF_tab + ' ' + SslcImg + ' ' + SslcPar + ' ' + rlks + ' ' +azlks
        os.system(call_str)
    
        call_str = 'multi_look ' + SslcImg + ' ' + SslcPar + ' ' + SamprlksImg + ' ' + SamprlksPar + ' ' + rlks + ' ' + azlks
        os.system(call_str) 
    
        nWidth = ut.read_gamma_par(SamprlksPar, 'read', 'range_samples')
        call_str = 'raspwr ' + SamprlksImg + ' ' + nWidth 
        os.system(call_str)  
    
    sys.exit(1)