astra.config#
Configuration management for the Astra observatory automation system.
This module provides configuration classes for managing Astra settings, observatory configurations, and asset paths. It handles YAML configuration files, directory initialization, and exposes a singleton Config for global configuration access.
Classes
|
Container for asset directory paths and log file used by Astra. |
|
Singleton class for managing Astra's configuration settings. |
|
Observatory-specific configuration management with YAML persistence. |
- class astra.config.Config(*args: Any, **kwargs: Any)[source]#
Bases:
objectSingleton class for managing Astra’s configuration settings.
This class loads configuration settings from a YAML file and provides methods to access and modify these settings. It ensures that only one instance of the configuration is created throughout the application.
- folder_assets#
The path to the folder containing assets.
- Type:
Path
- gaia_db#
The path to the Gaia database
- Type:
Path
- paths#
An instance of AssetPaths containing paths to asset folders and log file.
- Type:
Note
If no configuration file is found, the user is prompted to provide the necessary information during initialization of the Config object. The configuration file is saved and the necessary files and folders are created.
Initialise the configuration settings.
- Parameters:
observatory_name (str) – The name of the observatory.
folder_assets (Path | str) – The path to the folder containing assets.
gaia_db (Path | str) – The path to the Gaia database.
allow_default (bool) – Whether to raise a SystemExit if observatory configuration files were left unchanged.
propagate_observatory_name (bool) – Whether to automatically modify the observatory config files by substituting the observatory name. Mainly useful for testing.
reset (bool) – If True, resets the configuration by deleting the config file.
- CONFIG_PATH = PosixPath('/home/runner/.astra/astra_config.yml')#
The path to the directory containing template files.
- TEMPLATE_DIR = PosixPath('/home/runner/work/astra/astra/src/astra/config/templates')#
The format used for datetime strings.
- TIME_FORMAT = '%Y-%m-%d %H:%M:%S'#
- static __new__(cls, *args: Any, **kwargs: Any) Config[source]#
Ensure singleton pattern - only one Config instance exists.
- property observatory_config: ObservatoryConfig#
Load the observatory configuration.
- class astra.config.AssetPaths(folder_assets: Path | str)[source]#
Bases:
objectContainer for asset directory paths and log file used by Astra.
Manages the creation and organization of Astra’s asset directories including configuration, schedules, images, and logs.
Create AssetPaths and ensure on-disk folders and log file exist.
- Parameters:
folder_assets (Path | str) – Base path for Astra assets.
- class astra.config.ObservatoryConfig(config_path: str | Path, observatory_name: str)[source]#
Bases:
dictObservatory-specific configuration management with YAML persistence.
Extends dict to provide configuration loading, saving, backup creation, and automatic reload detection for observatory configuration files.
Examples
>>> from astra.config import ObservatoryConfig >>> observatory_config = ObservatoryConfig.from_config()
- load() None[source]#
Load observatory configuration from YAML file.
Uses ruamel.yaml to preserve comments and structure for later saving.
- reload() ObservatoryConfig[source]#
Reload configuration if file has been modified.
- Returns:
ObservatoryConfig – Self for method chaining.
- save(file_path: Path | str | None = None) None[source]#
Save configuration to YAML file with automatic backup.
Uses ruamel.yaml to preserve comments, structure, and formatting from the original file.
- Parameters:
file_path – Optional custom save path, defaults to original file path.
- backup_file_path(datetime_str: str = '') Path[source]#
Get backup file path with timestamp.
- Parameters:
datetime_str – Optional custom datetime string, defaults to current time.
- Returns:
Path – Full path to backup file.
- is_outdated() bool[source]#
Check if configuration file has been modified since last load.
- Returns:
bool – True if file has been modified externally.
- classmethod from_config(config: Config | None = None) ObservatoryConfig[source]#
Create ObservatoryConfig from main Config instance.
- Parameters:
config – Main Config instance, creates new one if None.
- Returns:
ObservatoryConfig – Configured instance for the observatory.
- Raises:
TypeError – If config is not a Config instance.
- load_fits_config() DataFrame[source]#
Load the FITS header configuration for this observatory.
- Returns:
pandas.DataFrame – DataFrame containing FITS header configuration indexed by the
headercolumn.
- get_device_config(device_type: str, device_name: str) Dict[str, Any][source]#
Return configuration dict for a specific device.
- Parameters:
device_type – Type of the device (e.g., ‘Telescope’, ‘Camera’).
device_name – Name of the specific device.
- Returns:
dict –
- Configuration dictionary for the specified device, or {}
if not found.