Example #1
0
def save_hdfeos5(inps, customTemplate=None):
    if not inps.geocoded:
        warnings.warn('Dataset is in radar coordinates, skip writting to HDF-EOS5 format.')
    else:
        # Add attributes from custom template to timeseries file
        if customTemplate is not None:
            ut.add_attribute(inps.timeseriesFile, customTemplate)

        # Save to HDF-EOS5 format
        print('--------------------------------------------')
        hdfeos5Cmd = ('save_hdfeos5.py {t} -c {c} -m {m} -g {g}'
                      ' -t {e}').format(t=inps.timeseriesFile,
                                        c=inps.tempCohFile,
                                        m=inps.maskFile,
                                        g=inps.geomFile,
                                        e=inps.templateFile)
        print(hdfeos5Cmd)
        atr = readfile.read_attribute(inps.timeseriesFile)
        SAT = sensor.get_unavco_mission_name(atr)
        try:
            inps.hdfeos5File = ut.get_file_list('{}_*.he5'.format(SAT))[0]
        except:
            inps.hdfeos5File = None
        if ut.run_or_skip(out_file=inps.hdfeos5File, in_file=[inps.timeseriesFile,
                                                              inps.tempCohFile,
                                                              inps.maskFile,
                                                              inps.geomFile]) == 'run':
            status = subprocess.Popen(hdfeos5Cmd, shell=True).wait()
            if status is not 0:
                raise Exception('Error while generating HDF-EOS5 time-series file.\n')
    return
Example #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['pysar.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 'GEOCODE' in ts_file:
                tcoh_file = './GEOCODE/geo_temporalCoherence.h5'
                mask_file = './GEOCODE/geo_maskTempCoh.h5'
                geom_file = './GEOCODE/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':
                pysar.save_hdfeos5.main(scp_args.split())
        else:
            print('save time-series to HDF-EOS5 format is OFF.')
        return
Example #3
0
def metadata_pysar2unavco(pysar_meta_dict_in, dateList):
    # Extract UNAVCO format metadata from PySAR attributes dictionary and dateList
    pysar_meta_dict = {}
    for key in pysar_meta_dict_in.keys():
        pysar_meta_dict[key] = pysar_meta_dict_in[key]
        for prefix in ['unavco.', 'hdfeos5.']:
            if prefix in key.lower():
                key2 = key.lower().split(prefix)[1]
                pysar_meta_dict[key2] = pysar_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(
            pysar_meta_dict)
    except ValueError:
        print('Missing required attribute: mission')

    # beam_mode/swath
    unavco_meta_dict['beam_mode'] = pysar_meta_dict['beam_mode']
    try:
        unavco_meta_dict['beam_swath'] = int(pysar_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(pysar_meta_dict['relative_orbit'])

    # processing info
    try:
        unavco_meta_dict['processing_type'] = pysar_meta_dict[
            'processing_type']
    except:
        unavco_meta_dict['processing_type'] = 'LOS_TIMESERIES'
    #unavco_meta_dict['processing_software'] = pysar_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 = [
        pysar_meta_dict['LON_REF1'], pysar_meta_dict['LON_REF3'],
        pysar_meta_dict['LON_REF4'], pysar_meta_dict['LON_REF2'],
        pysar_meta_dict['LON_REF1']
    ]

    lats = [
        pysar_meta_dict['LAT_REF1'], pysar_meta_dict['LAT_REF3'],
        pysar_meta_dict['LAT_REF4'], pysar_meta_dict['LAT_REF2'],
        pysar_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 pysar_meta_dict.keys():
        unavco_meta_dict['frame'] = int(pysar_meta_dict['frame'])
    elif 'first_frame' in pysar_meta_dict.keys():
        unavco_meta_dict['frame'] = int(pysar_meta_dict['first_frame'])
    else:
        unavco_meta_dict['frame'] = 0

    try:
        unavco_meta_dict['atmos_correct_method'] = pysar_meta_dict[
            'atmos_correct_method']
    except:
        pass
    try:
        unavco_meta_dict['post_processing_method'] = pysar_meta_dict[
            'post_processing_method']
    except:
        unavco_meta_dict['post_processing_method'] = 'PYSAR'
    try:
        unavco_meta_dict['processing_dem'] = pysar_meta_dict['processing_dem']
    except:
        pass
    try:
        unavco_meta_dict['unwrap_method'] = pysar_meta_dict['unwrap_method']
    except:
        pass

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

    #################################
    # insarmaps metadata
    #################################
    # footprint for data coverage
    if 'X_FIRST' in pysar_meta_dict.keys():
        lon0 = float(pysar_meta_dict['X_FIRST'])
        lat0 = float(pysar_meta_dict['Y_FIRST'])
        lon1 = lon0 + float(pysar_meta_dict['X_STEP']) * int(
            pysar_meta_dict['WIDTH'])
        lat1 = lat0 + float(pysar_meta_dict['Y_STEP']) * int(
            pysar_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