-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cddd003
commit 0577a8d
Showing
4 changed files
with
105 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
""" | ||
File loading functions for ISIS data, NOT using Mantid. | ||
""" | ||
from typing import NewType | ||
|
||
import scipp as sc | ||
|
||
PixelMaskFilename = NewType('PixelMaskFilename', str) | ||
|
||
|
||
MaskedDetectorIDs = NewType('MaskedDetectorIDs', sc.Variable) | ||
"""1-D variable listing all masked detector IDs.""" | ||
|
||
|
||
def read_xml_detector_masking(filename: PixelMaskFilename) -> MaskedDetectorIDs: | ||
"""Read a pixel mask from an XML file. | ||
The format is as follows, where the detids are inclusive ranges of detector IDs: | ||
<?xml version="1.0"?> | ||
<detector-masking> | ||
<group> | ||
<detids>1400203-1400218,1401199,1402190-1402223</detids> | ||
</group> | ||
</detector-masking> | ||
Parameters | ||
---------- | ||
filename: | ||
Path to the XML file. | ||
""" | ||
import xml.etree.ElementTree as ET # nosec | ||
|
||
tree = ET.parse(filename) # nosec | ||
root = tree.getroot() | ||
|
||
masked_detids = [] | ||
for group in root.findall('group'): | ||
for detids in group.findall('detids'): | ||
for detid in detids.text.split(','): | ||
detid = detid.strip() | ||
if '-' in detid: | ||
start, stop = detid.split('-') | ||
masked_detids += list(range(int(start), int(stop) + 1)) | ||
else: | ||
masked_detids.append(int(detid)) | ||
|
||
return MaskedDetectorIDs( | ||
sc.array(dims=['detector_id'], values=masked_detids, unit=None, dtype='int32') | ||
) | ||
|
||
|
||
providers = (read_xml_detector_masking,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters