Esempio n. 1
0
def geodmod(inpsdict):
    """prepare data for geodmod software"""
    if inpsdict['mimtpy.geodmod'] == 'yes':
        Dataset = inpsdict['mimtpy.geodmod.DataSet']
        Dataset = list(tuple([i for i in Dataset.split(',')]))
        for dataset in Dataset:
            print(
                '\n***********************Start processing {} dataset***********************'
                .format(dataset))
            # go to dataset_dir
            dataset_dir = os.path.abspath(
                os.path.join(os.getenv('SCRATCHDIR'), dataset, 'mintpy'))
            if not os.path.isdir(dataset_dir):
                raise Exception('Error! No such dir : {}'.format(dataset_dir))
            print('\nGo to project dir:', dataset_dir)
            os.chdir(dataset_dir)

            # create geodmod dir
            software = 'geodmod'
            outdir = os.path.abspath(os.path.join(dataset_dir, software))
            if not os.path.isdir(outdir):
                os.makedirs(outdir)

            # find the HDFEOS file name
            HDFEOS_file = mu.find_HDFEOS_fullname(dataset_dir)
            print('\nThe HDFEOS file is {}'.format(HDFEOS_file))
            atr = readfile.read_attribute(HDFEOS_file)

            # get the startdate and enddate
            startDate, endDate = mu.find_start_end_date(
                dataset_dir, inpsdict['mimtpy.geodmod.startDate'],
                inpsdict['mimtpy.geodmod.endDate'])
            if startDate == 'None':
                startDate = atr['START_DATE']
            if endDate == 'None':
                endDate = atr['END_DATE']

            # go to geodmod dir
            print('\nGo to geodmod dir:', outdir)
            os.chdir(outdir)

            # generate parameter list for HDFEOS_to_geotiff.py
            if inpsdict['mimtpy.geodmod.SNWE'] == 'None':
                scp_args = [
                    '../' + HDFEOS_file, '-s', startDate, '-e', endDate
                ]
            else:
                SNWE = inpsdict['mimtpy.geodmod.SNWE']
                SNWE = list(tuple([float(i) for i in SNWE.split(',')]))
                scp_args = [
                    '../' + HDFEOS_file, '-s', startDate, '-e', endDate,
                    '--bbox', SNWE
                ]

            scp_args = mu.seperate_str_byspace(scp_args)
            # run save_geodmod.py
            print('save_geodmod.py', scp_args)
            mimtpy.save_geodmod.main(scp_args.split())
    else:
        print('\nSkip geodmod step')
Esempio n. 2
0
def process_HDFEOS(inps, track, startDate, endDate, outdir, tmpdir):
    """process S1*.h5 file"""

    atr_asc = multitrack_utilities.find_HDFEOS_fullname("".join(
        [os.getenv('SCRATCHDIR') + '/' + track + '/mintpy/']))

    #save dataset of unw
    filename, extension = multitrack_utilities.seprate_filename_extension(
        "".join(atr_asc))[1:3]
    cmd_args = [
        filename + extension,
        "".join(['displacement-', startDate, '_', endDate]), '-o',
        "".join(['geo_', startDate, '_', endDate, '.unw'])
    ]
    print("save_roipac.py", cmd_args)
    args_str = multitrack_utilities.seperate_str_byspace(cmd_args)
    os.system(
        multitrack_utilities.seperate_str_byspace(
            ['save_roipac.py', args_str.split()]))

    # mv
    if os.path.exists(tmpdir) == False:
        os.makedirs(tmpdir)
    else:
        shutil.rmtree(tmpdir)
        os.makedirs(tmpdir)
    key1 = 'geo_'
    for file in os.listdir(os.getcwd()):
        if str.find(file, key1) != -1:
            shutil.move(file, tmpdir)

    copy_file('geo', 'unw', outdir)
    shutil.rmtree(tmpdir)
Esempio n. 3
0
def prep_gbis(inps):
    """prepare data that has to be written in *.mat file"""

    if str.find(str(inps.file), 'S1') != -1:
        key1 = 'S1'
        key2 = '.he5'
        for file in os.listdir(os.getcwd()):
            if str.find(file, key1) != -1 and str.find(file, key2) != -1:
                shutil.copy(file, inps.outdir)
        os.chdir("".join(inps.outdir))
        geom_file = multitrack_utilities.find_HDFEOS_fullname(os.getcwd())
    else:

        geom_file = 'geo_geometryRadar.h5'
    # metadata
    unw_file = 'geo_' + inps.startDate + '_' + inps.endDate + '.unw'
    inps.metadata = readfile.read_attribute(unw_file)
    inps.phase, atr = readfile.read(unw_file)

    # mask
    if not inps.mask_file or inps.mask_file == 'None':
        inps.mask = np.ones(
            (int(inps.metadata['LENGTH']), int(inps.metadata['WIDTH'])),
            dtype=np.bool_)
    else:
        inps.mask = readfile.read('geo_' + inps.mask_file)[0]

    # update mask to exclude pixel with NaN value
    inps.mask *= ~np.isnan(inps.phase)
    # set all masked out pixel to NaN
    inps.phase[inps.mask == 0] = np.nan

    # change reference point
    if inps.ref_lalo:
        coord = ut.coordinate(inps.metadata)
        ref_lat, ref_lon = inps.ref_lalo
        ref_y, ref_x = coord.geo2radar(ref_lat, ref_lon)[0:2]
        # update data
        inps.phase -= inps.phase[ref_y, ref_x]
        # update metadata
        inps.metadata['REF_LAT'] = ref_lat
        inps.metadata['REF_LON'] = ref_lon
        inps.metadata['REF_Y'] = ref_y
        inps.metadata['REF_X'] = ref_x

    # read geometry
    inps.lat, inps.lon = ut.get_lat_lon(inps.metadata)
    inps.inc_angle = readfile.read(geom_file, datasetName='incidenceAngle')[0]
    inps.head_angle = np.ones(inps.inc_angle.shape, dtype=np.float32) * float(
        inps.metadata['HEADING'])
    inps.height = readfile.read(geom_file, datasetName='height')[0]
    inps.lat[inps.mask == 0] = np.nan
    inps.lon[inps.mask == 0] = np.nan
    inps.inc_angle[inps.mask == 0] = np.nan
    inps.head_angle[inps.mask == 0] = np.nan
    inps.height[inps.mask == 0] = np.nan

    # output filename
    proj_name = atr['PROJECT_NAME']
    if not proj_name:
        raise ValueError('No custom/auto output filename found.')
    inps.outfile = '{}_{}_{}.mat'.format(proj_name, inps.startDate,
                                         inps.endDate)
    inps.outfile = os.path.join(inps.outdir, inps.outfile)
    inps.outfile = os.path.abspath(inps.outfile)

    #delete geo_*.h5 files
    multitrack_utilities.delete_tmpgeo(inps.outdir, 'S1_', '.he5')
    multitrack_utilities.delete_tmpgeo(inps.outdir, 'geo_', '.h5')
    return
Esempio n. 4
0
def velcumu(inpsdict):
    """generate velocity.h5 and velocity.tiff file or generate cumudisp_date1_date2.h5 and cumudisp_date1_date2_tiff."""
    if inpsdict['mimtpy.velcumu'] == 'yes':
        Dataset = inpsdict['mimtpy.velcumu.DataSet']
        Dataset = list(tuple([i for i in Dataset.split(',')]))
        for dataset in Dataset:
            print(
                '\n***********************Start processing {} dataset***********************'
                .format(dataset))
            # go to dataset_dir
            dataset_dir = os.path.abspath(
                os.path.join(os.getenv('SCRATCHDIR'), dataset, 'mintpy'))
            if not os.path.isdir(dataset_dir):
                raise Exception('Error! No such dir : {}'.format(dataset_dir))
            os.chdir(dataset_dir)
            print('\nGo to project dir:', dataset_dir)

            # create velocity or cumulative dir
            filetype = inpsdict['mimtpy.velcumu.type']
            outdir = os.path.abspath(os.path.join(dataset_dir, filetype))
            if not os.path.isdir(outdir):
                os.makedirs(outdir)
            print('\nthe output dir for {} is {}.\n'.format(filetype, outdir))

            # find the HDFEOS file name
            HDFEOS_file = mu.find_HDFEOS_fullname(dataset_dir)
            print('\nThe HDFEOS file is {}'.format(HDFEOS_file))
            atr = readfile.read_attribute(HDFEOS_file)

            # get the startdate and enddate
            startDate, endDate = mu.find_start_end_date(
                dataset_dir, inpsdict['mimtpy.velcumu.startDate'],
                inpsdict['mimtpy.velcumu.endDate'])
            if startDate == 'None':
                startDate = atr['START_DATE']
            if endDate == 'None':
                endDate = atr['END_DATE']

            # generate parameter list for HDFEOS_to_geotiff.py
            if inpsdict['mimtpy.velcumu.SNWE'] == 'None':
                if inpsdict['mimtpy.velcumu.mask'] == 'y':
                    scp_args = [
                        HDFEOS_file, filetype, '--date',
                        startDate + '_' + endDate, '--mask', '--outdir', outdir
                    ]
                else:
                    scp_args = [
                        HDFEOS_file, filetype, '--date',
                        startDate + '_' + endDate, '--outdir', outdir
                    ]
            else:
                SNWE = inpsdict['mimtpy.velcumu.SNWE']
                SNWE = list(tuple([float(i) for i in SNWE.split(',')]))
                if inpsdict['mimtpy.velcumu.mask'] == 'y':
                    scp_args = [
                        HDFEOS_file, filetype, '--date',
                        startDate + '_' + endDate, '--mask', '--bbox', SNWE,
                        '--outdir', outdir
                    ]
                else:
                    scp_args = [
                        HDFEOS_file, filetype, '--date',
                        startDate + '_' + endDate, '--bbox', SNWE, '--outdir',
                        outdir
                    ]

            scp_args = mu.seperate_str_byspace(scp_args)
            # run HDFEOS_to_geotiff.py
            print('HDFEOS_to_geotiff.py', scp_args)
            mimtpy.HDFEOS_to_geotiff.main(scp_args.split())
    else:
        print('\nSkip velcumu process')

    return
Esempio n. 5
0
def multitrack_run_software(inpsdict, folders, inps):
    """run save_geodmod/gbis for each track"""
    for project in folders:
        os.chdir("".join(
            [os.getenv('SCRATCHDIR') + '/' + project + '/mintpy/']))
        if inpsdict['DataType'] == 'HDFEOS':
            datafile = multitrack_utilities.find_HDFEOS_fullname("".join(
                [os.getenv('SCRATCHDIR') + '/' + project + '/mintpy/']))
        elif inpsdict['DataType'] == 'timeseries':
            datafile = multitrack_utilities.find_timeseries("".join(
                [os.getenv('SCRATCHDIR') + '/' + project + '/mintpy/']))
        elif inpsdict['DataType'] == 'ifgramStack':
            datafile = "".join([str(inpsdict['DataType']) + '.h5'])
        elif inpsdict['DataType'] == 'velocity':
            datafile = "".join([str(inpsdict['DataType']) + '.h5'])

        if inps.outdir == os.getenv('SCRATCHDIR'):
            inpsdict['outdir'] = inps.outdir + '/' + project + '/mintpy'
        else:
            inpsdict['outdir'] = inps.outdir + '/' + project

        if inps.ModelSoftware == 'geodmod':
            print(
                multitrack_utilities.seperate_str_byspace([
                    'save_geodmod.py', datafile, '-b', inpsdict['SNWE'], '-y',
                    inpsdict['latStep'], '-x', inpsdict['lonStep'], '-s',
                    inpsdict['startDate'], '-e', inpsdict['endDate'],
                    '-outdir', inpsdict['outdir']
                ]))
            completion_status = os.system(
                multitrack_utilities.seperate_str_byspace([
                    'save_geodmod.py', datafile, '-b', inpsdict['SNWE'], '-y',
                    inpsdict['latStep'], '-x', inpsdict['lonStep'], '-s',
                    inpsdict['startDate'], '-e', inpsdict['endDate'],
                    '-outdir', inpsdict['outdir']
                ]))
            if completion_status == 1:
                print('error when runing save_geodmod.py')
                exit(0)
        elif inps.ModelSoftware == 'gbis':
            if inpsdict['ref_lalo'][0] == 'None':
                if inpsdict['mask_file'] == 'None':
                    print('here!')
                    print(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '-outdir',
                            inpsdict['outdir']
                        ]))
                    completion_status = os.system(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '-outdir',
                            inpsdict['outdir']
                        ]))
                    if completion_status == 1:
                        raise Exception('error when runing save_gbis.py')
                else:
                    print(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '-m',
                            inpsdict['mask_file'], '-outdir',
                            inpsdict['outdir']
                        ]))
                    completion_status = os.system(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '-m',
                            inpsdict['mask_file'], '-outdir',
                            inpsdict['outdir']
                        ]))
                    if completion_status == 1:
                        raise Exception('error when runing save_gbis.py')
            else:
                if inpsdict['mask_file'] == 'None':
                    print(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '--ref-lalo',
                            inpsdict['ref_lalo'], '-outdir', inpsdict['outdir']
                        ]))
                    completion_status = os.system(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '--ref-lalo',
                            inpsdict['ref_lalo'], '-outdir', inpsdict['outdir']
                        ]))
                    if completion_status == 1:
                        raise Exception('error when runing save_gbis.py')
                else:
                    print(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '-m',
                            inpsdict['mask_file'], '--ref-lalo',
                            inpsdict['ref_lalo'], '-outdir', inpsdict['outdir']
                        ]))
                    completion_status = os.system(
                        multitrack_utilities.seperate_str_byspace([
                            'save_gbis_mimt.py', datafile, '-b',
                            inpsdict['SNWE'], '-y', inpsdict['latStep'], '-x',
                            inpsdict['lonStep'], '-s', inpsdict['startDate'],
                            '-e', inpsdict['endDate'], '-m',
                            inpsdict['mask_file'], '--ref-lalo',
                            inpsdict['ref_lalo'], '-outdir', inpsdict['outdir']
                        ]))
                    if completion_status == 1:
                        raise Exception('error when runing save_gbis.py')