Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 791d01c4e7168788973afcf74a8e3eccd0627d3d authored by S M T Chua on 24 February 2022, 04:26:55 UTC, committed by GitHub on 24 February 2022, 04:26:55 UTC
Merge pull request #378 from GeoscienceAustralia/develop
Release 0.6.1
2 parent s 8203989 + 1033836
  • Files
  • Changes
  • fac27fa
  • /
  • pyrate
  • /
  • main.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:791d01c4e7168788973afcf74a8e3eccd0627d3d
directory badge
swh:1:dir:587fbd88cb8dd57fe3334b42a7b43532c0033694
content badge
swh:1:cnt:e19bf0970fe5015639f52d40d4764c7ef972bfc3

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
main.py
#   This Python module is part of the PyRate software package.
#
#   Copyright 2022 Geoscience Australia
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
"""
This Python module defines executable run configuration for the PyRate software
"""

import os
import argparse
from argparse import RawTextHelpFormatter
import time
from pathlib import Path

import pyrate.constants as C
from pyrate.constants import CLI_DESCRIPTION
from pyrate import conv2tif, prepifg, correct, merge
from pyrate.core.logger import pyratelogger as log, configure_stage_log
from pyrate.core import mpiops
from pyrate.configuration import Configuration
from pyrate.core.shared import mpi_vs_multiprocess_logging
from pyrate.core.stack import stack_calc_wrapper
from pyrate.core.timeseries import timeseries_calc_wrapper


def _params_from_conf(config_file):
    config_file = os.path.abspath(config_file)
    config = Configuration(config_file)
    params = config.__dict__
    return params


def update_params_due_to_ifg_selection(config):
    params = config.__dict__
    if config.phase_closure_filtered_ifgs_list(params).exists():
        params = config.refresh_ifg_list(params)
        correct._create_ifg_dict(params)
        correct._update_params_with_tiles(params)
    return params


def main():
    start_time = time.time()

    parser = argparse.ArgumentParser(prog='pyrate', description=CLI_DESCRIPTION, add_help=True,
                                     formatter_class=RawTextHelpFormatter)
    parser.add_argument('-v', '--verbosity', type=str, default='INFO', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR'],
                        help="Increase output verbosity")

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    parser_conv2tif = subparsers.add_parser('conv2tif', help='<Optional> Convert interferograms to geotiff.',
                                            add_help=True)

    parser_prepifg = subparsers.add_parser(
        'prepifg', help='Perform multilooking, cropping and coherence masking to interferogram geotiffs.',
        add_help=True)

    parser_correct = subparsers.add_parser(
        'correct', help='Calculate and apply corrections to interferogram phase data.',
        add_help=True)

    parser_ts = subparsers.add_parser(
        'timeseries', help='<Optional> Timeseries inversion of interferogram phase data.', add_help=True
    )

    parser_stack = subparsers.add_parser('stack', help='<Optional> Stacking of interferogram phase data.',
                                         add_help=True)

    parser_merge = subparsers.add_parser(
        'merge', help="Reassemble computed tiles and save as geotiffs.",
        add_help=True)

    parser_workflow = subparsers.add_parser(
        'workflow', help="<Optional> Sequentially run all the PyRate processing steps.",
        add_help=True)
    for p in [parser_conv2tif, parser_prepifg, parser_correct, parser_merge, parser_ts, parser_stack, parser_workflow]:
        p.add_argument('-f', '--config_file', action="store", type=str, default=None,
                       help="Pass configuration file", required=False)

    args = parser.parse_args()

    params = mpiops.run_once(_params_from_conf, args.config_file)

    configure_stage_log(args.verbosity, args.command, Path(params[C.OUT_DIR]).joinpath('pyrate.log.').as_posix())

    log.debug("Starting PyRate")
    log.debug("Arguments supplied at command line: ")
    log.debug(args)

    if args.verbosity:
        log.setLevel(args.verbosity)
        log.info("Verbosity set to " + str(args.verbosity) + ".")

    if args.command == "conv2tif":
        conv2tif.main(params)

    if args.command == "prepifg":
        prepifg.main(params)

    if args.command == "correct":
        config_file = os.path.abspath(args.config_file)
        config = Configuration(config_file)
        correct.main(config)

    if args.command == "timeseries":
        config_file = os.path.abspath(args.config_file)
        config = Configuration(config_file)
        timeseries(config)

    if args.command == "stack":
        config_file = os.path.abspath(args.config_file)
        config = Configuration(config_file)
        stack(config)

    if args.command == "merge":
        merge.main(params)

    if args.command == "workflow":
        log.info("***********CONV2TIF**************")
        conv2tif.main(params)

        log.info("***********PREPIFG**************")
        params = mpiops.run_once(_params_from_conf, args.config_file)
        prepifg.main(params)

        log.info("***********CORRECT**************")
        # reset params as prepifg modifies params
        config_file = os.path.abspath(args.config_file)
        config = Configuration(config_file)
        correct.main(config)

        log.info("***********TIMESERIES**************")
        config = Configuration(config_file)
        timeseries(config)

        log.info("***********STACK**************")
        config = Configuration(config_file)
        stack(config)

        log.info("***********MERGE**************")
        params = mpiops.run_once(_params_from_conf, args.config_file)
        merge.main(params)

    log.info("--- Runtime = %s seconds ---" % (time.time() - start_time))


def timeseries(config: Configuration) -> None:
    params = config.__dict__
    mpi_vs_multiprocess_logging("timeseries", params)
    params = update_params_due_to_ifg_selection(config=config)
    timeseries_calc_wrapper(params)


def stack(config: Configuration) -> None:
    params = config.__dict__
    mpi_vs_multiprocess_logging("stack", params)
    params = update_params_due_to_ifg_selection(config=config)
    stack_calc_wrapper(params)


if __name__ == "__main__":
    main()
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API