1 | """ |
---|
2 | Module that contains classes to hold information read from |
---|
3 | reduced data files. |
---|
4 | |
---|
5 | A good description of the data members can be found in |
---|
6 | the CanSAS 1D XML data format: |
---|
7 | |
---|
8 | http://www.smallangles.net/wgwiki/index.php/cansas1d_documentation |
---|
9 | """ |
---|
10 | |
---|
11 | """ |
---|
12 | This software was developed by the University of Tennessee as part of the |
---|
13 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
14 | project funded by the US National Science Foundation. |
---|
15 | |
---|
16 | See the license text in license.txt |
---|
17 | |
---|
18 | copyright 2008, University of Tennessee |
---|
19 | """ |
---|
20 | |
---|
21 | from sans.guitools.plottables import Data1D as plottable_1D |
---|
22 | |
---|
23 | |
---|
24 | class Vector: |
---|
25 | """ |
---|
26 | Vector class to hold multi-dimensional objects |
---|
27 | """ |
---|
28 | ## x component |
---|
29 | x = None |
---|
30 | ## y component |
---|
31 | y = None |
---|
32 | ## z component |
---|
33 | z = None |
---|
34 | |
---|
35 | def __init__(self, x=None, y=None, z=None): |
---|
36 | """ |
---|
37 | Initialization. Components that are not |
---|
38 | set a set to None by default. |
---|
39 | |
---|
40 | @param x: x component |
---|
41 | @param y: y component |
---|
42 | @param z: z component |
---|
43 | """ |
---|
44 | self.x = x |
---|
45 | self.y = y |
---|
46 | self.z = z |
---|
47 | |
---|
48 | def __str__(self): |
---|
49 | return "x = %s\ty = %s\tz = %s" % (str(self.x), str(self.y), str(self.z)) |
---|
50 | |
---|
51 | |
---|
52 | class Detector: |
---|
53 | """ |
---|
54 | Class to hold detector information |
---|
55 | """ |
---|
56 | ## Name of the instrument [string] |
---|
57 | name = '' |
---|
58 | ## Sample to detector distance [float] [mm] |
---|
59 | distance = None |
---|
60 | ## Offset of this detector position in X, Y, (and Z if necessary) [Vector] [mm] |
---|
61 | offset = Vector() |
---|
62 | ## Orientation (rotation) of this detector in roll, pitch, and yaw [Vector] [degrees] |
---|
63 | orientation = Vector() |
---|
64 | ## Center of the beam on the detector in X and Y (and Z if necessary) [Vector] [pixel] |
---|
65 | beam_center = Vector() |
---|
66 | ## Pixel size in X, Y, (and Z if necessary) [Vector] [mm] |
---|
67 | pixel_size = Vector() |
---|
68 | ## Slit length of the instrument for this detector.[float] [mm] |
---|
69 | slit_length = None |
---|
70 | |
---|
71 | class Collimation: |
---|
72 | """ |
---|
73 | Class to hold collimation information |
---|
74 | """ |
---|
75 | ## Length [float] [mm] |
---|
76 | length = None |
---|
77 | ## Aperture size [Vector] [mm] |
---|
78 | aperture_size = Vector() |
---|
79 | ## Aperture distance [float] [m] |
---|
80 | aperture_distance = None |
---|
81 | |
---|
82 | class Source: |
---|
83 | """ |
---|
84 | Class to hold source information |
---|
85 | """ |
---|
86 | ## Radiation type [string] |
---|
87 | radiation = '' |
---|
88 | ## Beam size [Vector] [mm] |
---|
89 | beam_size = Vector() |
---|
90 | ## Beam shape [string] |
---|
91 | beam_shape = '' |
---|
92 | ## Wavelength [float] [Angstrom] |
---|
93 | wavelength = None |
---|
94 | ## Minimum wavelength [float] [Angstrom] |
---|
95 | wavelength_min = None |
---|
96 | ## Maximum wavelength [float] [Angstrom] |
---|
97 | wavelength_max = None |
---|
98 | ## Wavelength spread [float] [Angstrom] |
---|
99 | wavelength_spread = None |
---|
100 | |
---|
101 | """ |
---|
102 | Definitions of radiation types |
---|
103 | """ |
---|
104 | NEUTRON = 'neutron' |
---|
105 | XRAY = 'x-ray' |
---|
106 | MUON = 'muon' |
---|
107 | ELECTRON = 'electron' |
---|
108 | |
---|
109 | class Sample: |
---|
110 | """ |
---|
111 | Class to hold the sample description |
---|
112 | """ |
---|
113 | ## ID |
---|
114 | ID = '' |
---|
115 | ## Thickness [float] [mm] |
---|
116 | thickness = None |
---|
117 | ## Transmission [float] [%] |
---|
118 | transmission = None |
---|
119 | ## Temperature [float] [C] |
---|
120 | temperature = None |
---|
121 | ## Position [Vector] [mm] |
---|
122 | position = Vector() |
---|
123 | ## Orientation [Vector] [degrees] |
---|
124 | orientation = Vector() |
---|
125 | ## Details |
---|
126 | details = '' |
---|
127 | |
---|
128 | |
---|
129 | class DataInfo: |
---|
130 | """ |
---|
131 | Class to hold the data read from a file. |
---|
132 | It includes four blocks of data for the |
---|
133 | instrument description, the sample description, |
---|
134 | the data itself and any other meta data. |
---|
135 | """ |
---|
136 | ## Run number |
---|
137 | run = None |
---|
138 | ## File name |
---|
139 | filename = '' |
---|
140 | ## Notes |
---|
141 | notes = '' |
---|
142 | ## Processes (Action on the data) |
---|
143 | process = [] |
---|
144 | ## Detector information |
---|
145 | detector = Detector() |
---|
146 | ## Sample information |
---|
147 | sample = Sample() |
---|
148 | ## Source information |
---|
149 | source = Source() |
---|
150 | ## Additional meta-data |
---|
151 | meta_data = {} |
---|
152 | |
---|
153 | def __add__(self, data): |
---|
154 | """ |
---|
155 | Add two data sets |
---|
156 | |
---|
157 | @param data: data set to add to the current one |
---|
158 | @return: new data set |
---|
159 | @raise ValueError: raised when two data sets are incompatible |
---|
160 | """ |
---|
161 | raise RuntimeError, "DataInfo addition is not implemented yet" |
---|
162 | |
---|
163 | def __sub__(self, data): |
---|
164 | """ |
---|
165 | Subtract two data sets |
---|
166 | |
---|
167 | @param data: data set to subtract from the current one |
---|
168 | @return: new data set |
---|
169 | @raise ValueError: raised when two data sets are incompatible |
---|
170 | """ |
---|
171 | raise RuntimeError, "DataInfo subtraction is not implemented yet" |
---|
172 | |
---|
173 | def __mul__(self, constant): |
---|
174 | """ |
---|
175 | Multiply every entry of the current data set by a constant |
---|
176 | |
---|
177 | @param constant: constant to multiply the data by |
---|
178 | @return: new data set |
---|
179 | @raise ValueError: raised when the constant is not a float |
---|
180 | """ |
---|
181 | raise RuntimeError, "DataInfo multiplication is not implemented yet" |
---|
182 | |
---|
183 | def __div__(self, constant): |
---|
184 | """ |
---|
185 | """ |
---|
186 | raise RuntimeError, "DataInfo division is not implemented yet" |
---|
187 | |
---|
188 | |
---|
189 | class Data1D(plottable_1D, DataInfo): |
---|
190 | """ |
---|
191 | 1D data class |
---|
192 | """ |
---|
193 | def __init__(self, x, y, dx=None, dy=None): |
---|
194 | plottable_1D.__init__(self, x, y, dx, dy) |
---|
195 | |
---|
196 | def __str__(self): |
---|
197 | """ |
---|
198 | Nice printout |
---|
199 | """ |
---|
200 | _str = "File: %s\n" % self.filename |
---|
201 | |
---|
202 | _str += "Sample:\n" |
---|
203 | _str += " Transmission: %s\n" % str(self.sample.transmission) |
---|
204 | _str += " Thickness: %s\n" % str(self.sample.thickness) |
---|
205 | |
---|
206 | _str += "Source:\n" |
---|
207 | _str += " Wavelength: %s [A]\n" % str(self.source.wavelength) |
---|
208 | |
---|
209 | _str += "Detector:\n" |
---|
210 | _str += " Name: %s\n" % self.detector.name |
---|
211 | _str += " Distance: %s [mm]\n" % str(self.detector.distance) |
---|
212 | _str += " Beam_center: %s [pixel]\n" % str(self.detector.beam_center) |
---|
213 | |
---|
214 | _str += "Data:\n" |
---|
215 | _str += " Type: %s\n" % self.__class__.__name__ |
---|
216 | _str += " X-axis: %s\t[%s]\n" % (self._xaxis, self._xunit) |
---|
217 | _str += " Y-axis: %s\t[%s]\n" % (self._yaxis, self._yunit) |
---|
218 | _str += " Length: %g\n" % len(self.x) |
---|
219 | |
---|
220 | return _str |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | |
---|