|
13 | 13 | but it is not possible to reshape the data into all the logical dimensions. |
14 | 14 | """ |
15 | 15 |
|
16 | | -import scipp as sc |
17 | | -from ess.reduce import nexus |
18 | | - |
19 | | -from ess.powder.types import ( |
20 | | - Filename, |
21 | | - LoadedNeXusDetector, |
22 | | - NeXusDetectorName, |
23 | | - RawDetectorData, |
24 | | - RawSample, |
25 | | - RawSource, |
26 | | - ReducibleDetectorData, |
27 | | - RunType, |
28 | | - SamplePosition, |
29 | | - SourcePosition, |
30 | | -) |
| 16 | +from ess import powder |
31 | 17 |
|
32 | 18 | DETECTOR_BANK_SIZES = { |
33 | 19 | "endcap_backward_detector": { |
|
51 | 37 | "strip": 256, |
52 | 38 | "counter": 2, |
53 | 39 | }, |
54 | | - "high_resolution_detector": { |
55 | | - "strip": 32, |
56 | | - "other": -1, |
57 | | - }, |
| 40 | + "high_resolution_detector": {"strip": 32, "other": -1}, |
58 | 41 | "sans_detector": lambda x: x.fold( |
59 | 42 | dim="detector_number", |
60 | | - sizes={ |
61 | | - "strip": 32, |
62 | | - "other": -1, |
63 | | - }, |
| 43 | + sizes={"strip": 32, "other": -1}, |
64 | 44 | ), |
65 | 45 | } |
66 | 46 |
|
67 | 47 |
|
68 | | -def load_nexus_sample(file_path: Filename[RunType]) -> RawSample[RunType]: |
69 | | - return RawSample[RunType](nexus.load_sample(file_path)) |
70 | | - |
71 | | - |
72 | | -def dummy_load_sample(file_path: Filename[RunType]) -> RawSample[RunType]: |
73 | | - """ |
74 | | - In test files there is not always a sample, so we need a dummy. |
75 | | - """ |
76 | | - return RawSample[RunType]( |
77 | | - sc.DataGroup({'position': sc.vector(value=[0, 0, 0], unit='m')}) |
78 | | - ) |
79 | | - |
80 | | - |
81 | | -def load_nexus_source(file_path: Filename[RunType]) -> RawSource[RunType]: |
82 | | - return RawSource[RunType](nexus.load_source(file_path)) |
83 | | - |
84 | | - |
85 | | -def load_nexus_detector( |
86 | | - file_path: Filename[RunType], detector_name: NeXusDetectorName |
87 | | -) -> LoadedNeXusDetector[RunType]: |
88 | | - out = nexus.load_detector(file_path=file_path, detector_name=detector_name) |
89 | | - out.pop("pixel_shape", None) |
90 | | - return LoadedNeXusDetector[RunType](out) |
91 | | - |
92 | | - |
93 | | -def get_source_position( |
94 | | - raw_source: RawSource[RunType], |
95 | | -) -> SourcePosition[RunType]: |
96 | | - return SourcePosition[RunType](raw_source["position"]) |
97 | | - |
98 | | - |
99 | | -def get_sample_position( |
100 | | - raw_sample: RawSample[RunType], |
101 | | -) -> SamplePosition[RunType]: |
102 | | - return SamplePosition[RunType](raw_sample["position"]) |
103 | | - |
104 | | - |
105 | | -def get_detector_data( |
106 | | - detector: LoadedNeXusDetector[RunType], |
107 | | - detector_name: NeXusDetectorName, |
108 | | -) -> RawDetectorData[RunType]: |
109 | | - da = nexus.extract_detector_data(detector) |
110 | | - if detector_name in DETECTOR_BANK_SIZES: |
111 | | - da = da.fold(dim="detector_number", sizes=DETECTOR_BANK_SIZES[detector_name]) |
112 | | - return RawDetectorData[RunType](da) |
113 | | - |
114 | | - |
115 | | -def patch_detector_data( |
116 | | - detector_data: RawDetectorData[RunType], |
117 | | - source_position: SourcePosition[RunType], |
118 | | - sample_position: SamplePosition[RunType], |
119 | | -) -> ReducibleDetectorData[RunType]: |
120 | | - """ |
121 | | - Patch a detector data object with source and sample positions. |
122 | | - Also adds variances to the event data if they are missing. |
123 | | - """ |
124 | | - out = detector_data.copy(deep=False) |
125 | | - if out.bins is not None: |
126 | | - content = out.bins.constituents["data"] |
127 | | - if content.variances is None: |
128 | | - content.variances = content.values |
129 | | - out.coords["sample_position"] = sample_position |
130 | | - out.coords["source_position"] = source_position |
131 | | - return ReducibleDetectorData[RunType](out) |
| 48 | +def dream_detector_bank_sizes() -> powder.types.DetectorBankSizes | None: |
| 49 | + return powder.types.DetectorBankSizes(DETECTOR_BANK_SIZES) |
132 | 50 |
|
133 | 51 |
|
134 | | -providers = ( |
135 | | - load_nexus_sample, |
136 | | - load_nexus_source, |
137 | | - load_nexus_detector, |
138 | | - get_source_position, |
139 | | - get_sample_position, |
140 | | - get_detector_data, |
141 | | - patch_detector_data, |
142 | | -) |
| 52 | +providers = (*powder.nexus.providers, dream_detector_bank_sizes) |
143 | 53 | """ |
144 | | -Providers for loading and processing DREAM NeXus data. |
| 54 | +Providers for loading and processing NeXus data. |
145 | 55 | """ |
0 commit comments