astrocook.core.structures module#
- class astrocook.core.structures.SessionMetadata(constraints_by_uuid: Dict[str, ~typing.Dict[str, ~typing.Any]]=<factory>, v1_reconstruction_data: Any = None, log_history_json: Any = <factory>, log_type: str = 'v1_legacy', component_uuids: List[str] = <factory>, astrocook_version: str | None = None)[source]#
Bases:
objectCore immutable structure for holding constraints, configuration, and history.
This structure is designed to be serialized to a JSON or YAML file within the .acs archive. It separates the lightweight metadata from the heavy spectral arrays.
- Parameters:
constraints_by_uuid (dict) – A mapping of Component UUIDs to constraint dictionaries.
v1_reconstruction_data (Any) – Legacy data structure preserved for technical debt logging or V1 reconstruction.
log_history_json (Any) – The serialized log object (either a V2 dict or V1 JSON format).
log_type (str) – Type of log stored:
'v2'(the only one read back), or'unknown'when the session had no log. Older archives may carry'v1_artifact'(a wrapper of V1 logs that was never created, removed in phase 6) or'v1_legacy': their log is not restored. Defaults to'v1_legacy'.component_uuids (list of str) – An ordered list of all component UUIDs in the session.
astrocook_version (str or None) – The version of Astrocook that saved the archive;
Nonefor archives saved by versions up to 2.0.3, which did not record it (findings register F45).
- constraints_by_uuid: Dict[str, Dict[str, Any]]#
- v1_reconstruction_data: Any = None#
- log_history_json: Any#
- log_type: str = 'v1_legacy'#
- component_uuids: List[str]#
- astrocook_version: str | None = None#
- __init__(constraints_by_uuid: Dict[str, ~typing.Dict[str, ~typing.Any]]=<factory>, v1_reconstruction_data: Any = None, log_history_json: Any = <factory>, log_type: str = 'v1_legacy', component_uuids: List[str] = <factory>, astrocook_version: str | None = None) None#
- class astrocook.core.structures.DataColumn(values: ndarray, unit: Unit, description: str = '')[source]#
Bases:
objectImmutable container for a single column of data with physical units.
- Parameters:
values (np.ndarray) – The numerical data array.
unit (astropy.units.Unit) – The physical unit associated with the values.
description (str, optional) – A short description of the column’s content.
- values: ndarray#
- unit: Unit#
- description: str = ''#
- property quantity: Quantity#
Return the column data as an Astropy Quantity.
Combines the numerical values and the physical unit.
- property value: ndarray#
Return the raw numerical array.
Alias for
.valuesto support legacy/Astropy-style access.
- __init__(values: ndarray, unit: Unit, description: str = '') None#
- class astrocook.core.structures.SpectrumData(x: DataColumn, xmin: DataColumn, xmax: DataColumn, y: DataColumn, dy: DataColumn, aux_cols: Dict[str, ~astrocook.core.structures.DataColumn]=<factory>, meta: Dict[str, ~typing.Any]=<factory>, z_em: float = 0.0, resol: float = 0.0)[source]#
Bases:
objectImmutable core container for all spectral data.
This class holds the “heavy” numerical arrays (flux, wavelength, error) and auxiliary columns. It is the data payload for
Spectrum.- Parameters:
x (DataColumn) – The independent variable (wavelength or velocity).
xmin (DataColumn) – Lower bound of the x-bins.
xmax (DataColumn) – Upper bound of the x-bins.
y (DataColumn) – The dependent variable (flux density).
dy (DataColumn) – The 1-sigma uncertainty on
y.aux_cols (dict of DataColumn) – Additional columns (e.g.
'cont','model','abs_mask').meta (dict) – Header keywords and other metadata.
z_em (float) – Emission redshift of the target object.
resol (float) – Median resolving power \(R = \lambda / \Delta\lambda\).
- x: DataColumn#
- xmin: DataColumn#
- xmax: DataColumn#
- y: DataColumn#
- dy: DataColumn#
- aux_cols: Dict[str, DataColumn]#
- meta: Dict[str, Any]#
- z_em: float = 0.0#
- resol: float = 0.0#
- classmethod from_flat_data(x_values: ndarray, x_unit: Unit, y_values: ndarray, y_unit: Unit, dy_values: ndarray, xmin_values: ndarray | None = None, xmax_values: ndarray | None = None, aux_data: Dict[str, tuple] | None = None, meta: Dict[str, Any] | None = None, z_em: float = 0.0, resol: float = 0.0) SpectrumData[source]#
Factory method to create a SpectrumData from raw NumPy arrays.
- Parameters:
x_values (np.ndarray) – Wavelength/Velocity data.
x_unit (astropy.units.Unit) – Unit for the x-axis.
y_values (np.ndarray) – Flux data.
y_unit (astropy.units.Unit) – Unit for the y-axis (and dy).
dy_values (np.ndarray) – Error data.
xmin_values (np.ndarray, optional) – Lower bin edges. Defaults to
x_valuesif None.xmax_values (np.ndarray, optional) – Upper bin edges. Defaults to
x_valuesif None.aux_data (dict, optional) – Dictionary of auxiliary columns:
{'name': (values, unit, description)}.meta (dict, optional) – Metadata dictionary.
z_em (float, optional) – Emission redshift. Defaults to
0.0.
- Returns:
The initialized data object.
- Return type:
- __init__(x: DataColumn, xmin: DataColumn, xmax: DataColumn, y: DataColumn, dy: DataColumn, aux_cols: Dict[str, ~astrocook.core.structures.DataColumn]=<factory>, meta: Dict[str, ~typing.Any]=<factory>, z_em: float = 0.0, resol: float = 0.0) None#
- class astrocook.core.structures.ComponentData(id: int, z: float, dz: float | None, logN: float, dlogN: float | None, b: float, db: float | None, btur: float = 0.0, dbtur: float | None = None, func: str = 'voigt', series: str = 'Ly_a', chi2: float | None = None, resol: float | None = None, flags: Tuple[str, ...]=(), uuid: str = <factory>)[source]#
Bases:
objectImmutable data structure for a single absorption component (Voigt profile).
- id: int#
Internal integer ID (from V1 legacy logic).
- z: float#
Redshift of the component center
- dz: float | None#
Uncertainty on redshift.
- logN: float#
Logarithmic column density (cm^-2).
- dlogN: float | None#
Uncertainty on logN.
- b: float#
Doppler broadening parameter (km/s).
- db: float | None#
Uncertainty on b.
- btur: float = 0.0#
Turbulent broadening contribution (km/s).
- dbtur: float | None = None#
Uncertainty on btur.
- series: str = 'Ly_a'#
Atomic series name (e.g.,
'Ly_a','CIV').
- chi2: float | None = None#
Reduced Chi-Squared of the fit group this component belongs to.
- resol: float | None = None#
Resolution used for the fit.
- flags: Tuple[str, ...] = ()#
Warnings left by the last fit of the component (#517), see
astrocook.fitting.voigt_fitter.COMPONENT_FLAGS: a parameter ended at a bound of the fit, or the uncertainties could not be computed; ornot_fitted(phase 6-bis): Refit All could not fit its group, and it keeps its values from before. Cleared when a parameter is edited, and set again by the next fit.
- uuid: str#
A globally unique, stable identifier for V2 constraints and linking.
- __init__(id: int, z: float, dz: float | None, logN: float, dlogN: float | None, b: float, db: float | None, btur: float = 0.0, dbtur: float | None = None, func: str = 'voigt', series: str = 'Ly_a', chi2: float | None = None, resol: float | None = None, flags: Tuple[str, ...]=(), uuid: str = <factory>) None#
- class astrocook.core.structures.ParameterConstraint(is_free: bool, target_uuid: str | None = None, expression: str | None = None, v1_target_id: int | None = None)[source]#
Bases:
objectImmutable structure defining a constraint for a single parameter.
Used by the fitting engine to determine if a parameter is free, fixed, or linked to another component.
- is_free: bool#
If True, the parameter varies during minimization.
- target_uuid: str | None = None#
If set, this parameter is linked to the component with this UUID.
- expression: str | None = None#
A mathematical string expression for linking (e.g.
"p['{uuid}'].z").
- v1_target_id: int | None = None#
Legacy ID of the target component (for debugging/reconstruction only).
- __init__(is_free: bool, target_uuid: str | None = None, expression: str | None = None, v1_target_id: int | None = None) None#
- class astrocook.core.structures.SystemListData(components: ~typing.List[~astrocook.core.structures.ComponentData] = <factory>, v1_header_constraints: ~typing.Dict[str, ~typing.Any] = <factory>, parsed_constraints: ~typing.Dict[~typing.Tuple[str, str], ~astrocook.core.structures.ParameterConstraint] = <factory>, v2_constraints_map: ~typing.Dict[str, ~typing.Dict[str, ~astrocook.core.structures.ParameterConstraint]] = <factory>, v1_id_to_uuid_map: ~typing.Dict[int, str] = <factory>, v1_models_t: ~typing.Any = None, meta: ~typing.Dict[str, ~typing.Any] = <factory>)[source]#
Bases:
objectImmutable container for system components and constraints.
This class replaces the mutable tables used in V1. It holds the list of components and the maps defining their relationships.
- components: List[ComponentData]#
The list of absorption components.
- v1_header_constraints: Dict[str, Any]#
Legacy constraints from V1 file headers.
- parsed_constraints: Dict[Tuple[str, str], ParameterConstraint]#
Map of (Component UUID, Parameter Name) -> ParameterConstraint.
- v2_constraints_map: Dict[str, Dict[str, ParameterConstraint]]#
Constraint}}.
- Type:
Nested map {UUID
- Type:
{ParamName
- v1_id_to_uuid_map: Dict[int, str]#
Map of integer IDs to V2 UUIDs.
- v1_models_t: Any = None#
- meta: Dict[str, Any]#
Metadata for the system list.
- __init__(components: ~typing.List[~astrocook.core.structures.ComponentData] = <factory>, v1_header_constraints: ~typing.Dict[str, ~typing.Any] = <factory>, parsed_constraints: ~typing.Dict[~typing.Tuple[str, str], ~astrocook.core.structures.ParameterConstraint] = <factory>, v2_constraints_map: ~typing.Dict[str, ~typing.Dict[str, ~astrocook.core.structures.ParameterConstraint]] = <factory>, v1_id_to_uuid_map: ~typing.Dict[int, str] = <factory>, v1_models_t: ~typing.Any = None, meta: ~typing.Dict[str, ~typing.Any] = <factory>) None#
- class astrocook.core.structures.LogEntry(recipe_name: str, params: Dict[str, Any], reason: str | None = None)[source]#
Bases:
objectA single entry in the V2 analysis log.
Corresponds 1-to-1 with a state change in the Session history.
- __init__(recipe_name: str, params: Dict[str, Any], reason: str | None = None) None#
- recipe_name: str#
- params: Dict[str, Any]#
- reason: str | None = None#
Why the recipe was run, as given by who ran it (e.g. an agent through the MCP server); None if not given (phase 6-ter, PR 5a)
- astrocook.core.structures.NOTE_KINDS = ('note', 'gap', 'gap_seen')#
The kinds of the notes of a log that
HistoryLog.add_note()takes:note(what was done or decided outside the recipes),gap(what the analysis needed and no recipe provided, declared by the agent) andgap_seen(a gap seen by the MCP server); phase 6-ter, PR 5b
- class astrocook.core.structures.LogNote(text: str, after: int, kind: str = 'note')[source]#
Bases:
objectA note in the V2 analysis log: text that is not a state change (e.g. what an agent did outside the recipes), skipped by the replay.
The notes are kept apart from the entries, so that the entries stay 1-to-1 with the states of the history, and the logs saved with notes replay in the versions before them, which ignore the notes (phase 6-ter, PR 5a).
- __init__(text: str, after: int, kind: str = 'note') None#
- text: str#
- after: int#
it was written at the state made by the entry
after - 1(0: before any entry)- Type:
The number of entries before the note
- kind: str = 'note'#
One of
NOTE_KINDS; a log written by a later version may hold others, kept as read
- class astrocook.core.structures.HistoryLog[source]#
Bases:
objectManages the linear history of operations (Log V2).
This class maintains a list of
LogEntryobjects matching the stack of immutable states in the session manager. It supports truncation to handle branching history (undo/redo logic).- current_index: int#
Pointer to the currently active log entry (state), i.e. the last valid entry.
- notes: List[LogNote]#
The notes (list of
LogNote), in the order they were written; those written after an entry undone are undone with it.
- previous: HistoryLog | None#
The log of the archive the session was opened from (a
HistoryLog), or None: read only, shown while the session is open, never replayed nor saved again (F109: each saved archive is a node, its log goes from its original data to its state; seeopened_from()).
- property is_v2_log: bool#
Return True, indicating this is a V2-native log structure.
- classmethod opened_from(archive_log: HistoryLog | None) HistoryLog[source]#
The log of a session opened from an archive: empty, with the log of the archive as
previous.The rule of the sessions (F109): each saved archive is a node, with its original data (A, the
*_origmembers), its state (B) and the log from A to B. When it is opened, B becomes the new A and the log starts anew; the log of the archive is kept only to be read while the session is open. Its own previous log is not kept: the logs of the earlier nodes are in their archives.
- add_entry(recipe_name: str, params: Dict[str, Any], reason: str | None = None)[source]#
Add a new log entry, truncating any ‘future’ history (from Undo actions).
- Parameters:
recipe_name (str) – The name of the recipe executed.
params (dict) – The parameters used for the recipe.
reason (str, optional) – Why the recipe was run; empty text is no reason.
- add_note(text: str, kind: str = 'note') LogNote[source]#
Add a note at the current entry, without a state.
The entries undone are kept (a note is not a state, so the redo is still possible): the note is undone with the current entry, and dropped with it if a new entry replaces it.
- Parameters:
text (str) – The text of the note.
kind (str) – One of
NOTE_KINDS.
- Returns:
The note added.
- Return type:
- Raises:
ValueError – If the text is empty or the kind is not known.
- notes_at(after: int) List[LogNote][source]#
The notes written after
afterentries (at the state made by the entryafter - 1), in the order they were written.
- timeline(include_undone: bool = False) List[Tuple[Any, bool]][source]#
The entries and the notes in the order they were written.
- undo() bool[source]#
Move the history pointer back one step.
- Returns:
True if undo was successful, False if already before the first entry.
- Return type:
bool
- redo() bool[source]#
Move the history pointer forward one step.
- Returns:
True if redo was successful, False if already at the latest entry.
- Return type:
bool
- to_dict() Dict[str, Any][source]#
Serialize the active history (entries up to
current_index).Entries undone and not redone are not part of the saved state and are left out.
- Returns:
{'entries': [{'recipe_name': ..., 'params': ...}, ...], 'current_index': ...}; an entry has'reason'if it was given, and the log'notes'([{'text': ..., 'kind': ..., 'after': ...}, ...]) if it has any (phase 6-ter, PR 5a): a log without either is saved as before.- Return type:
dict
- classmethod from_dict(data: Dict[str, Any]) HistoryLog[source]#
Rebuild a log from the output of
to_dict().- Parameters:
data (dict) – The serialized log. Missing or malformed keys give an empty log.
- Returns:
The log, pointing at its last entry.
- Return type: