astrocook.recipes.params module#
Typed parameters of the recipes: one conversion, at the boundary.
The GUI dialogs, the session log, the log window and the scripts pass the
parameters of a recipe as strings ('5000.0', 'True', 'None');
the MCP server and the scripts may pass them typed. The decorator
typed_recipe() converts them once, to the types declared in the
recipe registry (astrocook.recipes.registry), and checks them
against its bounds before the recipe runs, so that the body of a recipe
receives typed values (phase 6-bis, PR 2).
resolve_params() gives the values a recipe actually used (the
parameters passed, converted, and the defaults of the others), which the
session log records (#573, item 3).
- astrocook.recipes.params.NONE_STRING = 'None'#
what the dialogs and the log write for None. An empty field of a dialog (
'') means None only for a parameter whose default is None (e.g. the start of Rebin: the range of the data); elsewhere it is an error, so that a field emptied by mistake does not switch an option off (Guido, phase 6-bis, PR 2a: an emptykappaof Rebin is not “no clipping”)- Type:
The string that means “no value” for an optional parameter
- astrocook.recipes.params.convert(param, value: Any) Any[source]#
valueconverted to the type ofparam(aParamSpec) and checked against its bounds;InvalidParameterif it cannot be.
- astrocook.recipes.params.convert_params(spec, params: Mapping[str, Any]) Dict[str, Any][source]#
The parameters of
specinparamsconverted to their types; the others (e.g.alias_map, deprecated parameters) unchanged.
- astrocook.recipes.params.resolve_params(name: str, params: Mapping[str, Any]) Dict[str, Any][source]#
The values that the recipe
nameuses withparams: those passed, converted, and the defaults of the others, in the order of the registry; for the session log (#573, item 3). The parameters passed that the registry does not declare (e.g.alias_map), and those of a name that is not a recipe, are returned as passed. A parameter passed by its old name is returned by the new one (phase 6-quater, PR 2).
- astrocook.recipes.params.DATA_ERRORS = (<class 'ValueError'>, <class 'KeyError'>, <class 'OSError'>)#
The errors of the core that mean “this data or this value cannot be used”: the decorator of the recipes turns them into RecipeFailed (Guido, phase 6-bis, PR 3). The others, usually bugs, go on as they are
- astrocook.recipes.params.collect_steps()[source]#
Collect, as
category.name, the recipes that the next recipe runs as its steps (phase 6-bis, PR 4: thestepsof a RecipeResult).
- astrocook.recipes.params.typed_recipe(method: Callable) Callable[source]#
Decorator of a recipe method, its boundary.
The parameters passed are converted to the types of the registry before the method runs (
InvalidParameterif one cannot be, or is out of its bounds). EveryRecipeErrorthat leaves the method records the recipe (so that the message names the recipe, and the steps of a pipeline); the errors of the core inDATA_ERRORSbecomeRecipeFailed, with the original error as their cause; any other exception (a bug) goes on unchanged, with a note naming the recipe. Nothing is logged here: the error is logged where it is caught (phase 6-bis, PR 3). Before the method runs, the prerequisites that the registry declares for it are filled, or their absence raised, as the policy ofastrocook.recipes.prerequisitessays (PR 5). A parameter passed by its old name (an alias in the registry) is passed to the method by its new name (phase 6-quater, PR 2).