API Reference#
Core Package#
tollan Package#
Top-level package for tollan.
tollan.cli Package#
Console script for tollan.
Configuration System#
tollan.config Package#
Configuration system using ConfigSourceList and RuntimeContext.
This module provides a modern configuration system with two main components.
Architecture:
RuntimeContext (entry point) - Manages config lifecycle and context
↓ owns
ConfigSourceList (config loader) - Loads and merges config from multiple sources
↓ consumed by
ConfigHandler (domain adapter) - Validates and caches domain-specific config
Sources Supported#
YAML files (including conditional loading with enable_if)
Dictionary sources
Environment files (.env)
Nested config source lists
- Basic Example:
>>> from pathlib import Path >>> from tollan.config import RuntimeContext >>> rc = RuntimeContext( ... config_sources=[ ... {"format": "dict", "source": {"app": "test"}, "order": 0}, ... { ... "format": "dict", ... "source": {"debug": True}, ... "order": 1, ... "enable_if": "env == 'production'", ... } ... ] ... ) >>> config_dict = rc.config_dict # Merged config dict (cached property) >>> config = rc.config # Validated RuntimeConfig model (cached property) >>> runtime_info = rc.runtime_info # Auto-detected runtime info
- CLI Example (with factory method):
>>> from pathlib import Path >>> from tollan.config import RuntimeContext >>> # CLI parsing example (doesn't require files) >>> rc = RuntimeContext.from_cli(cli_args=["--debug", "true", "--port", "8080"]) >>> rc.config_dict['debug'] True
- Context Override Example:
>>> with rc.set_context({"env": "production"}): ... prod_config = rc.config_dict
- Domain-Specific Example (with ConfigHandler):
>>> # See ConfigHandler documentation for complete example ...
Classes#
|
Base class for domain-specific configuration handlers. |
Base model class with immutability and YAML support. |
|
Base configuration model with runtime info. |
|
|
Entry point for runtime-aware configuration management. |
Runtime environment information. |
|
Mixin for handlers that extract a subkey from runtime config. |
Class Inheritance Diagram#
tollan.config.sources Package#
Configuration sources for loading config from various formats.
Functions#
|
Create a ConfigSourceList from various input formats. |
Classes#
A list of configuration sources with conditional loading. |
|
Configuration source from dictionary. |
|
Configuration source from .env file. |
|
Configuration source from nested list of sources. |
|
Configuration source from YAML file. |
Class Inheritance Diagram#
tollan.config.types Package#
Custom pydantic types for astronomy data validation.
This module provides custom Pydantic types for validating astronomy-specific data structures using astropy, including:
Time fields with format constraints
Quantity fields with physical type constraints
SkyCoord fields for celestial coordinates
Enhanced Path types with resolution and existence validation
Functions#
|
Create a pydantic field type for validating astropy Quantity. |
|
Create a pydantic field type for validating astropy Time. |
Classes#
Descriptor for accessing model field defaults. |
|
|
Custom JSON schema generator with type-specific serializers. |
|
Validator for Path types with rootpath context support. |
Class Inheritance Diagram#
Pipeline#
tollan.pipeline Package#
Pipeline utils.
Classes#
Base class for managing context objects in data containers. |
|
A helper class to access context stored in dict. |
|
A helper class to access context stored in metadata dict. |
Class Inheritance Diagram#
Plotting#
tollan.plot.mpl Module#
Matplotlib utility functions.
Functions#
|
Move an Axes object from a figure to a new one. |
tollan.plot.plotly Module#
Plotly utilities for multi-panel figures and Dash applications.
Key features: - SubplotGrid: Stateful builder for complex multi-panel layouts with rowspan/colspan - adjust_subplot_colorbars: Fix colorbar positioning in subplots - ColorPalette: Color scaling and cycling for consistent plot styling - show_in_dash: Quick interactive data visualization in Dash with tabs
Functions#
|
Adjust colorbar positions to align with subplot axes. |
|
Create an empty figure with optional placeholder text. |
|
Calculate data range with padding. |
|
Create layout dict with correct axis references for a specific subplot. |
|
Create a multi-panel figure with sensible defaults. |
|
Display data items in an interactive Dash application. |
|
Update layout for all subplots or specific subplot. |
Classes#
|
A class to manage colors from a named palette. |
|
Dash layout component for displaying data items in tabs. |
|
A helper class to build multi panel figure. |
Class Inheritance Diagram#
Utilities#
tollan.utils.cli Module#
A subpackage that provides CLI utilities.
Functions#
|
Return a nested dict from CLI arguments. |
|
Split the args based on regex match of the arg name. |
tollan.utils.dict Module#
Dictionary and nested container utilities.
This module provides utilities for working with dictionaries and nested container structures (dicts and lists), including recursive updates, flattening/unflattening, and container manipulation.
Functions#
|
Return a decorator to add decorated item to dict. |
|
Convert flat dict with dotted keys to nested dict structure. |
|
Return a dict from matching |
|
Return the Cartesian product of dicts. |
|
Return dict from dict with nested dicts. |
|
Update dict recursively. |
tollan.utils.file Module#
Utility functions for file operations.
Functions#
Return the full expanded absolute path. |
|
Ensure parent path of |
|
|
Return a readable object. |
|
Ensure |
|
Resolve symlink chain to target path. |
|
Touch file, the same as the shell command |
tollan.utils.fileloc Module#
File location handling utilities.
Functions#
Classes#
A model to hold file location info. |
|
|
A helper model for storing file loc data. |
Class Inheritance Diagram#
tollan.utils.fmt Module#
Formatting utilities for YAML, masks, and bitmasks.
Includes pretty-printing for YAML, numpy masks, and Flag-based bitmasks.
Functions#
|
Compute statistics for each flag in a bitmask. |
|
Pretty-format bitmask statistics as a summary table. |
|
Pretty-format a numpy fancy index, slice, or mask. |
|
Pretty-format a boolean mask as 'selected/total (percentage)'. |
|
Pretty-format an object as a YAML string. |
Classes#
|
Compute and format statistics for bitmask flags. |
Class Inheritance Diagram#
tollan.utils.log Module#
General logging utilities.
Features:
- Global loguru logger instance (logger)
- Decorators/context managers for logging entry/exit (logit) and timing (timeit)
- Logger reset utility (reset_logger)
Examples
>>> from tollan.utils.log import logger, logit, timeit
>>> @logit(logger.info, "Running task")
... def task():
... pass
>>> @timeit
... def timed_task():
... pass
Functions#
|
Reset the global logger to default configuration. |
Classes#
Class Inheritance Diagram#
tollan.utils.np Module#
NumPy and astropy.units utility functions.
Unified helpers for NumPy arrays and astropy quantities. Includes unit handling, reshaping, and complex array creation.
Functions#
|
Attach a unit to an array if unit is not None. |
|
Ensure data has the given unit (returns None if arr is None). |
|
Reshape an array, trimming elements if needed. |
|
Create a complex array from real and imaginary parts. |
Strip unit from first argument, reattach to result. |
|
|
Like numpy.arange, but for astropy quantities (unit-aware). |
Remove unit from array, returning (data, unit). |
tollan.utils.py Module#
Python utility classes and functions.
Functions#
|
Return the specifier name of a Python object (opposite of getobj). |
|
Return a Python object by dotted path (e.g. 'module:attr.subattr'). |
|
Load a Python module from a file path. |
|
Recursively get a nested attribute (e.g. 'a.b.c'). |
|
Recursively reload a module and all its submodules. |
Classes#
|
Proxy object for deferred initialization. |
Class Inheritance Diagram#
tollan.utils.sys Module#
System-related utility functions.
Functions#
Return the system hostname. |
|
Return the current user's username. |
|
|
Run a command in a pseudo-terminal (pty). |
tollan.utils.table Module#
Table validation utilities for astropy and pandas tables.
Provides unified helpers for working with both astropy Table/QTable and pandas DataFrame objects.
Examples
>>> from astropy.table import Table
>>> from tollan.utils.table import TableValidator
>>> tbl = Table([[1, 2, 3], [4, 5, 6]], names=['a', 'b'])
>>> TableValidator().has_all_cols(tbl, ['a', 'b'])
True
Classes#
Validator for astropy and pandas tables. |
Class Inheritance Diagram#
tollan.utils.typer Module#
Typer CLI utility functions.
This module extends Typer’s CLI functionality with custom options and utilities. The main feature is MultiOption, which enables variable-length option arguments in Typer commands, with automatic type conversion via Typer’s built-in system.
Functions#
|
Create a multi-argument option for Typer commands. |
|
Return a new CLI app with reasonable defaults. |
Classes#
|
Extended OptionInfo for multi-argument options. |
Class Inheritance Diagram#
tollan.utils.typing Module#
Type introspection utilities for working with generic types.
Functions#
|
Ensure a class attribute is set from typing arguments. |
|
Extract typing arguments from a class's generic base classes. |
tollan.utils.yaml Module#
YAML utilities for tollan.
This module provides custom YAML dumpers and loaders with support for astronomy-specific types (Time, Quantity, SkyCoord).
Examples
>>> from tollan.utils.yaml import yaml_dump
>>> from astropy.time import Time
>>> from astropy import units as u
>>> data = {'time': Time('2020-01-01'), 'length': 5.0 * u.m}
>>> yaml_str = yaml_dump(data)
>>> print(yaml_str)
length: 5.0 m
time: '2020-01-01T00:00:00.000'
Functions#
|
Add representers for numpy types to the given dumper class. |
Serialize data as YAML and write to a file, stream, or return as string. |
|
|
Load YAML data from a file, stream, or string. |
|
Load YAML data from a string or stream. |
Classes#
|
YAML dumper with support for astronomy types and common scientific objects. |