示例#1
0
def prepare_metadata(meta_file, geom_src_dir, box=None):
    print('-'*50)

    # extract metadata from ISCE to MintPy (ROIPAC) format
    meta = isce_utils.extract_isce_metadata(meta_file, update_mode=False)[0]

    if 'Y_FIRST' in meta.keys():
        geom_ext = '.geo.full'
    else:
        geom_ext = '.rdr.full'

    # add LAT/LON_REF1/2/3/4, HEADING, A/RLOOKS
    meta = isce_utils.extract_geometry_metadata(geom_src_dir,
                                                metadata=meta,
                                                box=box,
                                                fext_list=[geom_ext])

    # add LENGTH / WIDTH
    atr = readfile.read_attribute(os.path.join(geom_src_dir, 'lat{}'.format(geom_ext)))
    meta['LENGTH'] = atr['LENGTH']
    meta['WIDTH'] = atr['WIDTH']

    ## update metadata due to subset
    print('update metadata due to subset with bounding box')
    meta = ut.subset_attribute(meta, box)

    return meta
示例#2
0
def extract_isce_metadata(meta_file,
                          geom_dir=None,
                          rsc_file=None,
                          update_mode=True):
    """Extract metadata from ISCE stack products
    Parameters: meta_file : str, path of metadata file, reference/IW1.xml or referenceShelve/data.dat
                geom_dir  : str, path of geometry directory.
                rsc_file  : str, output file name of ROIPAC format rsc file
    Returns:    metadata  : dict
    """

    if not rsc_file:
        rsc_file = os.path.join(os.path.dirname(meta_file), 'data.rsc')

    # check existing rsc_file
    if update_mode and ut.run_or_skip(
            rsc_file, in_file=meta_file, check_readable=False) == 'skip':
        return readfile.read_roipac_rsc(rsc_file)

    # 1. extract metadata from XML / shelve file
    fbase = os.path.basename(meta_file)
    if fbase.startswith("IW"):
        print('extract metadata from ISCE/topsStack xml file:', meta_file)
        #metadata = extract_tops_metadata(meta_file)[0]
        metadata = isce_utils.extract_tops_metadata(meta_file)[0]
        metadata['sensor_type'] = 'tops'
    elif fbase.startswith("data"):
        print('extract metadata from ISCE/stripmapStack shelve file:',
              meta_file)
        #metadata = extract_stripmap_metadata(meta_file)[0]
        metadata = isce_utils.extract_stripmap_metadata(meta_file)[0]
        metadata['sensor_type'] = 'stripmap'
    elif fbase.endswith(".xml"):
        #metadata = extract_stripmap_metadata(meta_file)[0]
        metadata = isce_utils.extract_stripmap_metadata(meta_file)[0]

    else:
        raise ValueError(
            "unrecognized ISCE metadata file: {}".format(meta_file))

    # 2. extract metadata from geometry file
    if geom_dir:
        metadata = isce_utils.extract_geometry_metadata(geom_dir, metadata)

    # 3. common metadata
    metadata['PROCESSOR'] = 'isce'
    metadata['ANTENNA_SIDE'] = '-1'

    # convert all value to string format
    for key, value in metadata.items():
        metadata[key] = str(value)

    # write to .rsc file
    metadata = readfile.standardize_metadata(metadata)
    if rsc_file:
        print('writing ', rsc_file)
        writefile.write_roipac_rsc(metadata, rsc_file)
    return metadata
示例#3
0
def prepare_metadata(meta_file, geom_src_dir, box=None, nlks_x=1, nlks_y=1):
    print('-' * 50)

    # extract metadata from ISCE to MintPy (ROIPAC) format
    meta = isce_utils.extract_isce_metadata(meta_file, update_mode=False)[0]

    if 'Y_FIRST' in meta.keys():
        geom_ext = '.geo.full'
    else:
        geom_ext = '.rdr.full'

    # add LAT/LON_REF1/2/3/4, HEADING, A/RLOOKS
    meta = isce_utils.extract_geometry_metadata(geom_src_dir,
                                                meta=meta,
                                                box=box,
                                                fext_list=[geom_ext])

    # add LENGTH / WIDTH
    atr = readfile.read_attribute(
        os.path.join(geom_src_dir, 'lat{}'.format(geom_ext)))
    meta['LENGTH'] = atr['LENGTH']
    meta['WIDTH'] = atr['WIDTH']

    ## update metadata due to subset
    print('update metadata due to subset with bounding box')
    meta = attr.update_attribute4subset(meta, box)

    # apply optional user multilooking
    if nlks_x > 1:
        meta['RANGE_PIXEL_SIZE'] = str(
            float(meta['RANGE_PIXEL_SIZE']) * nlks_x)
        meta['RLOOKS'] = str(float(meta['RLOOKS']) * nlks_x)

    if nlks_y > 1:
        meta['AZIMUTH_PIXEL_SIZE'] = str(
            float(meta['AZIMUTH_PIXEL_SIZE']) * nlks_y)
        meta['ALOOKS'] = str(float(meta['ALOOKS']) * nlks_y)

    return meta