Script Reference
This page contains the documentation of modules needed to run as a script.
Main entrypoint
Main entrypoint for LABNIRS to SNIRF conversion when run as a script.
- labnirs2snirf.labnirs2snirf.main() int[source]
LABNIRS to SNIRF conversion script.
This function coordinates the full conversion workflow when run as python -m labnirs2snirf on the command line:
Parse command-line arguments
Configure logging based on user preferences
Read and parse LABNIRS data file
Optionally add probe position information
Write output in SNIRF format
- Returns:
Exit code: 0 for success, 1 for failure.
- Return type:
int
Notes
Exception handling is designed with the intention to reduce end-user exposure to stack traces and technical details. Most exceptions are hidden from end users, providing only a concise error message. Detailed error information can be obtained by increasing verbosity with -v flags and/or using –log to write to a log file.
Parsing command-line arguments
Module for handling command-line arguments.
- exception labnirs2snirf.args.ArgumentError[source]
Bases:
Labnirs2SnirfErrorError indicating invalid command-line arguments.
- class labnirs2snirf.args.Arguments(progname: str | None = 'labnirs2snirf')[source]
Bases:
objectClass to handle configuration and parsing of command-line arguments.
- Parameters:
progname (str or None, default=__package__) – Program name to display in help message. If None, defaults to package name.
- __init__(progname: str | None = 'labnirs2snirf')[source]
Initialize the Arguments parser.
- Parameters:
progname (str or None, default=__package__) – Program name to display in help message. If None, defaults to package name.
- __repr__() str[source]
Return a detailed string representation of the Arguments object.
- Returns:
String showing arguments stored.
- Return type:
str
- __str__() str[source]
Return a string representation of the Arguments object.
- Returns:
String showing arguments stored.
- Return type:
str
- drop: set[str] | None
- locations: Path | None
- log: bool
- parse(args: list[str]) Self[source]
Parse command-line arguments and populate the Arguments object.
- Parameters:
args (list[str]) – List of command-line arguments to parse. If empty, shows help.
- Returns:
Self with parsed argument values set as attributes.
- Return type:
Self
Notes
If –log is specified, verbosity is automatically set to at least 1. Drop values are converted to a set to avoid duplicates.
- parser: ArgumentParser
- source_file: Path
- target_file: Path
- type: str
- verbosity: int
Logging
Logging configuration utilities for the labnirs2snirf package.
- labnirs2snirf.log.config_logger(file_logging: bool = False, verbosity_level: int = 0) None[source]
Configure the root logger for the application.
- Parameters:
file_logging (bool, default = False) – If True, log messages will be written to a file. If False, log messages will be printed to the console.
verbosity_level (int, default = 0) – The verbosity level of the log messages. Must be between 0 and 3. Possible values: - 0: disabled (no logging) - 1: WARNING (warnings and above) - 2: INFO (informational messages and above) - 3: DEBUG (debugging messages and above)
Notes
This function should be called only once, at the start of the application, and only if it’s run as a script, not as a library. Most modules should invoke getLogger(__name__) to get a module-specific logger, which will inherit the configuration set here.