Skip to content

Commit 158f421

Browse files
committed
Do not strip suffixes from suggested internal names
Suffixes like '_r0', '_t0' etc. represent transformation chains in NeXus, not arbitrary naming conventions. These should be preserved in the suggested internal names. Changes: - Remove regex-based suffix stripping from suggest_internal_name() - Update docstring to remove misleading example about suffix removal - Rename tests test_removes_r0_suffix → test_preserves_r0_suffix - Rename tests test_removes_t0_suffix → test_preserves_t0_suffix - Update test expectations to preserve suffixes Note: The bifrost f144_log_streams configuration was generated with the old code that stripped suffixes. However, examining the current stream names (attenuator_1, temperature_0, etc.), none appear to match the pattern '_[rt]\d+$' that was being stripped, so no regeneration is needed at this time. If the original NeXus file contained streams with '_r0' or '_t0' suffixes, they would need to be regenerated to ensure accuracy. Original prompt: Please use a worktree and address the suffix-removal problem discussed in #589 (do not strip _r0 and the like, since it refers to "rotation 0", in fact do not strip any suffixes). Do we need to rerun the scripts that were used to generate the dict of names for bifrost?
1 parent d007bd4 commit 158f421

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/ess/livedata/nexus_helpers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,14 @@ def suggest_internal_name(info: StreamInfo) -> str:
125125
"""Suggest an internal name based on the group path.
126126
127127
Uses the parent group name (last path component before 'value', 'idle_flag', etc.)
128-
as the basis for the internal name, converting to snake_case.
128+
as the basis for the internal name.
129129
"""
130130
parts = info.group_path.split('/')
131131
# For paths like '.../rotation_stage/value', use 'rotation_stage'
132-
# For paths like '.../detector_tank_angle_r0/value', use 'detector_tank_angle'
133132
for i, part in enumerate(parts):
134133
if part in ('value', 'idle_flag', 'target_value'):
135134
if i > 0:
136-
name = parts[i - 1]
137-
# Remove common suffixes like '_r0', '_01' etc.
138-
name = re.sub(r'_[rt]\d+$', '', name)
139-
return name
135+
return parts[i - 1]
140136
# Fallback: use last non-value component
141137
return parts[-2] if len(parts) >= 2 else parts[-1]
142138

tests/nexus_helpers_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def test_extracts_name_before_idle_flag(self) -> None:
424424
)
425425
assert suggest_internal_name(info) == 'rotation_stage'
426426

427-
def test_removes_r0_suffix(self) -> None:
427+
def test_preserves_r0_suffix(self) -> None:
428428
info = StreamInfo(
429429
group_path='entry/instrument/detector_tank_angle_r0/value',
430430
topic='motion',
@@ -433,9 +433,9 @@ def test_removes_r0_suffix(self) -> None:
433433
parent_nx_class='NXpositioner',
434434
writer_module='f144',
435435
)
436-
assert suggest_internal_name(info) == 'detector_tank_angle'
436+
assert suggest_internal_name(info) == 'detector_tank_angle_r0'
437437

438-
def test_removes_t0_suffix(self) -> None:
438+
def test_preserves_t0_suffix(self) -> None:
439439
info = StreamInfo(
440440
group_path='entry/instrument/sample_stage_t0/value',
441441
topic='motion',
@@ -444,7 +444,7 @@ def test_removes_t0_suffix(self) -> None:
444444
parent_nx_class='NXpositioner',
445445
writer_module='f144',
446446
)
447-
assert suggest_internal_name(info) == 'sample_stage'
447+
assert suggest_internal_name(info) == 'sample_stage_t0'
448448

449449

450450
class TestFilterF144Streams:

0 commit comments

Comments
 (0)