Пример #1
0
    def run_save2hdfeos5(self, step_name):
        """Save displacement time-series and its aux data in geo coordinate into HDF-EOS5 format"""
        if self.template['mintpy.save.hdfEos5'] is True:
            # input
            ts_file = self.get_timeseries_filename(
                self.template)[step_name]['input']
            # Add attributes from custom template to timeseries file
            if self.customTemplate is not None:
                ut.add_attribute(ts_file, self.customTemplate)

            tcoh_file = 'temporalCoherence.h5'
            mask_file = 'geo_maskTempCoh.h5'
            geom_file = ut.check_loaded_dataset(self.workDir,
                                                print_msg=False)[2]
            if 'geo' in ts_file:
                tcoh_file = './geo/geo_temporalCoherence.h5'
                mask_file = './geo/geo_maskTempCoh.h5'
                geom_file = './geo/geo_{}'.format(os.path.basename(geom_file))

            # cmd
            print('--------------------------------------------')
            scp_args = '{f} -c {c} -m {m} -g {g} -t {t}'.format(
                f=ts_file,
                c=tcoh_file,
                m=mask_file,
                g=geom_file,
                t=self.templateFile)
            print('save_hdfeos5.py', scp_args)

            # output (check existing file)
            atr = readfile.read_attribute(ts_file)
            SAT = sensor.get_unavco_mission_name(atr)
            try:
                hdfeos5_file = get_file_list('{}_*.he5'.format(SAT))[0]
            except:
                hdfeos5_file = None
            if ut.run_or_skip(
                    out_file=hdfeos5_file,
                    in_file=[ts_file, tcoh_file, mask_file,
                             geom_file]) == 'run':
                mintpy.save_hdfeos5.main(scp_args.split())
        else:
            print('save time-series to HDF-EOS5 format is OFF.')
        return
Пример #2
0
    def run_save2hdfeos5(self, step_name):
        """Save displacement time-series and its aux data in geo coordinate into HDF-EOS5 format"""
        if self.template['mintpy.save.hdfEos5'] is True:
            # input
            ts_file = self.get_timeseries_filename(self.template)[step_name]['input']
            # Add attributes from custom template to timeseries file
            if self.customTemplate is not None:
                ut.add_attribute(ts_file, self.customTemplate)

            tcoh_file = 'temporalCoherence.h5'
            mask_file = 'geo_maskTempCoh.h5'
            geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2]
            if 'geo' in ts_file:
                tcoh_file = './geo/geo_temporalCoherence.h5'
                mask_file = './geo/geo_maskTempCoh.h5'
                geom_file = './geo/geo_{}'.format(os.path.basename(geom_file))

            # cmd
            print('--------------------------------------------')
            scp_args = '{f} -c {c} -m {m} -g {g} -t {t}'.format(f=ts_file,
                                                                c=tcoh_file,
                                                                m=mask_file,
                                                                g=geom_file,
                                                                t=self.templateFile)
            print('save_hdfeos5.py', scp_args)

            # output (check existing file)
            atr = readfile.read_attribute(ts_file)
            SAT = sensor.get_unavco_mission_name(atr)
            try:
                hdfeos5_file = get_file_list('{}_*.he5'.format(SAT))[0]
            except:
                hdfeos5_file = None
            if ut.run_or_skip(out_file=hdfeos5_file, in_file=[ts_file, tcoh_file, mask_file, geom_file]) == 'run':
                mintpy.save_hdfeos5.main(scp_args.split())
        else:
            print('save time-series to HDF-EOS5 format is OFF.')
        return
Пример #3
0
def metadata_mintpy2unavco(meta_dict_in, dateList):
    # Extract UNAVCO format metadata from MintPy attributes dictionary and dateList
    meta_dict = {}
    for key in meta_dict_in.keys():
        meta_dict[key] = meta_dict_in[key]
        for prefix in ['unavco.', 'hdfeos5.']:
            if prefix in key.lower():
                key2 = key.lower().split(prefix)[1]
                meta_dict[key2] = meta_dict_in[key]

    unavco_meta_dict = dict()
    #################################
    # Required metadata
    #################################
    # Given manually
    # mission
    # ERS,ENV,S1,RS1,RS2,CSK,TSX,JERS,ALOS,ALOS2
    try:
        unavco_meta_dict['mission'] = sensor.get_unavco_mission_name(meta_dict)
    except ValueError:
        print('Missing required attribute: mission')

    # beam_mode/swath
    unavco_meta_dict['beam_mode'] = meta_dict['beam_mode']
    try:
        unavco_meta_dict['beam_swath'] = int(meta_dict['beam_swath'])
    except:
        unavco_meta_dict['beam_swath'] = 0

    # relative_orbit, or track number
    #atr_dict['relative_orbit'] = int(re.match(r'(\w+)T([0-9+])',atr['PROJECT_NAME']).groups()[1])
    unavco_meta_dict['relative_orbit'] = int(meta_dict['relative_orbit'])

    # processing info
    try:
        unavco_meta_dict['processing_type'] = meta_dict['processing_type']
    except:
        unavco_meta_dict['processing_type'] = 'LOS_TIMESERIES'
    #unavco_meta_dict['processing_software'] = meta_dict['processing_software']

    # Grabbed by script
    # date info
    unavco_meta_dict['first_date'] = dt.datetime.strptime(
        dateList[0], '%Y%m%d').isoformat()[0:10]
    unavco_meta_dict['last_date'] = dt.datetime.strptime(
        dateList[-1], '%Y%m%d').isoformat()[0:10]

    # footprint
    lons = [
        meta_dict['LON_REF1'], meta_dict['LON_REF3'], meta_dict['LON_REF4'],
        meta_dict['LON_REF2'], meta_dict['LON_REF1']
    ]

    lats = [
        meta_dict['LAT_REF1'], meta_dict['LAT_REF3'], meta_dict['LAT_REF4'],
        meta_dict['LAT_REF2'], meta_dict['LAT_REF1']
    ]

    unavco_meta_dict['scene_footprint'] = "POLYGON((" + ",".join(
        [lon + ' ' + lat for lon, lat in zip(lons, lats)]) + "))"

    unavco_meta_dict['history'] = dt.datetime.utcnow().isoformat()[0:10]

    #################################
    # Recommended metadata
    #################################
    # Given manually
    if 'frame' in meta_dict.keys():
        unavco_meta_dict['frame'] = int(meta_dict['frame'])
    elif 'first_frame' in meta_dict.keys():
        unavco_meta_dict['frame'] = int(meta_dict['first_frame'])
    else:
        unavco_meta_dict['frame'] = 0

    try:
        unavco_meta_dict['atmos_correct_method'] = meta_dict[
            'atmos_correct_method']
    except:
        pass
    try:
        unavco_meta_dict['post_processing_method'] = meta_dict[
            'post_processing_method']
    except:
        unavco_meta_dict['post_processing_method'] = 'MintPy'
    try:
        unavco_meta_dict['processing_dem'] = meta_dict['processing_dem']
    except:
        pass
    try:
        unavco_meta_dict['unwrap_method'] = meta_dict['unwrap_method']
    except:
        pass

    # Grabbed by script
    try:
        unavco_meta_dict['flight_direction'] = meta_dict['ORBIT_DIRECTION'][
            0].upper()
    except:
        pass
    if meta_dict['ANTENNA_SIDE'] == '-1':
        unavco_meta_dict['look_direction'] = 'R'
    else:
        unavco_meta_dict['look_direction'] = 'L'
    try:
        unavco_meta_dict['polarization'] = meta_dict['POLARIZATION']
    except:
        pass
    try:
        unavco_meta_dict['prf'] = float(meta_dict['PRF'])
    except:
        pass
    try:
        unavco_meta_dict['wavelength'] = float(meta_dict['WAVELENGTH'])
    except:
        pass

    #################################
    # insarmaps metadata
    #################################
    # footprint for data coverage
    if 'X_FIRST' in meta_dict.keys():
        lon0 = float(meta_dict['X_FIRST'])
        lat0 = float(meta_dict['Y_FIRST'])
        lon1 = lon0 + float(meta_dict['X_STEP']) * int(meta_dict['WIDTH'])
        lat1 = lat0 + float(meta_dict['Y_STEP']) * int(meta_dict['LENGTH'])
        lons = [str(lon0), str(lon1), str(lon1), str(lon0), str(lon0)]
        lats = [str(lat0), str(lat0), str(lat1), str(lat1), str(lat0)]
        unavco_meta_dict['data_footprint'] = "POLYGON((" + ",".join(
            [lon + ' ' + lat for lon, lat in zip(lons, lats)]) + "))"
    else:
        print(
            'Input file is not geocoded, no data_footprint without X/Y_FIRST/STEP info.'
        )

    return unavco_meta_dict
Пример #4
0
def metadata_mintpy2unavco(meta_dict_in, dateList):
    # Extract UNAVCO format metadata from MintPy attributes dictionary and dateList
    meta_dict = {}
    for key in meta_dict_in.keys():
        meta_dict[key] = meta_dict_in[key]
        for prefix in ['unavco.', 'hdfeos5.']:
            if prefix in key.lower():
                key2 = key.lower().split(prefix)[1]
                meta_dict[key2] = meta_dict_in[key]

    unavco_meta_dict = dict()
    #################################
    # Required metadata
    #################################
    # Given manually
    # mission
    # ERS,ENV,S1,RS1,RS2,CSK,TSX,JERS,ALOS,ALOS2
    try:
        unavco_meta_dict['mission'] = sensor.get_unavco_mission_name(meta_dict)
    except ValueError:
        print('Missing required attribute: mission')

    # beam_mode/swath
    unavco_meta_dict['beam_mode'] = meta_dict['beam_mode']
    try:
        unavco_meta_dict['beam_swath'] = int(meta_dict['beam_swath'])
    except:
        unavco_meta_dict['beam_swath'] = 0

    # relative_orbit, or track number
    #atr_dict['relative_orbit'] = int(re.match(r'(\w+)T([0-9+])',atr['PROJECT_NAME']).groups()[1])
    unavco_meta_dict['relative_orbit'] = int(meta_dict['relative_orbit'])

    # processing info
    try:
        unavco_meta_dict['processing_type'] = meta_dict['processing_type']
    except:
        unavco_meta_dict['processing_type'] = 'LOS_TIMESERIES'
    #unavco_meta_dict['processing_software'] = meta_dict['processing_software']

    # Grabbed by script
    # date info
    unavco_meta_dict['first_date'] = dt.datetime.strptime(dateList[0], '%Y%m%d').isoformat()[0:10]
    unavco_meta_dict['last_date'] = dt.datetime.strptime(dateList[-1], '%Y%m%d').isoformat()[0:10]

    # footprint
    lons = [meta_dict['LON_REF1'],
            meta_dict['LON_REF3'],
            meta_dict['LON_REF4'],
            meta_dict['LON_REF2'],
            meta_dict['LON_REF1']]

    lats = [meta_dict['LAT_REF1'],
            meta_dict['LAT_REF3'],
            meta_dict['LAT_REF4'],
            meta_dict['LAT_REF2'],
            meta_dict['LAT_REF1']]

    unavco_meta_dict['scene_footprint'] = "POLYGON((" + ",".join(
        [lon+' '+lat for lon, lat in zip(lons, lats)]) + "))"

    unavco_meta_dict['history'] = dt.datetime.utcnow().isoformat()[0:10]

    #################################
    # Recommended metadata
    #################################
    # Given manually
    if 'frame' in meta_dict.keys():
        unavco_meta_dict['frame'] = int(meta_dict['frame'])
    elif 'first_frame' in meta_dict.keys():
        unavco_meta_dict['frame'] = int(meta_dict['first_frame'])
    else:
        unavco_meta_dict['frame'] = 0

    try:
        unavco_meta_dict['atmos_correct_method'] = meta_dict['atmos_correct_method']
    except:
        pass
    try:
        unavco_meta_dict['post_processing_method'] = meta_dict['post_processing_method']
    except:
        unavco_meta_dict['post_processing_method'] = 'MintPy'
    try:
        unavco_meta_dict['processing_dem'] = meta_dict['processing_dem']
    except:
        pass
    try:
        unavco_meta_dict['unwrap_method'] = meta_dict['unwrap_method']
    except:
        pass

    # Grabbed by script
    try:
        unavco_meta_dict['flight_direction'] = meta_dict['ORBIT_DIRECTION'][0].upper()
    except:
        pass
    if meta_dict['ANTENNA_SIDE'] == '-1':
        unavco_meta_dict['look_direction'] = 'R'
    else:
        unavco_meta_dict['look_direction'] = 'L'
    try:
        unavco_meta_dict['polarization'] = meta_dict['POLARIZATION']
    except:
        pass
    try:
        unavco_meta_dict['prf'] = float(meta_dict['PRF'])
    except:
        pass
    try:
        unavco_meta_dict['wavelength'] = float(meta_dict['WAVELENGTH'])
    except:
        pass

    #################################
    # insarmaps metadata
    #################################
    # footprint for data coverage
    if 'X_FIRST' in meta_dict.keys():
        lon0 = float(meta_dict['X_FIRST'])
        lat0 = float(meta_dict['Y_FIRST'])
        lon1 = lon0 + float(meta_dict['X_STEP'])*int(meta_dict['WIDTH'])
        lat1 = lat0 + float(meta_dict['Y_STEP'])*int(meta_dict['LENGTH'])
        lons = [str(lon0), str(lon1), str(lon1), str(lon0), str(lon0)]
        lats = [str(lat0), str(lat0), str(lat1), str(lat1), str(lat0)]
        unavco_meta_dict['data_footprint'] = "POLYGON((" + ",".join(
            [lon+' '+lat for lon, lat in zip(lons, lats)]) + "))"
    else:
        print('Input file is not geocoded, no data_footprint without X/Y_FIRST/STEP info.')

    return unavco_meta_dict