def main(argv):
    parser = build_parser()
    parseArgs = parser.parse_args()

    username = parseArgs.user
    password = parseArgs.password
    host = parseArgs.host
    db = parseArgs.db
    working_dir = parseArgs.folder

    # make sure we have a final / so the below code doesn't break
    if working_dir[-1] != "/":
        working_dir += "/"

    unavco_name = parseArgs.unavco_name
    attributes_file = working_dir + "add_Attribute.txt"
    attributes = readfile.read_template(attributes_file)
    dbController = InsarDatabaseController(username, password, host, db)
    dbController.connect()

    for key in attributes:
        print("Setting attribute " + key + " to " + attributes[key])
        if key == "plotAttributes":
            dbController.add_plot_attribute(unavco_name, key, attributes[key])
        else:
            dbController.add_attribute(unavco_name, key, attributes[key])

    dbController.index_table_on("extra_attributes", "area_id", "area_id_idx")
    dbController.close()
Example #2
0
def read_template2inps(template_file, inps=None):
    '''Read input template file into inps.ex_date'''
    if not inps:
        inps = cmdLineParse()
    template = readfile.read_template(template_file)
    key_list = list(template.keys())

    # Read template option
    prefix = 'pysar.velocity.'
    key = prefix + 'excludeDate'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.ex_date = ['exclude_date.txt']
        elif value == 'no':
            inps.ex_date = []
        else:
            inps.ex_date = value.replace(',', ' ').split()

    key = prefix + 'startDate'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.min_date = ptime.yyyymmdd(value)

    key = prefix + 'endDate'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.max_date = ptime.yyyymmdd(value)

    return inps
Example #3
0
def read_template2inps(templateFile, inps=None):
    '''Update inps with options from templateFile'''
    if not inps:
        inps = cmdLineParse()

    template = readfile.read_template(templateFile)
    key_list = list(template.keys())

    key = 'pysar.reference.date'
    if key in key_list:
        inps.ref_date = template[key]

    prefix = 'pysar.residualStd.'
    key = prefix+'maskFile'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.mask_file = 'maskTempCoh.h5'
        elif value == 'no':
            inps.mask_file = None
        else:
            inps.mask_file = value

    key = prefix+'ramp'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.ramp_type = 'quadratic'
        else:
            inps.ramp_type = 'no'

    return inps
Example #4
0
def main(argv):
    inps = cmdLineParse()
    # output filename
    ext = os.path.splitext(inps.ifgram_file)[1]
    if not inps.outfile:
        inps.outfile = os.path.splitext(inps.ifgram_file)[0]+'_unwCor'+ext

    # read template file
    if inps.template_file:
        template = readfile.read_template(inps.template_file)
        key = 'pysar.unwrapError.yx'
        if key in list(template.keys()):
            print('read '+key+' option from template file: '+inps.template_file)
            yx = template[key].replace(';',' ').replace(',',' ').split()
            yx = [int(i) for i in yx]
            inps.y = yx[0::2]
            inps.x = yx[1::2]

    # Memthod
    if inps.y and inps.x:
        inps.method = 'bridging'
    else:
        inps.method = 'phase_closure'
    print('unwrapping error correction using method: '+inps.method)

    #####
    if inps.method == 'phase_closure':
        inps.outfile = unwrap_error_correction_phase_closure(inps.ifgram_file, inps.mask_file, inps.outfile)

    elif inps.method == 'bridging':
        inps.outfile = unwrap_error_correction_bridging(inps.ifgram_file, inps.mask_file, inps.y, inps.x,\
                                                        inps.ramp_type, inps.outfile)[0]

    print('Done.')
    return inps.outfile
Example #5
0
def read_template2inps(template_file, inps=None):
    '''Read input template file into inps.ex_date'''
    if not inps:
        inps = cmdLineParse()
    template = readfile.read_template(template_file)
    key_list = list(template.keys())

    # Read template option
    prefix = 'pysar.topoError.'

    key = prefix + 'polyOrder'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.poly_order = 2
        else:
            inps.poly_order = int(value)

    key = prefix + 'excludeDate'
    if key in key_list:
        value = template[key]
        if value in ['auto', 'no']:
            inps.ex_date = []
        else:
            inps.ex_date = value.replace(',', ' ').split()

    key = prefix + 'stepFuncDate'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.step_date = ptime.yyyymmdd(value)
        else:
            inps.step_date = None

    return inps
Example #6
0
def main(argv):

    ##### Check Inputs
    if not argv or argv[0] in ['-h', '--help']:
        usage()
        sys.exit(1)
    if len(argv) < 2 or not argv[1]:
        raise Exception('\nAt lease 2 inputs are needed.\n')

    ##### Read Original Attributes
    #print '************ Add / Update HDF5 File Attributes *************'
    File = argv[0]
    atr = readfile.read_attribute(File)
    print('Input file is ' + atr['PROCESSOR'] + ' ' + atr['FILE_TYPE'] + ': ' +
          File)

    ##### Read New Attributes
    atr_new = dict()
    for i in range(1, len(argv)):
        if os.path.isfile(argv[i]):
            atr_tmp = readfile.read_template(argv[i])
            atr_new.update(atr_tmp)
        else:
            atr_tmp = argv[i].split('=')
            atr_new[atr_tmp[0].strip()] = atr_tmp[1].strip()
    print(
        "The following attributes will be added/updated, or removed if new value is 'None':"
    )
    info.print_attributes(atr_new)

    ext = os.path.splitext(File)[1]
    ##### Update h5 File
    if ext in ['.h5', '.he5']:
        File = ut.add_attribute(File, atr_new)
    else:
        if not ut.update_attribute_or_not(atr_new, atr):
            print(
                'All updated (removed) attributes already exists (do not exists) and have the same value, skip update.'
            )
        else:
            for key, value in atr_new.items():
                # delete the item is new value is None
                if value == 'None':
                    try:
                        atr.pop(key)
                    except:
                        pass
                else:
                    atr[key] = value
            if atr['PROCESSOR'] == 'roipac':
                print('writing >>> ' + File + '.rsc')
                writefile.write_roipac_rsc(atr, File + '.rsc')

    return File
Example #7
0
def read_template2inps(templateFile, inps=None):
    '''Update inps with pysar.residualRms.* option from templateFile'''
    if not inps:
        inps = cmdLineParse()

    template = readfile.read_template(templateFile)
    key_list = list(template.keys())

    prefix = 'pysar.residualRms.'

    key = prefix + 'maskFile'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.mask_file = 'maskTempCoh.h5'
        elif value == 'no':
            inps.mask_file = None
        else:
            inps.mask_file = value

    key = prefix + 'ramp'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.ramp_type = 'quadratic'
        else:
            inps.ramp_type = value

    key = prefix + 'threshold'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.min_rms = 0.02
        else:
            inps.min_rms = float(value)

    key = prefix + 'saveRefDate'
    if key in key_list:
        value = template[key]
        if value in ['auto', 'yes']:
            inps.save_reference_date = True
        else:
            inps.save_reference_date = False

    key = prefix + 'saveExcludeDate'
    if key in key_list:
        value = template[key]
        if value in ['auto', 'yes']:
            inps.save_exclude_date = True
        else:
            inps.save_exclude_date = False

    return inps
Example #8
0
def read_seed_template2inps(template_file, inps=None):
    '''Read seed/reference info from template file and update input namespace'''
    if not inps:
        inps = cmdLineParse([''])

    template = readfile.read_template(template_file)
    key_list = list(template.keys())

    prefix = 'pysar.reference.'

    key = prefix + 'yx'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.ref_y, inps.ref_x = [int(i) for i in value.split(',')]

    key = prefix + 'lalo'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.ref_lat, inps.ref_lon = [float(i) for i in value.split(',')]

    key = prefix + 'maskFile'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.mask_file = None
        elif value == 'no':
            inps.mask_file = None
        else:
            inps.mask_file = value

    key = prefix + 'coherenceFile'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.coherence_file = 'averageSpatialCoherence.h5'
        else:
            inps.coherence_file = value

    key = prefix + 'minCoherence'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.min_coherence = 0.85
        else:
            inps.min_coherence = float(value)

    return inps
Example #9
0
def main(argv):
    # import pdb; pdb.set_trace()

    messageRsmas.log(' '.join(argv))
    inps = command_line_parse()
    # moved below to parse methods
    # parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
    #                                 epilog=EXAMPLE)
    # parser.add_argument('custom_template_file', nargs='?',
    #                    help='custom template with option settings.\n')
    # inps = parser.parse_args()

    custom_template = readfile.read_template(inps.custom_template_file)

    # import pdb;
    # pdb.set_trace()
    if os.path.isdir('DEM'):
        shutil.rmtree('DEM')
    os.mkdir('DEM')
    os.chdir('DEM')

    # cwd = os.getcwd()

    if 'sentinelStack.demMethod' not in custom_template.keys():
        custom_template['sentinelStack.demMethod'] = 'bbox'

    if custom_template['sentinelStack.demMethod'] == 'bbox' and inps.ssara:
        call_ssara_dem()
    if inps.new:
        print('nice job kawan! You aren\' dumb!')
    if custom_template['sentinelStack.demMethod'] == 'bbox' and inps.isce:
        print('you started isce')
        call_isce_dem(custom_template)
        print('you finished isce')

    else:
        sys.exit('Error unspported demMethod option: ' +
                 custom_template['sentinelStack.demMethod'])

    print('\n###############################################')
    print('End of dem_rsmas.py')
    print('################################################\n')
Example #10
0
def read_subset_template2box(templateFile):
    '''Read pysar.subset.lalo/yx option from template file into box type
    Return None if not specified.
    '''
    tmpl = readfile.read_template(templateFile)
    try:
        sub = [i.strip() for i in tmpl['pysar.subset.lalo'].split(',')]
        sub_lat = sorted([float(i.strip()) for i in sub[0].split(':')])
        sub_lon = sorted([float(i.strip()) for i in sub[1].split(':')])
        geo_box = (sub_lon[0], sub_lat[1], sub_lon[1], sub_lat[0])
    except:
        geo_box = None
    try:
        sub = [i.strip() for i in tmpl['pysar.subset.yx'].split(',')]
        sub_y = sorted([int(i.strip()) for i in sub[0].split(':')])
        sub_x = sorted([int(i.strip()) for i in sub[1].split(':')])
        pix_box = (sub_x[0], sub_y[0], sub_x[1], sub_y[1])
    except:
        pix_box = None
    return pix_box, geo_box
Example #11
0
def main(argv):
  try:
    templateFile = argv[1]
  except:
    Usage();sys.exit(1)

  projectName = os.path.basename(templateFile.partition('.')[0])

  try:
     tssarProjectDir = os.getenv('TSSARDIR') +'/'+projectName
  except:
     tssarProjectDir = os.getenv('SCRATCHDIR') + '/' + projectName + "/TSSAR"     # FA 7/2015: adopted for new directory structure
 
  print "QQ " + tssarProjectDir
  if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir)
  os.chdir(tssarProjectDir)

  igramFile = 'LoadedData.h5'
  Modified_igramFile = 'Modified_LoadedData.h5'
  if os.path.isfile(Modified_igramFile):
    print Modified_igramFile + ' already exists.'
    igramFile=Modified_igramFile

  template = readfile.read_template(templateFile)
  Rlooks = template['Rlooks_unw']

#########################################
# Loading interferograms
#########################################
  print '******************************************'
  print''
  if os.path.isfile(igramFile):
    print igramFile + ' already exists.'
  else:
    loadCmd='load_data.py ' + templateFile 
    print loadCmd
    os.system(loadCmd)

#    copyDemCmd='copy_dem_trans.py ' + templateFile
#    print copyDemCmd
#    os.system(copyDemCmd)
  print''
  print '******************************************'


#########################################
# Check the subset
#########################################
  try:
    subset= template['pysar.subset.yx'].split(',')
    print subset
    print subset[0]
    subsetOutName='subset_'+igramFile
    subsetCmd='subset.py -f '+ igramFile + ' -y '+subset[0]+' -x '+subset[1] + ' -o ' + subsetOutName
    print '*****************************************'
    print 'Subset the area ...'
    print subsetCmd
    os.system(subsetCmd)
    igramFile=subsetOutName
    print '*****************************************'
  except:
    print '*****************************************'
    print 'No Subset selected. Processing the whole area'
    print '*****************************************'

#########################################
#Referencing all interferograms to the same pixel 
#########################################
  rdr_or_geo=radar_Or_geo(igramFile)  
  print '******************************************'
  print''
  if os.path.isfile('Seeded_'+igramFile):
    igramFile = 'Seeded_'+igramFile
    print igramFile + ' already exists.'
  else:
    print 'referncing all interferograms to the same pixel.'
    if 'pysar.seed.ll' in template.keys():
       'Checking the lat/lon refernce point' 
       lat= template['pysar.seed.ll'].split(',')[0]
       lon= template['pysar.seed.ll'].split(',')[1]
       seedCmd= 'SeedData.py -f ' + igramFile + ' -l ' +lat+ ' -L '+lon
    elif 'pysar.seed.yx' in template.keys():
       'Checking y/x reference point'
       y= template['pysar.seed.yx'].split(',')[0]
       x= template['pysar.seed.yx'].split(',')[1]
       seedCmd= 'seed_data.py -f ' + igramFile + ' -y ' +y+ ' -x '+x
    else: 
       seedCmd= 'seed_data.py -f ' + igramFile

    igramFile = 'Seeded_'+igramFile
    print seedCmd  
    os.system(seedCmd)
  print''
  print '******************************************'

############################################
#unwrapping error correction based on the 
# consistency of triplets of interferograms  
############################################
  print '******************************************'
  print''
  try:
       template['pysar.unwrap_error']
       if template['pysar.unwrap_error'] in ('y','yes','Yes','YES'):
         print 'unwrapping error correction might take a while depending on the size of your data set! '
         unwCmd='unwrap_error.py '+igramFile
         os.system(unwCmd)
         igramFile=igramFile.split('.')[0]+'_unwCor.h5'      
       else:
         print 'No unwrapping error correction.'
  except:
       print 'No unwrapping error correction.'
  print''
  print '******************************************'

#########################################
# inversion of interferograms
########################################
  print '******************************************'
  print''
  if os.path.isfile(igramFile.split('.')[0]+'_unwCor.h5'):
     igramFile = igramFile.split('.')[0]+'_unwCor.h5'
     print igramFile + ' exists.'

  if os.path.isfile('timeseries.h5'):
     print 'timeseries.h5 already exists, inversion is not needed.'
  else:
     invertCmd = 'igram_inversion.py '+ igramFile 
     print invertCmd
     os.system(invertCmd)
  timeseriesFile='timeseries.h5'
  print''
  print '******************************************'

##############################################
#temporal coherence: 
#A parameter to evaluate the consistency of 
# timeseries with the interferograms
##############################################
  print '******************************************'
  print''
#  if os.path.isfile('temporal_coherence.h5'):
#     print 'temporal_coherence.h5 already exists.'
#  else:
#     tempcohCmd='temporal_coherence.py '+igramFile+' '+timeseriesFile
#     print tempcohCmd
#     os.system(tempcohCmd)
  tempcohCmd='temporal_coherence.py '+igramFile+' '+timeseriesFile
  print tempcohCmd
  os.system(tempcohCmd)
  print''
  print '******************************************'


##############################################
#update Mask based on temporal coherence
# add by Yunjun Feb 15, 2015
##############################################
  print '******************************************'
  print''
  try:
       template['pysar.mask']
       if template['pysar.mask'] in ('yes','Yes','YES','y'):
         print 'Updating mask according to temporal coherence'
         cohT=template['pysar.mask.threshold']
         maskCmd='generate_mask.py -f temporal_coherence.h5 -m '+ cohT +' -M 1.0 -o Mask.h5'
         print maskCmd
         os.system(maskCmd)
       else:
         print 'No update for mask.'
  except:
       print 'No update for mask.'
  print''
  print '******************************************'


##############################################
# Generate incident angle
# add by Yunjun Feb 15, 2015 
##############################################
  print '******************************************'
  print''
  inciCmd='incidence_angle.py -f timeseries.h5'
  print inciCmd
  os.system(inciCmd)
  print''
  print '******************************************'

##############################################
#If Satellite is Envisat and if Coordinate
#system is radar then LOD correction
##############################################
  print '******************************************'
  print''
  h5file=h5py.File(timeseriesFile,'r')
  if rdr_or_geo =='radar':
    if h5file['timeseries'].attrs['PLATFORM']=='ENVISAT':
      LODcmd='lod.py '+timeseriesFile
      print LODcmd
      os.system(LODcmd)
      timeseriesFile=timeseriesFile.split('.')[0]+'_LODcor.h5'
  print''
  print '******************************************'


##############################################
# Tropospheric Correction
##############################################
  print '******************************************'
  print''

  try:
     if (template['pysar.tropospheric_delay'] in ('y','yes','Yes','YES')) and template['pysar.orbit_error.method']=='BaseTropCor':
         print '''
   +++++++++++++++++++++++++++++++++++++++++++++++++++
   WARNING:
       Orbital error correction was BaseTropCor.
       Tropospheric correction was already applied simultaneous with baseline error correction.
       Tropospheric correction can not be applied again.
       To apply the tropospheric correction separate from baseline error correction, chhose other existing options for orbital error correction.
    +++++++++++++++++++++++++++++++++++++++++++++++++++      
         '''
         template['pysar.tropospheric_delay']='no'
  except:
     print 'Checking the tropospheric delay correction ...'

  if template['pysar.tropospheric_delay'] in ('y','yes','Yes','YES'):     
    # demFile='radar_'+Rlooks+'rlks.hgt'
     demFile=template['pysar.dem']
     demFile=check_variable_name(demFile)
#     print 'DEM file: '+demFile
     if not os.path.isfile(demFile):
        print '++++++++++++++++++++++++++++++++++++++++++++++'
        print 'Error:'
        print 'DEM (radar_*rlks.hgt file) was not found!'
        print 'Continue without tropospheric correction ...'
        print '++++++++++++++++++++++++++++++++++++++++++++++'
     else:       
        if template['pysar.tropospheric_delay.method'] in ['height-correlation','height_correlation','Height-Correlation','Height_Correlation']:
           print 'tropospheric delay correction with height-correlation approach'
           try:
              polyOrder=template['pysar.trop.polyOrder']
           except:
              print 'Deafult polynomial order for troposphreic correction = 1'
              polyOrder='1'
           cmdTrop='tropospheric_correction.py'+ ' -f '+ timeseriesFile + ' -d '+ demfile + ' -p '+ polyOrder
           os.system(cmdTrop)
           timeseriesFile=timeseriesFile.split('.')[0]+'_tropCor.h5'
          
        elif template['pysar.tropospheric_delay.method']=='pyaps':
           print 'Atmospheric correction using Numerical Weather Models (using PyAPS software)'
           print 'reading DEM, source of NWM and acquisition time from template file'
           source_of_NWM=template['pysar.Numerical_Weather_Model']
           print 'Numerical Weather Model: '+source_of_NWM
           acquisition_time=template['pysar.acquisition_time']
           print 'acquisition time: '+acquisition_time
#           cmdTrop = ["tropcor_pyaps.py -f ",timeseriesFile," -d ",demFile," -s ",source_of_NWM," -h ",acquisition_time," -i incidence_angle.h5"]
           cmdTrop = 'tropcor_pyaps.py -f '+timeseriesFile+ ' -d '+ demFile +' -s ' + source_of_NWM + ' -h '+ acquisition_time + ' -i incidence_angle.h5'
           print cmdTrop
           os.system(cmdTrop)
#           subprocess.Popen(cmdTrop).wait()
           timeseriesFile=timeseriesFile.split('.')[0]+'_'+source_of_NWM+'.h5'
        else:
           print 'Atmospheric correction method not recognized.'
  else:
     print 'No atmospheric delay correction.'
  print''
  print '******************************************'

   
##############################################
#topographic residuals
##############################################
  print '******************************************'
  print''
  try:
       template['pysar.topo_error']
       if template['pysar.topo_error'] in ('yes','Yes','YES','y'):
         print 'Correcting topographic residuals'
         topoCmd='dem_error.py '+ timeseriesFile +' '+ igramFile
         print topoCmd
         os.system(topoCmd)
         timeseriesFile=timeseriesFile.split('.')[0]+'_demCor.h5'
       else:
         print 'No correction for topographic residuals.'
  except:
       print 'No correction for topographic residuals.'   
  print''
  print '******************************************'   

##############################################
#Orbit correction  
##############################################
  print '******************************************'
  print''
  try:
       template['pysar.orbit_error']
       if template['pysar.orbit_error'] in ('yes','Yes','YES','y'):
          try:
             orbit_error_method=template['pysar.orbit_error.method']
             print 'orbit error correction method : '+orbit_error_method
             if orbit_error_method in ['quadratic', 'plane', 'quardatic_range', 'quadratic_azimiuth', 'plane_range', 'plane_azimuth']: 
                orbitCmd='remove_plane.py '+timeseriesFile+' '+template['pysar.orbit_error.method'] #+ ' Mask.h5'
                timeseriesFile=timeseriesFile.split('.')[0]+'_'+template['pysar.orbit_error.method']+'.h5'
                print orbitCmd
                os.system(orbitCmd)
             elif orbit_error_method == 'baselineCor':
                orbitCmd='baseline_error.py ' +timeseriesFile #+ ' Mask.h5'
                print orbitCmd
                
                try:
                      h5file=h5py.File(timeseriesFile,'r')
                      daz=float(h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE'])
                      os.system(orbitCmd)
                      timeseriesFile=timeseriesFile.split('.')[0]+'_'+template['pysar.orbit_error.method']+'.h5'
                except:
                      print 'WARNING!'
                      print 'Skipping orbital error correction.'
                      print 'baselineCor method can only be applied in radar coordinate'
                        
             elif orbit_error_method =='BaseTropCor':
                demfile=template['pysar.dem']
                demfile=check_variable_name(demfile)
                try:
                    polyOrder=template['pysar.trop.polyOrder']
                except:
                    print 'Deafult polynomial order for troposphreic correction = 1'
                    polyOrder=1  
                try:
                   h5file=h5py.File(timeseriesFile,'r')
                   daz=float(h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE']) 
                   orbitCmd='baseline_trop.py '+timeseriesFile+' '+ demfile +' '+ polyOrder +'range_and_azimuth'
                   print 'Joint estimation of Baseline error and tropospheric delay [height-correlation approach]'
                   print orbitCmd
                   os.system(orbitCmd)
                   timeseriesFile=timeseriesFile.split('.')[0]+'_'+template['pysar.orbit_error.method']+'.h5'
                except:
                   print 'WARNING!'
                   print 'Skipping orbital error correction.'
                   print 'baselineCor method can only be applied in radar coordinate'
             else:
                print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++'
                print 'WARNING!'
                print 'Orbital error correction method was not recognized!'
                print 'Possible options are:'
                print 'quadratic, plane, quardatic_range, quadratic_azimiuth, plane_range, plane_azimuth,baselineCor,BaseTropCor'
                print 'Continue without orbital errors correction...'
                print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++'
                    
          except:
             print 'No orbital errors correction.'
       else:
          print 'No orbital errors correction.'
  except:
       print 'No orbital errors correction.'
  print''
  print '******************************************'

#############################################
#Velocity and rmse maps
#############################################

  print '******************************************'
  print''
  velCmd='timeseries2velocity.py '+timeseriesFile
  print velCmd
  os.system(velCmd)
  print''
  print '******************************************'

#############################################
#Masking the velocity based on the temporal 
#coherence or rmse if it's specified
#############################################
  print '******************************************'
  print''
  try:
       template['pysar.mask']
       if template['pysar.mask'] in ('yes','Yes','YES','y'):
          try: 
             template['pysar.mask.threshold']
             maskCmd='masking.py -f velocity.h5 -m temporal_coherence.h5 -t '+template['pysar.mask.threshold']
             print 'Masking the velocity file using the temporal coherence with the threshold of '+template['pysar.mask.threshold']
          except:
             maskCmd='Masking.py -f velocity.h5 -m temporal_coherence.h5 -t 0.7'
             print 'Masking the velocity file using the temporal coherence with the threshold of 0.7'
          
          os.system(maskCmd)
#          rmCmd='rm velocity.h5'
#          os.system(rmCmd)
#          mvCmd='mv velocity_masked.h5 velocity.h5'
#          os.system(mvCmd)
       else:
          print 'No masking applied'
  except:
       print 'No masking applied'
  print''
  print '******************************************'

############################################
#Geocoding
############################################
  print '******************************************'
  print''
  try:
       template['pysar.geocode']
       if template['pysar.geocode'] in ('y','yes','Yes','YES'):
          geomapFile='geomap_'+Rlooks+'rlks.trans'
#          geoCmd = 'geocode.py '+timeseriesFile+' '+geomapFile
#          print geoCmd
#          os.system(geoCmd)
          geoCmd = 'geocode.py velocity.h5 '+geomapFile
          print geoCmd
          os.system(geoCmd)
          geoCmd = 'geocode.py Mask.h5 '+geomapFile
          print geoCmd
          os.system(geoCmd)
          
#          maskCmd = 'Masking.py -f geo_'+timeseriesFile+' -m geo_Mask.h5'
#          print maskCmd
#          os.system(maskCmd)
          maskCmd = 'masking.py -f geo_velocity.h5 -m geo_Mask.h5'
          print maskCmd
          os.system(maskCmd)
       else:
          print 'No geocoding applied'
  except: 
       print 'No geocoding applied'
  print''
  print '******************************************'


#############################################
#                   PySAR v1.0              #
#############################################
  print''
  print '###############################################'
  print ''
  print 'End of PySAR processing.'
  print ''
  print '################################################'
Example #12
0
def main(argv):
    try:
        templateFile = argv[1]
    except:
        print '''
    *******************************************

       loading the processed data for PySAR:
	   interferograms (unwrapped and wrapped)
	   coherence files (generate Mask at the same time)
       
       Usage: load_data.py TEMPLATEFILE  

    *******************************************         
    '''
        sys.exit(1)

    templateContents = readfile.read_template(templateFile)
    projectName = os.path.basename(templateFile.partition('.')[0])

    ############# Assign workubf directory ##############################
    try:
        tssarProjectDir = os.getenv(
            'TSSARDIR'
        ) + '/' + projectName  # use TSSARDIR if environment variable exist
    except:
        tssarProjectDir = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + "/TSSAR"  # FA 7/2015: adopted for new directory structure

    print "QQ " + tssarProjectDir
    if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir)

    ########### Use defaults if paths not given in template file #########
    try:
        igramPath = templateContents['pysar.inputdata']
        igramPath = check_variable_name(igramPath)
    except:
        igramPath = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*c10.unw'

    try:
        corPath = templateContents['pysar.CorFiles']
        corPath = check_variable_name(corPath)
    except:
        corPath = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*.cor'

    try:
        wrapPath = templateContents['pysar.wrapped']
        wrapPath = check_variable_name(wrapPath)
    except:
        wrapPath = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + '/PROCESS/DONE/I*/filt_*0*sim_HDR_*rlks.int'

######################### Unwrapped Interferograms ########################
    try:
        if os.path.isfile(tssarProjectDir + '/LoadedData.h5'):
            print '\nLoadedData.h5' + '  already exists.\n'
            sys.exit(1)
        print 'loading interferograms ...'
        igramList = glob.glob(igramPath)
        k = 'interferograms'
        check_number(k, igramList)  # number check
        igramList, mode_width, mode_length = check_size(
            k, igramList)  # size check

        h5file = tssarProjectDir + '/LoadedData.h5'
        f = h5py.File(h5file)
        gg = f.create_group('interferograms')
        MaskZero = np.ones([int(mode_length), int(mode_width)])

        for igram in igramList:
            if not os.path.basename(igram) in f:
                print 'Adding ' + igram
                group = gg.create_group(os.path.basename(igram))
                amp, unw, unwrsc = readfile.read_float32(igram)
                MaskZero = amp * MaskZero

                dset = group.create_dataset(os.path.basename(igram),
                                            data=unw,
                                            compression='gzip')
                for key, value in unwrsc.iteritems():
                    group.attrs[key] = value

                d1, d2 = unwrsc['DATE12'].split('-')
                baseline_file = os.path.dirname(
                    igram) + '/' + d1 + '_' + d2 + '_baseline.rsc'
                baseline = readfile.read_rsc_file(baseline_file)
                for key, value in baseline.iteritems():
                    group.attrs[key] = value
            else:
                print os.path.basename(
                    h5file) + " already contains " + os.path.basename(igram)

        Mask = np.ones([int(mode_length), int(mode_width)])
        Mask[MaskZero == 0] = 0

        gm = f.create_group('mask')
        dset = gm.create_dataset('mask', data=Mask, compression='gzip')
        f.close()

        ########################################################################
        print 'writing to Mask.h5'
        h5file = 'Mask.h5'
        h5mask = h5py.File(h5file, 'w')
        group = h5mask.create_group('mask')
        dset = group.create_dataset(os.path.basename('mask'),
                                    data=Mask,
                                    compression='gzip')
        h5mask.close()

    except:
        print 'No unwrapped interferogram is loaded.\n'

############################# Coherence ################################
    try:
        if os.path.isfile(tssarProjectDir + '/Coherence.h5'):
            print '\nCoherence.h5' + '  already exists.\n'
            sys.exit(1)
        print 'loading corelation files ...'
        corList = glob.glob(corPath)
        k = 'coherence'
        check_number(k, corList)  # number check
        corList, mode_width, mode_length = check_size(k, corList)  # size check

        h5file = tssarProjectDir + '/Coherence.h5'
        fcor = h5py.File(h5file)
        gg = fcor.create_group('coherence')
        meanCoherence = np.zeros([int(mode_length), int(mode_width)])
        for cor in corList:
            if not os.path.basename(cor) in fcor:
                print 'Adding ' + cor
                group = gg.create_group(os.path.basename(cor))
                amp, unw, unwrsc = readfile.read_float32(cor)

                meanCoherence = meanCoherence + unw
                dset = group.create_dataset(os.path.basename(cor),
                                            data=unw,
                                            compression='gzip')
                for key, value in unwrsc.iteritems():
                    group.attrs[key] = value

                d1, d2 = unwrsc['DATE12'].split('-')
                baseline_file = os.path.dirname(
                    cor) + '/' + d1 + '_' + d2 + '_baseline.rsc'
                baseline = readfile.read_rsc_file(baseline_file)
                for key, value in baseline.iteritems():
                    group.attrs[key] = value
            else:
                print os.path.basename(
                    h5file) + " already contains " + os.path.basename(cor)

        meanCoherence = meanCoherence / (len(corList))
        print '********************************'
        print 'writing average_spatial_coherence.h5'
        h5file_CorMean = tssarProjectDir + '/average_spatial_coherence.h5'
        fcor_mean = h5py.File(h5file_CorMean, 'w')
        group = fcor_mean.create_group('mask')
        dset = group.create_dataset(os.path.basename('mask'),
                                    data=meanCoherence,
                                    compression='gzip')
        fcor_mean.close()
        print '********************************'
        print 'writing meanCoherence group to the interferogram file'
        gc = fcor.create_group('meanCoherence')
        dset = gc.create_dataset('meanCoherence',
                                 data=meanCoherence,
                                 compression='gzip')
        print '********************************'
        fcor.close()
    except:
        print 'No correlation file is loaded.\n'


########################## Wrapped Interferograms ############################
    try:
        if os.path.isfile(tssarProjectDir + '/Wrapped.h5'):
            print '\nWrapped.h5' + '  already exists.\n'
            sys.exit(1)
        print 'loading wrapped phase ...'
        wrapList = glob.glob(wrapPath)
        k = 'wrapped'
        check_number(k, wrapList)  # number check
        wrapList, mode_width, mode_length = check_size(k,
                                                       wrapList)  # size check

        h5file = tssarProjectDir + '/Wrapped.h5'
        fw = h5py.File(h5file)
        gg = fw.create_group('wrapped')
        for wrap in wrapList:
            if not os.path.basename(wrap) in fw:
                print 'Adding ' + wrap
                group = gg.create_group(os.path.basename(wrap))
                amp, unw, unwrsc = readfile.read_complex64(wrap)

                dset = group.create_dataset(os.path.basename(wrap),
                                            data=unw,
                                            compression='gzip')
                for key, value in unwrsc.iteritems():
                    group.attrs[key] = value

                d1, d2 = unwrsc['DATE12'].split('-')
                baseline_file = os.path.dirname(
                    wrap) + '/' + d1 + '_' + d2 + '_baseline.rsc'
                baseline = readfile.read_rsc_file(baseline_file)
                for key, value in baseline.iteritems():
                    group.attrs[key] = value
            else:
                print os.path.basename(
                    h5file) + " already contains " + os.path.basename(wrap)
        fw.close()
        print 'Writed ' + str(
            len(wrapList)) + ' wrapped interferograms to ' + h5file
    except:
        print 'No wrapped interferogram is loaded.\n'

    try:
        geomapFile = templateContents['pysar.geomap']
        geomapFile = check_variable_name(geomapFile)

        cpCmd = "cp " + geomapFile + " " + tssarProjectDir
        print cpCmd
        os.system(cpCmd)
        cpCmd = "cp " + geomapFile + ".rsc " + tssarProjectDir
        print cpCmd
        os.system(cpCmd)
    except:
        print "*********************************"
        print "Warning: no geomap file given"
        print "*********************************"
Example #13
0
def main(argv):
    try:
        templateFile = argv[1]
        print templateFile
    except:
        print '''
    *******************************************

       Copy DEM (radar and geo coordinate) and 
           geomap*.trans file from PROCESS folder
           to TSSAR folder
       
       Usage: copy_dem_trans.py TEMPLATEFILE  

    *******************************************         
    '''
        sys.exit(1)

    templateContents = readfile.read_template(templateFile)
    projectName = os.path.basename(templateFile.partition('.')[0])
    masterDate = templateContents['masterDate']
    Rlooks = templateContents['Rlooks_unw']

    try:
        processDir = os.getenv('PROCESSDIR') + '/' + projectName
        tssarDir = os.getenv('TSSARDIR') + '/' + projectName
    except:
        processDir = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + '/PROCESS'  # FA 7/2015: adopted for new directory structure
        tssarDir = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + '/TSSAR'  # FA 7/2015: adopted for new directory structure
        #tssarDir  = scratchDirectory + '/' + projectName + "/TSSAR"

    print "QQ: AFTER: " + processDir
    print "QQ: AFTER: " + tssarDir
    sys.exit(1)
    """copy geomap_*rlks.trans"""
    geomapPath = processDir + '/GEO/geo_' + masterDate + '*'
    geomapList = glob.glob(geomapPath)
    numGeomap = len(geomapList)
    if numGeomap > 0:
        geomapDir = geomapList[0]
        geomapFile = geomapDir + '/geomap_' + Rlooks + 'rlks.trans'
        geomapRscFile = geomapFile + '.rsc'
        #    print geomapFile
        #    print geomapRscFile
        geomapCmd = 'cp ' + geomapFile + ' ' + geomapRscFile + ' ' + tssarDir
        print geomapCmd
        os.system(geomapCmd)
    else:
        print 'WARNING: no geomap file of master interferograms found!'
        print 'Check the PROCESS/Project/GEO folder.'
        sys.exit(1)
    """copy radar_*rlks.hgt"""
    doneIgramPath = processDir + '/DONE/IFGRAM_*'
    doneIgramList = glob.glob(doneIgramPath)
    numDoneIgram = len(doneIgramList)
    if numDoneIgram > 0:
        doneIgramDir = doneIgramList[0]
        radarHgt = doneIgramDir + '/radar_' + Rlooks + 'rlks.hgt'
        radarHgtRsc = radarHgt + '.rsc'
        #    print radarHgt
        #    print radarHgtRsc
        radarCmd = 'cp ' + radarHgt + ' ' + radarHgtRsc + ' ' + tssarDir
        print radarCmd
        os.system(radarCmd)
    else:
        print 'WARNING: no radar_*rlks.hgt file found!'
        print 'Check the PROCESS/Project/DONE folder.'
        sys.exit(1)
    """copy DEM file from $DEMDIR"""
    demPath = templateContents['DEM']
    demRscPath = demPath + '.rsc'
    demCmd = 'cp ' + demPath + ' ' + demRscPath + ' ' + tssarDir
    print demCmd
    os.system(demCmd)
Example #14
0
def main(argv):
  try:
    templateFile = argv[1]
    print templateFile
  except:
    print '''
    *******************************************

       Copy DEM (radar and geo coordinate) and 
           geomap*.trans file from PROCESS folder
           to TSSAR folder
       
       Usage: copy_dem_trans.py TEMPLATEFILE  

    *******************************************         
    '''
    sys.exit(1)

  templateContents = readfile.read_template(templateFile)
  projectName = os.path.basename(templateFile.partition('.')[0])
  masterDate = templateContents['masterDate']
  Rlooks = templateContents['Rlooks_unw']

  try: 
     processDir = os.getenv('PROCESSDIR') +'/'+ projectName
     tssarDir = os.getenv('TSSARDIR') +'/'+projectName
  except:
     processDir = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS'                           # FA 7/2015: adopted for new directory structure
     tssarDir   = os.getenv('SCRATCHDIR') + '/' + projectName + '/TSSAR'                             # FA 7/2015: adopted for new directory structure
     #tssarDir  = scratchDirectory + '/' + projectName + "/TSSAR"

  print "QQ: AFTER: " + processDir
  print "QQ: AFTER: " + tssarDir
  sys.exit(1)


  """copy geomap_*rlks.trans"""
  geomapPath = processDir+'/GEO/geo_'+masterDate+'*'
  geomapList = glob.glob(geomapPath)
  numGeomap = len(geomapList)
  if numGeomap>0:
    geomapDir = geomapList[0]
    geomapFile = geomapDir+'/geomap_'+Rlooks+'rlks.trans'
    geomapRscFile = geomapFile+'.rsc'
#    print geomapFile
#    print geomapRscFile
    geomapCmd = 'cp '+geomapFile+' '+geomapRscFile+' '+tssarDir
    print geomapCmd
    os.system(geomapCmd)
  else:
    print 'WARNING: no geomap file of master interferograms found!'
    print 'Check the PROCESS/Project/GEO folder.'
    sys.exit(1)

  """copy radar_*rlks.hgt"""
  doneIgramPath = processDir+'/DONE/IFGRAM_*'
  doneIgramList = glob.glob(doneIgramPath)
  numDoneIgram = len(doneIgramList)
  if numDoneIgram>0:
    doneIgramDir = doneIgramList[0]
    radarHgt = doneIgramDir+'/radar_'+Rlooks+'rlks.hgt'
    radarHgtRsc = radarHgt + '.rsc'
#    print radarHgt
#    print radarHgtRsc
    radarCmd = 'cp '+radarHgt+' '+radarHgtRsc+' '+tssarDir
    print radarCmd
    os.system(radarCmd)
  else:
    print 'WARNING: no radar_*rlks.hgt file found!'
    print 'Check the PROCESS/Project/DONE folder.'
    sys.exit(1)


  """copy DEM file from $DEMDIR"""
  demPath=templateContents['DEM']
  demRscPath=demPath+'.rsc'
  demCmd = 'cp '+demPath+' '+demRscPath+' '+tssarDir
  print demCmd
  os.system(demCmd)
Example #15
0
def main(argv):
    try:
        templateFile = argv[1]
    except:
        Usage()
        sys.exit(1)

    projectName = os.path.basename(templateFile.partition('.')[0])

    try:
        tssarProjectDir = os.getenv('TSSARDIR') + '/' + projectName
    except:
        tssarProjectDir = os.getenv(
            'SCRATCHDIR'
        ) + '/' + projectName + "/TSSAR"  # FA 7/2015: adopted for new directory structure

    print "QQ " + tssarProjectDir
    if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir)
    os.chdir(tssarProjectDir)

    igramFile = 'LoadedData.h5'
    Modified_igramFile = 'Modified_LoadedData.h5'
    if os.path.isfile(Modified_igramFile):
        print Modified_igramFile + ' already exists.'
        igramFile = Modified_igramFile

    template = readfile.read_template(templateFile)
    Rlooks = template['Rlooks_unw']

    #########################################
    # Loading interferograms
    #########################################
    print '******************************************'
    print ''
    if os.path.isfile(igramFile):
        print igramFile + ' already exists.'
    else:
        loadCmd = 'load_data.py ' + templateFile
        print loadCmd
        os.system(loadCmd)

#    copyDemCmd='copy_dem_trans.py ' + templateFile
#    print copyDemCmd
#    os.system(copyDemCmd)
    print ''
    print '******************************************'

    #########################################
    # Check the subset
    #########################################
    try:
        subset = template['pysar.subset.yx'].split(',')
        print subset
        print subset[0]
        subsetOutName = 'subset_' + igramFile
        subsetCmd = 'subset.py -f ' + igramFile + ' -y ' + subset[
            0] + ' -x ' + subset[1] + ' -o ' + subsetOutName
        print '*****************************************'
        print 'Subset the area ...'
        print subsetCmd
        os.system(subsetCmd)
        igramFile = subsetOutName
        print '*****************************************'
    except:
        print '*****************************************'
        print 'No Subset selected. Processing the whole area'
        print '*****************************************'

#########################################
#Referencing all interferograms to the same pixel
#########################################
    rdr_or_geo = radar_Or_geo(igramFile)
    print '******************************************'
    print ''
    if os.path.isfile('Seeded_' + igramFile):
        igramFile = 'Seeded_' + igramFile
        print igramFile + ' already exists.'
    else:
        print 'referncing all interferograms to the same pixel.'
        if 'pysar.seed.ll' in template.keys():
            'Checking the lat/lon refernce point'
            lat = template['pysar.seed.ll'].split(',')[0]
            lon = template['pysar.seed.ll'].split(',')[1]
            seedCmd = 'SeedData.py -f ' + igramFile + ' -l ' + lat + ' -L ' + lon
        elif 'pysar.seed.yx' in template.keys():
            'Checking y/x reference point'
            y = template['pysar.seed.yx'].split(',')[0]
            x = template['pysar.seed.yx'].split(',')[1]
            seedCmd = 'seed_data.py -f ' + igramFile + ' -y ' + y + ' -x ' + x
        else:
            seedCmd = 'seed_data.py -f ' + igramFile

        igramFile = 'Seeded_' + igramFile
        print seedCmd
        os.system(seedCmd)
    print ''
    print '******************************************'

    ############################################
    #unwrapping error correction based on the
    # consistency of triplets of interferograms
    ############################################
    print '******************************************'
    print ''
    try:
        template['pysar.unwrap_error']
        if template['pysar.unwrap_error'] in ('y', 'yes', 'Yes', 'YES'):
            print 'unwrapping error correction might take a while depending on the size of your data set! '
            unwCmd = 'unwrap_error.py ' + igramFile
            os.system(unwCmd)
            igramFile = igramFile.split('.')[0] + '_unwCor.h5'
        else:
            print 'No unwrapping error correction.'
    except:
        print 'No unwrapping error correction.'
    print ''
    print '******************************************'

    #########################################
    # inversion of interferograms
    ########################################
    print '******************************************'
    print ''
    if os.path.isfile(igramFile.split('.')[0] + '_unwCor.h5'):
        igramFile = igramFile.split('.')[0] + '_unwCor.h5'
        print igramFile + ' exists.'

    if os.path.isfile('timeseries.h5'):
        print 'timeseries.h5 already exists, inversion is not needed.'
    else:
        invertCmd = 'igram_inversion.py ' + igramFile
        print invertCmd
        os.system(invertCmd)
    timeseriesFile = 'timeseries.h5'
    print ''
    print '******************************************'

    ##############################################
    #temporal coherence:
    #A parameter to evaluate the consistency of
    # timeseries with the interferograms
    ##############################################
    print '******************************************'
    print ''
    #  if os.path.isfile('temporal_coherence.h5'):
    #     print 'temporal_coherence.h5 already exists.'
    #  else:
    #     tempcohCmd='temporal_coherence.py '+igramFile+' '+timeseriesFile
    #     print tempcohCmd
    #     os.system(tempcohCmd)
    tempcohCmd = 'temporal_coherence.py ' + igramFile + ' ' + timeseriesFile
    print tempcohCmd
    os.system(tempcohCmd)
    print ''
    print '******************************************'

    ##############################################
    #update Mask based on temporal coherence
    # add by Yunjun Feb 15, 2015
    ##############################################
    print '******************************************'
    print ''
    try:
        template['pysar.mask']
        if template['pysar.mask'] in ('yes', 'Yes', 'YES', 'y'):
            print 'Updating mask according to temporal coherence'
            cohT = template['pysar.mask.threshold']
            maskCmd = 'generate_mask.py -f temporal_coherence.h5 -m ' + cohT + ' -M 1.0 -o Mask.h5'
            print maskCmd
            os.system(maskCmd)
        else:
            print 'No update for mask.'
    except:
        print 'No update for mask.'
    print ''
    print '******************************************'

    ##############################################
    # Generate incident angle
    # add by Yunjun Feb 15, 2015
    ##############################################
    print '******************************************'
    print ''
    inciCmd = 'incidence_angle.py -f timeseries.h5'
    print inciCmd
    os.system(inciCmd)
    print ''
    print '******************************************'

    ##############################################
    #If Satellite is Envisat and if Coordinate
    #system is radar then LOD correction
    ##############################################
    print '******************************************'
    print ''
    h5file = h5py.File(timeseriesFile, 'r')
    if rdr_or_geo == 'radar':
        if h5file['timeseries'].attrs['PLATFORM'] == 'ENVISAT':
            LODcmd = 'lod.py ' + timeseriesFile
            print LODcmd
            os.system(LODcmd)
            timeseriesFile = timeseriesFile.split('.')[0] + '_LODcor.h5'
    print ''
    print '******************************************'

    ##############################################
    # Tropospheric Correction
    ##############################################
    print '******************************************'
    print ''

    try:
        if (template['pysar.tropospheric_delay'] in ('y', 'yes', 'Yes', 'YES')
            ) and template['pysar.orbit_error.method'] == 'BaseTropCor':
            print '''
   +++++++++++++++++++++++++++++++++++++++++++++++++++
   WARNING:
       Orbital error correction was BaseTropCor.
       Tropospheric correction was already applied simultaneous with baseline error correction.
       Tropospheric correction can not be applied again.
       To apply the tropospheric correction separate from baseline error correction, chhose other existing options for orbital error correction.
    +++++++++++++++++++++++++++++++++++++++++++++++++++      
         '''
            template['pysar.tropospheric_delay'] = 'no'
    except:
        print 'Checking the tropospheric delay correction ...'

    if template['pysar.tropospheric_delay'] in ('y', 'yes', 'Yes', 'YES'):
        # demFile='radar_'+Rlooks+'rlks.hgt'
        demFile = template['pysar.dem']
        demFile = check_variable_name(demFile)
        #     print 'DEM file: '+demFile
        if not os.path.isfile(demFile):
            print '++++++++++++++++++++++++++++++++++++++++++++++'
            print 'Error:'
            print 'DEM (radar_*rlks.hgt file) was not found!'
            print 'Continue without tropospheric correction ...'
            print '++++++++++++++++++++++++++++++++++++++++++++++'
        else:
            if template['pysar.tropospheric_delay.method'] in [
                    'height-correlation', 'height_correlation',
                    'Height-Correlation', 'Height_Correlation'
            ]:
                print 'tropospheric delay correction with height-correlation approach'
                try:
                    polyOrder = template['pysar.trop.polyOrder']
                except:
                    print 'Deafult polynomial order for troposphreic correction = 1'
                    polyOrder = '1'
                cmdTrop = 'tropospheric_correction.py' + ' -f ' + timeseriesFile + ' -d ' + demfile + ' -p ' + polyOrder
                os.system(cmdTrop)
                timeseriesFile = timeseriesFile.split('.')[0] + '_tropCor.h5'

            elif template['pysar.tropospheric_delay.method'] == 'pyaps':
                print 'Atmospheric correction using Numerical Weather Models (using PyAPS software)'
                print 'reading DEM, source of NWM and acquisition time from template file'
                source_of_NWM = template['pysar.Numerical_Weather_Model']
                print 'Numerical Weather Model: ' + source_of_NWM
                acquisition_time = template['pysar.acquisition_time']
                print 'acquisition time: ' + acquisition_time
                #           cmdTrop = ["tropcor_pyaps.py -f ",timeseriesFile," -d ",demFile," -s ",source_of_NWM," -h ",acquisition_time," -i incidence_angle.h5"]
                cmdTrop = 'tropcor_pyaps.py -f ' + timeseriesFile + ' -d ' + demFile + ' -s ' + source_of_NWM + ' -h ' + acquisition_time + ' -i incidence_angle.h5'
                print cmdTrop
                os.system(cmdTrop)
                #           subprocess.Popen(cmdTrop).wait()
                timeseriesFile = timeseriesFile.split(
                    '.')[0] + '_' + source_of_NWM + '.h5'
            else:
                print 'Atmospheric correction method not recognized.'
    else:
        print 'No atmospheric delay correction.'
    print ''
    print '******************************************'

    ##############################################
    #topographic residuals
    ##############################################
    print '******************************************'
    print ''
    try:
        template['pysar.topo_error']
        if template['pysar.topo_error'] in ('yes', 'Yes', 'YES', 'y'):
            print 'Correcting topographic residuals'
            topoCmd = 'dem_error.py ' + timeseriesFile + ' ' + igramFile
            print topoCmd
            os.system(topoCmd)
            timeseriesFile = timeseriesFile.split('.')[0] + '_demCor.h5'
        else:
            print 'No correction for topographic residuals.'
    except:
        print 'No correction for topographic residuals.'
    print ''
    print '******************************************'

    ##############################################
    #Orbit correction
    ##############################################
    print '******************************************'
    print ''
    try:
        template['pysar.orbit_error']
        if template['pysar.orbit_error'] in ('yes', 'Yes', 'YES', 'y'):
            try:
                orbit_error_method = template['pysar.orbit_error.method']
                print 'orbit error correction method : ' + orbit_error_method
                if orbit_error_method in [
                        'quadratic', 'plane', 'quardatic_range',
                        'quadratic_azimiuth', 'plane_range', 'plane_azimuth'
                ]:
                    orbitCmd = 'remove_plane.py ' + timeseriesFile + ' ' + template[
                        'pysar.orbit_error.method']  #+ ' Mask.h5'
                    timeseriesFile = timeseriesFile.split('.')[
                        0] + '_' + template['pysar.orbit_error.method'] + '.h5'
                    print orbitCmd
                    os.system(orbitCmd)
                elif orbit_error_method == 'baselineCor':
                    orbitCmd = 'baseline_error.py ' + timeseriesFile  #+ ' Mask.h5'
                    print orbitCmd

                    try:
                        h5file = h5py.File(timeseriesFile, 'r')
                        daz = float(
                            h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE'])
                        os.system(orbitCmd)
                        timeseriesFile = timeseriesFile.split(
                            '.')[0] + '_' + template[
                                'pysar.orbit_error.method'] + '.h5'
                    except:
                        print 'WARNING!'
                        print 'Skipping orbital error correction.'
                        print 'baselineCor method can only be applied in radar coordinate'

                elif orbit_error_method == 'BaseTropCor':
                    demfile = template['pysar.dem']
                    demfile = check_variable_name(demfile)
                    try:
                        polyOrder = template['pysar.trop.polyOrder']
                    except:
                        print 'Deafult polynomial order for troposphreic correction = 1'
                        polyOrder = 1
                    try:
                        h5file = h5py.File(timeseriesFile, 'r')
                        daz = float(
                            h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE'])
                        orbitCmd = 'baseline_trop.py ' + timeseriesFile + ' ' + demfile + ' ' + polyOrder + 'range_and_azimuth'
                        print 'Joint estimation of Baseline error and tropospheric delay [height-correlation approach]'
                        print orbitCmd
                        os.system(orbitCmd)
                        timeseriesFile = timeseriesFile.split(
                            '.')[0] + '_' + template[
                                'pysar.orbit_error.method'] + '.h5'
                    except:
                        print 'WARNING!'
                        print 'Skipping orbital error correction.'
                        print 'baselineCor method can only be applied in radar coordinate'
                else:
                    print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++'
                    print 'WARNING!'
                    print 'Orbital error correction method was not recognized!'
                    print 'Possible options are:'
                    print 'quadratic, plane, quardatic_range, quadratic_azimiuth, plane_range, plane_azimuth,baselineCor,BaseTropCor'
                    print 'Continue without orbital errors correction...'
                    print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++'

            except:
                print 'No orbital errors correction.'
        else:
            print 'No orbital errors correction.'
    except:
        print 'No orbital errors correction.'
    print ''
    print '******************************************'

    #############################################
    #Velocity and rmse maps
    #############################################

    print '******************************************'
    print ''
    velCmd = 'timeseries2velocity.py ' + timeseriesFile
    print velCmd
    os.system(velCmd)
    print ''
    print '******************************************'

    #############################################
    #Masking the velocity based on the temporal
    #coherence or rmse if it's specified
    #############################################
    print '******************************************'
    print ''
    try:
        template['pysar.mask']
        if template['pysar.mask'] in ('yes', 'Yes', 'YES', 'y'):
            try:
                template['pysar.mask.threshold']
                maskCmd = 'masking.py -f velocity.h5 -m temporal_coherence.h5 -t ' + template[
                    'pysar.mask.threshold']
                print 'Masking the velocity file using the temporal coherence with the threshold of ' + template[
                    'pysar.mask.threshold']
            except:
                maskCmd = 'Masking.py -f velocity.h5 -m temporal_coherence.h5 -t 0.7'
                print 'Masking the velocity file using the temporal coherence with the threshold of 0.7'

            os.system(maskCmd)


#          rmCmd='rm velocity.h5'
#          os.system(rmCmd)
#          mvCmd='mv velocity_masked.h5 velocity.h5'
#          os.system(mvCmd)
        else:
            print 'No masking applied'
    except:
        print 'No masking applied'
    print ''
    print '******************************************'

    ############################################
    #Geocoding
    ############################################
    print '******************************************'
    print ''
    try:
        template['pysar.geocode']
        if template['pysar.geocode'] in ('y', 'yes', 'Yes', 'YES'):
            geomapFile = 'geomap_' + Rlooks + 'rlks.trans'
            #          geoCmd = 'geocode.py '+timeseriesFile+' '+geomapFile
            #          print geoCmd
            #          os.system(geoCmd)
            geoCmd = 'geocode.py velocity.h5 ' + geomapFile
            print geoCmd
            os.system(geoCmd)
            geoCmd = 'geocode.py Mask.h5 ' + geomapFile
            print geoCmd
            os.system(geoCmd)

            #          maskCmd = 'Masking.py -f geo_'+timeseriesFile+' -m geo_Mask.h5'
            #          print maskCmd
            #          os.system(maskCmd)
            maskCmd = 'masking.py -f geo_velocity.h5 -m geo_Mask.h5'
            print maskCmd
            os.system(maskCmd)
        else:
            print 'No geocoding applied'
    except:
        print 'No geocoding applied'
    print ''
    print '******************************************'

    #############################################
    #                   PySAR v1.0              #
    #############################################
    print ''
    print '###############################################'
    print ''
    print 'End of PySAR processing.'
    print ''
    print '################################################'
Example #16
0
def read_template2inps(templateFile, inps=None):
    '''Read network options from template file into Namespace variable inps'''
    template_dict = readfile.read_template(templateFile)
    if not template_dict:
        print('Empty template: '+templateFile)
        return None
    keyList = list(template_dict.keys())

    if not inps:
        inps = cmdLineParse([''])

    # Read network option regardless of prefix
    for key in keyList:
        if 'selectPairs.'    in key:   template_dict[key.split('selectPairs.')[1]]    = template_dict[key]
        if 'pysar.network.'  in key:   template_dict[key.split('pysar.network.')[1]]  = template_dict[key]
        if 'select.network.' in key:   template_dict[key.split('select.network.')[1]] = template_dict[key]
    keyList = list(template_dict.keys())
    for key, value in template_dict.items():
        if value.lower() in ['off','false','n']:  template_dict[key] = 'no'
        if value.lower() in ['on', 'true', 'y']:  template_dict[key] = 'yes'

    # Update inps value if not existed
    if not inps.method:
        if   'selectMethod' in keyList:  inps.method = template_dict['selectMethod']
        elif 'method'       in keyList:  inps.method = template_dict['method']
        else: inps.method = 'all'

    if not inps.perp_base_max:
        if 'perpBaseMax'  in keyList:  inps.perp_base_max = float(template_dict['perpBaseMax'])
        else: inps.perp_base_max = 500.0

    if not inps.temp_base_max:
        if 'lengthDayMax'   in keyList:  inps.temp_base_max = float(template_dict['lengthDayMax'])
        elif 'tempBaseMax'  in keyList:  inps.temp_base_max = float(template_dict['tempBaseMax'])
        else: inps.temp_base_max = 1800.0

    if not inps.temp_base_min:
        if 'lengthDayMin'   in keyList:  inps.temp_base_min = float(template_dict['lengthDayMin'])
        elif 'tempBaseMin'  in keyList:  inps.temp_base_min = float(template_dict['tempBaseMin'])
        else: inps.temp_base_min = 0.0

    if 'seasonal'     in keyList and template_dict['seasonal'].lower()     == 'no': inps.keep_seasonal = False
    if 'keepSeasonal' in keyList and template_dict['keepSeasonal'].lower() == 'no': inps.keep_seasonal = False

    if not inps.dop_overlap_min:
        if 'DopOverlapThresh'   in keyList:  inps.dop_overlap_min = float(template_dict['DopOverlapThresh'])
        elif 'dopOverlapThresh' in keyList:  inps.dop_overlap_min = float(template_dict['dopOverlapThresh'])
        elif 'dopOverlapMin'    in keyList:  inps.dop_overlap_min = float(template_dict['dopOverlapMin'])
        else: inps.dop_overlap_min = 15.0

    if not inps.reference_file and 'referenceFile' in keyList:  inps.reference_file = template_dict['referenceFile']
    if not inps.increment_num:
        if 'incrementNum'  in keyList:  inps.increment_num  = int(template_dict['incrementNum'])
        else: inps.increment_num = 3

    if not inps.temp_perp_list:
        if 'dayPerpList'    in keyList:  inps.temp_perp_list = template_dict['dayPerpList']
        elif 'tempPerpList' in keyList:  inps.temp_perp_list = template_dict['tempPerpList']
        else: inps.temp_perp_list = '16,1600;32,800;48,600;64,200'
        inps.temp_perp_list = [[float(j) for j in i.split(',')] for i in inps.temp_perp_list.split(';')]

    if not inps.exclude_date and 'excludeDate' in keyList:
        ex_date_list = [i for i in template_dict['excludeDate'].split(',')]
        inps.exclude_date = ptime.yymmdd(ex_date_list)

    if not inps.start_date and 'startDate' in keyList:
        inps.start_date = ptime.yyyymmdd(template_dict['startDate'])
    if not inps.end_date and 'endDate' in keyList:
        inps.end_date = ptime.yyyymmdd(template_dict['endDate'])

    if not inps.m_date and 'masterDate' in keyList:
        inps.m_date = ptime.yymmdd(template_dict['masterDate'])

    return inps
Example #17
0
def load_data_from_template(inps):
    '''Load dataset for PySAR time series using input template'''
    ##------------------------------------ Read Input Path -------------------------------------##
    # Initial value
    inps.unw = None
    inps.cor = None
    inps.trans = None
    inps.dem_radar = None
    inps.dem_geo = None

    # 1.1 Read template contents (support multiple template files input)
    inps.template_file = [os.path.abspath(i) for i in inps.template_file]
    # Move default template file pysarApp_template.txt to the end of list, so that it has highest priority
    default_template_file = [i for i in inps.template_file if 'pysarApp' in i]
    if default_template_file:
        inps.template_file.remove(default_template_file[0])
        inps.template_file.append(default_template_file[0])
    template = dict()
    # Read file by file
    for File in inps.template_file:
        temp_dict = readfile.read_template(File)
        for key, value in temp_dict.items():
            temp_dict[key] = ut.check_variable_name(value)
        template.update(temp_dict)
    keyList = list(template.keys())

    # Project Name
    if not inps.project_name:
        inps.template_filename = [os.path.basename(i) for i in inps.template_file]
        try:  inps.template_filename.remove('pysarApp_template.txt')
        except:  pass
        if inps.template_filename:
            inps.project_name = os.path.splitext(inps.template_filename[0])[0]

    for key in ['processor','processing_software','unavco.processing_software','pysar.insarProcessor']:
        if key in keyList:
            value = template[key]
            if value == 'auto':
                inps.insar_processor = 'roipac'
            else:
                inps.insar_processor = value

    print('--------------------------------------------')
    print('InSAR processing software: '+inps.insar_processor)
    if 'pysar.unwrapFiles'    in keyList:   inps.unw   = template['pysar.unwrapFiles']
    if 'pysar.corFiles'       in keyList:   inps.cor   = template['pysar.corFiles']
    if 'pysar.transFile'      in keyList:   inps.trans = template['pysar.transFile']
    if 'pysar.demFile.radarCoord' in keyList:   inps.dem_radar = template['pysar.demFile.radarCoord']
    if 'pysar.demFile.geoCoord'   in keyList:   inps.dem_geo   = template['pysar.demFile.geoCoord']

    # Check existed single dataset files
    inps_tmp = argparse.Namespace()
    inps_tmp = ut.check_loaded_dataset(inps.timeseries_dir, inps_tmp, print_msg=False)
    if (not inps.trans     or inps.trans     == 'auto') and inps_tmp.trans_file    :  inps.trans     = inps_tmp.trans_file
    if (not inps.dem_radar or inps.dem_radar == 'auto') and inps_tmp.dem_radar_file:  inps.dem_radar = inps_tmp.dem_radar_file
    if (not inps.dem_geo   or inps.dem_geo   == 'auto') and inps_tmp.dem_geo_file  :  inps.dem_geo   = inps_tmp.dem_geo_file

    # 1.2 Auto Setting for Geodesy Lab - University of Miami 
    if pysar.miami_path and 'SCRATCHDIR' in os.environ and inps.project_name:
        inps = auto_path_miami(inps, template)

    # 1.3 get snap_connect.byt path if .unw is input
    if inps.unw:
        inps.snap_connect = inps.unw.split('.unw')[0]+'_snap_connect.byt'
    else:
        inps.snap_connect = None

    # PYSAR directory
    if not inps.timeseries_dir:
        inps.timeseries_dir = os.getcwd()
    if not os.path.isdir(inps.timeseries_dir):
        os.makedirs(inps.timeseries_dir)
    #print "PySAR working directory: "+inps.timeseries_dir

    # TEMPLATE file directory (to support relative path input)
    inps.template_dir = os.path.dirname(inps.template_file[-1])
    os.chdir(inps.template_dir)
    print('Go to TEMPLATE directory: '+inps.template_dir)
    print('unwrapped interferograms to load: '+str(inps.unw))
    #print 'wrapped   interferograms to load: '+str(inps.int)
    print('spatial coherence  files to load: '+str(inps.cor))
    print('transformation     file to load: '+str(inps.trans))
    print('DEM file in radar coord to load: '+str(inps.dem_radar))
    print('DEM file in geo   coord to load: '+str(inps.dem_geo))

    ##------------------------------------ Loading into HDF5 ---------------------------------------##
    # required - unwrapped interferograms
    inps.ifgram_file = load_file(inps.unw, vars(inps))

    # optional but recommended files - multi_group_hdf5_file
    inps.coherence_file = load_file(inps.cor, vars(inps))
    #inps.wrap_ifgram_file = load_file(inps.int, vars(inps))
    if inps.snap_connect:
        inps.snap_connect_file = load_file(inps.snap_connect, vars(inps))

    # optional but recommend files - single_dataset file
    inps.trans_file = load_file(inps.trans, vars(inps))
    inps.dem_radar_file = load_file(inps.dem_radar, vars(inps))
    inps.dem_geo_file = load_file(inps.dem_geo, vars(inps))

    os.chdir(inps.timeseries_dir)
    print('Go back to PYSAR directory: '+inps.timeseries_dir)
    return inps
Example #18
0
def main(argv):
  try:
    templateFile = argv[1]
  except:
    print '''
    *******************************************

       loading the processed data for PySAR:
	   interferograms (unwrapped and wrapped)
	   coherence files (generate Mask at the same time)
       
       Usage: load_data.py TEMPLATEFILE  

    *******************************************         
    '''
    sys.exit(1)

  templateContents = readfile.read_template(templateFile)
  projectName = os.path.basename(templateFile.partition('.')[0])

############# Assign workubf directory ##############################
  try:
    tssarProjectDir = os.getenv('TSSARDIR') +'/'+projectName                     # use TSSARDIR if environment variable exist
  except:
    tssarProjectDir = os.getenv('SCRATCHDIR') + '/' + projectName + "/TSSAR"     # FA 7/2015: adopted for new directory structure

  print "QQ " + tssarProjectDir
  if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir)

########### Use defaults if paths not given in template file #########
  try:
    igramPath=templateContents['pysar.inputdata']
    igramPath=check_variable_name(igramPath)
  except:
    igramPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*c10.unw'

  try:
    corPath=templateContents['pysar.CorFiles']
    corPath=check_variable_name(corPath)
  except:
    corPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*.cor'

  try:
    wrapPath=templateContents['pysar.wrapped']
    wrapPath=check_variable_name(wrapPath)
  except:
    wrapPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/I*/filt_*0*sim_HDR_*rlks.int'

######################### Unwrapped Interferograms ########################
  try:
    if os.path.isfile(tssarProjectDir+'/LoadedData.h5'):
      print '\nLoadedData.h5'+ '  already exists.\n'
      sys.exit(1)
    print 'loading interferograms ...'
    igramList = glob.glob(igramPath)    
    k = 'interferograms'
    check_number(k,igramList)	# number check 
    igramList,mode_width,mode_length = check_size(k,igramList)	# size check

    h5file = tssarProjectDir+'/LoadedData.h5'
    f = h5py.File(h5file)
    gg = f.create_group('interferograms')
    MaskZero=np.ones([int(mode_length),int(mode_width)])

    for igram in igramList:
      if not os.path.basename(igram) in f:
        print 'Adding ' + igram
        group = gg.create_group(os.path.basename(igram))
        amp,unw,unwrsc = readfile.read_float32(igram)
        MaskZero=amp*MaskZero
 
        dset = group.create_dataset(os.path.basename(igram), data=unw, compression='gzip')
        for key,value in unwrsc.iteritems():
          group.attrs[key] = value

        d1,d2=unwrsc['DATE12'].split('-')
        baseline_file=os.path.dirname(igram)+'/'+d1+'_'+d2+'_baseline.rsc'
        baseline=readfile.read_rsc_file(baseline_file)
        for key,value in baseline.iteritems():
          group.attrs[key] = value
      else:
        print os.path.basename(h5file) + " already contains " + os.path.basename(igram)

    Mask=np.ones([int(mode_length),int(mode_width)])
    Mask[MaskZero==0]=0
  
    gm = f.create_group('mask')
    dset = gm.create_dataset('mask', data=Mask, compression='gzip')
    f.close()

########################################################################
    print 'writing to Mask.h5'
    h5file = 'Mask.h5'
    h5mask = h5py.File(h5file,'w')
    group=h5mask.create_group('mask')
    dset = group.create_dataset(os.path.basename('mask'), data=Mask, compression='gzip')
    h5mask.close()

  except:
    print 'No unwrapped interferogram is loaded.\n'

############################# Coherence ################################
  try:
    if os.path.isfile(tssarProjectDir+'/Coherence.h5'):
      print '\nCoherence.h5'+ '  already exists.\n'
      sys.exit(1)
    print 'loading corelation files ...'
    corList = glob.glob(corPath)
    k = 'coherence'
    check_number(k,corList)   # number check 
    corList,mode_width,mode_length = check_size(k,corList)     # size check

    h5file = tssarProjectDir+'/Coherence.h5'
    fcor = h5py.File(h5file)
    gg = fcor.create_group('coherence')
    meanCoherence=np.zeros([int(mode_length),int(mode_width)])
    for cor in corList:
      if not os.path.basename(cor) in fcor:
        print 'Adding ' + cor
        group = gg.create_group(os.path.basename(cor))
        amp,unw,unwrsc = readfile.read_float32(cor)

        meanCoherence=meanCoherence+unw
        dset = group.create_dataset(os.path.basename(cor), data=unw, compression='gzip')
        for key,value in unwrsc.iteritems():
           group.attrs[key] = value

        d1,d2=unwrsc['DATE12'].split('-')
        baseline_file=os.path.dirname(cor)+'/'+d1+'_'+d2+'_baseline.rsc'
        baseline=readfile.read_rsc_file(baseline_file)
        for key,value in baseline.iteritems():
           group.attrs[key] = value
      else:
        print os.path.basename(h5file) + " already contains " + os.path.basename(cor)

    meanCoherence=meanCoherence/(len(corList))
    print '********************************'
    print 'writing average_spatial_coherence.h5'
    h5file_CorMean = tssarProjectDir+'/average_spatial_coherence.h5'
    fcor_mean = h5py.File(h5file_CorMean,'w')
    group=fcor_mean.create_group('mask')
    dset = group.create_dataset(os.path.basename('mask'), data=meanCoherence, compression='gzip')
    fcor_mean.close()
    print '********************************'
    print 'writing meanCoherence group to the interferogram file'
    gc = fcor.create_group('meanCoherence')
    dset = gc.create_dataset('meanCoherence', data=meanCoherence, compression='gzip')   
    print '********************************' 
    fcor.close()
  except:
    print 'No correlation file is loaded.\n'

########################## Wrapped Interferograms ############################
  try:
    if os.path.isfile(tssarProjectDir+'/Wrapped.h5'):
      print '\nWrapped.h5'+ '  already exists.\n'
      sys.exit(1)
    print 'loading wrapped phase ...'
    wrapList = glob.glob(wrapPath)
    k = 'wrapped'
    check_number(k,wrapList)   # number check 
    wrapList,mode_width,mode_length = check_size(k,wrapList)     # size check

    h5file = tssarProjectDir+'/Wrapped.h5'
    fw = h5py.File(h5file)
    gg = fw.create_group('wrapped')
    for wrap in wrapList:
      if not os.path.basename(wrap) in fw:
        print 'Adding ' + wrap
        group = gg.create_group(os.path.basename(wrap))
        amp,unw,unwrsc = readfile.read_complex64(wrap)

        dset = group.create_dataset(os.path.basename(wrap), data=unw, compression='gzip')
        for key,value in unwrsc.iteritems():
           group.attrs[key] = value

        d1,d2=unwrsc['DATE12'].split('-')
        baseline_file=os.path.dirname(wrap)+'/'+d1+'_'+d2+'_baseline.rsc'
        baseline=readfile.read_rsc_file(baseline_file)
        for key,value in baseline.iteritems():
           group.attrs[key] = value
      else:
        print os.path.basename(h5file) + " already contains " + os.path.basename(wrap)
    fw.close()
    print 'Writed '+str(len(wrapList))+' wrapped interferograms to '+h5file
  except:
    print 'No wrapped interferogram is loaded.\n'

  try:
    geomapFile=templateContents['pysar.geomap']
    geomapFile=check_variable_name(geomapFile)

    cpCmd="cp " + geomapFile + " " + tssarProjectDir
    print cpCmd
    os.system(cpCmd)
    cpCmd="cp " + geomapFile + ".rsc " + tssarProjectDir
    print cpCmd
    os.system(cpCmd)
  except:
    print "*********************************"
    print "Warning: no geomap file given"
    print "*********************************"
Example #19
0
def read_template2inps(template_file, inps=None):
    '''Read input template options into Namespace inps'''
    if not inps:
        inps = cmdLineParse()

    template = readfile.read_template(inps.template_file)
    key_list = list(template.keys())

    # Coherence-based network modification
    prefix = 'pysar.network.'

    key = prefix + 'coherenceBased'
    if key in key_list and template[key] in ['auto', 'yes']:
        inps.coherence_based = True

    key = prefix + 'keepMinSpanTree'
    if key in key_list and template[key] in ['no']:
        inps.keep_mst = False

    key = prefix + 'coherenceFile'
    if key in key_list:
        if template[key] == 'auto':
            inps.coherence_file = 'coherence.h5'
        else:
            inps.coherence_file = template[key]

    # find coherence file from input files if inps.coherence_file does not exists.
    if inps.coherence_based and not os.path.isfile(inps.coherence_file):
        k_list = [readfile.read_attribute(f)['FILE_TYPE'] for f in inps.file]
        try:
            coh_file_idx = k_list.index('coherence')
        except ValueError:
            print(
                'No coherence file found! Can not use coherence-based method without it.'
            )
        inps.coherence_file = inps.file[coh_file_idx]

    key = prefix + 'minCoherence'
    if key in key_list:
        if template[key] == 'auto':
            inps.min_coherence = 0.7
        else:
            inps.min_coherence = float(template[key])

    key = prefix + 'maskFile'
    if key in key_list:
        value = template[key]
        if value == 'auto':
            inps.mask_file = 'mask.h5'
        elif value == 'no':
            inps.mask_file = None
        else:
            inps.mask_file = value

    key = prefix + 'maskAoi.yx'
    if key in key_list:
        value = template[key]
        if value in ['auto', 'no']:
            inps.aoi_pix_box = None
        else:
            tmp = [i.strip() for i in value.split(',')]
            sub_y = sorted([int(i.strip()) for i in tmp[0].split(':')])
            sub_x = sorted([int(i.strip()) for i in tmp[1].split(':')])
            inps.aoi_pix_box = (sub_x[0], sub_y[0], sub_x[1], sub_y[1])

    key = prefix + 'maskAoi.lalo'
    if key in key_list:
        value = template[key]
        if value in ['auto', 'no']:
            inps.aoi_geo_box = None
        else:
            tmp = [i.strip() for i in value.split(',')]
            sub_lat = sorted([float(i.strip()) for i in tmp[0].split(':')])
            sub_lon = sorted([float(i.strip()) for i in tmp[1].split(':')])
            inps.aoi_geo_box = (sub_lon[0], sub_lat[1], sub_lon[1], sub_lat[0])
            # Check trans file
            try:
                inps.trans_file = ut.get_file_list(inps.trans_file)[0]
            except:
                inps.trans_file = None
                print(
                    'Warning: no mapping transformation file found! Can not use '
                    + key + ' option without it.')
                print('skip this option.')
                inps.aoi_pix_box = None

    ## Network Modification based on thresholds
    key = prefix + 'tempBaseMax'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.max_temp_baseline = float(value)

    key = prefix + 'perpBaseMax'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.max_perp_baseline = float(value)

    key = prefix + 'referenceFile'
    if key in key_list:
        value = template[key]
        if value in ['auto', 'no']:
            inps.reference_file = None
        else:
            inps.reference_file = value

    key = prefix + 'excludeDate'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.exclude_date = [i for i in value.replace(',', ' ').split()]

    key = prefix + 'excludeIfgIndex'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.exclude_ifg_index = [
                i for i in value.replace(',', ' ').split()
            ]

    key = prefix + 'startDate'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.start_date = ptime.yymmdd(value)

    key = prefix + 'endDate'
    if key in key_list:
        value = template[key]
        if value not in ['auto', 'no']:
            inps.end_date = ptime.yymmdd(value)

    return inps