コード例 #1
0
ファイル: stacking.py プロジェクト: whigg/PySAR
def main(iargs=None):
    inps = cmd_line_parse(iargs)
    print('\n*************** Stacking ******************')
    ut.temporal_average(inps.file,
                        datasetName=inps.dataset_name,
                        outFile=inps.outfile)
    return
コード例 #2
0
def main(iargs=None):
    inps = cmd_line_parse(iargs)
    if inps.template_file:
        inps = read_template2inps(inps.template_file, inps)

    elif all(not i for i in [
            inps.referenceFile, inps.tempBaseMax, inps.perpBaseMax,
            inps.connNumMax, inps.excludeIfgIndex, inps.excludeDate,
            inps.coherenceBased, inps.startDate, inps.endDate, inps.reset,
            inps.manual
    ]):
        msg = 'No input option found to remove interferogram, exit.\n'
        msg += 'To manually modify network, please use --manual option '
        raise Exception(msg)

    if inps.reset:
        print('--------------------------------------------------')
        reset_network(inps.file)
        return inps.file

    inps.date12_to_drop = get_date12_to_drop(inps)

    if inps.date12_to_drop is not None:
        ifgramStack(inps.file).update_drop_ifgram(
            date12List_to_drop=inps.date12_to_drop)
        print('--------------------------------------------------')
        ut.nonzero_mask(inps.file)
        print('--------------------------------------------------')
        ut.temporal_average(inps.file,
                            datasetName='coherence',
                            updateMode=True)
        # Touch spatial average txt file of coherence if it's existed
        ut.touch(
            os.path.splitext(os.path.basename(inps.file))[0] +
            '_coherence_spatialAvg.txt')

        # Plot result
        if inps.plot:
            print('\nplot modified network and save to file.')
            plotCmd = 'plot_network.py {} --nodisplay'.format(inps.file)
            if inps.template_file:
                plotCmd += ' --template {}'.format(inps.template_file)
            print(plotCmd)
            os.system(plotCmd)
        print('Done.')
    return
コード例 #3
0
ファイル: temporal_average.py プロジェクト: fossabot/PySAR
def main(iargs=None):
    start_time = time.time()
    inps = cmd_line_parse(iargs)

    inps.outfile = check_output_filename(inps)
    inps.outfile = ut.temporal_average(inps.file,
                                       datasetName=inps.datasetName,
                                       outFile=inps.outfile)

    m, s = divmod(time.time() - start_time, 60)
    print('\ntime used: {:02.0f} mins {:02.1f} secs'.format(m, s))
    return inps.outfile
コード例 #4
0
def main(iargs=None):
    start_time = time.time()
    inps = cmd_line_parse(iargs)

    inps.outfile = check_output_filename(inps)

    if inps.update_mode and run_or_skip(inps) == 'skip':
        return inps.outfile

    inps.outfile = ut.temporal_average(inps.file,
                                       datasetName=inps.datasetName,
                                       outFile=inps.outfile)

    m, s = divmod(time.time() - start_time, 60)
    print('time used: {:02.0f} mins {:02.1f} secs\n'.format(m, s))
    return inps.outfile
コード例 #5
0
def reference_file(inps):
    """Seed input file with option from input namespace
    Return output file name if succeed; otherwise, return None
    """
    if not inps:
        inps = cmd_line_parse([''])
    atr = readfile.read_attribute(inps.file)
    if (inps.ref_y and inps.ref_x and 'REF_Y' in atr.keys()
            and inps.ref_y == int(atr['REF_Y'])
            and inps.ref_x == int(atr['REF_X']) and not inps.force):
        print(
            'Same reference pixel is already selected/saved in file, skip updating.'
        )
        return inps.file

    # Get stack and mask
    stack = ut.temporal_average(inps.file,
                                datasetName='unwrapPhase',
                                updateMode=True,
                                outFile=False)[0]
    mask = np.multiply(~np.isnan(stack), stack != 0.)
    if np.nansum(mask) == 0.0:
        raise ValueError(
            'no pixel found with valid phase value in all datasets.')

    if inps.ref_y and inps.ref_x and mask[inps.ref_y, inps.ref_x] == 0.:
        raise ValueError(
            'reference y/x have nan value in some dataset. Please re-select.')

    # Find reference y/x
    if not inps.ref_y or not inps.ref_x:
        if inps.method == 'maxCoherence':
            inps.ref_y, inps.ref_x = select_max_coherence_yx(
                coh_file=inps.coherenceFile,
                mask=mask,
                min_coh=inps.minCoherence)
        elif inps.method == 'random':
            inps.ref_y, inps.ref_x = random_select_reference_yx(mask)
        elif inps.method == 'manual':
            inps = manual_select_reference_yx(stack, inps, mask)
    if not inps.ref_y or not inps.ref_x:
        raise ValueError('ERROR: no reference y/x found.')

    # Seeding file with reference y/x
    atrNew = reference_point_attribute(atr, y=inps.ref_y, x=inps.ref_x)
    if not inps.write_data:
        print('Add/update ref_x/y attribute to file: ' + inps.file)
        print(atrNew)
        inps.outfile = ut.add_attribute(inps.file, atrNew)

    else:
        if not inps.outfile:
            inps.outfile = '{}_seeded{}'.format(
                os.path.splitext(inps.file)[0],
                os.path.splitext(inps.file)[1])
        k = atr['FILE_TYPE']

        # For ifgramStack file, update data value directly, do not write to new file
        if k == 'ifgramStack':
            f = h5py.File(inps.file, 'r+')
            ds = f[k].get('unwrapPhase')
            for i in range(ds.shape[0]):
                ds[i, :, :] -= ds[i, inps.ref_y, inps.ref_x]
            f[k].attrs.update(atrNew)
            f.close()
            inps.outfile = inps.file

        elif k == 'timeseries':
            data = timeseries(inps.file).read()
            for i in range(data.shape[0]):
                data[i, :, :] -= data[i, inps.ref_y, inps.ref_x]
            obj = timeseries(inps.outfile)
            atr.update(atrNew)
            obj.write2hdf5(data=data, metadata=atr, refFile=inps.file)
            obj.close()
        else:
            print('writing >>> ' + inps.outfile)
            data = readfile.read(inps.file)[0]
            data -= data[inps.ref_y, inps.ref_x]
            atr.update(atrNew)
            writefile.write(data, out_file=inps.outfile, metadata=atr)
    ut.touch([inps.coherenceFile, inps.maskFile])
    return inps.outfile