pelagos_py.utils.parameter_spec#
- pelagos_py.utils.parameter_spec.is_required(spec: dict) bool[source]#
Return whether a single parameter spec describes a required parameter.
- pelagos_py.utils.parameter_spec.matches_type(spec: dict, value) bool[source]#
Return whether
valuesatisfies a single parameter spec’stype.A spec with no
typeaccepts anything. Special cases:Noneis accepted whenNoneis the declared default (a sentinel meaning e.g. “compute it”, as withdark_value).boolis a subclass ofintbut is only accepted whenboolis explicitly listed — soacceleration_threshold: no(YAMLFalse) is rejected for afloatparameter.an
intis accepted where afloatis expected (e.g.20for a threshold), since YAML has no way to force a whole-number float.
- pelagos_py.utils.parameter_spec.type_errors(schema: dict, params: dict) list[str][source]#
Return
"name (expected X, got Y)"messages for type-mismatched params.Only user-supplied values present in
schemaare checked; omitted parameters and undeclared keys are out of scope here (defaults are trusted, and unknown keys are handled separately).
- pelagos_py.utils.parameter_spec.resolve(schema: dict, params: dict, *, label: str = 'component', allowed_extra=()) dict[source]#
Resolve user-supplied
paramsagainst aschema.Every parameter declared in
schemais returned: user values are passed through, omitted optional parameters fall back to theirdefault, and any omitted required parameter raisesValueError.Unknown parameters — keys present in
paramsbut not declared inschemanor listed inallowed_extra— raiseValueErrorso config typos are caught early.allowed_extraexists for framework/mixin keys that a handler other than the schema consumes (e.g.qc_handling_settings).- Parameters:
schema (dict) – The component’s
parameter_schema.params (dict) – The user-supplied parameters for this component.
label (str, optional) – Name used in error messages (typically the step/QC name).
allowed_extra (iterable of str, optional) – Parameter names that are permitted even though they are not in
schema.
- Returns:
Resolved
{name: value}for every parameter inschema.- Return type:
- Raises:
ValueError – If a required parameter is missing, or an unknown parameter is supplied.