source: sasview/DataLoader/data_info.py @ ea5551f

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ea5551f was a3084ada, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Reduction file data class

  • Property mode set to 100644
File size: 6.4 KB
Line 
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"""
12This software was developed by the University of Tennessee as part of the
13Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
14project funded by the US National Science Foundation.
15
16See the license text in license.txt
17
18copyright 2008, University of Tennessee
19"""
20
21from sans.guitools.plottables import Data1D as plottable_1D
22
23 
24class 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
52class 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
71class 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
82class 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"""
104NEUTRON  = 'neutron'
105XRAY     = 'x-ray'
106MUON     = 'muon'
107ELECTRON = 'electron'
108   
109class 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 
129class 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       
189class 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
Note: See TracBrowser for help on using the repository browser.