Skip to content

cli

Command Line Interface

Command line interface tool for SCT.

Design choices

The root command group is a LazyGroup (a RichGroup subclass) that defers subcommand loading until invocation. This keeps import sct, sct --version, sct --help and sct info fast, without importing the scientific stack (perseo, numpy, …) or any analysis implementation.

Subcommands are still written as typer.Typer apps. The bridge function _typer_to_click converts them to click.Command objects at load time so they plug into the lazy group. This avoids a rewrite of every subcommand while enabling deferred imports.

Note

typer.Typer does not expose a hook to intercept subcommand resolution: commands are registered eagerly via add_typer(). Subclassing RichGroup (which inherits from click.Group) gives get_command() / list_commands() override points, which is what makes true lazy loading possible.

Attributes

ANALYSIS_ENTRY_POINT_GROUP module-attribute

Python
ANALYSIS_ENTRY_POINT_GROUP = 'sct.analyses'

Classes

LazyGroup

Bases: RichGroup

A RichGroup whose subcommands are resolved (and imported) on demand.

typer.Typer registers subcommands eagerly via add_typer(), which defeats lazy loading. By subclassing RichGroup (which provides the rich-click help formatting) we override get_command() and list_commands() to resolve subcommands only when they are actually invoked or listed in help output.

get_command() returns a _DeferredCommand stub that holds only the subcommand's name and short_help; the actual typer.Typer-based command object (and all its imports) is materialized on first invocation.

invoke() also bridges Typer-forked exception types (Exit, ClickException) back to click's own exceptions so that Command.main() handles them correctly.

Attributes

lazy_subcommands instance-attribute
Python
lazy_subcommands = lazy_subcommands or {}

Methods:

__init__
Python
__init__(*args, lazy_subcommands: dict[str, _LazySubcommand] | None = None, **kwargs)
invoke
Python
invoke(ctx: Context) -> Any

typer vendors its own copy of click internals (typer._click), so its Exit and ClickException classes are distinct from click.exceptions.Exit / click.exceptions.ClickException. LazyGroup.invoke catches the Typer variants and re-raises them as the corresponding click types so that Command.main() handles them correctly in both CLI and test usage.

list_commands
Python
list_commands(ctx: Context) -> list[str]
get_command
Python
get_command(ctx: Context, cmd_name: str) -> click.Command | None

Functions:

app

Python
app(ctx: Context, config: Path | None) -> None

Common utilities for command line implementations.

Attributes

console module-attribute

Python
console = Console()

InputProductOption module-attribute

Python
InputProductOption = Path

InputPointTargetSource module-attribute

Python
InputPointTargetSource = Path | None

OutputDirectoryOption module-attribute

Python
OutputDirectoryOption = Path | None

GraphsOption module-attribute

Python
GraphsOption = bool

RadiometricQuantityOption module-attribute

Python
RadiometricQuantityOption = Literal['beta', 'gamma', 'sigma']

AntennaPatternInputOption module-attribute

Python
AntennaPatternInputOption = Path | None

ExternalOrbitInputOption module-attribute

Python
ExternalOrbitInputOption = Path | None

ExternalCorrectionInputProductOption module-attribute

Python
ExternalCorrectionInputProductOption = Path | None

Functions:

logging_to_file

Python
logging_to_file(path: Path | None)

Context manager to safely add a file handler to sct logger.

Parameters:

Name Type Description Default
path Path | None

path to log file to be used, if None, no file handler is added

required

display_title

Python
display_title(title: str) -> None

Display a title in the CLI.

log_elapsed_time

Python
log_elapsed_time(logged_name: str)

Decorate function to log elapsed time with the given name.

graceful_exit

Python
graceful_exit(name: str)

Decorate function to gracefully log and exit in case of errors.

supports_unicode

Python
supports_unicode() -> bool

Return whether the console encoding supports our CLI symbols.

CLI Utilities

Command Line Interface auxiliary utilities.

Attributes

utilities_app module-attribute

Python
utilities_app = typer.Typer(help='SCT Auxiliary CLI tools.')

DateOption module-attribute

Python
DateOption = datetime

ProductDateOption module-attribute

Python
ProductDateOption = datetime | None

RosamondSourceOption module-attribute

Python
RosamondSourceOption = Path

SARCalNetSourceOption module-attribute

Python
SARCalNetSourceOption = Path

AnalysisCenterOption module-attribute

Python
AnalysisCenterOption = str

EmailOption module-attribute

Python
EmailOption = str

ResolutionOption module-attribute

Python
ResolutionOption = str

Classes

Functions:

convert_rosamond_csv

Python
convert_rosamond_csv(source: RosamondSourceOption, date: DateOption, output_directory: OutputDirectoryOption = None) -> None

Convert downloaded Rosamond Point Targets dataset .csv file to SCT compliant .csv file.

download_ionex_tec_maps

Python
download_ionex_tec_maps(date: DateOption, analysis_center: AnalysisCenterOption, email: EmailOption, output_directory: OutputDirectoryOption) -> None

Download IONEX TEC maps from NASA/CDDIS archive.

download_tropospheric_vmf3_maps

Python
download_tropospheric_vmf3_maps(date: DateOption, resolution: ResolutionOption, output_directory: OutputDirectoryOption) -> None

Download VMF3 Tropospheric Products.

convert_sarcalnet_json_to_csv

Python
convert_sarcalnet_json_to_csv(source: SARCalNetSourceOption, product_date: ProductDateOption = None, output_directory: OutputDirectoryOption = None) -> None

Convert downloaded SARCalNet survey .json file to SCT compliant .csv file. Product date can be provided to select the closest survey available, otherwise the latest survey is selected.