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

AssetPaths(folder_assets)

Container for asset directory paths and log file used by Astra.

Config(*args, **kwargs)

Singleton class for managing Astra's configuration settings.

ObservatoryConfig(config_path, observatory_name)

Observatory-specific configuration management with YAML persistence.

class astra.config.Config(*args: Any, **kwargs: Any)[source]#

Bases: object

Singleton 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.

observatory_name#

The name of the observatory.

Type:

str

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:

AssetPaths

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.

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.

save() None[source]#

Save current configuration settings to YAML file.

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.

class astra.config.AssetPaths(folder_assets: Path | str)[source]#

Bases: object

Container 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.

archive_log_file() None[source]#

Archive the current log file with a timestamp.

class astra.config.ObservatoryConfig(config_path: str | Path, observatory_name: str)[source]#

Bases: dict

Observatory-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()
config_path: Path#
observatory_name: str#
property file_path: Path#

Get path to the observatory configuration YAML file.

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.

save_backup() None[source]#

Create timestamped backup of current configuration file.

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 header column.

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.