astrocook.recipes.result module#

The structured result of a recipe (phase 6-bis, PR 4).

run() runs a recipe of the registry and returns a RecipeResult: the new session (or sessions), what changed in it, listed and not only counted (the components added, removed and changed, the columns, the properties), the warnings the recipe logged, the recipes it ran as steps, and the values of the parameters it used. The GUI, the MCP server and the scripts that want the whole result call it; the methods of the recipes keep returning the session (Guido, decision 1 of the phase).

What changed is found by comparing the session before and after, in one place for every recipe (Guido’s choice at the start of PR 4: a generic comparison, not a description written by each recipe). What a recipe knows and the comparison cannot see (the score of an identification, the groups a fit could not fit) goes in extra, PR 4b; the fields of what the algorithms do not provide yet (the uncertainty of the continuum, the credibility of an identification and its alternatives) are there, empty, so that phase 7 fills them without changing the interface.

astrocook.recipes.result.COMPONENT_FIELDS = ('series', 'z', 'logN', 'b', 'btur', 'resol', 'flags')#

The parameters of a component compared by compare_sessions()

class astrocook.recipes.result.ComponentRef(uuid: str, series: str, z: float, logN: float, b: float)[source]#

Bases: object

A component, as a change names it.

uuid: str#
series: str#
z: float#
logN: float#
b: float#
__init__(uuid: str, series: str, z: float, logN: float, b: float) → None#
class astrocook.recipes.result.ComponentChange(component: ComponentRef, changed: Mapping[str, Tuple[Any, Any]])[source]#

Bases: object

A component whose parameters changed: changed maps a parameter to its values before and after.

component: ComponentRef#
changed: Mapping[str, Tuple[Any, Any]]#
__init__(component: ComponentRef, changed: Mapping[str, Tuple[Any, Any]]) → None#
class astrocook.recipes.result.Changes(components_added: ComponentRef, ...]=(), components_removed: ComponentRef, ...]=(), components_changed: ComponentChange, ...]=(), columns_added: Tuple[str, ...]=(), columns_removed: Tuple[str, ...]=(), columns_changed: Tuple[str, ...]=(), properties_changed: Mapping[str, ~typing.Tuple[~typing.Any, ~typing.Any]]=<factory>)[source]#

Bases: object

What a recipe changed in a session (compare_sessions()).

components_added: Tuple[ComponentRef, ...] = ()#
components_removed: Tuple[ComponentRef, ...] = ()#
components_changed: Tuple[ComponentChange, ...] = ()#
columns_added: Tuple[str, ...] = ()#
columns_removed: Tuple[str, ...] = ()#
columns_changed: Tuple[str, ...] = ()#
properties_changed: Mapping[str, Tuple[Any, Any]]#

before and after

Type:

name, object, pixels, z_em, resolution (median R), units

property empty: bool#

True if nothing changed.

describe() → List[str][source]#

The changes in a few words each, e.g. ['3 components added', "column 'cont' changed"].

__init__(components_added: ComponentRef, ...]=(), components_removed: ComponentRef, ...]=(), components_changed: ComponentChange, ...]=(), columns_added: Tuple[str, ...]=(), columns_removed: Tuple[str, ...]=(), columns_changed: Tuple[str, ...]=(), properties_changed: Mapping[str, ~typing.Tuple[~typing.Any, ~typing.Any]]=<factory>) → None#
class astrocook.recipes.result.RecipeResult(recipe: str, title: str, session: ~typing.Any, branching: bool, changes: ~typing.Any, params: ~typing.Mapping[str, ~typing.Any], warnings: ~typing.Tuple[str, ...] = (), steps: ~typing.Tuple[str, ...] = (), value: ~typing.Any = None, extra: ~typing.Mapping[str, ~typing.Any] = <factory>, provided: ~typing.Tuple[~typing.Any, ...] = (), continuum_uncertainty: ~typing.Any = None, credibility: ~typing.Any = None, alternatives: ~typing.Tuple[~typing.Any, ...] = ())[source]#

Bases: object

The result of a recipe run by run().

recipe: str#

The recipe, as category.name

title: str#

Its title (the brief of the registry)

session: Any#

The new session; a tuple for a recipe that opens several (e.g. extract_preset with two regions); None for a recipe whose result is not a session (value)

branching: bool#

The result opens a new session, instead of being the next state of the same one

changes: Any#

What changed, compared with the session the recipe ran on; one per session of session when it is a tuple

params: Mapping[str, Any]#

The values of the parameters the recipe used, defaults included

warnings: Tuple[str, ...] = ()#

The warnings the recipe logged

steps: Tuple[str, ...] = ()#

The recipes it ran as steps, as category.name, in their order

value: Any = None#

The result when it is not a session (the redshift of detect_anchor, whether export_ascii wrote a file)

extra: Mapping[str, Any]#

What the recipe knows and the comparison cannot see (PR 4b): removed (uuid -> why a component of the session was removed), discarded (uuid -> why a component the recipe made was dropped, e.g. a narrow line of a pipeline), not_fitted (the components whose group could not be fitted), candidates and regions (the identification of identify_lines)

provided: Tuple[Any, ...] = ()#

The recipes run first to provide what the session lacked (PR 5), as ProvidedStep: each with its session, for the callers that keep the history and the log

continuum_uncertainty: Any = None#

the uncertainty of the continuum, the credibility of an identification and its alternatives

Type:

Reserved for phase 7 (the algorithms do not provide them yet)

credibility: Any = None#
alternatives: Tuple[Any, ...] = ()#
property sessions: Tuple[Any, ...]#

The new sessions, always as a tuple.

property notes: Tuple[str, ...]#

What the user should know of the result besides the changes (phase 6-bis, PR 4c, Guido): the components removed and why, those a pipeline made and dropped, those whose fit failed, the candidate systems found; one line each, e.g. '2 components removed: logN < min_logN = 14.0 (too weak)'.

property counts: Tuple[str, ...]#

The notes in a word each, for a status bar, e.g. ('2 removed', '1 not fitted').

property summary: str#

the recipe, what changed, the warnings.

Type:

One line

__init__(recipe: str, title: str, session: ~typing.Any, branching: bool, changes: ~typing.Any, params: ~typing.Mapping[str, ~typing.Any], warnings: ~typing.Tuple[str, ...] = (), steps: ~typing.Tuple[str, ...] = (), value: ~typing.Any = None, extra: ~typing.Mapping[str, ~typing.Any] = <factory>, provided: ~typing.Tuple[~typing.Any, ...] = (), continuum_uncertainty: ~typing.Any = None, credibility: ~typing.Any = None, alternatives: ~typing.Tuple[~typing.Any, ...] = ()) → None#
astrocook.recipes.result.SAME_PARAMETER_RTOL = 1e-08#

Relative size below which a parameter of a component is the same after a refit: the optimizer returns the values of the start to ~1e-10 and the result listed such components as changed (trial 3 of the MCP server, PR 7)

astrocook.recipes.result.compare_sessions(before, after) → Changes[source]#

What changed from the session before to after.

astrocook.recipes.result.report(key: str, value: Any) → None[source]#

Put value in the extra of the result, under key: what a recipe knows and the comparison of the sessions cannot see (PR 4b). A list value is extended by the steps that report it again. Nothing happens outside run().

astrocook.recipes.result.report_removed(uuids, reason: str) → None[source]#

Say why the components uuids were removed: extra['removed'] maps each to its reason (the comparison lists them, not why).

astrocook.recipes.result.run(session, recipe: str, *, on_missing: str | None = None, **params) → RecipeResult[source]#

Run the recipe recipe ('category.name', or the name alone) on session and return its RecipeResult.

The parameters are given as to the method of the recipe (typed, or as strings); a recipe that cannot do what was asked raises its RecipeError, as the method does. on_missing is the policy for a prerequisite the session lacks, "provide" or "raise" (astrocook.recipes.prerequisites); by default, the one in force.