|
7 | 7 | # pylint: disable=invalid-name # Allows short reference names like x, y, ... |
8 | 8 | # guitest: show |
9 | 9 |
|
10 | | -from sigima.objects import create_signal_from_param |
| 10 | +from sigima.objects import SignalObj, TableKind, TableResult, create_signal_from_param |
| 11 | +from sigima.tests.helpers import check_scalar_result |
11 | 12 | from sigima.tests.signal.pulse_unit_test import ( |
12 | 13 | create_test_square_params, |
13 | 14 | create_test_step_params, |
14 | 15 | ) |
15 | 16 |
|
| 17 | +from datalab.adapters_metadata import TableAdapter |
16 | 18 | from datalab.tests import datalab_test_app_context |
17 | 19 |
|
18 | 20 |
|
| 21 | +def __check_table(obj: SignalObj) -> TableResult: |
| 22 | + """Check that the object has a pulse features table.""" |
| 23 | + tables = list(TableAdapter.iterate_from_obj(obj)) |
| 24 | + assert len(tables) == 1 |
| 25 | + table = tables[0].result |
| 26 | + assert table.kind == TableKind.PULSE_FEATURES |
| 27 | + return table |
| 28 | + |
| 29 | + |
19 | 30 | def test_pulse_features_app(): |
20 | 31 | """Pulse features application test.""" |
21 | 32 | with datalab_test_app_context(console=False) as win: |
22 | 33 | panel = win.signalpanel |
| 34 | + |
| 35 | + # Add first signal and extract features |
23 | 36 | s1 = create_signal_from_param(create_test_step_params()) |
24 | 37 | panel.add_object(s1) |
25 | 38 | panel.processor.run_feature("extract_pulse_features") |
| 39 | + |
| 40 | + # Check that features are extracted |
| 41 | + table1 = __check_table(s1) |
| 42 | + assert table1["signal_shape"][0] == "step" |
| 43 | + assert table1["polarity"][0] == 1.0 |
| 44 | + for name, expected_value in (("amplitude", 4.9), ("rise_time", 1.5)): |
| 45 | + check_scalar_result(name, table1[name][0], expected_value, rtol=1e-2) |
| 46 | + |
| 47 | + # Add second signal and extract features |
26 | 48 | s2 = create_signal_from_param(create_test_square_params()) |
27 | 49 | panel.add_object(s2) |
28 | 50 | panel.processor.run_feature("extract_pulse_features") |
29 | 51 |
|
| 52 | + # Check that features are extracted |
| 53 | + table2 = __check_table(s2) |
| 54 | + assert table2["signal_shape"][0] == "square" |
| 55 | + assert table2["polarity"][0] == 1.0 |
| 56 | + for name, expected_value in ( |
| 57 | + ("amplitude", 4.94), |
| 58 | + ("rise_time", 1.60), |
| 59 | + ("fall_time", 3.95), |
| 60 | + ("fwhm", 5.49), |
| 61 | + ): |
| 62 | + check_scalar_result(name, table2[name][0], expected_value, rtol=1e-2) |
| 63 | + |
30 | 64 |
|
31 | 65 | if __name__ == "__main__": |
32 | 66 | test_pulse_features_app() |
0 commit comments