Changeset 4fe4394 in sasview


Ignore:
Timestamp:
Oct 10, 2008 4:47:33 PM (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:
ae60f86
Parents:
2139c3f
Message:

implemented smearer selection

Location:
DataLoader
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/qsmearing.py

    rd00f8ff r4fe4394  
    88copyright 2008, University of Tennessee 
    99""" 
     10 
     11#TODO: improvement: allow for varying dQ as a function of Q 
     12 
    1013import numpy 
    1114import math 
     
    1518    """ 
    1619        Creates the right type of smearer according  
    17         to the data 
    18     """ 
    19     pass 
     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 
     33    """ 
     34    # Sanity check. If we are not dealing with a SANS Data1D 
     35    # object, just return None 
     36    if data1D.__class__.__name__ != 'Data1D' \ 
     37        or not hasattr(data1D, "dxl") or not hasattr(data1D, "dxw"): 
     38        return None 
     39     
     40    # Look for resolution smearing data 
     41    _found_resolution = False 
     42    if data1D.dx is not None and len(data1D.dx)==len(data1D.x): 
     43         
     44        # Check that we have non-zero data 
     45        if data1D.dx[0]>0.0: 
     46            _found_resolution = True 
     47         
     48    # If we found resolution smearing data, return a QSmearer 
     49    if _found_resolution == True: 
     50        return QSmearer(data1D) 
     51 
     52    # Look for slit smearing data 
     53    _found_slit = False 
     54    if data1D.dxl is not None and len(data1D.dxl)==len(data1D.x) \ 
     55        and data1D.dxw is not None and len(data1D.dxw)==len(data1D.x): 
     56         
     57        # Check that we have non-zero data 
     58        if data1D.dxl[0]>0.0 or data1D.dxw[0]>0.0: 
     59            _found_slit = True 
     60         
     61        # Sanity check: all data should be the same as a function of Q 
     62        for item in data1D.dxl: 
     63            if data1D.dxl[0] != item: 
     64                _found_resolution = False 
     65                break 
     66             
     67        for item in data1D.dxw: 
     68            if data1D.dxw[0] != item: 
     69                _found_resolution = False 
     70                break 
     71             
     72    # If we found slit smearing data, return a slit smearer 
     73    if _found_slit == True: 
     74        return SlitSmearer(data1D) 
     75     
     76    return None 
     77             
    2078 
    2179class _BaseSmearer(object): 
     
    213271                # Compute the fraction of the Gaussian contributing 
    214272                # to the q bin between q_min and q_max 
    215                 value =  scipy.special.erf( (q_max-q_j)/(math.sqrt(2.0)*self.width) )  
    216                 value -=scipy.special.erf( (q_min-q_j)/(math.sqrt(2.0)*self.width) )  
     273                value =  scipy.special.erf( (q_max-q_j)/(math.sqrt(2.0)*self.width[j]) )  
     274                value -=scipy.special.erf( (q_min-q_j)/(math.sqrt(2.0)*self.width[j]) )  
    217275 
    218276                weights[i][j] += value 
     
    235293         
    236294        ## Slit width 
    237         self.width = 0 
     295        self.width = numpy.zeros(len(data1D.x)) 
    238296        if data1D.dx is not None and len(data1D.dx)==len(data1D.x): 
    239             self.width = data1D.dx[0] 
    240             # Sanity check 
    241             for value in data1D.dx: 
    242                 if value != self.width: 
    243                     raise RuntimeError, "dQ must be the same for all data" 
     297            self.width = data1D.dx 
    244298         
    245299        ## Number of Q bins 
  • DataLoader/readers/danse_reader.py

    rb99ac227 r4fe4394  
    155155             
    156156            # Qx and Qy vectors 
     157            theta = pixel / distance / 100.0 
     158            stepq = 4.0*math.pi/wavelength * math.sin(theta/2.0)  
    157159            for i_x in range(size_x): 
    158160                theta = (i_x-center_x+1)*pixel / distance / 100.0 
     
    235237             
    236238            # Store limits of the image (2D array) 
     239            xmin    =xmin-stepq/2.0 
     240            xmax    =xmax+stepq/2.0 
     241            ymin    =ymin-stepq/2.0 
     242            ymax    =ymax+stepq/2.0 
     243             
    237244            if has_converter == True and output.Q_unit != '1/A': 
    238245                xmin = data_conv_q(xmin, units=output.Q_unit) 
  • DataLoader/test/utest_smearing.py

    rd00f8ff r4fe4394  
    88from DataLoader.loader import  Loader 
    99from DataLoader.data_info import Data1D, Data2D 
    10 from DataLoader.qsmearing import SlitSmearer, QSmearer 
     10from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection 
    1111  
    1212import os.path 
     
    2121        dxl = 0.00*numpy.ones(10) 
    2222        dxw = 0.00*numpy.ones(10) 
     23        dx = 0.00*numpy.ones(10) 
    2324         
     25        self.data.dx = dx 
    2426        self.data.x = x 
    2527        self.data.y = y 
Note: See TracChangeset for help on using the changeset viewer.