Ignore:
File:
1 edited

Legend:

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

    rf8aa738 rc6728e1  
    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 
     
    1313import logging 
    1414import sys 
     15from sasmodels import sesans 
     16import numpy as np  # type: ignore 
     17from numpy import pi, exp  # type: ignore 
    1518 
    1619from sasmodels.resolution import Slit1D, Pinhole1D 
     20from sasmodels.sesans import SESANS1D 
    1721from sasmodels.resolution2d import Pinhole2D 
     22from src.sas.sascalc.data_util.nxsunit import Converter 
     23 
    1824 
    1925def smear_selection(data, model = None): 
     
    3642    # Sanity check. If we are not dealing with a SAS Data1D 
    3743    # object, just return None 
     44 
     45    # This checks for 2D data (does not throw exception because fail is common) 
    3846    if  data.__class__.__name__ not in ['Data1D', 'Theory1D']: 
    3947        if data == None: 
     
    4250            return None 
    4351        return Pinhole2D(data) 
    44  
     52    # This checks for 1D data with smearing info in the data itself (again, fail is likely; no exceptions) 
    4553    if  not hasattr(data, "dx") and not hasattr(data, "dxl")\ 
    4654         and not hasattr(data, "dxw"): 
     
    4856 
    4957    # Look for resolution smearing data 
     58    # This is the code that checks for SESANS data; it looks for the file loader 
     59    # TODO: change other sanity checks to check for file loader instead of data structure? 
     60    _found_sesans = False 
     61    #if data.dx is not None and data.meta_data['loader']=='SESANS': 
     62    if data.dx is not None and data.isSesans: 
     63        #if data.dx[0] > 0.0: 
     64        if numpy.size(data.dx[data.dx <= 0]) == 0: 
     65            _found_sesans = True 
     66        #if data.dx[0] <= 0.0: 
     67        if numpy.size(data.dx[data.dx <= 0]) > 0: 
     68            raise ValueError('one or more of your dx values are negative, please check the data file!') 
     69    if _found_sesans == True: 
     70        #Pre-compute the Hankel matrix (H) 
     71        qmax, qunits = data.sample.zacceptance 
     72        hankel=sesans.SesansTransform() 
     73        sesans.SesansTransform.set_transform(hankel, 
     74        SE = Converter(data._xunit)(data.x, "A"), 
     75        zaccept = Converter(qunits)(qmax, "1/A"), 
     76        Rmax = 10000000) 
     77        # Then return the actual transform, as if it were a smearing function 
     78        return PySmear(SESANS1D(data, hankel._H0, hankel._H, hankel.q), model) 
     79 
    5080    _found_resolution = False 
    5181    if data.dx is not None and len(data.dx) == len(data.x): 
     
    92122        self.model = model 
    93123        self.resolution = resolution 
    94         self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     124        if hasattr(self.resolution, 'data'): 
     125            if self.resolution.data.meta_data['loader'] == 'SESANS': # Always True if file extension is '.ses'! 
     126                self.offset = 0 
     127            # This is default behaviour, for future resolution/transform functions this needs to be revisited. 
     128            else: 
     129                self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     130        else: 
     131            self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     132 
     133        #self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
    95134 
    96135    def apply(self, iq_in, first_bin=0, last_bin=None): 
     
    126165        q[first:last+1]. 
    127166        """ 
     167 
    128168        q = self.resolution.q 
    129169        first = numpy.searchsorted(q, q_min) 
Note: See TracChangeset for help on using the changeset viewer.