Changeset a9f579c in sasview for src/sas/sascalc/data_util


Ignore:
Timestamp:
Jan 17, 2017 2:18:58 PM (7 years ago)
Author:
jhbakker
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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
aad41bb
Parents:
ef0e644
Message:

Manually added in all the SESANS modifications from Jurtest

File:
1 edited

Legend:

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

    rd3911e3 ra9f579c  
    1313import logging 
    1414import sys 
    15  
     15from sasmodels import sesans 
     16import numpy as np  # type: ignore 
     17from numpy import pi, exp # type:ignore 
    1618from sasmodels.resolution import Slit1D, Pinhole1D 
     19from sasmodels.sesans import SESANS1D 
    1720from sasmodels.resolution2d import Pinhole2D 
     21from src.sas.sascalc.data_util.nxsunit import Converter 
    1822 
    1923def smear_selection(data, model = None): 
     
    3640    # Sanity check. If we are not dealing with a SAS Data1D 
    3741    # object, just return None 
     42    # This checks for 2D data (does not throw exception because fail is common) 
    3843    if  data.__class__.__name__ not in ['Data1D', 'Theory1D']: 
    3944        if data == None: 
     
    4146        elif data.dqx_data == None or data.dqy_data == None: 
    4247            return None 
    43         return PySmear2D(data, model) 
    44  
     48        return Pinhole2D(data) 
     49    # This checks for 1D data with smearing info in the data itself (again, fail is likely; no exceptions) 
    4550    if  not hasattr(data, "dx") and not hasattr(data, "dxl")\ 
    4651         and not hasattr(data, "dxw"): 
     
    4853 
    4954    # Look for resolution smearing data 
     55    # This is the code that checks for SESANS data; it looks for the file loader 
     56    # TODO: change other sanity checks to check for file loader instead of data structure? 
     57    _found_sesans = False 
     58    #if data.dx is not None and data.meta_data['loader']=='SESANS': 
     59    if data.dx is not None and data.isSesans: 
     60        #if data.dx[0] > 0.0: 
     61        if numpy.size(data.dx[data.dx <= 0]) == 0: 
     62            _found_sesans = True 
     63        # if data.dx[0] <= 0.0: 
     64        if numpy.size(data.dx[data.dx <= 0]) > 0: 
     65            raise ValueError('one or more of your dx values are negative, please check the data file!') 
     66 
     67    if _found_sesans == True: 
     68        #Pre-compute the Hankel matrix (H) 
     69        qmax, qunits = data.sample.zacceptance 
     70        hankel = sesans.SesansTransform() 
     71        sesans.SesansTransform.set_transform(hankel, 
     72        SE = Converter(data._xunit)(data.x, "A"), 
     73        zaccept = Converter(qunits)(qmax, "1/A"), 
     74        Rmax = 10000000) 
     75        # Then return the actual transform, as if it were a smearing function 
     76        return PySmear(SESANS1D(data, hankel._H0, hankel._H, hankel.q), model) 
     77 
    5078    _found_resolution = False 
    5179    if data.dx is not None and len(data.dx) == len(data.x): 
     
    92120        self.model = model 
    93121        self.resolution = resolution 
    94         self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     122 
     123        if hasattr(self.resolution, 'data'): 
     124            if self.resolution.data.meta_data['loader'] == 'SESANS':  # Always True if file extension is '.ses'! 
     125                self.offset = 0 
     126            # This is default behaviour, for future resolution/transform functions this needs to be revisited. 
     127            else: 
     128                self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     129        else: 
     130            self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     131 
     132        # self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
    95133 
    96134    def apply(self, iq_in, first_bin=0, last_bin=None): 
Note: See TracChangeset for help on using the changeset viewer.