Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/qsmearing.py

    r235f514 rba91f71  
    55#This software was developed by the University of Tennessee as part of the 
    66#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    7 #project funded by the US National Science Foundation.  
     7#project funded by the US National Science Foundation. 
    88#See the license text in license.txt 
    99#copyright 2008, University of Tennessee 
    1010###################################################################### 
     11import numpy 
    1112import math 
    1213import logging 
     
    1718 
    1819from sasmodels.resolution import Slit1D, Pinhole1D 
    19 from sasmodels.sesans import SesansTransform 
     20from sasmodels.sesans import SesansTransform, OrientedSesansTransform 
    2021from sasmodels.resolution2d import Pinhole2D 
    2122from .nxsunit import Converter 
     
    4243    # This checks for 2D data (does not throw exception because fail is common) 
    4344    if  data.__class__.__name__ not in ['Data1D', 'Theory1D']: 
    44         if data is None: 
     45        if data == None: 
    4546            return None 
    46         elif data.dqx_data is None or data.dqy_data is None: 
     47        elif data.dqx_data == None or data.dqy_data == None: 
    4748            return None 
    4849        return PySmear2D(data) 
     
    5960    if data.dx is not None and data.isSesans: 
    6061        #if data.dx[0] > 0.0: 
    61         if np.size(data.dx[data.dx <= 0]) == 0: 
     62        if numpy.size(data.dx[data.dx <= 0]) == 0: 
    6263            _found_sesans = True 
    6364        # if data.dx[0] <= 0.0: 
    64         if np.size(data.dx[data.dx <= 0]) > 0: 
     65        if numpy.size(data.dx[data.dx <= 0]) > 0: 
    6566            raise ValueError('one or more of your dx values are negative, please check the data file!') 
    6667 
     
    7172        zaccept = Converter(qunits)(qmax, "1/A"), 
    7273        Rmax = 10000000 
    73         hankel = SesansTransform(data.x, SElength, zaccept, Rmax) 
     74        # data must have the isoriented flag here! 
    7475        # Then return the actual transform, as if it were a smearing function 
    75         return PySmear(hankel, model, offset=0) 
     76        if getattr(data, 'isoriented', False): 
     77            costransform = OrientedSesansTransform(data.x, SElength, zaccept, Rmax) 
     78            return PySmear(costransform, model, offset=0) 
     79        else: 
     80            hankel = SesansTransform(data.x, SElength, zaccept, Rmax) 
     81            return PySmear(hankel, model, offset=0) 
    7682 
    7783    _found_resolution = False 
     
    120126        self.resolution = resolution 
    121127        if offset is None: 
    122             offset = np.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     128            offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
    123129        self.offset = offset 
    124130 
     
    133139        first_bin:last_bin set to the resolution smeared values. 
    134140        """ 
    135         if last_bin is None: last_bin = len(iq_in) 
    136         start, end = first_bin + self.offset, last_bin + self.offset 
    137141        q_calc = self.resolution.q_calc 
    138         iq_calc = np.empty_like(q_calc) 
    139         if start > 0: 
    140             iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 
    141         if end+1 < len(q_calc): 
    142             iq_calc[end+1:] = self.model.evalDistribution(q_calc[end+1:]) 
    143         iq_calc[start:end+1] = iq_in[first_bin:last_bin+1] 
     142        if isinstance(q_calc, tuple): 
     143            # We are 2D -> 1D! 
     144            iq_calc = self.model.evalDistribution(q_calc) 
     145        else: 
     146            if last_bin is None: last_bin = len(iq_in) 
     147            start, end = first_bin + self.offset, last_bin + self.offset 
     148            iq_calc = numpy.empty_like(q_calc) 
     149            if start > 0: 
     150                iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 
     151            if end+1 < len(q_calc): 
     152                iq_calc[end+1:] = self.model.evalDistribution(q_calc[end+1:]) 
     153            iq_calc[start:end+1] = iq_in[first_bin:last_bin+1] 
    144154        smeared = self.resolution.apply(iq_calc) 
    145155        return smeared 
     
    156166        """ 
    157167        q = self.resolution.q 
    158         first = np.searchsorted(q, q_min) 
    159         last = np.searchsorted(q, q_max) 
     168        first = numpy.searchsorted(q, q_min) 
     169        last = numpy.searchsorted(q, q_max) 
    160170        return first, min(last,len(q)-1) 
    161171 
Note: See TracChangeset for help on using the changeset viewer.