Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Changed:
instead of zeros as a fill value for runs with a varying number of pulses
(!347).
- [imshow2()][extra.utils.imshow2] will now add a colorbar automatically (!351).
- [DelayLineDetector][extra.components.DelayLineDetector] now longer attaches an index level for each row in [hits()][extra.components.DelayLineDetector.hits] and [signals()][extra.components.DelayLineDetector.signals] (!362).
- [AdqRawChannel][extra.components.AdqRawChannel] now longer attaches an index level for each row in [train_edges()][extra.components.AdqRawChannel.train_edges] and [pulse_edges()][extra.components.AdqRawChannel.pulse_edges] (!362).
Comment thread
philsmt marked this conversation as resolved.

## [2025.1]

Expand Down
4 changes: 2 additions & 2 deletions src/extra/components/adq.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ def _shape_edges(self, edges, amplitudes, index):
from . import DelayLineDetector

edges = DelayLineDetector._build_reduced_pd(
None, edges, index, entry_level='edgeIndex')
None, edges, index)
amplitudes = DelayLineDetector._build_reduced_pd(
None, amplitudes, index, entry_level='edgeIndex')
None, amplitudes, index)

return pd.DataFrame({'edge': edges, 'amplitude': amplitudes})

Expand Down
19 changes: 11 additions & 8 deletions src/extra/components/dld.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ def _build_reduced_pd(self, data, index, entry_level=None, mask_func=None):
if entry_level is not None:
index_df[entry_level] = np.flatnonzero(finite_mask) % num_rows

return pd_cls(np.ascontiguousarray(raw[finite_mask]),
pd.MultiIndex.from_frame(index_df))
if len(index_df.columns) > 1:
# Multiple index columns, create a MultiIndex again.
index = pd.MultiIndex.from_frame(index_df)
else:
# If only a single column is left, build a simple index.
index = pd.Index(index_df[next(iter(index_df.columns))])

return pd_cls(np.ascontiguousarray(raw[finite_mask]), index)

@staticmethod
def insert_aligned_columns(df, columns):
Expand Down Expand Up @@ -229,8 +235,7 @@ def insert_aligned_columns(df, columns):
if shared_index[:2] == df.index.names[:2]:
# Same pulse dimensions as the dataframe.
if num_per_pulse is None:
num_per_pulse = df.groupby(
level=df.index.names[:-1]).size()
num_per_pulse = df.groupby(level=df.index.names).size()

align = num_per_pulse

Expand Down Expand Up @@ -386,8 +391,7 @@ def signals(self, pulse_dim='pulseId', extra_columns={}, max_method=None):

df = self._build_reduced_pd(
(kd := self._instrument_src['rec.signals']).ndarray(),
self._align_pulse_index(kd, pulse_dim), 'signalIndex',
mask_func)
self._align_pulse_index(kd, pulse_dim), None, mask_func)

if extra_columns:
self.insert_aligned_columns(df, extra_columns)
Expand Down Expand Up @@ -427,8 +431,7 @@ def hits(self, pulse_dim='pulseId', extra_columns={}, max_method=None):

df = self._build_reduced_pd(
(kd := self._instrument_src['rec.hits']).ndarray(),
self._align_pulse_index(kd, pulse_dim), 'hitIndex',
mask_func)
self._align_pulse_index(kd, pulse_dim), None, mask_func)

if extra_columns:
self.insert_aligned_columns(df, extra_columns)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_components_adq.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_train_edges(mock_sqs_remi_run):

assert isinstance(df, pd.DataFrame)
np.testing.assert_array_equal(df.columns, ['edge', 'amplitude'])
np.testing.assert_array_equal(df.index.names, ['trainId', 'edgeIndex'])
np.testing.assert_array_equal(df.index.name, 'trainId')
assert len(df) == 100

np.testing.assert_allclose(df['edge'], 8944.0)
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_pulse_edges(mock_sqs_remi_run):
assert isinstance(df, pd.DataFrame)
np.testing.assert_array_equal(df.columns, ['edge', 'amplitude'])
np.testing.assert_array_equal(
df.index.names, ['trainId', 'pulseId', 'edgeIndex'])
df.index.names, ['trainId', 'pulseId'])
assert len(df) == 40

np.testing.assert_array_equal(
Expand Down
3 changes: 1 addition & 2 deletions tests/test_components_dld.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def test_dld_df(mock_sqs_remi_run, key, pulse_dim):
df = getattr(dld, f'{key}s')(pulse_dim)

assert (df.columns == list(dtype.names)).all()
assert df.index.names == [
'trainId', pulse_dim, 'fel', 'ppl', f'{key}Index']
assert df.index.names == ['trainId', pulse_dim, 'fel', 'ppl']

# Check counts per pulse, should be a repeating pattern of 1-4.
np.testing.assert_equal(
Expand Down