plesty.lib.analyzer
Analyzer framework: schema-declared transforms from raw device data to results.
Submodules
Exceptions
Raised when analysis inputs or outputs violate the declared schema. |
|
Raised when an analyzer's schema declaration is invalid. |
Classes
Base class for PLESTY analyzers: schema-declared data transforms. |
Package Contents
- exception plesty.lib.analyzer.AnalysisValidationError
Bases:
ValueErrorRaised when analysis inputs or outputs violate the declared schema.
Initialize self. See help(type(self)) for accurate signature.
- class plesty.lib.analyzer.Analyzer(**params: Any)
Bases:
abc.ABCBase class for PLESTY analyzers: schema-declared data transforms.
Subclasses declare
input_schema/output_schemaand implement exactly one method,analyze(). Analysis parameters (including calibration objects or references) are passed as keyword arguments to the constructor and stored onparams, from where they enter the provenance stamp of every result.Schema entries map an input/output name to a dict with keys:
dtype— required: a dtype token understood byplesty.lib.data.types.resolve_dtype()(float,array_float,table2d, …).unit— unit filled onto outputs that do not set one.description— human-readable meaning; filled onto outputs.shape— arrays only: expected shape;Noneentries are free dimensions, e.g.[None, 2].required— inputs only: whether the input must be supplied (defaultTrue).
Store the analysis parameters and validate the schema declarations.
- Parameters:
**params (Any) – Analysis parameters and calibration handles. They are introspectable via
paramsand recorded in the provenance stamp of every result.
- input_schema: ClassVar[dict[str, dict[str, Any]]]
name → schema entry.
- Type:
Declared inputs of
analyze()
- output_schema: ClassVar[dict[str, dict[str, Any]]]
name → schema entry.
- Type:
Declared outputs of
analyze()
- params: dict[str, Any]
Analysis parameters passed to the constructor (calibration included).
- abstractmethod analyze(**inputs: Any) dict[str, Any]
Transform the schema-declared inputs into the schema-declared outputs.
Implementations receive validated inputs as keyword arguments and return a dict with exactly the
output_schemanames as keys. Output metadata (name/unit/description) may be left unset — the base machinery fills it from the schema.- Parameters:
**inputs (Any) – Validated inputs, one keyword per
input_schemaname.- Returns:
Mapping of output name to result value.
- Return type:
dict[str, Any]
- __call__(**inputs: Any) dict[str, Any]
Validate inputs, run
analyze(), validate and stamp outputs.- Parameters:
**inputs (Any) – One keyword per
input_schemaname; optional inputs may be omitted.- Returns:
Mapping of output name to result value; array/table results carry a
provenanceattribute.- Raises:
AnalysisValidationError – If inputs or outputs violate the schema.
- Return type:
dict[str, Any]
- provenance() dict[str, Any]
Return the provenance stamp: analyzer identity, version, parameters.
- Return type:
dict[str, Any]
- static _validate_schema(schema: dict[str, dict[str, Any]], allowed_keys: frozenset[str], label: str) None
Validate a schema declaration, raising
AnalyzerSchemaError.- Parameters:
schema (dict[str, dict[str, Any]])
allowed_keys (frozenset[str])
label (str)
- Return type:
None
- _validate_inputs(inputs: dict[str, Any]) dict[str, Any]
Check input names, dtypes, and shapes against
input_schema.- Parameters:
inputs (dict[str, Any])
- Return type:
dict[str, Any]
- _finalize_outputs(outputs: Any) dict[str, Any]
Validate outputs, fill schema metadata, and stamp provenance.
- Parameters:
outputs (Any)
- Return type:
dict[str, Any]
- _conform(name: str, value: Any, entry: dict[str, Any], direction: str) Any
Check one value against its schema entry, coercing raw arrays.
- Parameters:
name (str)
value (Any)
entry (dict[str, Any])
direction (str)
- Return type:
Any
- _conform_array(name: str, value: Any, entry: dict[str, Any], direction: str) plesty.lib.data.array.PlestyArray
Coerce array-likes to
PlestyArrayand check the shape.- Parameters:
name (str)
value (Any)
entry (dict[str, Any])
direction (str)
- Return type:
- exception plesty.lib.analyzer.AnalyzerSchemaError
Bases:
ValueErrorRaised when an analyzer’s schema declaration is invalid.
Initialize self. See help(type(self)) for accurate signature.