Reference on kuibit.argparse_helper

The argparse_helper module provides helper functions to write scripts that are controlled by command-line arguments or configuration files.

The intended way to use this module is, schematically

from kuibit import argparse_helper as kah

parser = kah.init_argparse(desc="Description")
# Next we add everything we need
kah.add_figure_to_parser(parser)

# Specific arguments
parser.add_argument("--arg1", help="Specific argument")

# Finally
args = kah.get_args(parser)

# args is Namespace that contains all the arguments provided via
# command-line, configuration file, or environment variable
kuibit.argparse_helper.add_figure_to_parser(parser, default_figname=None, add_limits=False)[source]

Add parameters that have to do with a figure as output to a given parser.

This function edits ‘’parser’’ in place.

The options added are:

  • figname

  • fig-extension

  • tikz-clean-figure

If add_limits is True, then also add:

  • xmin

  • xmax

  • ymin

  • ymax

Parameters
  • default_figname (str) – Default name of the output figure.

  • add_limits (bool) – Add xmin, xmax, ymin, ymax.

  • parser (configargparse.ArgumentParser) – Argparse parser (generated with init_argparse()).

kuibit.argparse_helper.add_grid_structure_to_parser(parser, edge_color='black', alpha=0.5)[source]

Add parameters that have to do with drawing the grid structure.

This function edits parser in place.

The options added are:

  • rl-show

  • rl-edge-color

  • rl-alpha

Parameters
  • edge_color (anything accepted by the drawing package) – Color of the edge of the components.

  • alpha (float) – Number between 0 and 1 that identifies the opacity of the horizon.

  • parser (configargparse.ArgumentParser) – Argparse parser (generated with init_argparse())

kuibit.argparse_helper.add_grid_to_parser(parser, dimensions=2)[source]

Add parameters that have to do with grid configurations to the given parser.

This function edits parser in place.

The options added are:

  • resolution

  • x0 (origin)

  • ``x1 (corner)

  • axis (for dimension = 1)

  • plane (for dimension = 2)

Parameters
  • parser (configargparse.ArgumentParser) – Argparse parser to which the grid options have to be added.

  • dimensions (int) – Number of grid dimensions to consider (1, 2, or 3).

kuibit.argparse_helper.add_horizon_to_parser(parser, color='k', edge_color='w', alpha=1, time_tolerance=0.1)[source]

Add parameters that have to do with a apparent horizons to a given parser.

This function edits parser in place.

The options added are:

  • ah-show

  • ah-color

  • ah-edge-color

  • ah-alpha

  • ah-time-tolerance

Parameters
  • color (anything accepted by the drawing package) – Color of the horizons.

  • edge_color (anything accepted by the drawing package) – Color of the edge of the horizons.

  • alpha (float) – Number between 0 and 1 that identifies the opacity of the horizon.

  • time_tolerance (float) – Time tolerance allowed for finding an horizon.

  • parser (configargparse.ArgumentParser) – Argparse parser (generated with init_argparse())

kuibit.argparse_helper.get_args(parser, args=None)[source]

Process argparse arguments.

If args is None, the command line arguments are used. Otherwise, args is used (useful for testing and debugging).

Parameters

args (list) – List of command-line options.

Returns

Arguments as read from command line or from args.

Return type

argparse Namespace

kuibit.argparse_helper.get_program_name()[source]

Return the name of the current script.

Returns

Name of file executing the code.

Return type

str

kuibit.argparse_helper.init_argparse(*args, **kwargs)[source]

Initialize a new argparse with given arguments.

Unknown arguments are passed to configargparse.ArgParser.

Returns

Argparse parser.

Return type

configargparse.ArgumentParser