Skip to content

Load SUMO coordinate from GEANT4 CSV files #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
5 changes: 5 additions & 0 deletions src/ess/dream/io/geant4.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _load_raw_events(file_path: str) -> sc.DataArray:
table = sc.io.load_csv(
file_path, sep="\t", header_parser="bracket", data_columns=[]
)
table.coords['sumo'] = table.coords['det ID']
table.coords.pop("lambda", None)
table = table.rename_dims(row="event")
return sc.DataArray(
Expand All @@ -90,10 +91,14 @@ def group(key: str, da: sc.DataArray) -> sc.DataArray:
if key in ["high_resolution", "sans"]:
# Only the HR and SANS detectors have sectors.
res = da.group("sector", *elements)
elif key in ["endcap_backward", "endcap_forward"]:
# Other banks only have a single SUMO.
res = da.group("sumo", *elements)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if other banks only have a single SUMO, we can still group them by SUMO, no...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. But that would be the use? This extra dimension would get in the way of plotting and would always have to be sliced out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure how many times we have to filter the endcap for this reason.
If it's not in many places, I think not-grouping is fine.

else:
res = da.group(*elements)
res.coords['position'] = res.bins.coords.pop('position').bins.mean()
res.bins.coords.pop("sector", None)
res.bins.coords.pop("sumo", None)
return res

return {key: sc.DataGroup(events=group(key, da)) for key, da in detectors.items()}
Expand Down
11 changes: 9 additions & 2 deletions tests/dream/geant4_reduction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ def test_workflow_is_deterministic(workflow):

def test_pipeline_can_compute_intermediate_results(workflow):
workflow = powder.with_pixel_mask_filenames(workflow, [])
result = workflow.compute(NormalizedByProtonCharge[SampleRun])
assert set(result.dims) == {'segment', 'wire', 'counter', 'strip', 'module'}
results = workflow.compute((NormalizedByProtonCharge[SampleRun], NeXusDetectorName))
result = results[NormalizedByProtonCharge[SampleRun]]

detector_name = results[NeXusDetectorName]
expected_dims = {'segment', 'wire', 'counter', 'strip', 'module'}
if detector_name in ('endcap_backward', 'endcap_forward'):
expected_dims.add('sumo')

assert set(result.dims) == expected_dims


def test_pipeline_group_by_two_theta(workflow):
Expand Down
5 changes: 5 additions & 0 deletions tests/dream/io/geant4_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_load_geant4_csv_mantle_has_expected_coords(file):
assert_index_coord(mantle.coords["wire"], values=set(range(1, 33)))
assert_index_coord(mantle.coords["strip"], values=set(range(1, 257)))
assert "sector" not in mantle.coords
assert "sumo" not in mantle.coords

assert "sector" not in mantle.bins.coords
assert "tof" in mantle.bins.coords
Expand All @@ -127,6 +128,7 @@ def test_load_geant4_csv_endcap_backward_has_expected_coords(file):
assert_index_coord(endcap.coords["counter"])
assert_index_coord(endcap.coords["wire"], values=set(range(1, 17)))
assert_index_coord(endcap.coords["strip"], values=set(range(1, 17)))
assert_index_coord(endcap.coords["sumo"], values=set(range(3, 7)))
assert "sector" not in endcap.coords

assert "sector" not in endcap.bins.coords
Expand All @@ -141,6 +143,7 @@ def test_load_geant4_csv_endcap_forward_has_expected_coords(file):
assert_index_coord(endcap.coords["counter"])
assert_index_coord(endcap.coords["wire"], values=set(range(1, 17)))
assert_index_coord(endcap.coords["strip"], values=set(range(1, 17)))
assert_index_coord(endcap.coords["sumo"], values=set(range(3, 7)))
assert "sector" not in endcap.coords

assert "sector" not in endcap.bins.coords
Expand All @@ -156,6 +159,7 @@ def test_load_geant4_csv_high_resolution_has_expected_coords(file):
assert_index_coord(hr.coords["wire"], values=set(range(1, 17)))
assert_index_coord(hr.coords["strip"], values=set(range(1, 33)))
assert_index_coord(hr.coords["sector"], values=set(range(1, 5)))
assert "sumo" not in hr.coords

assert "tof" in hr.bins.coords
assert "position" in hr.coords
Expand All @@ -172,6 +176,7 @@ def test_load_geant4_csv_sans_has_expected_coords(file):
assert_index_coord(sans.coords["wire"], values=set(range(1, 17)))
assert_index_coord(sans.coords["strip"], values=set(range(1, 33)))
assert_index_coord(sans.coords["sector"], values=set(range(1, 5)))
assert "sumo" not in sans.coords

assert "tof" in sans.bins.coords
assert "position" in sans.coords
Expand Down