stoner_measurement.plugins.transform.branch_split.BranchSplitPlugin¶
- class stoner_measurement.plugins.transform.branch_split.BranchSplitPlugin(parent=None)[source]¶
Bases:
BranchSplittingMixin,TraceChannelSelectionMixin,TransformPluginSplit a cyclic trace into rising and falling acquisition branches.
Use this transform when a trace contains both increasing and decreasing passes through an independent variable, such as the two directions of a field, voltage, or position sweep. The transform detects turning points in acquisition order and produces separate traces containing all rising branches and all falling branches.
The General tab selects the source trace, the independent variable, the output channel scope, and the names of the two output traces. Choose All channels to retain every source column, or Selected channels to choose a subset. The independent variable is retained as the x column in both outputs. The Advanced tab controls Savitzky-Golay smoothing, turning-point prominence, and the minimum accepted branch length.
The source must contain at least three finite independent-variable values and identifiable branches in both directions. Output rows retain their original acquisition order and preserve source names, units, and column roles where possible. Invalid configuration or a trace with only one direction is logged and produces no output.
- Variables:
trace_key (str) – Catalogue key of the source trace.
channel_mode (str) – Whether all source channels or only selected channels are copied.
x_channel_key (str) – Selected independent-variable key;
"x"uses the source x role.channel_keys (list[str]) – Selected output-channel keys when
channel_modeis"selected".rising_trace_name (str) – Output name for rows whose independent variable increases.
falling_trace_name (str) – Output name for rows whose independent variable decreases.
turning_points (list[int]) – Acquisition indices of the most recently detected turning points.
branch_directions (list[int]) – Directions of the most recently detected branches, using
1for rising and-1for falling.instance_name (str) – Inherited Python identifier for this instance in the Script tab and QtConsole.
comment (str) – Inherited optional note displayed beside this step.
sequence_engine (SequenceEngine | None) – Inherited owning engine and its live namespace; None while detached.
data (dict[str, Any]) – Inherited latest output mapping populated by run(), containing scalar and/or TraceData results.
smoothing_window (int) – Inherited Savitzky-Golay window length for branch detection.
smoothing_polyorder (int) – Inherited order used to smooth the independent variable.
turning_point_prominence (float) – Inherited minimum prominence as a fraction of the x span.
minimum_branch_length (int) – Inherited minimum accepted branch length in samples.
Notes
Advanced settings are omitted from JSON while they retain their defaults, keeping saved sequences compact.
- Keyword Parameters:
parent (QObject | None) – Optional Qt parent object.
Examples
With an instance named
branch_splitin the sequence, use the QtConsole to inspect or edit it before running. Substitute your instance name if different; result data reflects completed steps:branch_split.channel_mode = "all" branch_split.minimum_branch_length = 10 branch_split.data
- 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]¶
Declare typed transform results without repeating output names.
- 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().
- to_json() dict[str, Any][source]¶
Serialise this plugin’s configuration to a JSON-compatible dict.
The returned dict contains at minimum:
"type"— the plugin sub-type tag (e.g."trace","state")."class"— the fully qualified class path"module:ClassName"used byfrom_json()to reconstruct the exact subclass."instance_name"— the currentinstance_name.
Subclasses should call
super().to_json()and then add their own configuration keys to the returned dict.- Returns:
A JSON-serialisable dictionary representing this plugin’s current configuration.
- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> d = plugin.to_json() >>> d["type"] 'trace' >>> d["instance_name"] 'dummy' >>> "class" in d True
- 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]}