Skip to content

How to add a new program to mintpy

Zhang Yunjun edited this page Jan 24, 2023 · 2 revisions

Notes on how to add a new program to mintpy, using dem_error.py as an example:

  1. In src/mintpy/cli directory, create a script dem_error.py for the command line interface (CLI), which usually includes the following functions:

    • create_parser() to create a CLI parser, with help message and example usage

    • [optional] read_template2inps() to read the template options into a Namespace object inps

    • cmd_line_parse() to call the above two functions to parse the command line inputs, and/or apply extra checkings and default values (if it's not supported natively via argparse yet), in the order of:

      • parse [--> import --> check --> default].
    • main() to call both the CLI (cmd_line_parse) and core functions (e.g., from mintpy.dem_error), in the order of:

      • parse --> import [--> run or skip] --> run

The idea is to import the basic (and fast) sub-module mintpy.utils.arg_utils at the top of the script, and only import other (heavy) sub-modules if needed after parsing. Check mintpy.cli.dem_error.py as an example.

  1. In src/mintpy directory, create a script dem_error.py for the core functionalities, with an overall function (e.g, correct_dem_error(inps)) to be called by the CLI main function (e.g., mintpy.cli.dem_error.main()), and/or a run_or_skip() function. Check mintpy.dem_error.py as an example.

  2. In src/mintpy/__main__.py file, add a sub-parser function for your script, and call it in the main parser function, so that it's available as mintpy dem_error in the command line.

  3. In setup.py file, add an entry-point for your script, so that it's available as dem_error.py in the command line.

Welcome

Software Design

Clone this wiki locally