Skip to content

Commit 577c7b5

Browse files
committed
Add application test for pulse features with ROIs
(cherry picked from commit 82abef5)
1 parent df0f772 commit 577c7b5

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

datalab/adapters_plotpy/objects/scalar.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,26 +442,34 @@ def create_pulse_visualization_items(
442442
"""
443443
items = []
444444
df = self.result_adapter.to_dataframe()
445+
446+
# Use the full signal data for all visualizations
447+
# Note: pulse features x-coordinates (xstartmin, xendmin, etc.) are stored
448+
# in the full signal coordinate system, even when computed on ROIs
449+
x, y = obj.x, obj.y
450+
445451
for _, row in df.iterrows():
446452
# Start baseline
447453
xs0, xs1 = row["xstartmin"], row["xstartmax"]
448-
ys = pulse.get_range_mean_y(obj.x, obj.y, (xs0, xs1))
454+
ys = pulse.get_range_mean_y(x, y, (xs0, xs1))
449455
if are_values_valid([xs0, xs1, ys]):
450456
items.append(create_pulse_segment(xs0, ys, xs1, ys, "Start baseline"))
451457
# End baseline
452458
xe0, xe1 = row["xendmin"], row["xendmax"]
453-
ye = pulse.get_range_mean_y(obj.x, obj.y, (xe0, xe1))
459+
ye = pulse.get_range_mean_y(x, y, (xe0, xe1))
454460
if are_values_valid([xe0, xe1, ye]):
455461
items.append(create_pulse_segment(xe0, ye, xe1, ye, "End baseline"))
456462
if "xplateaumin" in row and "xplateaumax" in row:
457463
xp0, xp1 = row["xplateaumin"], row["xplateaumax"]
458-
yp = pulse.get_range_mean_y(obj.x, obj.y, (xp0, xp1))
464+
yp = pulse.get_range_mean_y(x, y, (xp0, xp1))
459465
if are_values_valid([xp0, xp1, yp]):
460466
items.append(create_pulse_segment(xp0, yp, xp1, yp, "Plateau"))
461467
for metric in ("x0", "x50", "x100"):
462468
if metric in row:
463-
x = row[metric]
469+
x_crossing = row[metric]
464470
metric_str = metric.replace("x", "x|<sub>") + "%</sub>"
465-
if are_values_valid([x]):
466-
items.append(create_pulse_crossing_marker("v", x, metric_str))
471+
if are_values_valid([x_crossing]):
472+
items.append(
473+
create_pulse_crossing_marker("v", x_crossing, metric_str)
474+
)
467475
return items
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.
2+
3+
"""
4+
Pulse features with ROIs application test.
5+
"""
6+
7+
# pylint: disable=invalid-name # Allows short reference names like x, y, ...
8+
# guitest: show
9+
10+
from __future__ import annotations
11+
12+
from sigima.objects import SignalObj, TableResult
13+
from sigima.params import PulseFeaturesParam
14+
from sigima.tests.signal.pulse.pulse_features_roi_unit_test import (
15+
check_results_equal,
16+
generate_source_signal,
17+
)
18+
19+
from datalab.gui.panel.signal import SignalPanel
20+
from datalab.tests import datalab_test_app_context
21+
22+
23+
def __extract_pulse_features(panel: SignalPanel, obj: SignalObj) -> TableResult:
24+
"""Extract pulse features."""
25+
panel.objview.select_objects([obj])
26+
param = PulseFeaturesParam()
27+
param.update_from_obj(obj)
28+
rdata = panel.processor.run_feature("extract_pulse_features", param)
29+
assert len(rdata.results) == 1
30+
return rdata.results[0]
31+
32+
33+
def test_pulse_features_roi_app():
34+
"""Pulse features with ROIs application test."""
35+
with datalab_test_app_context(console=False) as win:
36+
panel = win.signalpanel
37+
38+
# Test signal with multiple ROIs defined around peaks of the spectrum
39+
sig = generate_source_signal()
40+
panel.add_object(sig)
41+
pf_sig = __extract_pulse_features(panel, sig)
42+
43+
# Extract ROIs in separate signals and test each one
44+
panel.processor.run_feature("extract_roi", params=sig.roi.to_params(sig))
45+
pf_extracted_sigs = []
46+
for nb_sig in (2, 3, 4):
47+
extracted_sig = panel.objmodel.get_object_from_number(nb_sig)
48+
pf_extracted_sig = __extract_pulse_features(panel, extracted_sig)
49+
pf_extracted_sigs.append(pf_extracted_sig)
50+
51+
check_results_equal(pf_sig, pf_extracted_sigs)
52+
53+
54+
if __name__ == "__main__":
55+
test_pulse_features_roi_app()

0 commit comments

Comments
 (0)