Changeset 0997158f in sasview for DataLoader


Ignore:
Timestamp:
Jun 1, 2010 3:20:09 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
a45622a
Parents:
54180f9
Message:

working on documentation

Location:
DataLoader
Files:
83 added
14 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/data_info.py

    r3cd95c8 r0997158f  
    99""" 
    1010 
    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 If you use DANSE applications to do scientific research that leads to  
    17 publication, we ask that you acknowledge the use of the software with the  
    18 following sentence: 
    19  
    20 "This work benefited from DANSE software developed under NSF award DMR-0520547."  
    21  
    22 copyright 2008, University of Tennessee 
    23 """ 
     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#If you use DANSE applications to do scientific research that leads to  
     16#publication, we ask that you acknowledge the use of the software with the  
     17#following sentence: 
     18#This work benefited from DANSE software developed under NSF award DMR-0520547. 
     19#copyright 2008, University of Tennessee 
     20 
    2421 
    2522#TODO: Keep track of data manipulation in the 'process' data structure. 
     
    3431class plottable_1D: 
    3532    """ 
    36         Data1D is a place holder for 1D plottables. 
     33    Data1D is a place holder for 1D plottables. 
    3734    """ 
    3835    # The presence of these should be mutually exclusive with the presence of Qdev (dx) 
     
    7067class plottable_2D: 
    7168    """ 
    72         Data2D is a place holder for 2D plottables. 
     69    Data2D is a place holder for 2D plottables. 
    7370    """ 
    7471    xmin = None 
     
    118115class Vector: 
    119116    """ 
    120         Vector class to hold multi-dimensional objects 
     117    Vector class to hold multi-dimensional objects 
    121118    """ 
    122119    ## x component 
     
    129126    def __init__(self, x=None, y=None, z=None): 
    130127        """ 
    131             Initialization. Components that are not 
    132             set a set to None by default. 
    133              
    134             @param x: x component 
    135             @param y: y component 
    136             @param z: z component 
     128        Initialization. Components that are not 
     129        set a set to None by default. 
     130         
     131        :param x: x component 
     132        :param y: y component 
     133        :param z: z component 
     134         
    137135        """ 
    138136        self.x = x 
     
    146144class Detector: 
    147145    """ 
    148         Class to hold detector information 
     146    Class to hold detector information 
    149147    """ 
    150148    ## Name of the instrument [string] 
     
    171169    def __init__(self): 
    172170        """ 
    173             Initialize class attribute that are objects... 
     171         
     172        Initialize class attribute that are objects... 
     173         
    174174        """ 
    175175        self.offset      = Vector() 
     
    215215class Collimation: 
    216216    """ 
    217         Class to hold collimation information 
     217    Class to hold collimation information 
    218218    """ 
    219219    ## Name 
     
    241241class Source: 
    242242    """ 
    243         Class to hold source information 
     243    Class to hold source information 
    244244    """   
    245245    ## Name 
     
    289289     
    290290"""  
    291     Definitions of radiation types 
     291Definitions of radiation types 
    292292""" 
    293293NEUTRON  = 'neutron' 
     
    298298class Sample: 
    299299    """ 
    300         Class to hold the sample description 
     300    Class to hold the sample description 
    301301    """ 
    302302    ## Short name for sample 
     
    347347class Process: 
    348348    """ 
    349         Class that holds information about the processes 
    350         performed on the data. 
     349    Class that holds information about the processes 
     350    performed on the data. 
    351351    """ 
    352352    name = '' 
     
    374374class DataInfo: 
    375375    """ 
    376         Class to hold the data read from a file. 
    377         It includes four blocks of data for the 
    378         instrument description, the sample description, 
    379         the data itself and any other meta data. 
     376    Class to hold the data read from a file. 
     377    It includes four blocks of data for the 
     378    instrument description, the sample description, 
     379    the data itself and any other meta data. 
    380380    """ 
    381381    ## Title  
     
    408408    def __init__(self): 
    409409        """ 
    410             Initialization 
     410        Initialization 
    411411        """ 
    412412        ## Title  
     
    438438    def __str__(self): 
    439439        """ 
    440             Nice printout 
     440        Nice printout 
    441441        """ 
    442442        _str =  "File:            %s\n" % self.filename 
     
    464464    def __add__(self, other): 
    465465        """ 
    466             Add two data sets 
    467              
    468             @param other: data set to add to the current one 
    469             @return: new data set 
    470             @raise ValueError: raised when two data sets are incompatible 
     466        Add two data sets 
     467         
     468        :param other: data set to add to the current one 
     469        :return: new data set 
     470        :raise ValueError: raised when two data sets are incompatible 
    471471        """ 
    472472        def operation(a, b): return a+b 
     
    475475    def __radd__(self, other): 
    476476        """ 
    477             Add two data sets 
    478              
    479             @param other: data set to add to the current one 
    480             @return: new data set 
    481             @raise ValueError: raised when two data sets are incompatible 
     477        Add two data sets 
     478         
     479        :param other: data set to add to the current one 
     480         
     481        :return: new data set 
     482         
     483        :raise ValueError: raised when two data sets are incompatible 
     484         
    482485        """ 
    483486        def operation(a, b): return b+a 
     
    486489    def __sub__(self, other): 
    487490        """ 
    488             Subtract two data sets 
    489              
    490             @param other: data set to subtract from the current one 
    491             @return: new data set 
    492             @raise ValueError: raised when two data sets are incompatible 
     491        Subtract two data sets 
     492         
     493        :param other: data set to subtract from the current one 
     494         
     495        :return: new data set 
     496         
     497        :raise ValueError: raised when two data sets are incompatible 
     498         
    493499        """ 
    494500        def operation(a, b): return a-b 
     
    497503    def __rsub__(self, other): 
    498504        """ 
    499             Subtract two data sets 
    500              
    501             @param other: data set to subtract from the current one 
    502             @return: new data set 
    503             @raise ValueError: raised when two data sets are incompatible 
     505        Subtract two data sets 
     506         
     507        :param other: data set to subtract from the current one 
     508         
     509        :return: new data set 
     510         
     511        :raise ValueError: raised when two data sets are incompatible 
     512         
    504513        """ 
    505514        def operation(a, b): return b-a 
     
    508517    def __mul__(self, other): 
    509518        """ 
    510             Multiply two data sets 
    511              
    512             @param other: data set to subtract from the current one 
    513             @return: new data set 
    514             @raise ValueError: raised when two data sets are incompatible 
     519        Multiply two data sets 
     520         
     521        :param other: data set to subtract from the current one 
     522         
     523        :return: new data set 
     524         
     525        :raise ValueError: raised when two data sets are incompatible 
     526         
    515527        """ 
    516528        def operation(a, b): return a*b 
     
    519531    def __rmul__(self, other): 
    520532        """ 
    521             Multiply two data sets 
    522              
    523             @param other: data set to subtract from the current one 
    524             @return: new data set 
    525             @raise ValueError: raised when two data sets are incompatible 
     533        Multiply two data sets 
     534         
     535        :param other: data set to subtract from the current one 
     536         
     537        :return: new data set 
     538         
     539        :raise ValueError: raised when two data sets are incompatible 
    526540        """ 
    527541        def operation(a, b): return b*a 
     
    530544    def __div__(self, other): 
    531545        """ 
    532             Divided a data set by another 
    533              
    534             @param other: data set that the current one is divided by 
    535             @return: new data set 
    536             @raise ValueError: raised when two data sets are incompatible 
     546        Divided a data set by another 
     547         
     548        :param other: data set that the current one is divided by 
     549         
     550        :return: new data set 
     551         
     552        :raise ValueError: raised when two data sets are incompatible 
     553         
    537554        """ 
    538555        def operation(a, b): return a/b 
     
    541558    def __rdiv__(self, other): 
    542559        """ 
    543             Divided a data set by another 
    544              
    545             @param other: data set that the current one is divided by 
    546             @return: new data set 
    547             @raise ValueError: raised when two data sets are incompatible 
     560        Divided a data set by another 
     561         
     562        :param other: data set that the current one is divided by 
     563         
     564        :return: new data set 
     565         
     566        :raise ValueError: raised when two data sets are incompatible 
     567         
    548568        """ 
    549569        def operation(a, b): return b/a 
     
    552572class Data1D(plottable_1D, DataInfo): 
    553573    """ 
    554         1D data class 
     574    1D data class 
    555575    """ 
    556576    x_unit = '1/A' 
     
    564584    def __str__(self): 
    565585        """ 
    566             Nice printout 
     586        Nice printout 
    567587        """ 
    568588        _str =  "%s\n" % DataInfo.__str__(self) 
     
    578598    def is_slit_smeared(self): 
    579599        """ 
    580             Check whether the data has slit smearing information 
    581              
    582             @return: True is slit smearing info is present, False otherwise 
     600        Check whether the data has slit smearing information 
     601         
     602        :return: True is slit smearing info is present, False otherwise 
     603         
    583604        """ 
    584605        def _check(v):             
     
    593614    def clone_without_data(self, length=0, clone=None): 
    594615        """ 
    595             Clone the current object, without copying the data (which 
    596             will be filled out by a subsequent operation). 
    597             The data arrays will be initialized to zero. 
    598              
    599             @param length: length of the data array to be initialized 
    600             @param clone: if provided, the data will be copied to clone 
     616        Clone the current object, without copying the data (which 
     617        will be filled out by a subsequent operation). 
     618        The data arrays will be initialized to zero. 
     619         
     620        :param length: length of the data array to be initialized 
     621        :param clone: if provided, the data will be copied to clone 
    601622        """ 
    602623        from copy import deepcopy 
     
    625646    def _validity_check(self, other): 
    626647        """ 
    627             Checks that the data lengths are compatible. 
    628             Checks that the x vectors are compatible. 
    629             Returns errors vectors equal to original 
    630             errors vectors if they were present or vectors 
    631             of zeros when none was found. 
    632              
    633             @param other: other data set for operation 
    634             @return: dy for self, dy for other [numpy arrays] 
    635             @raise ValueError: when lengths are not compatible 
     648        Checks that the data lengths are compatible. 
     649        Checks that the x vectors are compatible. 
     650        Returns errors vectors equal to original 
     651        errors vectors if they were present or vectors 
     652        of zeros when none was found. 
     653         
     654        :param other: other data set for operation 
     655         
     656        :return: dy for self, dy for other [numpy arrays] 
     657         
     658        :raise ValueError: when lengths are not compatible 
     659         
    636660        """ 
    637661        dy_other = None 
     
    685709class Data2D(plottable_2D, DataInfo): 
    686710    """ 
    687         2D data class 
     711    2D data class 
    688712    """ 
    689713    ## Units for Q-values 
     
    724748    def clone_without_data(self, length=0, clone=None): 
    725749        """ 
    726             Clone the current object, without copying the data (which 
    727             will be filled out by a subsequent operation). 
    728             The data arrays will be initialized to zero. 
    729              
    730             @param length: length of the data array to be initialized 
    731             @param clone: if provided, the data will be copied to clone 
     750        Clone the current object, without copying the data (which 
     751        will be filled out by a subsequent operation). 
     752        The data arrays will be initialized to zero. 
     753         
     754        :param length: length of the data array to be initialized 
     755        :param clone: if provided, the data will be copied to clone 
    732756        """ 
    733757        from copy import deepcopy 
     
    761785    def _validity_check(self, other): 
    762786        """ 
    763             Checks that the data lengths are compatible. 
    764             Checks that the x vectors are compatible. 
    765             Returns errors vectors equal to original 
    766             errors vectors if they were present or vectors 
    767             of zeros when none was found. 
    768              
    769             @param other: other data set for operation 
    770             @return: dy for self, dy for other [numpy arrays] 
    771             @raise ValueError: when lengths are not compatible 
     787        Checks that the data lengths are compatible. 
     788        Checks that the x vectors are compatible. 
     789        Returns errors vectors equal to original 
     790        errors vectors if they were present or vectors 
     791        of zeros when none was found. 
     792         
     793        :param other: other data set for operation 
     794         
     795        :return: dy for self, dy for other [numpy arrays] 
     796         
     797        :raise ValueError: when lengths are not compatible 
     798         
    772799        """ 
    773800        err_other = None 
     
    797824    def _perform_operation(self, other, operation): 
    798825        """ 
    799             Perform 2D operations between data sets 
    800              
    801             @param other: other data set 
    802             @param operation: function defining the operation 
     826        Perform 2D operations between data sets 
     827         
     828        :param other: other data set 
     829        :param operation: function defining the operation 
     830         
    803831        """ 
    804832        # First, check the data compatibility 
  • DataLoader/loader.py

    rfd4b6f8 r0997158f  
     1 
     2##################################################################### 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6#See the license text in license.txt 
     7#copyright 2008, University of Tennessee 
     8###################################################################### 
     9 
    110""" 
    211    File handler to support different file extensions. 
     
    1221    a directory (for instance, a user plug-in directory) and 
    1322    look for new readers/writers. 
    14 """ 
    15  
    16 """ 
    17 This software was developed by the University of Tennessee as part of the 
    18 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    19 project funded by the US National Science Foundation.  
    20  
    21 See the license text in license.txt 
    22  
    23 copyright 2008, University of Tennessee 
    2423""" 
    2524 
     
    3736class Registry(ExtensionRegistry): 
    3837    """ 
    39         Registry class for file format extensions. 
    40         Readers and writers are supported. 
     38    Registry class for file format extensions. 
     39    Readers and writers are supported. 
    4140    """ 
    4241     
     
    6564    def load(self, path, format=None): 
    6665        """ 
    67             Call the loader for the file type of path. 
    68      
    69             @param path: file path 
    70             @param format: explicit extension, to force the use of a particular reader 
    71      
    72             Defaults to the ascii (multi-column) reader 
    73             if no reader was registered for the file's 
    74             extension.    
     66        Call the loader for the file type of path. 
     67 
     68        :param path: file path 
     69        :param format: explicit extension, to force the use of a particular reader 
     70 
     71        Defaults to the ascii (multi-column) reader 
     72        if no reader was registered for the file's 
     73        extension.    
    7574        """ 
    7675        try: 
     
    8382    def find_plugins(self, dir): 
    8483        """ 
    85             Find readers in a given directory. This method 
    86             can be used to inspect user plug-in directories to 
    87             find new readers/writers. 
    88              
    89             @param dir: directory to search into 
    90             @return: number of readers found 
     84        Find readers in a given directory. This method 
     85        can be used to inspect user plug-in directories to 
     86        find new readers/writers. 
     87         
     88        :param dir: directory to search into 
     89         
     90        :return: number of readers found 
    9191        """ 
    9292        readers_found = 0 
     
    138138    def associate_file_type(self, ext, module): 
    139139        """ 
    140             Look into a module to find whether it contains a  
    141             Reader class. If so, APPEND it to readers and (potentially) 
    142             to the list of writers for the given extension 
    143              
    144             @param ext: file extension [string] 
    145             @param module: module object 
     140        Look into a module to find whether it contains a  
     141        Reader class. If so, APPEND it to readers and (potentially) 
     142        to the list of writers for the given extension 
     143         
     144        :param ext: file extension [string] 
     145        :param module: module object 
    146146        """ 
    147147        reader_found = False 
     
    180180    def associate_file_reader(self, ext, loader): 
    181181        """ 
    182             Append a reader object to readers 
    183              
    184             @param ext: file extension [string] 
    185             @param module: reader object 
     182        Append a reader object to readers 
     183         
     184        :param ext: file extension [string] 
     185        :param module: reader object 
    186186        """ 
    187187        reader_found = False 
     
    211211    def _identify_plugin(self, module): 
    212212        """ 
    213             Look into a module to find whether it contains a  
    214             Reader class. If so, add it to readers and (potentially) 
    215             to the list of writers. 
    216             @param module: module object 
     213        Look into a module to find whether it contains a  
     214        Reader class. If so, add it to readers and (potentially) 
     215        to the list of writers. 
     216        :param module: module object 
     217         
    217218        """ 
    218219        reader_found = False 
     
    252253    def lookup_writers(self, path): 
    253254        """ 
    254         Return the loader associated with the file type of path. 
    255          
    256         Raises ValueError if file type is not known. 
     255        :return: the loader associated with the file type of path. 
     256         
     257        :Raises ValueError: if file type is not known. 
    257258        """         
    258259        # Find matching extensions 
     
    282283        Raises ValueError if no writer is available. 
    283284        Raises KeyError if format is not available. 
     285         
    284286        May raise a writer-defined exception if writer fails.         
    285287        """ 
     
    299301class Loader(object): 
    300302    """ 
    301         Utility class to use the Registry as a singleton. 
     303    Utility class to use the Registry as a singleton. 
    302304    """ 
    303305    ## Registry instance 
     
    306308    def associate_file_type(self, ext, module): 
    307309        """ 
    308             Look into a module to find whether it contains a  
    309             Reader class. If so, append it to readers and (potentially) 
    310             to the list of writers for the given extension 
    311              
    312             @param ext: file extension [string] 
    313             @param module: module object 
     310        Look into a module to find whether it contains a  
     311        Reader class. If so, append it to readers and (potentially) 
     312        to the list of writers for the given extension 
     313         
     314        :param ext: file extension [string] 
     315        :param module: module object 
    314316        """ 
    315317        return self.__registry.associate_file_type(ext, module) 
     
    317319    def associate_file_reader(self, ext, loader): 
    318320        """ 
    319             Append a reader object to readers 
    320              
    321             @param ext: file extension [string] 
    322             @param module: reader object 
     321        Append a reader object to readers 
     322         
     323        :param ext: file extension [string] 
     324        :param module: reader object 
    323325        """ 
    324326        return self.__registry.associate_file_reader(ext, loader) 
     
    326328    def load(self, file, format=None): 
    327329        """ 
    328             Load a file 
    329              
    330             @param file: file name (path) 
    331             @param format: specified format to use (optional) 
    332             @return: DataInfo object 
     330        Load a file 
     331         
     332        :param file: file name (path) 
     333        :param format: specified format to use (optional) 
     334        :return: DataInfo object 
    333335        """ 
    334336        return self.__registry.load(file, format) 
     
    336338    def save(self, file, data, format): 
    337339        """ 
    338             Save a DataInfo object to file 
    339             @param file: file name (path) 
    340             @param data: DataInfo object 
    341             @param format: format to write the data in  
     340        Save a DataInfo object to file 
     341        :param file: file name (path) 
     342        :param data: DataInfo object 
     343        :param format: format to write the data in  
    342344        """ 
    343345        return self.__registry.save(file, data, format) 
     
    345347    def _get_registry_creation_time(self): 
    346348        """ 
    347             Internal method used to test the uniqueness 
    348             of the registry object 
     349        Internal method used to test the uniqueness 
     350        of the registry object 
    349351        """ 
    350352        return self.__registry._created 
     
    352354    def find_plugins(self, dir): 
    353355        """ 
    354             Find plugins in a given directory 
    355             @param dir: directory to look into to find new readers/writers 
     356        Find plugins in a given directory 
     357         
     358        :param dir: directory to look into to find new readers/writers 
    356359        """ 
    357360        return self.__registry.find_plugins(dir) 
  • DataLoader/manipulations.py

    rf265927 r0997158f  
     1 
     2##################################################################### 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6#See the license text in license.txt 
     7#copyright 2008, University of Tennessee 
     8###################################################################### 
     9 
    110""" 
    211    Data manipulations for 2D data sets. 
     
    514""" 
    615 
    7 """ 
    8 This software was developed by the University of Tennessee as part of the 
    9 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    10 project funded by the US National Science Foundation.  
    11  
    12 See the license text in license.txt 
    13  
    14 copyright 2008, University of Tennessee 
    15 """ 
     16 
    1617#TODO: copy the meta data from the 2D object to the resulting 1D object 
    1718 
     
    2223def get_q(dx, dy, det_dist, wavelength): 
    2324    """ 
    24         @param dx: x-distance from beam center [mm] 
    25         @param dy: y-distance from beam center [mm] 
    26         @return: q-value at the given position 
     25    :param dx: x-distance from beam center [mm] 
     26    :param dy: y-distance from beam center [mm] 
     27     
     28    :return: q-value at the given position 
    2729    """ 
    2830    # Distance from beam center in the plane of detector 
     
    3335 
    3436def get_q_compo(dx, dy, det_dist, wavelength,compo=None): 
    35     #This reduces tiny error at very large q. 
    36     #Implementation of this func is not started yet.<--ToDo 
     37    """ 
     38    This reduces tiny error at very large q. 
     39    Implementation of this func is not started yet.<--ToDo 
     40    """ 
    3741    if dy==0: 
    3842        if dx>=0: 
     
    5357def flip_phi(phi): 
    5458    """ 
    55         Correct phi to within the 0 <= to <= 2pi range 
    56         @return: phi in >=0 and <=2Pi 
     59    Correct phi to within the 0 <= to <= 2pi range 
     60     
     61    :return: phi in >=0 and <=2Pi 
    5762    """ 
    5863    Pi = math.pi 
     
    6772def reader2D_converter(data2d=None): 
    6873    """ 
    69         convert old 2d format opened by IhorReader or danse_reader to new Data2D format 
    70         @param data2d: 2d array of Data2D object 
    71         @return: 1d arrays of Data2D object 
     74    convert old 2d format opened by IhorReader or danse_reader to new Data2D format 
     75     
     76    :param data2d: 2d array of Data2D object 
     77     
     78    :return: 1d arrays of Data2D object 
     79     
    7280    """ 
    7381    if data2d.data==None or data2d.x_bins==None or data2d.y_bins==None: 
     
    103111class _Slab(object): 
    104112    """ 
    105         Compute average I(Q) for a region of interest 
     113    Compute average I(Q) for a region of interest 
    106114    """ 
    107115    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001): 
     
    123131    def _avg(self, data2D, maj): 
    124132        """ 
    125              Compute average I(Q_maj) for a region of interest. 
    126              The major axis is defined as the axis of Q_maj. 
    127              The minor axis is the axis that we average over. 
    128               
    129              @param data2D: Data2D object 
    130              @param maj_min: min value on the major axis 
    131              @return: Data1D object 
     133        Compute average I(Q_maj) for a region of interest. 
     134        The major axis is defined as the axis of Q_maj. 
     135        The minor axis is the axis that we average over. 
     136          
     137        :param data2D: Data2D object 
     138        :param maj_min: min value on the major axis 
     139         
     140        :return: Data1D object 
    132141        """ 
    133142        if len(data2D.detector) != 1: 
     
    221230class SlabY(_Slab): 
    222231    """ 
     232    Compute average I(Qy) for a region of interest 
     233    """ 
     234    def __call__(self, data2D): 
     235        """ 
    223236        Compute average I(Qy) for a region of interest 
     237          
     238        :param data2D: Data2D object 
     239         
     240        :return: Data1D object 
     241        """ 
     242        return self._avg(data2D, 'y') 
     243         
     244class SlabX(_Slab): 
     245    """ 
     246    Compute average I(Qx) for a region of interest 
    224247    """ 
    225248    def __call__(self, data2D): 
    226249        """ 
    227              Compute average I(Qy) for a region of interest 
    228               
    229              @param data2D: Data2D object 
    230              @return: Data1D object 
    231         """ 
    232         return self._avg(data2D, 'y') 
    233          
    234 class SlabX(_Slab): 
    235     """ 
    236250        Compute average I(Qx) for a region of interest 
    237     """ 
    238     def __call__(self, data2D): 
    239         """ 
    240              Compute average I(Qx) for a region of interest 
    241               
    242              @param data2D: Data2D object 
    243              @return: Data1D object 
     251          
     252        :param data2D: Data2D object 
     253         
     254        :return: Data1D object 
     255         
    244256        """ 
    245257        return self._avg(data2D, 'x')  
     
    247259class Boxsum(object): 
    248260    """ 
    249         Perform the sum of counts in a 2D region of interest. 
     261    Perform the sum of counts in a 2D region of interest. 
    250262    """ 
    251263    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
     
    261273    def __call__(self, data2D): 
    262274        """ 
    263              Perform the sum in the region of interest  
    264               
    265              @param data2D: Data2D object 
    266              @return: number of counts, error on number of counts 
     275        Perform the sum in the region of interest  
     276          
     277        :param data2D: Data2D object 
     278         
     279        :return: number of counts, error on number of counts 
     280         
    267281        """ 
    268282        y, err_y, y_counts = self._sum(data2D) 
     
    276290    def _sum(self, data2D): 
    277291        """ 
    278              Perform the sum in the region of interest  
    279              @param data2D: Data2D object 
    280              @return: number of counts, error on number of counts, number of entries summed 
     292        Perform the sum in the region of interest  
     293         
     294        :param data2D: Data2D object 
     295         
     296        :return: number of counts, error on number of counts, number of entries summed 
     297         
    281298        """ 
    282299        if len(data2D.detector) != 1: 
     
    328345class Boxavg(Boxsum): 
    329346    """ 
    330         Perform the average of counts in a 2D region of interest. 
     347    Perform the average of counts in a 2D region of interest. 
    331348    """ 
    332349    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
     
    335352    def __call__(self, data2D): 
    336353        """ 
    337              Perform the sum in the region of interest  
    338               
    339              @param data2D: Data2D object 
    340              @return: average counts, error on average counts 
     354        Perform the sum in the region of interest  
     355          
     356        :param data2D: Data2D object 
     357         
     358        :return: average counts, error on average counts 
     359         
    341360        """ 
    342361        y, err_y, y_counts = self._sum(data2D) 
     
    350369def get_pixel_fraction_square(x, xmin, xmax): 
    351370    """ 
    352          Return the fraction of the length  
    353          from xmin to x.  
    354           
    355              A            B 
    356          +-----------+---------+ 
    357          xmin        x         xmax 
    358           
    359          @param x: x-value 
    360          @param xmin: minimum x for the length considered 
    361          @param xmax: minimum x for the length considered 
    362          @return: (x-xmin)/(xmax-xmin) when xmin < x < xmax 
    363           
     371    Return the fraction of the length  
     372    from xmin to x.:: 
     373    
     374      
     375           A            B 
     376       +-----------+---------+ 
     377       xmin        x         xmax 
     378      
     379    :param x: x-value 
     380    :param xmin: minimum x for the length considered 
     381    :param xmax: minimum x for the length considered 
     382     
     383    :return: (x-xmin)/(xmax-xmin) when xmin < x < xmax 
     384     
    364385    """ 
    365386    if x<=xmin: 
     
    373394class CircularAverage(object): 
    374395    """ 
    375         Perform circular averaging on 2D data 
    376          
    377         The data returned is the distribution of counts 
    378         as a function of Q 
     396    Perform circular averaging on 2D data 
     397     
     398    The data returned is the distribution of counts 
     399    as a function of Q 
    379400    """ 
    380401    def __init__(self, r_min=0.0, r_max=0.0, bin_width=0.0005): 
     
    388409    def __call__(self, data2D): 
    389410        """ 
    390             Perform circular averaging on the data 
    391              
    392             @param data2D: Data2D object 
    393             @return: Data1D object 
     411        Perform circular averaging on the data 
     412         
     413        :param data2D: Data2D object 
     414         
     415        :return: Data1D object 
    394416        """ 
    395417        # Get data 
     
    465487class Ring(object): 
    466488    """ 
    467         Defines a ring on a 2D data set. 
    468         The ring is defined by r_min, r_max, and 
    469         the position of the center of the ring. 
    470          
    471         The data returned is the distribution of counts 
    472         around the ring as a function of phi. 
    473          
    474         Phi_min and phi_max should be defined between 0 and 2*pi  
    475         in anti-clockwise starting from the x- axis on the left-hand side 
     489    Defines a ring on a 2D data set. 
     490    The ring is defined by r_min, r_max, and 
     491    the position of the center of the ring. 
     492     
     493    The data returned is the distribution of counts 
     494    around the ring as a function of phi. 
     495     
     496    Phi_min and phi_max should be defined between 0 and 2*pi  
     497    in anti-clockwise starting from the x- axis on the left-hand side 
    476498    """ 
    477499    #Todo: remove center. 
     
    490512    def __call__(self, data2D): 
    491513        """ 
    492             Apply the ring to the data set. 
    493             Returns the angular distribution for a given q range 
    494              
    495             @param data2D: Data2D object 
    496             @return: Data1D object 
     514        Apply the ring to the data set. 
     515        Returns the angular distribution for a given q range 
     516         
     517        :param data2D: Data2D object 
     518         
     519        :return: Data1D object 
    497520        """ 
    498521        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
     
    562585def get_pixel_fraction(qmax, q_00, q_01, q_10, q_11): 
    563586    """ 
    564         Returns the fraction of the pixel defined by 
    565         the four corners (q_00, q_01, q_10, q_11) that  
    566         has q < qmax. 
    567          
     587    Returns the fraction of the pixel defined by 
     588    the four corners (q_00, q_01, q_10, q_11) that  
     589    has q < qmax.:: 
     590     
    568591                q_01                q_11 
    569592        y=1         +--------------+ 
     
    575598         
    576599                    x=0            x=1 
    577          
     600     
    578601    """ 
    579602     
     
    631654def get_intercept(q, q_0, q_1): 
    632655    """ 
    633         Returns the fraction of the side at which the 
    634         q-value intercept the pixel, None otherwise. 
    635         The values returned is the fraction ON THE SIDE 
    636         OF THE LOWEST Q. 
    637          
    638          
    639          
    640                 A        B     
    641          +-----------+--------+ 
    642          0                    1     <--- pixel size 
    643           
    644         Q_0 -------- Q ----- Q_1    <--- equivalent Q range 
    645          
    646          
     656    Returns the fraction of the side at which the 
     657    q-value intercept the pixel, None otherwise. 
     658    The values returned is the fraction ON THE SIDE 
     659    OF THE LOWEST Q. :: 
     660     
     661     
     662            A           B     
     663        +-----------+--------+    <--- pixel size 
     664        0                    1      
     665        Q_0 -------- Q ----- Q_1   <--- equivalent Q range 
    647666        if Q_1 > Q_0, A is returned 
    648667        if Q_1 < Q_0, B is returned 
    649          
    650668        if Q is outside the range of [Q_0, Q_1], None is returned 
    651669          
     
    661679class _Sector: 
    662680    """ 
    663         Defines a sector region on a 2D data set. 
    664         The sector is defined by r_min, r_max, phi_min, phi_max, 
    665         and the position of the center of the ring  
    666         where phi_min and phi_max are defined by the right and left lines wrt central line 
    667         and phi_max could be less than phi_min.  
    668         
    669         Phi is defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side 
     681    Defines a sector region on a 2D data set. 
     682    The sector is defined by r_min, r_max, phi_min, phi_max, 
     683    and the position of the center of the ring  
     684    where phi_min and phi_max are defined by the right and left lines wrt central line 
     685    and phi_max could be less than phi_min.  
     686    
     687    Phi is defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side 
    670688    """ 
    671689    def __init__(self, r_min, r_max, phi_min=0, phi_max=2*math.pi,nbins=20): 
     
    679697    def _agv(self, data2D, run='phi'): 
    680698        """ 
    681             Perform sector averaging. 
    682              
    683             @param data2D: Data2D object 
    684             @param run:  define the varying parameter ('phi' , 'q' , or 'q2') 
    685             @return: Data1D object 
     699        Perform sector averaging. 
     700         
     701        :param data2D: Data2D object 
     702        :param run:  define the varying parameter ('phi' , 'q' , or 'q2') 
     703         
     704        :return: Data1D object 
    686705        """ 
    687706        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
     
    793812class SectorPhi(_Sector): 
    794813    """ 
    795         Sector average as a function of phi. 
    796         I(phi) is return and the data is averaged over Q. 
    797          
    798         A sector is defined by r_min, r_max, phi_min, phi_max. 
    799         The number of bin in phi also has to be defined. 
     814    Sector average as a function of phi. 
     815    I(phi) is return and the data is averaged over Q. 
     816     
     817    A sector is defined by r_min, r_max, phi_min, phi_max. 
     818    The number of bin in phi also has to be defined. 
    800819    """ 
    801820    def __call__(self, data2D): 
    802821        """ 
    803             Perform sector average and return I(phi). 
    804              
    805             @param data2D: Data2D object 
    806             @return: Data1D object 
     822        Perform sector average and return I(phi). 
     823         
     824        :param data2D: Data2D object 
     825        :return: Data1D object 
    807826        """ 
    808827 
     
    811830class SectorQ(_Sector): 
    812831    """ 
    813         Sector average as a function of Q for both symatric wings. 
    814         I(Q) is return and the data is averaged over phi. 
    815          
    816         A sector is defined by r_min, r_max, phi_min, phi_max. 
    817         r_min, r_max, phi_min, phi_max >0.   
    818         The number of bin in Q also has to be defined. 
     832    Sector average as a function of Q for both symatric wings. 
     833    I(Q) is return and the data is averaged over phi. 
     834     
     835    A sector is defined by r_min, r_max, phi_min, phi_max. 
     836    r_min, r_max, phi_min, phi_max >0.   
     837    The number of bin in Q also has to be defined. 
    819838    """ 
    820839    def __call__(self, data2D): 
    821840        """ 
    822             Perform sector average and return I(Q). 
    823              
    824             @param data2D: Data2D object 
    825             @return: Data1D object 
     841        Perform sector average and return I(Q). 
     842         
     843        :param data2D: Data2D object 
     844         
     845        :return: Data1D object 
    826846        """ 
    827847        return self._agv(data2D, 'q2') 
     
    829849class Ringcut(object): 
    830850    """ 
    831         Defines a ring on a 2D data set. 
    832         The ring is defined by r_min, r_max, and 
    833         the position of the center of the ring. 
    834          
    835         The data returned is the region inside the ring 
    836          
    837         Phi_min and phi_max should be defined between 0 and 2*pi  
    838         in anti-clockwise starting from the x- axis on the left-hand side 
     851    Defines a ring on a 2D data set. 
     852    The ring is defined by r_min, r_max, and 
     853    the position of the center of the ring. 
     854     
     855    The data returned is the region inside the ring 
     856     
     857    Phi_min and phi_max should be defined between 0 and 2*pi  
     858    in anti-clockwise starting from the x- axis on the left-hand side 
    839859    """ 
    840860    def __init__(self, r_min=0, r_max=0, center_x=0, center_y=0 ): 
     
    851871    def __call__(self, data2D): 
    852872        """ 
    853             Apply the ring to the data set. 
    854             Returns the angular distribution for a given q range 
    855              
    856             @param data2D: Data2D object 
    857             @return: index array in the range 
     873        Apply the ring to the data set. 
     874        Returns the angular distribution for a given q range 
     875         
     876        :param data2D: Data2D object 
     877         
     878        :return: index array in the range 
    858879        """ 
    859880        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
     
    875896class Boxcut(object): 
    876897    """ 
    877         Find a rectangular 2D region of interest. 
     898    Find a rectangular 2D region of interest. 
    878899    """ 
    879900    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
     
    889910    def __call__(self, data2D): 
    890911        """ 
    891            Find a rectangular 2D region of interest. 
    892               
    893            @param data2D: Data2D object 
    894            @return: mask, 1d array (len = len(data))  
    895                with Trues where the data points are inside ROI, otherwise False 
     912       Find a rectangular 2D region of interest. 
     913          
     914       :param data2D: Data2D object 
     915       :return: mask, 1d array (len = len(data))  
     916           with Trues where the data points are inside ROI, otherwise False 
    896917        """ 
    897918        mask = self._find(data2D) 
     
    901922    def _find(self, data2D): 
    902923        """ 
    903              Find a rectangular 2D region of interest.  
    904              @param data2D: Data2D object 
    905              @return: out, 1d array (length = len(data))  
    906                with Trues where the data points are inside ROI, otherwise Falses 
     924        Find a rectangular 2D region of interest.  
     925         
     926        :param data2D: Data2D object 
     927         
     928        :return: out, 1d array (length = len(data))  
     929           with Trues where the data points are inside ROI, otherwise Falses 
    907930        """ 
    908931        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
     
    921944class Sectorcut(object): 
    922945    """ 
    923         Defines a sector (major + minor) region on a 2D data set. 
    924         The sector is defined by phi_min, phi_max, 
    925         where phi_min and phi_max are defined by the right and left lines wrt central line.  
    926         
    927         Phi_min and phi_max are given in units of radian  
    928         and (phi_max-phi_min) should not be larger than pi 
     946    Defines a sector (major + minor) region on a 2D data set. 
     947    The sector is defined by phi_min, phi_max, 
     948    where phi_min and phi_max are defined by the right and left lines wrt central line.  
     949    
     950    Phi_min and phi_max are given in units of radian  
     951    and (phi_max-phi_min) should not be larger than pi 
    929952    """ 
    930953    def __init__(self,phi_min=0, phi_max=math.pi): 
     
    934957    def __call__(self, data2D): 
    935958        """ 
    936            Find a rectangular 2D region of interest. 
    937              
    938            @param data2D: Data2D object 
    939            @return: mask, 1d array (len = len(data))  
    940                with Trues where the data points are inside ROI, otherwise False 
     959        Find a rectangular 2D region of interest. 
     960         
     961        :param data2D: Data2D object 
     962         
     963        :return: mask, 1d array (len = len(data))  
     964         
     965        with Trues where the data points are inside ROI, otherwise False 
    941966        """ 
    942967        mask = self._find(data2D) 
     
    946971    def _find(self, data2D): 
    947972        """ 
    948              Find a rectangular 2D region of interest.  
    949              @param data2D: Data2D object 
    950              @return: out, 1d array (length = len(data))  
    951                with Trues where the data points are inside ROI, otherwise Falses 
     973        Find a rectangular 2D region of interest.  
     974         
     975        :param data2D: Data2D object 
     976         
     977        :return: out, 1d array (length = len(data))  
     978         
     979        with Trues where the data points are inside ROI, otherwise Falses 
    952980        """ 
    953981        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
  • DataLoader/qsmearing.py

    rf72333f r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    5  
    6 See the license text in license.txt 
    7  
    8 copyright 2009, University of Tennessee 
    9 """ 
     1 
     2##################################################################### 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6#See the license text in license.txt 
     7#copyright 2008, University of Tennessee 
     8###################################################################### 
    109 
    1110import DataLoader.extensions.smearer as smearer 
     
    1716def smear_selection(data1D): 
    1817    """ 
    19         Creates the right type of smearer according  
    20         to the data. 
    21      
    22         The canSAS format has a rule that either 
    23         slit smearing data OR resolution smearing data 
    24         is available.  
    25          
    26         For the present purpose, we choose the one that 
    27         has none-zero data. If both slit and resolution 
    28         smearing arrays are filled with good data  
    29         (which should not happen), then we choose the 
    30         resolution smearing data.  
    31          
    32         @param data1D: Data1D object 
     18    Creates the right type of smearer according  
     19    to the data. 
     20 
     21    The canSAS format has a rule that either 
     22    slit smearing data OR resolution smearing data 
     23    is available.  
     24     
     25    For the present purpose, we choose the one that 
     26    has none-zero data. If both slit and resolution 
     27    smearing arrays are filled with good data  
     28    (which should not happen), then we choose the 
     29    resolution smearing data.  
     30     
     31    :param data1D: Data1D object 
    3332    """ 
    3433    # Sanity check. If we are not dealing with a SANS Data1D 
     
    9493    def __deepcopy__(self, memo={}): 
    9594        """ 
    96             Return a valid copy of self. 
    97             Avoid copying the _smearer C object and force a matrix recompute 
    98             when the copy is used.   
     95        Return a valid copy of self. 
     96        Avoid copying the _smearer C object and force a matrix recompute 
     97        when the copy is used.   
    9998        """ 
    10099        result = _BaseSmearer() 
     
    107106    def get_bin_range(self, q_min=None, q_max=None): 
    108107        """ 
    109             @param q_min: minimum q-value to smear 
    110             @param q_max: maximum q-value to smear  
     108         
     109        :param q_min: minimum q-value to smear 
     110        :param q_max: maximum q-value to smear 
     111          
    111112        """ 
    112113        # If this is the first time we call for smearing, 
     
    143144    def __call__(self, iq_in, first_bin=0, last_bin=None): 
    144145        """ 
    145             Perform smearing 
     146        Perform smearing 
    146147        """ 
    147148        # If this is the first time we call for smearing, 
     
    170171class _SlitSmearer(_BaseSmearer): 
    171172    """ 
    172         Slit smearing for I(q) array 
     173    Slit smearing for I(q) array 
    173174    """ 
    174175     
    175176    def __init__(self, nbins=None, width=None, height=None, min=None, max=None): 
    176177        """ 
    177             Initialization 
    178              
    179             @param iq: I(q) array [cm-1] 
    180             @param width: slit width [A-1] 
    181             @param height: slit height [A-1] 
    182             @param min: Q_min [A-1] 
    183             @param max: Q_max [A-1] 
     178        Initialization 
     179             
     180        :param iq: I(q) array [cm-1] 
     181        :param width: slit width [A-1] 
     182        :param height: slit height [A-1] 
     183        :param min: Q_min [A-1] 
     184        :param max: Q_max [A-1] 
     185         
    184186        """ 
    185187        _BaseSmearer.__init__(self) 
     
    202204    def _initialize_smearer(self): 
    203205        """ 
    204             Initialize the C++ smearer object. 
    205             This method HAS to be called before smearing 
     206        Initialize the C++ smearer object. 
     207        This method HAS to be called before smearing 
    206208        """ 
    207209        #self._smearer = smearer.new_slit_smearer(self.width, self.height, self.min, self.max, self.nbins) 
     
    211213    def get_unsmeared_range(self, q_min, q_max): 
    212214        """ 
    213             Determine the range needed in unsmeared-Q to cover 
    214             the smeared Q range 
     215        Determine the range needed in unsmeared-Q to cover 
     216        the smeared Q range 
    215217        """ 
    216218        # Range used for input to smearing 
     
    226228class SlitSmearer(_SlitSmearer): 
    227229    """ 
    228         Adaptor for slit smearing class and SANS data 
     230    Adaptor for slit smearing class and SANS data 
    229231    """ 
    230232    def __init__(self, data1D): 
    231233        """ 
    232             Assumption: equally spaced bins of increasing q-values. 
    233              
    234             @param data1D: data used to set the smearing parameters 
     234        Assumption: equally spaced bins of increasing q-values. 
     235         
     236        :param data1D: data used to set the smearing parameters 
    235237        """ 
    236238        # Initialization from parent class 
     
    267269class _QSmearer(_BaseSmearer): 
    268270    """ 
    269         Perform Gaussian Q smearing 
     271    Perform Gaussian Q smearing 
    270272    """ 
    271273         
    272274    def __init__(self, nbins=None, width=None, min=None, max=None): 
    273275        """ 
    274             Initialization 
    275              
    276             @param nbins: number of Q bins 
    277             @param width: array standard deviation in Q [A-1] 
    278             @param min: Q_min [A-1] 
    279             @param max: Q_max [A-1] 
     276        Initialization 
     277         
     278        :param nbins: number of Q bins 
     279        :param width: array standard deviation in Q [A-1] 
     280        :param min: Q_min [A-1] 
     281        :param max: Q_max [A-1] 
    280282        """ 
    281283        _BaseSmearer.__init__(self) 
     
    294296    def _initialize_smearer(self): 
    295297        """ 
    296             Initialize the C++ smearer object. 
    297             This method HAS to be called before smearing 
     298        Initialize the C++ smearer object. 
     299        This method HAS to be called before smearing 
    298300        """ 
    299301        #self._smearer = smearer.new_q_smearer(numpy.asarray(self.width), self.min, self.max, self.nbins) 
     
    303305    def get_unsmeared_range(self, q_min, q_max): 
    304306        """ 
    305             Determine the range needed in unsmeared-Q to cover 
    306             the smeared Q range 
    307             Take 3 sigmas as the offset between smeared and unsmeared space 
     307        Determine the range needed in unsmeared-Q to cover 
     308        the smeared Q range 
     309        Take 3 sigmas as the offset between smeared and unsmeared space 
    308310        """ 
    309311        # Range used for input to smearing 
     
    318320        return _qmin_unsmeared, _qmax_unsmeared 
    319321         
    320          
    321          
     322     
    322323class QSmearer(_QSmearer): 
    323324    """ 
    324         Adaptor for Gaussian Q smearing class and SANS data 
     325    Adaptor for Gaussian Q smearing class and SANS data 
    325326    """ 
    326327    def __init__(self, data1D): 
    327328        """ 
    328             Assumption: equally spaced bins of increasing q-values. 
    329              
    330             @param data1D: data used to set the smearing parameters 
     329        Assumption: equally spaced bins of increasing q-values. 
     330         
     331        :param data1D: data used to set the smearing parameters 
    331332        """ 
    332333        # Initialization from parent class 
  • DataLoader/readers/IgorReader.py

    readf1f9 r0997158f  
     1 
     2############################################################################ 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6#If you use DANSE applications to do scientific research that leads to  
     7#publication, we ask that you acknowledge the use of the software with the  
     8#following sentence: 
     9#This work benefited from DANSE software developed under NSF award DMR-0520547.  
     10#copyright 2008, University of Tennessee 
     11############################################################################# 
     12 
    113""" 
    214    IGOR 2D reduced file reader 
    3 """ 
    4  
    5 """ 
    6 This software was developed by the University of Tennessee as part of the 
    7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    8 project funded by the US National Science Foundation.  
    9  
    10 If you use DANSE applications to do scientific research that leads to  
    11 publication, we ask that you acknowledge the use of the software with the  
    12 following sentence: 
    13  
    14 "This work benefited from DANSE software developed under NSF award DMR-0520547."  
    15  
    16 copyright 2008, University of Tennessee 
    1715""" 
    1816 
  • DataLoader/readers/abs_reader.py

    rfe78c7b r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    5  
    6 See the license text in license.txt 
    7  
    8 copyright 2008, University of Tennessee 
    9 """ 
     1##################################################################### 
     2#This software was developed by the University of Tennessee as part of the 
     3#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     4#project funded by the US National Science Foundation.  
     5#See the license text in license.txt 
     6#copyright 2008, University of Tennessee 
     7###################################################################### 
    108 
    119import numpy 
     
    2119class Reader: 
    2220    """ 
    23         Class to load IGOR reduced .ABS files 
     21    Class to load IGOR reduced .ABS files 
    2422    """ 
    2523    ## File type 
     
    3230    def read(self, path): 
    3331        """  
    34             Load data file 
    35              
    36             @param path: file path 
    37             @return: Data1D object, or None 
    38             @raise RuntimeError: when the file can't be opened 
    39             @raise ValueError: when the length of the data vectors are inconsistent 
     32        Load data file. 
     33         
     34        :param path: file path 
     35         
     36        :return: Data1D object, or None 
     37         
     38        :raise RuntimeError: when the file can't be opened 
     39        :raise ValueError: when the length of the data vectors are inconsistent 
    4040        """ 
    4141        if os.path.isfile(path): 
  • DataLoader/readers/ascii_reader.py

    rc7c5ef8 r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    5  
    6 See the license text in license.txt 
    7  
    8 copyright 2008, University of Tennessee 
    9 """ 
     1 
     2 
     3############################################################################ 
     4#This software was developed by the University of Tennessee as part of the 
     5#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     6#project funded by the US National Science Foundation.  
     7#If you use DANSE applications to do scientific research that leads to  
     8#publication, we ask that you acknowledge the use of the software with the  
     9#following sentence: 
     10#This work benefited from DANSE software developed under NSF award DMR-0520547.  
     11#copyright 2008, University of Tennessee 
     12############################################################################# 
     13 
    1014 
    1115import numpy 
     
    2226class Reader: 
    2327    """ 
    24         Class to load ascii files (2, 3 or 4 columns) 
     28    Class to load ascii files (2, 3 or 4 columns). 
    2529    """ 
    2630    ## File type 
     
    3943    def read(self, path): 
    4044        """  
    41             Load data file 
    42              
    43             @param path: file path 
    44             @return: Data1D object, or None 
    45             @raise RuntimeError: when the file can't be opened 
    46             @raise ValueError: when the length of the data vectors are inconsistent 
     45        Load data file 
     46         
     47        :param path: file path 
     48         
     49        :return: Data1D object, or None 
     50         
     51        :raise RuntimeError: when the file can't be opened 
     52        :raise ValueError: when the length of the data vectors are inconsistent 
    4753        """ 
    4854        if os.path.isfile(path): 
  • DataLoader/readers/associations.py

    rded62ce r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    51 
    6 See the license text in license.txt 
    72 
    8 copyright 2009, University of Tennessee 
    9 """ 
     3############################################################################ 
     4#This software was developed by the University of Tennessee as part of the 
     5#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     6#project funded by the US National Science Foundation.  
     7#If you use DANSE applications to do scientific research that leads to  
     8#publication, we ask that you acknowledge the use of the software with the  
     9#following sentence: 
     10#This work benefited from DANSE software developed under NSF award DMR-0520547.  
     11#copyright 2009, University of Tennessee 
     12############################################################################# 
     13 
    1014 
    1115""" 
    12     Module to associate default readers to file extensions. 
    13     The module reads an xml file to get the readers for each file extension. 
    14     The readers are tried in order they appear when reading a file. 
     16Module to associate default readers to file extensions. 
     17The module reads an xml file to get the readers for each file extension. 
     18The readers are tried in order they appear when reading a file. 
    1519""" 
    1620 
     
    2630def read_associations(loader, settings='defaults.xml'): 
    2731    """ 
    28         Read the specified settings file to associate 
    29         default readers to file extension. 
    30          
    31         @param loader: Loader object 
    32         @param settings: path to the XML settings file [string] 
     32    Read the specified settings file to associate 
     33    default readers to file extension. 
     34     
     35    :param loader: Loader object 
     36    :param settings: path to the XML settings file [string] 
    3337    """ 
    3438    reader_dir = os.path.dirname(__file__) 
     
    6973def register_readers(registry_function): 
    7074    """ 
    71         Function called by the registry/loader object to register 
    72         all default readers using a call back function. 
    73          
    74         WARNING: this method is now obsolete 
     75    Function called by the registry/loader object to register 
     76    all default readers using a call back function. 
    7577     
    76         @param registry_function: function to be called to register each reader 
     78    :WARNING: this method is now obsolete 
     79 
     80    :param registry_function: function to be called to register each reader 
    7781    """ 
    7882    logging.info("register_readers is now obsolete: use read_associations()") 
  • DataLoader/readers/cansas_reader.py

    rfe78c7b r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    5  
    6 See the license text in license.txt 
    7  
    8 copyright 2008, 2009, University of Tennessee 
    9 """ 
     1 
     2 
     3############################################################################ 
     4#This software was developed by the University of Tennessee as part of the 
     5#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     6#project funded by the US National Science Foundation.  
     7#If you use DANSE applications to do scientific research that leads to  
     8#publication, we ask that you acknowledge the use of the software with the  
     9#following sentence: 
     10#This work benefited from DANSE software developed under NSF award DMR-0520547.  
     11#copyright 2008,2009 University of Tennessee 
     12############################################################################# 
     13 
    1014# Known issue: reader not compatible with multiple SASdata entries 
    1115# within a single SASentry. Will raise a runtime error. 
     
    3741def write_node(doc, parent, name, value, attr={}): 
    3842    """ 
    39         @param doc: document DOM 
    40         @param parent: parent node 
    41         @param name: tag of the element 
    42         @param value: value of the child text node 
    43         @param attr: attribute dictionary 
    44         @return: True if something was appended, otherwise False 
     43    :param doc: document DOM 
     44    :param parent: parent node 
     45    :param name: tag of the element 
     46    :param value: value of the child text node 
     47    :param attr: attribute dictionary 
     48     
     49    :return: True if something was appended, otherwise False 
    4550    """ 
    4651    if value is not None: 
     
    5560def get_content(location, node): 
    5661    """ 
    57         Get the first instance of the content of a xpath location 
    58          
    59         @param location: xpath location 
    60         @param node: node to start at 
    61         @return: Element, or None 
     62    Get the first instance of the content of a xpath location. 
     63     
     64    :param location: xpath location 
     65    :param node: node to start at 
     66     
     67    :return: Element, or None 
    6268    """ 
    6369    nodes = node.xpath(location, namespaces={'ns': CANSAS_NS}) 
     
    7076def get_float(location, node): 
    7177    """ 
    72         Get the content of a node as a float  
    73          
    74         @param location: xpath location 
    75         @param node: node to start at 
     78    Get the content of a node as a float  
     79     
     80    :param location: xpath location 
     81    :param node: node to start at 
    7682    """ 
    7783    nodes = node.xpath(location, namespaces={'ns': CANSAS_NS}) 
     
    96102class Reader: 
    97103    """ 
    98         Class to load cansas 1D XML files 
    99          
    100         Dependencies: 
    101             The CanSas reader requires PyXML 0.8.4 or later. 
     104    Class to load cansas 1D XML files 
     105     
     106    :Dependencies: 
     107        The CanSas reader requires PyXML 0.8.4 or later. 
    102108    """ 
    103109    ## CanSAS version 
     
    116122    def read(self, path): 
    117123        """  
    118             Load data file 
    119              
    120             @param path: file path 
    121             @return: Data1D object if a single SASentry was found,  
    122                         or a list of Data1D objects if multiple entries were found, 
    123                         or None of nothing was found 
    124             @raise RuntimeError: when the file can't be opened 
    125             @raise ValueError: when the length of the data vectors are inconsistent 
     124        Load data file 
     125         
     126        :param path: file path 
     127         
     128        :return: Data1D object if a single SASentry was found,  
     129                    or a list of Data1D objects if multiple entries were found, 
     130                    or None of nothing was found 
     131                     
     132        :raise RuntimeError: when the file can't be opened 
     133        :raise ValueError: when the length of the data vectors are inconsistent 
    126134        """ 
    127135        output = [] 
     
    162170    def _parse_entry(self, dom): 
    163171        """ 
    164             Parse a SASentry 
    165              
    166             @param node: SASentry node 
    167             @return: Data1D object 
     172        Parse a SASentry 
     173         
     174        :param node: SASentry node 
     175         
     176        :return: Data1D object 
    168177        """ 
    169178        x = numpy.zeros(0) 
     
    510519    def _to_xml_doc(self, datainfo): 
    511520        """ 
    512             Create an XML document to contain the content of a Data1D 
    513              
    514             @param datainfo: Data1D object 
     521        Create an XML document to contain the content of a Data1D 
     522         
     523        :param datainfo: Data1D object 
    515524        """ 
    516525         
     
    696705    def write(self, filename, datainfo): 
    697706        """ 
    698             Write the content of a Data1D as a CanSAS XML file 
    699              
    700             @param filename: name of the file to write 
    701             @param datainfo: Data1D object 
     707        Write the content of a Data1D as a CanSAS XML file 
     708         
     709        :param filename: name of the file to write 
     710        :param datainfo: Data1D object 
    702711        """ 
    703712        # Create XML document 
     
    710719    def _store_float(self, location, node, variable, storage, optional=True): 
    711720        """ 
    712             Get the content of a xpath location and store 
    713             the result. Check that the units are compatible 
    714             with the destination. The value is expected to 
    715             be a float. 
    716              
    717             The xpath location might or might not exist. 
    718             If it does not exist, nothing is done 
    719              
    720             @param location: xpath location to fetch 
    721             @param node: node to read the data from 
    722             @param variable: name of the data member to store it in [string] 
    723             @param storage: data object that has the 'variable' data member 
    724             @param optional: if True, no exception will be raised if unit conversion can't be done 
    725      
    726             @raise ValueError: raised when the units are not recognized 
     721        Get the content of a xpath location and store 
     722        the result. Check that the units are compatible 
     723        with the destination. The value is expected to 
     724        be a float. 
     725         
     726        The xpath location might or might not exist. 
     727        If it does not exist, nothing is done 
     728         
     729        :param location: xpath location to fetch 
     730        :param node: node to read the data from 
     731        :param variable: name of the data member to store it in [string] 
     732        :param storage: data object that has the 'variable' data member 
     733        :param optional: if True, no exception will be raised if unit conversion can't be done 
     734 
     735        :raise ValueError: raised when the units are not recognized 
    727736        """ 
    728737        entry = get_content(location, node) 
     
    767776    def _store_content(self, location, node, variable, storage): 
    768777        """ 
    769             Get the content of a xpath location and store 
    770             the result. The value is treated as a string. 
    771              
    772             The xpath location might or might not exist. 
    773             If it does not exist, nothing is done 
    774              
    775             @param location: xpath location to fetch 
    776             @param node: node to read the data from 
    777             @param variable: name of the data member to store it in [string] 
    778             @param storage: data object that has the 'variable' data member 
    779             @return: return a list of errors 
     778        Get the content of a xpath location and store 
     779        the result. The value is treated as a string. 
     780         
     781        The xpath location might or might not exist. 
     782        If it does not exist, nothing is done 
     783         
     784        :param location: xpath location to fetch 
     785        :param node: node to read the data from 
     786        :param variable: name of the data member to store it in [string] 
     787        :param storage: data object that has the 'variable' data member 
     788         
     789        :return: return a list of errors 
    780790        """ 
    781791        entry = get_content(location, node) 
  • DataLoader/readers/danse_reader.py

    readf1f9 r0997158f  
     1 
     2 
     3############################################################################ 
     4#This software was developed by the University of Tennessee as part of the 
     5#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     6#project funded by the US National Science Foundation.  
     7#If you use DANSE applications to do scientific research that leads to  
     8#publication, we ask that you acknowledge the use of the software with the  
     9#following sentence: 
     10#This work benefited from DANSE software developed under NSF award DMR-0520547.  
     11#copyright 2008, University of Tennessee 
     12############################################################################# 
     13 
    114""" 
    215    DANSE/SANS file reader 
    3 """ 
    4  
    5 """ 
    6 This software was developed by the University of Tennessee as part of the 
    7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    8 project funded by the US National Science Foundation.  
    9  
    10 If you use DANSE applications to do scientific research that leads to  
    11 publication, we ask that you acknowledge the use of the software with the  
    12 following sentence: 
    13  
    14 "This work benefited from DANSE software developed under NSF award DMR-0520547."  
    15  
    16 copyright 2008, University of Tennessee 
    1716""" 
    1817 
     
    3433class Reader: 
    3534    """ 
    36         Example data manipulation 
     35    Example data manipulation 
    3736    """ 
    3837    ## File type 
     
    4544    def read(self, filename=None): 
    4645        """ 
    47             Open and read the data in a file 
    48             @param file: path of the file 
     46        Open and read the data in a file 
     47        @param file: path of the file 
    4948        """ 
    5049         
     
    215214                 
    216215                 
    217             # Store all data ###################################### 
     216            # Store all data  
    218217            # Store wavelength 
    219218            if has_converter==True and output.source.wavelength_unit != 'A': 
  • DataLoader/readers/hfir1d_reader.py

    rfe78c7b r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    51 
    6 See the license text in license.txt 
    7  
    8 copyright 2008, University of Tennessee 
    9 """ 
     2##################################################################### 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6#See the license text in license.txt 
     7#copyright 2008, University of Tennessee 
     8###################################################################### 
    109 
    1110import numpy 
     
    2221class Reader(object): 
    2322    """ 
    24         Class to load HFIR 1D 4-column files 
     23    Class to load HFIR 1D 4-column files 
    2524    """ 
    2625    ## File type 
     
    3332    def read(self, path): 
    3433        """  
    35             Load data file 
    36              
    37             @param path: file path 
    38             @return: Data1D object, or None 
    39             @raise RuntimeError: when the file can't be opened 
    40             @raise ValueError: when the length of the data vectors are inconsistent 
     34        Load data file 
     35         
     36        :param path: file path 
     37         
     38        :return: Data1D object, or None 
     39         
     40        :raise RuntimeError: when the file can't be opened 
     41        :raise ValueError: when the length of the data vectors are inconsistent 
    4142        """ 
    4243        if os.path.isfile(path): 
  • DataLoader/readers/red2d_reader.py

    r59a2dab r0997158f  
     1 
     2##################################################################### 
     3#This software was developed by the University of Tennessee as part of the 
     4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     5#project funded by the US National Science Foundation.  
     6#See the license text in license.txt 
     7#copyright 2008, University of Tennessee 
     8###################################################################### 
     9 
    110""" 
    211    TXT/IGOR 2D Q Map file reader 
    312""" 
    413 
    5 """ 
    6 This software was developed by the University of Tennessee as part of the 
    7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    8 project funded by the US National Science Foundation.  
    9  
    10 If you use DANSE applications to do scientific research that leads to  
    11 publication, we ask that you acknowledge the use of the software with the  
    12 following sentence: 
    13  
    14 "This work benefited from DANSE software developed under NSF award DMR-0520547."  
    15  
    16 copyright 2008, University of Tennessee 
    17 """ 
    1814 
    1915import os, sys 
  • DataLoader/readers/tiff_reader.py

    rfe78c7b r0997158f  
     1 
     2 
     3##################################################################### 
     4#This software was developed by the University of Tennessee as part of the 
     5#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     6#project funded by the US National Science Foundation.  
     7#See the license text in license.txt 
     8#copyright 2008, University of Tennessee 
     9###################################################################### 
    110""" 
    211    Image reader. Untested.  
    312""" 
    413 
    5 """ 
    6 This software was developed by the University of Tennessee as part of the 
    7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    8 project funded by the US National Science Foundation.  
    914 
    10 See the license text in license.txt 
    11  
    12 copyright 2008, University of Tennessee 
    13 """ 
    1415#TODO: load and check data and orientation of the image (needs rendering) 
    1516 
     
    2021class Reader: 
    2122    """ 
    22         Example data manipulation 
     23    Example data manipulation 
    2324    """ 
    2425    ## File type 
     
    3334    def read(self, filename=None): 
    3435        """ 
    35             Open and read the data in a file 
    36             @param file: path of the file 
     36        Open and read the data in a file 
     37         
     38        :param file: path of the file 
    3739        """ 
    3840        try: 
  • DataLoader/smearing_2d.py

    rc6a48c27 r0997158f  
    1 """ 
    2 This software was developed by the University of Tennessee as part of the 
    3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 project funded by the US National Science Foundation.  
    5  
    6 See the license text in license.txt 
    7  
    8 copyright 2009, University of Tennessee 
    9 """ 
     1##################################################################### 
     2#This software was developed by the University of Tennessee as part of the 
     3#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     4#project funded by the US National Science Foundation.  
     5#See the license text in license.txt 
     6#copyright 2008, University of Tennessee 
     7###################################################################### 
     8 
    109## TODO: Need test,and check Gaussian averaging 
    1110import numpy, math,time 
     
    2120class Smearer2D: 
    2221    """ 
    23         Gaussian Q smearing class for SANS 2d data 
     22    Gaussian Q smearing class for SANS 2d data 
    2423    """ 
    2524      
    26     def __init__(self, data=None,model=None,index=None,limit=LIMIT,accuracy='Low'): 
    27         """ 
    28             Assumption: equally spaced bins in dq_r, dq_phi space. 
    29              
    30             @param data: 2d data used to set the smearing parameters 
    31             @param model: model function 
    32             @param index: 1d array with len(data) to define the range of the calculation: elements are given as True or False 
    33             @param nr: number of bins in dq_r-axis 
    34             @param nphi: number of bins in dq_phi-axis 
     25    def __init__(self, data=None, model=None, index=None,  
     26                 limit=LIMIT, accuracy='Low'): 
     27        """ 
     28        Assumption: equally spaced bins in dq_r, dq_phi space. 
     29         
     30        :param data: 2d data used to set the smearing parameters 
     31        :param model: model function 
     32        :param index: 1d array with len(data) to define the range of the calculation: elements are given as True or False 
     33        :param nr: number of bins in dq_r-axis 
     34        :param nphi: number of bins in dq_phi-axis 
    3535        """ 
    3636        ## data 
     
    5252    def get_data(self):    
    5353        """ 
    54             get qx_data, qy_data, dqx_data,dqy_data,and calculate phi_data=arctan(qx_data/qy_data) 
     54        get qx_data, qy_data, dqx_data,dqy_data,and calculate phi_data=arctan(qx_data/qy_data) 
    5555        """ 
    5656        if self.data == None or self.data.__class__.__name__ == 'Data1D': 
     
    6868        return True 
    6969     
    70     def set_accuracy(self,accuracy='Low'):    
    71         """ 
    72             Set accuracy:  string 
     70    def set_accuracy(self, accuracy='Low'):    
     71        """ 
     72        Set accuracy. 
     73         
     74        :param accuracy:  string 
    7375        """ 
    7476        self.accuracy = accuracy 
    7577 
    76     def set_smearer(self,smearer = True): 
    77         """ 
    78             Set whether or not smearer will be used 
     78    def set_smearer(self, smearer=True): 
     79        """ 
     80        Set whether or not smearer will be used 
     81         
     82        :param smearer: smear object 
     83         
    7984        """ 
    8085        self.smearer = smearer 
    8186         
    82     def set_data(self,data=None):    
    83         """ 
    84             Set data:  1d arrays 
     87    def set_data(self, data=None):    
     88        """ 
     89        Set data. 
     90         
     91        :param data: DataLoader.Data_info type 
    8592        """ 
    8693        self.data = data 
    8794   
    8895             
    89     def set_model(self,model=None):    
    90         """ 
    91             Set model 
     96    def set_model(self, model=None):    
     97        """ 
     98        Set model. 
     99         
     100        :param model: sans.models instance 
    92101        """ 
    93102        self.model = model   
    94103            
    95     def set_index(self,index=None):    
    96         """ 
    97             Set index: 1d arrays 
    98         """ 
    99  
     104    def set_index(self, index=None):    
     105        """ 
     106        Set index. 
     107         
     108        :param index: 1d arrays 
     109        """ 
    100110        self.index = index        
    101111     
    102112    def get_value(self): 
    103113        """ 
    104             Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, then find smeared intensity 
    105             # For the default values, this is equivalent (but by using numpy array  
    106             # the speed optimized by a factor of ten)to the following: 
    107             ===================================================================================== 
    108             ## Remove the singular points if exists 
     114        Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, then find smeared intensity 
     115        For the default values, this is equivalent (but by using numpy array  
     116        the speed optimized by a factor of ten)to the following: :: 
     117        
     118        
     119            Remove the singular points if exists 
    109120            self.dqx_data[self.dqx_data==0]=SIGMA_ZERO 
    110121            self.dqy_data[self.dqy_data==0]=SIGMA_ZERO 
     122             
    111123            for phi in range(0,4): 
    112124                for r in range(0,5): 
     
    114126                    r = r+0.25 
    115127                    dphi = phi*2.0*math.pi/4.0 + numpy.arctan(self.qy_data[index_model]/self.dqy_data[index_model]/self.qx_data[index_model]*/self.dqx_data[index_model]) 
    116                     dq = r*numpy.sqrt( self.dqx_data[index_model]*self.dqx_data[index_model] \ 
     128                    dq = r*sqrt( self.dqx_data[index_model]*self.dqx_data[index_model] \ 
    117129                        + self.dqy_data[index_model]*self.dqy_data[index_model] ) 
    118                     #integrant of math.exp(-0.5*r*r) r dr at each bins : The integration may not need. 
    119                     weight_res[n] = math.exp(-0.5*((r-0.25)*(r-0.25)))-math.exp(-0.5*((r-0.25)*(r-0.25))) 
    120                     #if phi !=0 and r != 0: 
    121                     qx_res=numpy.append(qx_res,self.qx_data[index_model]+ dq*math.cos(dphi)) 
    122                     qy_res=numpy.append(qy_res,self.qy_data[index_model]+ dq*math.sin(dphi)) 
    123             ## Then compute I(qx_res,qy_res) and do weighted averaging.  
    124             ===================================================================================== 
     130                    #integrant of exp(-0.5*r*r) r dr at each bins : The integration may not need. 
     131                    weight_res[n] = e^{(-0.5*((r-0.25)*(r-0.25)))}- e^{(-0.5*((r-0.25)*(r-0.25)))} 
     132                    #if phi != 0 and r != 0: 
     133                    qx_res = numpy.append(qx_res,self.qx_data[index_model]+ dq * cos(dphi)) 
     134                    qy_res = numpy.append(qy_res,self.qy_data[index_model]+ dq * sin(dphi)) 
     135                     
     136        Then compute I(qx_res,qy_res) and do weighted averaging.  
     137         
    125138        """ 
    126139        valid = self.get_data() 
Note: See TracChangeset for help on using the changeset viewer.