Changeset 99d1af6 in sasview


Ignore:
Timestamp:
Aug 5, 2008 10:25:15 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
b99ac227
Parents:
37d9521
Message:

Update to readers, with unit conversion

Location:
DataLoader
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/data_info.py

    rb39c817 r99d1af6  
    2626import math 
    2727 
    28 class Data2D: 
     28class plottable_2D: 
    2929    """ 
    3030        Data2D is a place holder for 2D plottables, which are  
     
    3535    ymin = None 
    3636    ymax = None 
    37     image = None 
    38    
     37    data = None 
     38    err_data = None 
     39     
     40    # Units 
     41    _xaxis = '' 
     42    _xunit = '' 
     43    _yaxis = '' 
     44    _yunit = '' 
     45    _zaxis = '' 
     46    _zunit = '' 
     47     
     48    def __init__(self, data=None, err_data=None): 
     49        self.data = data 
     50        self.err_data = err_data 
     51         
     52    def xaxis(self, label, unit): 
     53        self._xaxis = label 
     54        self._xunit = unit 
     55         
     56    def yaxis(self, label, unit): 
     57        self._yaxis = label 
     58        self._yunit = unit 
     59             
     60    def zaxis(self, label, unit): 
     61        self._zaxis = label 
     62        self._zunit = unit 
     63             
    3964class Vector: 
    4065    """ 
     
    80105    orientation = Vector() 
    81106    orientation_unit = 'degree' 
    82     ## Center of the beam on the detector in X and Y (and Z if necessary) [Vector] [pixel] 
     107    ## Center of the beam on the detector in X and Y (and Z if necessary) [Vector] [mm] 
    83108    beam_center = Vector() 
    84109    beam_center_unit = 'mm' 
     
    282307    errors = [] 
    283308             
    284     # Private method to perform operation. Not implemented for DataInfo, 
    285     # but should be implemented for each data class inherited from DataInfo 
    286     # that holds actual data (ex.: Data1D) 
    287     def _perform_operation(self, other, operation): return NotImplemented 
    288  
    289     def __add__(self, other): 
    290         """ 
    291             Add two data sets 
    292              
    293             @param other: data set to add to the current one 
    294             @return: new data set 
    295             @raise ValueError: raised when two data sets are incompatible 
    296         """ 
    297         def operation(a, b): return a+b 
    298         return self._perform_operation(other, operation) 
    299          
    300     def __radd__(self, other): 
    301         """ 
    302             Add two data sets 
    303              
    304             @param other: data set to add to the current one 
    305             @return: new data set 
    306             @raise ValueError: raised when two data sets are incompatible 
    307         """ 
    308         def operation(a, b): return b+a 
    309         return self._perform_operation(other, operation) 
    310          
    311     def __sub__(self, other): 
    312         """ 
    313             Subtract two data sets 
    314              
    315             @param other: data set to subtract from the current one 
    316             @return: new data set 
    317             @raise ValueError: raised when two data sets are incompatible 
    318         """ 
    319         def operation(a, b): return a-b 
    320         return self._perform_operation(other, operation) 
    321          
    322     def __rsub__(self, other): 
    323         """ 
    324             Subtract two data sets 
    325              
    326             @param other: data set to subtract from the current one 
    327             @return: new data set 
    328             @raise ValueError: raised when two data sets are incompatible 
    329         """ 
    330         def operation(a, b): return b-a 
    331         return self._perform_operation(other, operation) 
    332          
    333     def __mul__(self, other): 
    334         """ 
    335             Multiply two data sets 
    336              
    337             @param other: data set to subtract from the current one 
    338             @return: new data set 
    339             @raise ValueError: raised when two data sets are incompatible 
    340         """ 
    341         def operation(a, b): return a*b 
    342         return self._perform_operation(other, operation) 
    343          
    344     def __rmul__(self, other): 
    345         """ 
    346             Multiply two data sets 
    347              
    348             @param other: data set to subtract from the current one 
    349             @return: new data set 
    350             @raise ValueError: raised when two data sets are incompatible 
    351         """ 
    352         def operation(a, b): return b*a 
    353         return self._perform_operation(other, operation) 
    354          
    355     def __div__(self, other): 
    356         """ 
    357             Divided a data set by another 
    358              
    359             @param other: data set that the current one is divided by 
    360             @return: new data set 
    361             @raise ValueError: raised when two data sets are incompatible 
    362         """ 
    363         def operation(a, b): return a/b 
    364         return self._perform_operation(other, operation) 
    365          
    366     def __rdiv__(self, other): 
    367         """ 
    368             Divided a data set by another 
    369              
    370             @param other: data set that the current one is divided by 
    371             @return: new data set 
    372             @raise ValueError: raised when two data sets are incompatible 
    373         """ 
    374         def operation(a, b): return b/a 
    375         return self._perform_operation(other, operation)             
    376              
    377 class Data1D(plottable_1D, DataInfo): 
    378     """ 
    379         1D data class 
    380     """ 
    381     x_unit = '1/A' 
    382     y_unit = '1/cm' 
    383      
    384     def __init__(self, x, y, dx=None, dy=None): 
    385         plottable_1D.__init__(self, x, y, dx, dy) 
    386          
    387309    def __str__(self): 
    388310        """ 
     
    403325        for item in self.notes: 
    404326            _str += "%s\n" % str(item) 
    405          
     327 
     328        return _str 
     329             
     330    # Private method to perform operation. Not implemented for DataInfo, 
     331    # but should be implemented for each data class inherited from DataInfo 
     332    # that holds actual data (ex.: Data1D) 
     333    def _perform_operation(self, other, operation): return NotImplemented 
     334 
     335    def __add__(self, other): 
     336        """ 
     337            Add two data sets 
     338             
     339            @param other: data set to add to the current one 
     340            @return: new data set 
     341            @raise ValueError: raised when two data sets are incompatible 
     342        """ 
     343        def operation(a, b): return a+b 
     344        return self._perform_operation(other, operation) 
     345         
     346    def __radd__(self, other): 
     347        """ 
     348            Add two data sets 
     349             
     350            @param other: data set to add to the current one 
     351            @return: new data set 
     352            @raise ValueError: raised when two data sets are incompatible 
     353        """ 
     354        def operation(a, b): return b+a 
     355        return self._perform_operation(other, operation) 
     356         
     357    def __sub__(self, other): 
     358        """ 
     359            Subtract two data sets 
     360             
     361            @param other: data set to subtract from the current one 
     362            @return: new data set 
     363            @raise ValueError: raised when two data sets are incompatible 
     364        """ 
     365        def operation(a, b): return a-b 
     366        return self._perform_operation(other, operation) 
     367         
     368    def __rsub__(self, other): 
     369        """ 
     370            Subtract two data sets 
     371             
     372            @param other: data set to subtract from the current one 
     373            @return: new data set 
     374            @raise ValueError: raised when two data sets are incompatible 
     375        """ 
     376        def operation(a, b): return b-a 
     377        return self._perform_operation(other, operation) 
     378         
     379    def __mul__(self, other): 
     380        """ 
     381            Multiply two data sets 
     382             
     383            @param other: data set to subtract from the current one 
     384            @return: new data set 
     385            @raise ValueError: raised when two data sets are incompatible 
     386        """ 
     387        def operation(a, b): return a*b 
     388        return self._perform_operation(other, operation) 
     389         
     390    def __rmul__(self, other): 
     391        """ 
     392            Multiply two data sets 
     393             
     394            @param other: data set to subtract from the current one 
     395            @return: new data set 
     396            @raise ValueError: raised when two data sets are incompatible 
     397        """ 
     398        def operation(a, b): return b*a 
     399        return self._perform_operation(other, operation) 
     400         
     401    def __div__(self, other): 
     402        """ 
     403            Divided a data set by another 
     404             
     405            @param other: data set that the current one is divided by 
     406            @return: new data set 
     407            @raise ValueError: raised when two data sets are incompatible 
     408        """ 
     409        def operation(a, b): return a/b 
     410        return self._perform_operation(other, operation) 
     411         
     412    def __rdiv__(self, other): 
     413        """ 
     414            Divided a data set by another 
     415             
     416            @param other: data set that the current one is divided by 
     417            @return: new data set 
     418            @raise ValueError: raised when two data sets are incompatible 
     419        """ 
     420        def operation(a, b): return b/a 
     421        return self._perform_operation(other, operation)             
     422             
     423class Data1D(plottable_1D, DataInfo): 
     424    """ 
     425        1D data class 
     426    """ 
     427    x_unit = '1/A' 
     428    y_unit = '1/cm' 
     429     
     430    def __init__(self, x, y, dx=None, dy=None): 
     431        plottable_1D.__init__(self, x, y, dx, dy) 
     432         
     433    def __str__(self): 
     434        """ 
     435            Nice printout 
     436        """ 
     437        _str =  "%s\n" % DataInfo.__str__(self) 
     438     
    406439        _str += "Data:\n" 
    407440        _str += "   Type:         %s\n" % self.__class__.__name__ 
     
    502535        return result 
    503536         
     537class Data2D(plottable_2D, DataInfo): 
     538    """ 
     539        2D data class 
     540    """ 
     541    ## Units for Q-values 
     542    Q_unit = '1/A' 
     543     
     544    ## Units for I(Q) values 
     545    I_unit = '1/cm' 
     546     
     547    ## Vector of Q-values at the center of each bin in x 
     548    x_bins = [] 
     549     
     550    ## Vector of Q-values at the center of each bin in y 
     551    y_bins = [] 
     552     
     553     
     554    def __init__(self, data=None, err_data=None): 
     555        plottable_2D.__init__(self, data, err_data) 
     556 
     557    def __str__(self): 
     558        _str =  "%s\n" % DataInfo.__str__(self) 
     559         
     560        _str += "Data:\n" 
     561        _str += "   Type:         %s\n" % self.__class__.__name__ 
     562        _str += "   X- & Y-axis:  %s\t[%s]\n" % (self._yaxis, self._yunit) 
     563        _str += "   Z-axis:       %s\t[%s]\n" % (self._zaxis, self._zunit) 
     564        leny = 0 
     565        if len(self.data)>0: 
     566            leny = len(self.data[0]) 
     567        _str += "   Length:       %g x %g\n" % (len(self.data), leny) 
     568         
     569        return _str 
     570   
  • DataLoader/readers/abs_reader.py

    r8780e9a r99d1af6  
    1111import numpy 
    1212import os 
    13 from DataLoader.data_info import Data1D 
    14  
     13from DataLoader.data_info import Data1D, Detector 
     14 
     15has_converter = True 
     16try: 
     17    from data_util.nxsunit import Converter 
     18except: 
     19    has_converter = False 
     20     
    1521class Reader: 
    1622    """ 
     
    4551                dy = numpy.zeros(0) 
    4652                output = Data1D(x, y, dy=dy) 
     53                detector = Detector() 
     54                output.detector.append(detector) 
    4755                self.filename = output.filename = basename 
    4856                 
     
    5058                is_center = False 
    5159                is_data_started = False 
     60                 
     61                data_conv_q = None 
     62                data_conv_i = None 
     63                 
     64                if has_converter == True and output.x_unit != '1/A': 
     65                    data_conv_q = Converter('1/A') 
     66                    # Test it 
     67                    data_conv_q(1.0, output.x_unit) 
     68                     
     69                if has_converter == True and output.y_unit != '1/cm': 
     70                    data_conv_i = Converter('1/cm') 
     71                    # Test it 
     72                    data_conv_i(1.0, output.y_unit) 
    5273                 
    5374                for line in lines: 
     
    6081                        # Wavelength in Angstrom 
    6182                        try: 
    62                             output.source.wavelength = float(line_toks[1]) 
     83                            value = float(line_toks[1]) 
     84                            if has_converter==True and output.source.wavelength_unit != 'A': 
     85                                conv = Converter('A') 
     86                                output.source.wavelength = conv(value, units=output.source.wavelength_unit) 
     87                            else: 
     88                                output.source.wavelength = value 
    6389                        except: 
    6490                            raise ValueError,"IgorReader: can't read this file, missing wavelength" 
     
    6692                        # Distance in meters 
    6793                        try: 
    68                             output.detector.distance = float(line_toks[3])*1000.0 
     94                            value = float(line_toks[3]) 
     95                            if has_converter==True and detector.distance_unit != 'm': 
     96                                conv = Converter('m') 
     97                                detector.distance = conv(value, units=detector.distance_unit) 
     98                            else: 
     99                                detector.distance = value 
    69100                        except: 
    70101                            raise ValueError,"IgorReader: can't read this file, missing distance" 
    71102                         
    72                         # Transmission 
     103                        # Transmission  
    73104                        try: 
    74105                            output.sample.transmission = float(line_toks[4]) 
     
    77108                            pass 
    78109                     
    79                         # Thickness 
    80                         try: 
    81                             output.sample.thickness = float(line_toks[5]) 
     110                        # Thickness in mm 
     111                        try: 
     112                            value = float(line_toks[5]) 
     113                            if has_converter==True and output.sample.thickness_unit != 'mm': 
     114                                conv = Converter('mm') 
     115                                output.sample.thickness = conv(value, units=output.sample.thickness_unit) 
     116                            else: 
     117                                output.sample.thickness = value 
    82118                        except: 
    83119                            # Thickness is not a mandatory entry 
     
    95131                        center_x = float(line_toks[0]) 
    96132                        center_y = float(line_toks[1]) 
    97                         output.detector.beam_center.x = center_x 
    98                         output.detector.beam_center.y = center_y 
     133                         
     134                        # Bin size 
     135                        if has_converter==True and detector.pixel_size_unit != 'mm': 
     136                            conv = Converter('mm') 
     137                            detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 
     138                            detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 
     139                        else: 
     140                            detector.pixel_size.x = 5.0 
     141                            detector.pixel_size.y = 5.0 
     142                         
     143                        # Store beam center in distance units 
     144                        # Det 640 x 640 mm 
     145                        if has_converter==True and detector.beam_center_unit != 'mm': 
     146                            conv = Converter('mm') 
     147                            detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 
     148                            detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 
     149                        else: 
     150                            detector.beam_center.x = center_x*5.0 
     151                            detector.beam_center.y = center_y*5.0 
    99152                         
    100153                        # Detector type 
    101154                        try: 
    102                             output.detector.name = line_toks[7] 
     155                            detector.name = line_toks[7] 
    103156                        except: 
    104157                            # Detector name is not a mandatory entry 
     
    116169                            _y  = float(toks[1])  
    117170                            _dy = float(toks[2]) 
     171                             
     172                            if data_conv_q is not None: 
     173                                _x = data_conv_q(_x, units=output.x_unit) 
     174                                 
     175                            if data_conv_i is not None: 
     176                                _y = data_conv_i(_y, units=output.y_unit) 
     177                                _dy = data_conv_i(_dy, units=output.y_unit) 
    118178                            
    119179                            x  = numpy.append(x,   _x)  
     
    142202                output.y = y 
    143203                output.dy = dy 
    144                 output.xaxis("\\rm{Q}", 'A^{-1}') 
    145                 output.yaxis("\\rm{I(Q)}","cm^{-1}") 
     204                if data_conv_q is not None: 
     205                    output.xaxis("\\rm{Q}", output.x_unit) 
     206                else: 
     207                    output.xaxis("\\rm{Q}", 'A^{-1}') 
     208                if data_conv_i is not None: 
     209                    output.yaxis("\\{I(Q)}", output.y_unit) 
     210                else: 
     211                    output.yaxis("\\rm{I(Q)}","cm^{-1}") 
    146212                 
    147213                return output 
  • DataLoader/readers/ascii_reader.py

    r4d2a0d1 r99d1af6  
    1212import os 
    1313from DataLoader.data_info import Data1D 
     14 
     15has_converter = True 
     16try: 
     17    from data_util.nxsunit import Converter 
     18except: 
     19    has_converter = False 
    1420 
    1521class Reader: 
     
    4753                output = Data1D(x, y, dy=dy) 
    4854                self.filename = output.filename = basename 
     55            
     56                data_conv_q = None 
     57                data_conv_i = None 
     58                 
     59                if has_converter == True and output.x_unit != '1/A': 
     60                    data_conv_q = Converter('1/A') 
     61                    # Test it 
     62                    data_conv_q(1.0, output.x_unit) 
     63                     
     64                if has_converter == True and output.y_unit != '1/cm': 
     65                    data_conv_i = Converter('1/cm') 
     66                    # Test it 
     67                    data_conv_i(1.0, output.y_unit) 
     68            
    4969                 
    5070                # The first good line of data will define whether 
     
    5878                        _y = float(toks[1]) 
    5979                         
     80                        if data_conv_q is not None: 
     81                            _x = data_conv_q(_x, units=output.x_unit) 
     82                             
     83                        if data_conv_i is not None: 
     84                            _y = data_conv_i(_y, units=output.y_unit)                         
     85                         
    6086                        # If we have an extra token, check 
    6187                        # whether it can be interpreted as a 
     
    6591                            try: 
    6692                                _dy = float(toks[2]) 
     93                                 
     94                                if data_conv_i is not None: 
     95                                    _dy = data_conv_i(_dy, units=output.y_unit) 
     96                                 
    6797                            except: 
    6898                                # The third column is not a float, skip it. 
     
    96126                output.y = y 
    97127                output.dy = dy if has_error == True else None 
    98                 output.xaxis("\\rm{Q}", 'A^{-1}') 
    99                 output.yaxis("\\rm{I(Q)}","cm^{-1}") 
    100                  
     128                if data_conv_q is not None: 
     129                    output.xaxis("\\rm{Q}", output.x_unit) 
     130                else: 
     131                    output.xaxis("\\rm{Q}", 'A^{-1}') 
     132                if data_conv_i is not None: 
     133                    output.yaxis("\\{I(Q)}", output.y_unit) 
     134                else: 
     135                    output.yaxis("\\rm{I(Q)}","cm^{-1}") 
    101136                 
    102137                return output 
  • DataLoader/readers/cansas_reader.py

    rb39c817 r99d1af6  
    426426        data_info.dx = dx 
    427427        data_info.dy = dy 
    428         data_info.xaxis("\\rm{Q}", 'A^{-1}') 
    429         data_info.yaxis("\\rm{I(Q)}","cm^{-1}") 
    430  
     428        if data_conv_q is not None: 
     429            data_info.xaxis("\\rm{Q}", output.x_unit) 
     430        else: 
     431            data_info.xaxis("\\rm{Q}", 'A^{-1}') 
     432        if data_conv_i is not None: 
     433            data_info.yaxis("\\{I(Q)}", output.y_unit) 
     434        else: 
     435            data_info.yaxis("\\rm{I(Q)}","cm^{-1}") 
     436         
    431437        return data_info 
    432438 
  • DataLoader/readers/danse_reader.py

    r68f6ae2 r99d1af6  
    11""" 
    2     Test plug-in 
     2    DANSE/SANS file reader 
    33""" 
    44 
    55import math 
    6 import pylab 
     6import os 
    77import copy 
    88import numpy 
    99import logging 
     10from DataLoader.data_info import Data2D, Detector 
     11 
     12# Look for unit converter 
     13has_converter = True 
     14try: 
     15    from data_util.nxsunit import Converter 
     16except: 
     17    has_converter = False 
    1018 
    1119class Reader: 
     
    5462            fversion   = 1.0 
    5563             
     64            output = Data2D() 
     65            output.filename = os.path.basename(filename) 
     66            detector = Detector() 
     67            output.detector.append(detector) 
     68             
     69            output.data = numpy.zeros([size_x,size_y]) 
     70            output.err_data = numpy.zeros([size_x,size_y]) 
     71             
     72            data_conv_q = None 
     73            data_conv_i = None 
     74             
     75            if has_converter == True and output.Q_unit != '1/A': 
     76                data_conv_q = Converter('1/A') 
     77                # Test it 
     78                data_conv_q(1.0, output.Q_unit) 
     79                 
     80            if has_converter == True and output.I_unit != '1/cm': 
     81                data_conv_i = Converter('1/cm') 
     82                # Test it 
     83                data_conv_i(1.0, output.I_unit)             
     84         
    5685            read_on = True 
    5786            while read_on: 
     
    6392                if toks[0]=="FORMATVERSION": 
    6493                    fversion = float(toks[1]) 
    65                 if toks[0]=="WAVELENGTH": 
    66                     wavelength = float(toks[1]) 
     94                if toks[0]=="WAVELENGTH":     
     95                    wavelength = float(toks[1])                 
    6796                elif toks[0]=="DISTANCE": 
    6897                    distance = float(toks[1]) 
     
    95124                            val = float(toks[0]) 
    96125                            err = float(toks[1]) 
     126                            if data_conv_i is not None: 
     127                                val = data_conv_i(val, units=output.y_unit) 
     128                                err = data_conv_i(err, units=output.y_unit) 
    97129                            data.append(val) 
    98130                            error.append(err) 
    99131                        except: 
    100132                            logging.info("Skipping line:%s,%s" %( data_str,sys.exc_value)) 
    101                             #print "Skipping line:%s" % data_str 
    102                             #print sys.exc_value 
    103133             
    104134            # Initialize  
     
    109139            xmin = None 
    110140            xmax = None 
    111             Z = None 
    112          
    113              
    114             x = numpy.zeros(size_x) 
    115             y = numpy.zeros(size_y) 
    116             X, Y = pylab.meshgrid(x, y) 
    117             Z = copy.deepcopy(X) 
    118             E = copy.deepcopy(X) 
     141             
     142            #x = numpy.zeros(size_x) 
     143            #y = numpy.zeros(size_y) 
     144            #X, Y = pylab.meshgrid(x, y) 
     145            #Z = copy.deepcopy(X) 
     146            #E = copy.deepcopy(X) 
    119147            itot = 0 
    120148            i_x = 0 
     
    125153                theta = (i_x-center_x+1)*pixel / distance / 100.0 
    126154                qx = 4.0*math.pi/wavelength * math.sin(theta/2.0) 
     155                 
     156                if has_converter == True and output.Q_unit != '1/A': 
     157                    qx = data_conv_q(qx, units=output.Q_unit) 
     158                 
    127159                x_vals.append(qx) 
    128160                if xmin==None or qx<xmin: 
     
    136168                theta = (i_y-center_y+1)*pixel / distance / 100.0 
    137169                qy = 4.0*math.pi/wavelength * math.sin(theta/2.0) 
     170                 
     171                if has_converter == True and output.Q_unit != '1/A': 
     172                    qy = data_conv_q(qy, units=output.Q_unit) 
     173                 
    138174                y_vals.append(qy) 
    139175                if ymin==None or qy<ymin: 
     
    142178                    ymax = qy 
    143179             
     180            # Store the data in the 2D array 
    144181            for i_pt in range(len(data)): 
    145                 val = data[i_pt] 
    146182                try: 
    147                     value = float(val) 
     183                    value = float(data[i_pt]) 
    148184                except: 
    149                     continue 
     185                    # For version 1.0, the data were still 
     186                    # stored as strings at this point. 
     187                    logging.info("Skipping entry (v1.0):%s,%s" %(str(data[i_pt]), sys.exc_value)) 
    150188                 
    151189                # Get bin number 
     
    156194                    i_x += 1 
    157195                     
    158                 Z[size_y-1-i_y][i_x] = value 
     196                output.data[size_y-1-i_y][i_x] = value 
    159197                if fversion>1.0: 
    160                     E[size_y-1-i_y][i_x] = error[i_pt] 
     198                    output.err_data[size_y-1-i_y][i_x] = error[i_pt] 
    161199                 
    162200                itot += 1 
    163             from readInfo import ReaderInfo    
    164             output = ReaderInfo() 
    165             output.wavelength = wavelength 
    166             output.xbins      = size_x 
    167             output.ybins      = size_y 
    168             output.center_x   = center_x 
    169             output.center_y   = center_y 
    170             # Store the distance in [mm] 
    171             output.distance   = distance*1000.0 
    172             output.x_vals     = x_vals 
    173             output.y_vals     = y_vals 
    174             output.xmin       = xmin 
    175             output.xmax       = xmax 
    176             output.ymin       = ymin 
    177             output.ymax       = ymax 
    178             output.pixel_size = pixel 
    179             output.image      = Z 
    180             output.x          = x_vals 
    181             output.y          = y_vals 
    182             output.type       = "2D " 
     201                 
     202            # Store all data ###################################### 
     203            # Store wavelength 
     204            if has_converter==True and output.source.wavelength_unit != 'A': 
     205                conv = Converter('A') 
     206                wavelength = conv(wavelength, units=output.source.wavelength_unit) 
     207            output.source.wavelength = wavelength 
     208                 
     209            # Store distance 
     210            if has_converter==True and detector.distance_unit != 'm': 
     211                conv = Converter('m') 
     212                distance = conv(distance, units=detector.distance_unit) 
     213            detector.distance = distance 
     214             
     215            # Store pixel size 
     216            if has_converter==True and detector.pixel_size_unit != 'mm': 
     217                conv = Converter('mm') 
     218                pixel = conv(pixel, units=detector.pixel_size_unit) 
     219            detector.pixel_size.x = pixel 
     220            detector.pixel_size.y = pixel 
     221 
     222            # Store beam center in distance units 
     223            detector.beam_center.x = center_x*pixel 
     224            detector.beam_center.y = center_y*pixel 
     225             
     226            # Store limits of the image (2D array) 
     227            if has_converter == True and output.Q_unit != '1/A': 
     228                xmin = data_conv_q(xmin, units=output.Q_unit) 
     229                xmax = data_conv_q(xmax, units=output.Q_unit) 
     230                ymin = data_conv_q(ymin, units=output.Q_unit) 
     231                ymax = data_conv_q(ymax, units=output.Q_unit) 
     232            output.xmin = xmin 
     233            output.xmax = xmax 
     234            output.ymin = ymin 
     235            output.ymax = ymax 
     236             
     237            # Store x and y axis bin centers 
     238            output.x_bins     = x_vals 
     239            output.y_bins     = y_vals 
     240            
     241            # Units 
     242            if data_conv_q is not None: 
     243                output.xaxis("\\rm{Q}", output.Q_unit) 
     244                output.yaxis("\\rm{Q}", output.Q_unit) 
     245            else: 
     246                output.xaxis("\\rm{Q}", 'A^{-1}') 
     247                output.yaxis("\\rm{Q}", 'A^{-1}') 
     248                 
     249            if data_conv_i is not None: 
     250                output.zaxis("\\{I(Q)}", output.I_unit) 
     251            else: 
     252                output.zaxis("\\rm{I(Q)}","cm^{-1}") 
    183253            
    184254            if not fversion>=1.0: 
    185                 #output.error  = E 
    186255                raise ValueError,"Danse_reader can't read this file %s"%filename 
    187256            else: 
     
    190259         
    191260        return None 
     261 
     262if __name__ == "__main__":  
     263    reader = Reader() 
     264    print reader.read("../test/MP_New.sans") 
     265     
Note: See TracChangeset for help on using the changeset viewer.