1
2
3 """
4 Load a NeXus file into a reflectometry data structure.
5 """
6 import os
7
8 from reflectometry.reduction import refldata, nexus
9
11 """
12 Load the summary info for all entries in a NeXus file.
13 """
14 tree = nexus.read(filename)
15 measurements = []
16 for name,entry in tree.nodes():
17 if entry.nxclass == 'NXentry':
18 measurements.append(NeXusRefl(entry,filename))
19 return measurements
20
21
23 """
24 NeXus reflectometry entry.
25
26 See `reflectometry.reduction.refldata.ReflData` for details.
27 """
28 format = "NeXus"
29
44
45
50
52 """
53 Slit names have not been standardized. Instead sort the
54 NXaperature components by distance and assign them according
55 to serial order, negative aperatures first and positive second.
56 """
57 slits = instrument.find('NXaperature')
58
59
60
61
62
63
64
65
66 slits.sort(lambda a,b: -1 if a.distance < b.distance else 1)
67 index = 0
68 for slit in slits:
69 d = slit.distance.value('meters')
70 if d <= 0:
71
72 if index == 0:
73 self.slit1.distance = d
74 index += 1
75 elif index == 1:
76 self.slit2.distance = d
77 index += 1
78 elif d > 0:
79
80 if index < 2: index = 2
81 if index == 2:
82 self.slit3.distance = d
83 index += 1
84 elif index == 3:
85 self.slit4.distance = d
86 index += 1
87
89 entry = self.entry
90 self.instrument = entry.NXinstrument.name.value
91 self.probe = 'neutron'
92
93
94 self.monitor.source_power_units = 'coulombs'
95 self.monitor.source_power \
96 = entry.proton_charge.read(self.monitor.source_power_units)
97 self.monitor.count_time = entry.duration.read('seconds')
98 self.monitor.base = 'power'
99
100
101
102
103
104
105
106
107
108 sample = entry.NXsample
109 self.sample.description = sample.name.value
110
111
112
113
114
115
116 instrument = entry.NXinstrument
117 self._load_slits(instrument)
118 moderator = instrument.NXmoderator
119 self.moderator.distance = moderator.distance.read('meters')
120 self.moderator.type = moderator.type.value
121 self.moderator.temperature = moderator.temperature.read('kelvin')
122