astrocook.recipes.prerequisites module#
What a recipe needs from the session, and who provides it (phase 6-bis, PR 5).
The registry declares what each recipe requires (z_em, the
resolution, the continuum) and what it provides; this module
says what is missing for a recipe (missing(), for the GUI and the
MCP server, which ask before the recipe runs) and fills the gaps at the
boundary of the recipe (fill(), called by typed_recipe),
following a policy chosen by the script:
"provide"(the default): what a recipe can provide with its defaults is provided first, with a WARNING (the continuum, by Auto-estimate Continuum); what no recipe can provide by itself (the emission redshift, the resolution) is left to the recipe, which goes on as before with its own WARNING (Guido: the numbers do not change);"raise": aMissingPrerequisitethat says what is missing and which recipe provides it.
The policy is set for a block of a script with policy(), or for one
call with run(..., on_missing="raise").
- astrocook.recipes.prerequisites.POLICIES = ('provide', 'raise')#
The policies of the scripts
- class astrocook.recipes.prerequisites.Prerequisite(name: str, missing: str, check: Callable[[Any], bool], automatic: str | None = None)[source]#
Bases:
objectSomething a recipe can require from the session.
- name: str#
- missing: str#
Said when it is missing, e.g. “the spectrum has no continuum”
- check: Callable[[Any], bool]#
Whether the session has it (from its spectrum)
- automatic: str | None = None#
The recipe that provides it with its defaults, as
category.name; None when a value must be given (e.g. z_em)
- __init__(name: str, missing: str, check: Callable[[Any], bool], automatic: str | None = None) None#
- class astrocook.recipes.prerequisites.Missing(name: str, reason: str, providers: Tuple[str, ...], automatic: str | None)[source]#
Bases:
objectA prerequisite that a recipe needs and the session does not have.
- name: str#
z_em,resolutionorcontinuum
- reason: str#
e.g. “the spectrum has no continuum”
- providers: Tuple[str, ...]#
The recipes that provide it, as
category.name
- automatic: str | None#
The one that provides it with its defaults, or None
- property message: str#
The reason and how to fill the gap, e.g. “The spectrum has no continuum: Auto-estimate continuum (single-click) (continuum.estimate_auto) provides it with its defaults”; all the recipes that provide it are in
providers.
- __init__(name: str, reason: str, providers: Tuple[str, ...], automatic: str | None) None#
- class astrocook.recipes.prerequisites.ProvidedStep(recipe: str, params: Mapping[str, Any], reason: str, session: Any)[source]#
Bases:
objectA recipe run first to provide a prerequisite (policy “provide”).
- recipe: str#
The recipe, as
category.name
- params: Mapping[str, Any]#
The values of its parameters (its defaults), for the session log
- reason: str#
Why it was run, e.g. “the spectrum has no continuum”
- session: Any#
The session it gave, on which the recipe then ran
- __init__(recipe: str, params: Mapping[str, Any], reason: str, session: Any) None#
- astrocook.recipes.prerequisites.providers_of(name: str) Tuple[str, ...][source]#
The recipes that declare that they provide
name, ascategory.name, the automatic one first.
- astrocook.recipes.prerequisites.missing(session, recipe) Tuple[Missing, ...][source]#
What
recipe(aRecipeSpec) needs andsessiondoes not have; pure, nothing is run.
- astrocook.recipes.prerequisites.policy(name: str) Iterator[None][source]#
The policy for the recipes run in the block:
"provide"or"raise".>>> with policy("raise"): ... session = session.absorbers.refit_all()
- astrocook.recipes.prerequisites.collect_provided() Iterator[List[ProvidedStep]][source]#
The steps run to provide the prerequisites of the outermost recipe called in the block (used by
runand by the callers that write the session log).