Пример #1
0
def prepare_metadata(iDict):
    processor = iDict['processor']
    script_name = 'prep_{}.py'.format(processor)
    print('-'*50)
    print('prepare metadata files for {} products'.format(processor))

    if processor in ['gamma', 'hyp3', 'roipac', 'snap']:
        # import prep_module
        if processor == 'gamma':
            from mintpy import prep_gamma as prep_module
        elif processor == 'hyp3':
            from mintpy import prep_hyp3 as prep_module
        elif processor == 'roipac':
            from mintpy import prep_roipac as prep_module
        elif processor == 'snap':
            from mintpy import prep_snap as prep_module

        # run prep_{processor} module
        for key in [i for i in iDict.keys() if (i.startswith('mintpy.load.') and i.endswith('File'))]:
            if len(glob.glob(str(iDict[key]))) > 0:
                # print command line
                script_name = '{}.py'.format(os.path.basename(prep_module.__name__).split('.')[-1])
                iargs = [iDict[key]]
                if processor == 'gamma' and iDict['PLATFORM']:
                    iargs += ['--sensor', iDict['PLATFORM'].lower()]
                print(script_name, ' '.join(iargs))
                # run
                prep_module.main(iargs)

    elif processor == 'isce':
        from mintpy import prep_isce
        from mintpy.utils.isce_utils import get_processor

        # metadata
        meta_files = sorted(glob.glob(iDict['mintpy.load.metaFile']))
        if len(meta_files) > 0:
            meta_file = meta_files[0]
        else:
            warnings.warn('No input metadata file found: {}'.format(iDict['mintpy.load.metaFile']))
            meta_file = 'auto'

        # auxliary data
        baseline_dir = iDict['mintpy.load.baselineDir']
        geom_dir = os.path.dirname(iDict['mintpy.load.demFile'])

        # observation
        obs_keys = ['mintpy.load.unwFile', 'mintpy.load.azOffFile']
        obs_keys = [i for i in obs_keys if i in iDict.keys()]
        obs_paths = [iDict[key] for key in obs_keys if iDict[key].lower() != 'auto']
        if len(obs_paths) > 0:
            processor = get_processor(meta_file)
            if processor == 'alosStack':
                obs_dir = os.path.dirname(obs_paths[0])
            else:
                obs_dir = os.path.dirname(os.path.dirname(obs_paths[0]))
            obs_file = os.path.basename(obs_paths[0])
        else:
            obs_dir = None
            obs_file = None

        # compose list of input arguments
        iargs = ['-m', meta_file, '-g', geom_dir]
        if baseline_dir:
            iargs += ['-b', baseline_dir]
        if obs_dir is not None:
            iargs += ['-d', obs_dir, '-f', obs_file]

        # run module
        print('prep_isce.py', ' '.join(iargs))
        try:
            prep_isce.main(iargs)
        except:
            warnings.warn('prep_isce.py failed. Assuming its result exists and continue...')

    elif processor == 'aria':
        from mintpy import prep_aria

        ## compose input arguments
        # use the default template file if exists & input
        default_temp_files = [fname for fname in iDict['template_file'] if fname.endswith('smallbaselineApp.cfg')]
        if len(default_temp_files) > 0:
            temp_file = default_temp_files[0]
        else:
            temp_file = iDict['template_file'][0]
        iargs = ['--template', temp_file]

        # file name/dir/path
        ARG2OPT_DICT = {
            '--stack-dir'           : 'mintpy.load.unwFile',
            '--unwrap-stack-name'   : 'mintpy.load.unwFile',
            '--coherence-stack-name': 'mintpy.load.corFile',
            '--conn-comp-stack-name': 'mintpy.load.connCompFile',
            '--dem'                 : 'mintpy.load.demFile',
            '--incidence-angle'     : 'mintpy.load.incAngleFile',
            '--azimuth-angle'       : 'mintpy.load.azAngleFile',
            '--water-mask'          : 'mintpy.load.waterMaskFile',
        }

        for arg_name, opt_name in ARG2OPT_DICT.items():
            arg_value = iDict.get(opt_name, 'auto')
            if arg_value.lower() not in ['auto', 'no', 'none']:
                if arg_name.endswith('dir'):
                    iargs += [arg_name, os.path.dirname(arg_value)]
                elif arg_name.endswith('name'):
                    iargs += [arg_name, os.path.basename(arg_value)]
                else:
                    iargs += [arg_name, arg_value]

        # configurations
        if iDict['compression']:
            iargs += ['--compression', iDict['compression']]
        if iDict['updateMode']:
            iargs += ['--update']

        ## run
        print('prep_aria.py', ' '.join(iargs))
        try:
            prep_aria.main(iargs)
        except:
            warnings.warn('prep_aria.py failed. Assuming its result exists and continue...')

    elif processor == 'gmtsar':
        from mintpy import prep_gmtsar

        # use the custom template file if exists & input
        custom_temp_files = [fname for fname in iDict['template_file'] if not fname.endswith('smallbaselineApp.cfg')]
        if len(custom_temp_files) == 0:
            raise FileExistsError('Custom template file NOT found and is required for GMTSAR!')

        # run prep_*.py
        iargs = [custom_temp_files[0], '--mintpy-dir', os.path.dirname(iDict['outdir'])]
        print('prep_gmtsar.py', ' '.join(iargs))
        try:
            prep_gmtsar.main(iargs)
        except:
            warnings.warn('prep_gmtsar.py failed. Assuming its result exists and continue...')

    else:
        msg = 'un-recognized InSAR processor: {}'.format(processor)
        msg += '\nsupported processors: {}'.format(PROCESSOR_LIST)
        raise ValueError(msg)

    return
Пример #2
0
def prepare_metadata(inpsDict):
    processor = inpsDict['processor']
    script_name = 'prep_{}.py'.format(processor)
    print('-' * 50)
    print('prepare metadata files for {} products'.format(processor))

    if processor in ['gamma', 'roipac', 'snap']:
        # import prep_module
        if processor == 'gamma':
            from mintpy import prep_gamma as prep_module
        elif processor == 'roipac':
            from mintpy import prep_roipac as prep_module
        elif processor == 'snap':
            from mintpy import prep_snap as prep_module

        # run prep_{processor} module
        for key in [
                i for i in inpsDict.keys()
                if (i.startswith('mintpy.load.') and i.endswith('File'))
        ]:
            if len(glob.glob(str(inpsDict[key]))) > 0:
                # print command line
                script_name = '{}.py'.format(
                    os.path.basename(prep_module.__name__).split('.')[-1])
                iargs = [inpsDict[key]]
                if processor == 'gamma' and inpsDict['PLATFORM']:
                    iargs += ['--sensor', inpsDict['PLATFORM'].lower()]
                print(script_name, ' '.join(iargs))
                # run
                prep_module.main(iargs)

    elif processor == 'isce':
        from mintpy import prep_isce
        from mintpy.utils.isce_utils import get_processor

        meta_files = sorted(glob.glob(inpsDict['mintpy.load.metaFile']))
        if len(meta_files) < 1:
            warnings.warn('No input metadata file found: {}'.format(
                inpsDict['mintpy.load.metaFile']))

        try:
            # metadata and auxliary data
            meta_file = meta_files[0]
            baseline_dir = inpsDict['mintpy.load.baselineDir']
            geom_dir = os.path.dirname(inpsDict['mintpy.load.demFile'])

            # observation
            obs_keys = ['mintpy.load.unwFile', 'mintpy.load.azOffFile']
            obs_keys = [i for i in obs_keys if i in inpsDict.keys()]
            obs_paths = [
                inpsDict[key] for key in obs_keys
                if inpsDict[key].lower() != 'auto'
            ]
            if len(obs_paths) > 0:
                processor = get_processor(meta_file)
                if processor == 'alosStack':
                    obs_dir = os.path.dirname(obs_paths[0])
                else:
                    obs_dir = os.path.dirname(os.path.dirname(obs_paths[0]))
                obs_file = os.path.basename(obs_paths[0])
            else:
                obs_dir = None
                obs_file = None

            # compose list of input arguments
            iargs = ['-m', meta_file, '-g', geom_dir]
            if baseline_dir:
                iargs += ['-b', baseline_dir]
            if obs_dir is not None:
                iargs += ['-d', obs_dir, '-f', obs_file]
            print('prep_isce.py', ' '.join(iargs))

            # run module
            prep_isce.main(iargs)

        except:
            pass
    return