astra.config#
Configuration management for Astra observatory automation system.
This module provides configuration classes for managing Astra’s settings, observatory configurations, and asset paths. It handles YAML configuration files, directory initialization, and provides a singleton pattern for global configuration access.
- Classes:
Config: Main configuration singleton for Astra settings AssetPaths: Container for asset directory paths ObservatoryConfig: Observatory-specific configuration management _ConfigInitialiser: Helper class for initial configuration setup
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.
- CONFIG_PATH#
The path to the configuration YAML file.
- Type:
Path
- TEMPLATE_DIR#
The path to the directory containing template files.
- Type:
Path
- 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.
- CONFIG_PATH = PosixPath('/opt/build/repo/src/astra/config/astra_config.yml')#
- TEMPLATE_DIR = PosixPath('/opt/build/repo/src/astra/config/templates')#
- 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.
- reset(remove_assets: bool = False) None[source]#
Reset configuration by removing config file and optionally assets.
- Parameters:
remove_assets – If True, also removes the assets folder after confirmation.
- as_datetime(date_string: str) datetime[source]#
Convert string to datetime using configured format.
- Parameters:
date_string – Date string to convert.
- Returns:
datetime – Parsed datetime object.
- _load_from_file() Dict[str, str][source]#
Load configuration from YAML file.
- Returns:
dict – Configuration data from file.
- 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.
- class astra.config._ConfigInitialiser[source]#
Bases:
objectHelper class for initial configuration setup through user prompts.
Handles the first-time setup process including directory creation, user input validation, and initial configuration file generation.
- DEFAULT_ASSETS_PATH = PosixPath('/opt/buildhome/Documents/Astra')#
- static run(observatory_name: str | None, folder_assets: Path | str | None, gaia_db: Path | str | None) None[source]#
Create initial configuration through user prompts.
- Parameters:
observatory_name – Name of the observatory.
folder_assets – Path to assets folder.
gaia_db – Path to Gaia database file.
- static _prompt_assets_path() Path[source]#
Prompt user for assets folder location.
- Returns:
Path – Validated path to assets folder.
- static _prompt_gaia_db_path() str | None[source]#
Prompt user for Gaia database location.
- Returns:
str or None – Path to Gaia database file or None if not using local DB.
- static _validate_paths(folder_assets: Path | str | None, gaia_db: Path | str | None) None[source]#
Validate user-provided path arguments.
- Parameters:
folder_assets – Path to assets folder.
gaia_db – Path to Gaia database file.
- Raises:
TypeError – If paths are not str or Path types.
FileNotFoundError – If gaia_db path doesn’t exist.
- 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.
- static _deep_update(target: dict, source: dict) None[source]#
Deep update target dict with source dict values.
Preserves ruamel.yaml CommentedMap structure and comments while updating values. Only updates existing keys or adds new ones; doesn’t remove keys from target.
- Parameters:
target – Dictionary to update (modified in place, preserves CommentedMap).
source – Dictionary with new values to merge in.
- 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 as a pandas DataFrame.
- Parameters:
observatory_name (str) – Name of the observatory.
- Returns:
pd.DataFrame – DataFrame containing FITS header configuration.
- 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.