Esempio n. 1
0
def main(argv):

    inps = cmdLineParse()
    #print '\n****************** mask *********************'
    inps.file = ut.get_file_list(inps.file)
    print('number of file to mask: ' + str(len(inps.file)))
    print(inps.file)

    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(inps.file))

    # masking
    if len(inps.file) == 1:
        mask_file(inps.file[0], inps.mask_file, inps.outfile, vars(inps))

    elif inps.parallel:
        #num_cores = min(multiprocessing.cpu_count(), len(inps.file))
        #print 'parallel processing using %d cores ...'%(num_cores)
        Parallel(n_jobs=num_cores)(
            delayed(mask_file)(File, inps.mask_file, inps_dict=vars(inps))
            for File in inps.file)
    else:
        for File in inps.file:
            print('-------------------------------------------')
            mask_file(File, inps.mask_file, inps_dict=vars(inps))

    print('Done.')
    return
Esempio n. 2
0
def main(argv):
    inps = cmdLineParse()
    inps.file = ut.get_file_list(inps.file)

    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(inps.file))

    # multilooking
    if len(inps.file) == 1:
        multilook_file(inps.file[0], inps.lks_y, inps.lks_x, inps.outfile)

    elif inps.parallel:
        #num_cores = min(multiprocessing.cpu_count(), len(inps.file))
        #print 'parallel processing using %d cores ...'%(num_cores)
        Parallel(n_jobs=num_cores)(
            delayed(multilook_file)(file, inps.lks_y, inps.lks_x)
            for file in inps.file)
    else:
        for File in inps.file:
            print('-------------------------------------------')
            multilook_file(File, inps.lks_y, inps.lks_x)

    print('Done.')
    return
Esempio n. 3
0
def main(argv):
    inps = cmdLineParse()
    inps.file = ut.get_file_list(inps.file, abspath=True)

    # Check input file type
    ext = os.path.splitext(inps.file[0])[1]
    if ext not in ['.unw', '.cor', '.int']:
        print('No need to extract attributes for ROI_PAC ' + ext + ' file')
        return

    print('number of files: ' + str(len(inps.file)))

    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(inps.file))

    if len(inps.file) == 1:
        extract_attribute(inps.file[0])
    elif inps.parallel:
        Parallel(n_jobs=num_cores)(delayed(extract_attribute)(file)
                                   for file in inps.file)
    else:
        for File in inps.file:
            extract_attribute(File)

    return
Esempio n. 4
0
def main(argv):
    inps = cmdLineParse()
    inps.file = ut.get_file_list(inps.file)
    print('number of files to geocode: ' + str(len(inps.file)))
    print(inps.file)
    print('interpolation method: ' + inps.method)
    print('fill_value: ' + str(inps.fill_value))

    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(inps.file))

    #####
    if len(inps.file) == 1:
        geocode_file_with_geo_lut(inps.file[0], inps.lookup_file, inps.method,
                                  inps.fill_value, inps.outfile)
    elif inps.parallel:
        Parallel(n_jobs=num_cores)(delayed(geocode_file_with_geo_lut)\
                                   (fname, inps.lookup_file, inps.method, inps.fill_value) for fname in inps.file)
    else:
        for fname in inps.file:
            geocode_file_with_geo_lut(fname, inps.lookup_file, inps.method,
                                      inps.fill_value)

    print('Done.')
    return
Esempio n. 5
0
def subset_file_list(fileList, inps):
    '''Subset file list'''
    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(fileList))

    ##### Subset files
    if len(fileList) == 1:
        subset_file(fileList[0], vars(inps), inps.outfile)

    elif inps.parallel:
        #num_cores = min(multiprocessing.cpu_count(), len(fileList))
        #print 'parallel processing using %d cores ...'%(num_cores)
        Parallel(n_jobs=num_cores)(delayed(subset_file)(file, vars(inps))
                                   for file in fileList)
    else:
        for File in fileList:
            print('----------------------------------------------------')
            subset_file(File, vars(inps))
    return
Esempio n. 6
0
def main(argv):
    inps = cmdLineParse()
    inps.file = ut.get_file_list(inps.file, abspath=True)
    print('number of files: ' + str(len(inps.file)))

    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(inps.file))

    ##### multiple datasets files
    ext = os.path.splitext(inps.file[0])[1]
    if ext in ['.unw', '.cor', '.int']:
        if len(inps.file) == 1:
            extract_attribute_interferogram(inps.file[0])
        elif inps.parallel:
            Parallel(n_jobs=num_cores)(
                delayed(extract_attribute_interferogram)(file)
                for file in inps.file)
        else:
            for File in inps.file:
                extract_attribute_interferogram(File)

    ##### Single dataset files
    elif ext in ['.dem']:
        for File in inps.file:
            atr_file = extract_attribute_dem_geo(File)
    elif ext in ['.hgt_sim']:
        for File in inps.file:
            atr_file = extract_attribute_dem_radar(File)
    elif ext in ['.UTM_TO_RDC']:
        for File in inps.file:
            atr_file = extract_attribute_lookup_table(File)
    else:
        print('No need to extract attributes for Gamma ' + ext + ' file')

    print('Done.')
    return
Esempio n. 7
0
def main(argv):
    inps = cmdLineParse()
    inps.file = ut.get_file_list(inps.file)

    atr = readfile.read_attribute(inps.file[0])
    length = int(atr['FILE_LENGTH'])
    width = int(atr['WIDTH'])

    if inps.reset:
        print(
            '----------------------------------------------------------------------------'
        )
        for file in inps.file:
            remove_reference_pixel(file)
        return

    ##### Check Input Coordinates
    # Read ref_y/x/lat/lon from reference/template
    # priority: Direct Input > Reference File > Template File
    if inps.template_file:
        print('reading reference info from template: ' + inps.template_file)
        inps = read_seed_template2inps(inps.template_file, inps)
    if inps.reference_file:
        print('reading reference info from reference: ' + inps.reference_file)
        inps = read_seed_reference2inps(inps.reference_file, inps)

    ## Do not use ref_lat/lon input for file in radar-coord
    #if not 'X_FIRST' in atr.keys() and (inps.ref_lat or inps.ref_lon):
    #    print 'Lat/lon reference input is disabled for file in radar coord.'
    #    inps.ref_lat = None
    #    inps.ref_lon = None

    # Convert ref_lat/lon to ref_y/x
    if inps.ref_lat and inps.ref_lon:
        if 'X_FIRST' in list(atr.keys()):
            inps.ref_y = subset.coord_geo2radar(inps.ref_lat, atr, 'lat')
            inps.ref_x = subset.coord_geo2radar(inps.ref_lon, atr, 'lon')
        else:
            # Convert lat/lon to az/rg for radar coord file using geomap*.trans file
            inps.ref_y, inps.ref_x = ut.glob2radar(np.array(inps.ref_lat), np.array(inps.ref_lon),\
                                                   inps.trans_file, atr)[0:2]
        print('Input reference point in lat/lon: ' +
              str([inps.ref_lat, inps.ref_lon]))
    print('Input reference point in   y/x  : ' + str([inps.ref_y, inps.ref_x]))

    # Do not use ref_y/x outside of data coverage
    if (inps.ref_y and inps.ref_x
            and not (0 <= inps.ref_y <= length and 0 <= inps.ref_x <= width)):
        inps.ref_y = None
        inps.ref_x = None
        print('WARNING: input reference point is OUT of data coverage!')
        print('Continue with other method to select reference point.')

    # Do not use ref_y/x in masked out area
    if inps.ref_y and inps.ref_x and inps.mask_file:
        print('mask: ' + inps.mask_file)
        mask = readfile.read(inps.mask_file)[0]
        if mask[inps.ref_y, inps.ref_x] == 0:
            inps.ref_y = None
            inps.ref_x = None
            print('WARNING: input reference point is in masked OUT area!')
            print('Continue with other method to select reference point.')

    ##### Select method
    if inps.ref_y and inps.ref_x:
        inps.method = 'input-coord'
    elif inps.coherence_file:
        if os.path.isfile(inps.coherence_file):
            inps.method = 'max-coherence'
        else:
            inps.coherence_file = None

    if inps.method == 'manual':
        inps.parallel = False
        print('Parallel processing is disabled for manual seeding method.')

    ##### Seeding file by file
    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(
            len(inps.file))

    if len(inps.file) == 1:
        seed_file_inps(inps.file[0], inps, inps.outfile)

    elif inps.parallel:
        #num_cores = min(multiprocessing.cpu_count(), len(inps.file))
        #print 'parallel processing using %d cores ...'%(num_cores)
        Parallel(n_jobs=num_cores)(delayed(seed_file_inps)(file, inps)
                                   for file in inps.file)
    else:
        for File in inps.file:
            seed_file_inps(File, inps)

    print('Done.')
    return
Esempio n. 8
0
def main(argv):
    
    inps = cmdLineParse()
    inps.file = ut.get_file_list(inps.file)
    print('input file(s): '+str(len(inps.file)))
    print(inps.file)
    
    #print '\n*************** Phase Ramp Removal ***********************'
    atr = readfile.read_attribute(inps.file[0])
    length = int(atr['FILE_LENGTH'])
    width = int(atr['WIDTH'])

    # Read mask file if inputed
    if inps.mask_file == 'no':  inps.mask_file = None
    if inps.mask_file:
        try:
            mask_atr = readfile.read_attribute(inps.mask_file)
        except:
            print('Can not open mask file: '+inps.mask_file)
            inps.mask_file = None

    # Update mask for multiple surfaces
    if inps.ysub:
        # Read mask
        if not inps.mask_file:
            Mask_temp = readfile.read(inps.mask_file)[0]
            Mask = np.zeros((length, width), dtype=np.float32)
            Mask[Mask_temp!=0] = 1
        else:
            Mask = np.ones((length, width))
        
        # Update mask for multiple surface from inps.ysub
        mask_multiSurface = np.zeros((length,width), dtype=np.float32)
        surfNum = len(inps.ysub)/2
        if surfNum == 1:
            mask_multiSurface = Mask
        else:
            i = 0
            mask_multiSurface[inps.ysub[2*i]:inps.ysub[2*i+1],:] = Mask[inps.ysub[2*i]:inps.ysub[2*i+1],:]
            for i in range(1,surfNum):
                if inps.ysub[2*i] < inps.ysub[2*i-1]:
                    mask_multiSurface[inps.ysub[2*i]:inps.ysub[2*i-1],:]  += Mask[inps.ysub[2*i]:inps.ysub[2*i-1],:]*(i+1)
                    mask_multiSurface[inps.ysub[2*i]:inps.ysub[2*i-1],:]  /= 2
                    mask_multiSurface[inps.ysub[2*i-1]:inps.ysub[2*i+1],:] = Mask[inps.ysub[2*i-1]:inps.ysub[2*i+1],:]*(i+1)
                else:
                    mask_multiSurface[inps.ysub[2*i]:inps.ysub[2*i+1],:]   = Mask[inps.ysub[2*i]:inps.ysub[2*i+1],:]*(i+1)
         
        # Write updated mask for multiple surfaces into file
        outFile = 'mask_'+str(surfNum)+inps.surface_type+'.h5'
        atr['FILE_TYPE'] = 'mask'
        writefile.write(mask_multiSurface, atr, outFile)
        print('saved mask to '+outFile)

    ############################## Removing Phase Ramp #######################################
    # check outfile and parallel option
    if inps.parallel:
        num_cores, inps.parallel, Parallel, delayed = ut.check_parallel(len(inps.file))

    if len(inps.file) == 1:
        rm.remove_surface(inps.file[0], inps.surface_type, inps.mask_file, inps.outfile, inps.ysub)

    elif inps.parallel:
        #num_cores = min(multiprocessing.cpu_count(), len(inps.file))
        #print 'parallel processing using %d cores ...'%(num_cores)
        Parallel(n_jobs=num_cores)(delayed(rm.remove_surface)(file, inps.surface_type, inps.mask_file, ysub=inps.ysub)\
                                   for file in inps.file)

    else:
        for File in inps.file:
            print('------------------------------------------')
            rm.remove_surface(File, inps.surface_type, inps.mask_file, ysub=inps.ysub)
    
    print('Done.')
    return