stoner_measurement.plugins.transform.base.TransformPlugin¶
- class stoner_measurement.plugins.transform.base.TransformPlugin(parent: QObject | None = None)[source]¶
Bases:
QObject,BasePluginAbstract base class for plugins that transform or reduce data.
A
TransformPluginaccepts a dictionary of named input arrays/scalars, validates that all required keys are present, and returns a dictionary of named output arrays/scalars. Subclasses must implementname,required_inputs,declared_outputs(), andtransform(). The old output-name properties remain supported for legacy plugins and are derived views for unified declarations.The class provides:
Input validation —
validate_inputs()raisesValueErrorif any key listed inrequired_inputsis missing from the data dict. It is called automatically by the defaultrun()helper.Run helper —
run()validates inputs, callstransform(), emitstransform_complete, and returns the result dict.Description —
descriptionprovides a human-readable summary of the computation performed.
- Variables:
transform_complete (pyqtSignal[dict]) – Emitted after
transform()returns successfully, with the result dict as its argument.- Keyword Parameters:
parent (QObject | None) – Optional Qt parent object.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _Scale(TransformPlugin): ... @property ... def name(self): return "Scale" ... @property ... def required_inputs(self): return ["y"] ... @property ... def output_names(self): return ["y_scaled"] ... def transform(self, data): ... return {"y_scaled": [v * 2 for v in data["y"]]} >>> p = _Scale() >>> p.plugin_type 'transform' >>> p.description '' >>> result = p.run({"y": [1.0, 2.0, 3.0]}) >>> result["y_scaled"] [2.0, 4.0, 6.0]
- comment_changed¶
Qt signal.
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal's arguments.
- config_tabs(parent: QWidget | None = None) list[tuple[str, QWidget]][source]¶
Return configuration tabs for this transform plugin.
Produces a single Data tab that places the instance-name editor (from
_general_config_widget()) at the top, followed by a horizontal separator and the data-selection widget returned by_build_data_tab(). An optional About tab is appended when_about_html()returns non-Nonecontent.Subclasses that need additional tabs (e.g. a Fit Function or Parameters tab) should call
super().config_tabs(parent)to obtain the base Data tab and then insert their extra tabs before the optional About tab.- Keyword Parameters:
parent (QWidget | None) – Optional Qt parent widget.
- Returns:
List of
(tab_title, widget)pairs starting with the combined Data tab.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _T(TransformPlugin): ... @property ... def name(self): return "T" ... @property ... def required_inputs(self): return [] ... @property ... def output_names(self): return [] ... def transform(self, data): return {} >>> tabs = _T().config_tabs() >>> tabs[0][0] 'Data' >>> 'General' not in [t for t, _ in tabs] True
- declared_outputs() PluginOutputs[source]¶
Adapt old transform naming properties to typed declarations.
- property description: str¶
Human-readable summary of the computation performed.
- Returns:
Descriptive text; default is an empty string.
- Return type:
(str)
- generate_action_code(indent: int, sub_steps: list, render_sub_step: Callable) list[str][source]¶
Return action code lines that run this transform plugin.
- Parameters:
indent (int) – Number of four-space indentation levels for the emitted lines.
sub_steps (list) – Ignored for
TransformPlugin(leaf node).render_sub_step (Callable) – Ignored for
TransformPlugin.
- Returns:
Lines calling
run({})on the plugin instance.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _T(TransformPlugin): ... @property ... def name(self): return "T" ... @property ... def required_inputs(self): return [] ... @property ... def output_names(self): return [] ... def transform(self, data): return {} >>> t = _T() >>> lines = t.generate_action_code(1, [], lambda s, i: []) >>> " t.run({})" in lines True
- property has_lifecycle: bool¶
Transform plugins have no instrument lifecycle.
- Returns:
Always
False. The sequence engine therefore omitsconnect(),configure(), anddisconnect()calls for transform plugins when generating sequence code.- Return type:
(bool)
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _T(TransformPlugin): ... @property ... def name(self): return "T" ... @property ... def required_inputs(self): return [] ... @property ... def output_names(self): return [] ... def transform(self, data): return {} >>> _T().has_lifecycle False
- instance_name_changed¶
Qt signal.
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal's arguments.
- property output_trace_names: list[str]¶
Return the compatibility view of unified output declarations.
- property output_value_names: list[str]¶
Return the compatibility view of unified output declarations.
- property plugin_type: str¶
Short tag identifying this plugin as a transform.
- Returns:
Always
"transform".- Return type:
(str)
- rename_trace_output(old_name: str, new_name: str) None[source]¶
Rename a trace output and propagate its catalogue identity downstream.
- abstract property required_inputs: list[str]¶
Names of input datasets that
transform()requires.validate_inputs()raisesValueErrorif any of these keys are absent from the data dict passed totransform().
- run(data: dict[str, Any]) dict[str, Any][source]¶
Validate data, run
transform(), emit the result, and return it.This is the preferred entry point for the sequence engine: it combines input validation, the computation, and signal emission in a single call.
- Parameters:
- Returns:
The dict returned by
transform().- Return type:
- Raises:
ValueError – If any key in
required_inputsis absent from data.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _Double(TransformPlugin): ... @property ... def name(self): return "Double" ... @property ... def required_inputs(self): return ["x"] ... @property ... def output_names(self): return ["x2"] ... def transform(self, data): return {"x2": data["x"] * 2} >>> p = _Double() >>> p.run({"x": 3}) {'x2': 6}
- abstractmethod transform(data: dict[str, Any]) dict[str, Any][source]¶
Compute the transform and return the result.
- Parameters:
data (dict[str, Any]) – Named input arrays or scalars. All keys listed in
required_inputsare guaranteed to be present when called viarun().- Returns:
Named output arrays or scalars. Should contain at least the keys listed in
output_names.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _Negate(TransformPlugin): ... @property ... def name(self): return "Negate" ... @property ... def required_inputs(self): return ["y"] ... @property ... def output_names(self): return ["y_neg"] ... def transform(self, data): return {"y_neg": [-v for v in data["y"]]} >>> p = _Negate() >>> p.transform({"y": [1.0, -2.0]}) {'y_neg': [-1.0, 2.0]}
- transform_complete¶
Qt signal.
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal's arguments.
- validate_inputs(data: dict[str, Any]) None[source]¶
Raise
ValueErrorif any required input keys are missing.- Parameters:
- Raises:
ValueError – If one or more keys from
required_inputsare absent from data.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.transform import TransformPlugin >>> class _T(TransformPlugin): ... @property ... def name(self): return "T" ... @property ... def required_inputs(self): return ["a", "b"] ... @property ... def output_names(self): return ["c"] ... def transform(self, data): return {"c": data["a"]} >>> p = _T() >>> p.validate_inputs({"a": 1, "b": 2}) # no error >>> import pytest >>> with pytest.raises(ValueError, match="b"): ... p.validate_inputs({"a": 1})