Changeset 55bc5a7f in sasview for src/sas/sascalc


Ignore:
Timestamp:
Dec 19, 2016 2:40:37 AM (8 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:
b61bd57
Parents:
e1e41de (diff), 67b0a99 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into Jurtest2

Location:
src/sas/sascalc
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    r5e906207 rbbd0f37  
    162162                    else: 
    163163                        self.current_dataset.x = data_set.flatten() 
     164                    continue 
     165                elif key == u'Qdev': 
     166                    self.current_dataset.dx = data_set.flatten() 
    164167                    continue 
    165168                elif key == u'Qy': 
  • 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) 
  • src/sas/sascalc/dataloader/data_info.py

    r1b1a1c1 r1fac6c0  
    2525import numpy 
    2626import math 
    27  
    28 class plottable_sesans1D(object): 
    29     """ 
    30     SESANS is a place holder for 1D SESANS plottables. 
    31  
    32     #TODO: This was directly copied from the plottables_1D. Modified Somewhat. 
    33     #Class has been updated. 
    34     """ 
    35     # The presence of these should be mutually 
    36     # exclusive with the presence of Qdev (dx) 
    37     x = None 
    38     y = None 
    39     lam = None 
    40     dx = None 
    41     dy = None 
    42     dlam = None 
    43     ## Slit smearing length 
    44     dxl = None 
    45     ## Slit smearing width 
    46     dxw = None 
    47  
    48     # Units 
    49     _xaxis = '' 
    50     _xunit = '' 
    51     _yaxis = '' 
    52     _yunit = '' 
    53  
    54     def __init__(self, x, y, lam, dx=None, dy=None, dlam=None): 
    55 #        print "SESANS plottable working" 
    56         self.x = numpy.asarray(x) 
    57         self.y = numpy.asarray(y) 
    58         self.lam = numpy.asarray(lam) 
    59         if dx is not None: 
    60             self.dx = numpy.asarray(dx) 
    61         if dy is not None: 
    62             self.dy = numpy.asarray(dy) 
    63         if dlam is not None: 
    64             self.dlam = numpy.asarray(dlam) 
    65  
    66     def xaxis(self, label, unit): 
    67         """ 
    68         set the x axis label and unit 
    69         """ 
    70         self._xaxis = label 
    71         self._xunit = unit 
    72  
    73     def yaxis(self, label, unit): 
    74         """ 
    75         set the y axis label and unit 
    76         """ 
    77         self._yaxis = label 
    78         self._yunit = unit 
    79  
    80  
    8127class plottable_1D(object): 
    8228    """ 
     
    9440    dxw = None 
    9541 
     42    ## SESANS specific params (wavelengths for spin echo length calculation) 
     43 
     44    lam = None 
     45    dlam = None 
     46 
    9647    # Units 
    9748    _xaxis = '' 
     
    10051    _yunit = '' 
    10152 
    102     def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None): 
     53    def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None): 
    10354        self.x = numpy.asarray(x) 
    10455        self.y = numpy.asarray(y) 
     
    11162        if dxw is not None: 
    11263            self.dxw = numpy.asarray(dxw) 
     64        if lam is not None: 
     65            self.lam = numpy.asarray(lam) 
     66        if dlam is not None: 
     67            self.dlam = numpy.asarray(dlam) 
    11368 
    11469    def xaxis(self, label, unit): 
     
    736691        return self._perform_union(other) 
    737692 
    738 class SESANSData1D(plottable_sesans1D, DataInfo): 
    739     """ 
    740     SESANS 1D data class 
    741     """ 
    742     x_unit = 'nm' 
    743     y_unit = 'pol' 
    744  
    745     def __init__(self, x=None, y=None, lam=None, dx=None, dy=None, dlam=None): 
     693class Data1D(plottable_1D, DataInfo): 
     694    """ 
     695    1D data class 
     696    """ 
     697    #if plottable_1D.lam is None: # This means it's SANS data! 
     698     #   x_unit = '1/A' 
     699      #  y_unit = '1/cm' 
     700    #elif plottable_1D.lam is not None: # This means it's SESANS data! 
     701     #   x_unit = 'A' 
     702      #  y_unit = 'pol' 
     703    #else: # and if it's neither, you get punished! 
     704     #   raise(TypeError,'This is neither SANS nor SESANS data, what the hell are you doing??') 
     705 
     706    def __init__(self, x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=False): 
     707        self.isSesans = isSesans 
    746708        DataInfo.__init__(self) 
    747         plottable_sesans1D.__init__(self, x, y, lam, dx, dy, dlam) 
     709        plottable_1D.__init__(self, x, y, dx, dy,None, None, lam, dlam) 
     710        if self.isSesans: 
     711            x_unit = 'A' 
     712            y_unit = 'pol' 
     713        elif not self.isSesans: # it's SANS data! (Could also be simple else statement, but i prefer exhaustive conditionals...-JHB) 
     714            x_unit = '1/A' 
     715            y_unit = '1/cm' 
     716        else: # and if it's neither, you get punished! 
     717            raise(TypeError,'This is neither SANS nor SESANS data, what the hell are you doing??') 
    748718 
    749719    def __str__(self): 
     
    759729        return _str 
    760730 
    761     def clone_without_data(self, length=0, clone=None): 
    762         """ 
    763         Clone the current object, without copying the data (which 
    764         will be filled out by a subsequent operation). 
    765         The data arrays will be initialized to zero. 
    766  
    767         :param length: length of the data array to be initialized 
    768         :param clone: if provided, the data will be copied to clone 
    769         """ 
    770         from copy import deepcopy 
    771         if clone is None or not issubclass(clone.__class__, Data1D): 
    772             x = numpy.zeros(length) 
    773             dx = numpy.zeros(length) 
    774             y = numpy.zeros(length) 
    775             dy = numpy.zeros(length) 
    776             clone = Data1D(x, y, dx=dx, dy=dy) 
    777  
    778         clone.title = self.title 
    779         clone.run = self.run 
    780         clone.filename = self.filename 
    781         clone.instrument = self.instrument 
    782         clone.notes = deepcopy(self.notes) 
    783         clone.process = deepcopy(self.process) 
    784         clone.detector = deepcopy(self.detector) 
    785         clone.sample = deepcopy(self.sample) 
    786         clone.source = deepcopy(self.source) 
    787         clone.collimation = deepcopy(self.collimation) 
    788         clone.trans_spectrum = deepcopy(self.trans_spectrum) 
    789         clone.meta_data = deepcopy(self.meta_data) 
    790         clone.errors = deepcopy(self.errors) 
    791  
    792         return clone 
    793  
    794 class Data1D(plottable_1D, DataInfo): 
    795     """ 
    796     1D data class 
    797     """ 
    798     x_unit = '1/A' 
    799     y_unit = '1/cm' 
    800  
    801     def __init__(self, x, y, dx=None, dy=None): 
    802         DataInfo.__init__(self) 
    803         plottable_1D.__init__(self, x, y, dx, dy) 
    804  
    805     def __str__(self): 
    806         """ 
    807         Nice printout 
    808         """ 
    809         _str = "%s\n" % DataInfo.__str__(self) 
    810         _str += "Data:\n" 
    811         _str += "   Type:         %s\n" % self.__class__.__name__ 
    812         _str += "   X-axis:       %s\t[%s]\n" % (self._xaxis, self._xunit) 
    813         _str += "   Y-axis:       %s\t[%s]\n" % (self._yaxis, self._yunit) 
    814         _str += "   Length:       %g\n" % len(self.x) 
    815         return _str 
    816  
    817731    def is_slit_smeared(self): 
    818732        """ 
     
    843757            y = numpy.zeros(length) 
    844758            dy = numpy.zeros(length) 
    845             clone = Data1D(x, y, dx=dx, dy=dy) 
     759            lam = numpy.zeros(length) 
     760            dlam = numpy.zeros(length) 
     761            clone = Data1D(x, y, lam=lam, dx=dx, dy=dy, dlam=dlam ) 
    846762 
    847763        clone.title = self.title 
  • src/sas/sascalc/dataloader/readers/sesans_reader.py

    r1c0e3b0 ra01af35  
    88import numpy 
    99import os 
    10 from sas.sascalc.dataloader.data_info import SESANSData1D 
     10from sas.sascalc.dataloader.data_info import Data1D 
    1111 
    1212# Check whether we have a converter available 
     
    5959                    raise  RuntimeError, "sesans_reader: cannot open %s" % path 
    6060                buff = input_f.read() 
    61 #                print buff 
    6261                lines = buff.splitlines() 
    63 #                print lines 
    64                 #Jae could not find python universal line spliter: 
    65                 #keep the below for now 
    66                 # some ascii data has \r line separator, 
    67                 # try it when the data is on only one long line 
    68 #                if len(lines) < 2 : 
    69 #                    lines = buff.split('\r') 
    70                   
    7162                x  = numpy.zeros(0) 
    7263                y  = numpy.zeros(0) 
     
    8374                tdlam = numpy.zeros(0) 
    8475                tdx = numpy.zeros(0) 
    85 #                print "all good" 
    86                 output = SESANSData1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam) 
    87 #                print output                 
     76                output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, isSesans=True ) 
    8877                self.filename = output.filename = basename 
    8978 
    90 #                #Initialize counters for data lines and header lines. 
    91 #                is_data = False  # Has more than 5 lines 
    92 #                # More than "5" lines of data is considered as actual 
    93 #                # data unless that is the only data 
    94 #                mum_data_lines = 5 
    95 #                # To count # of current data candidate lines 
    96 #                i = -1 
    97 #                # To count total # of previous data candidate lines 
    98 #                i1 = -1 
    99 #                # To count # of header lines 
    100 #                j = -1 
    101 #                # Helps to count # of header lines 
    102 #                j1 = -1 
    103 #                #minimum required number of columns of data; ( <= 4). 
    104 #                lentoks = 2 
    10579                paramnames=[] 
    10680                paramvals=[] 
     
    11185                Pvals=[] 
    11286                dPvals=[] 
    113 #                print x 
    114 #                print zvals 
    11587                for line in lines: 
    11688                    # Initial try for CSV (split on ,) 
     
    12294                    if len(toks)>5: 
    12395                        zvals.append(toks[0]) 
    124                         dzvals.append(toks[1]) 
    125                         lamvals.append(toks[2]) 
    126                         dlamvals.append(toks[3]) 
    127                         Pvals.append(toks[4]) 
    128                         dPvals.append(toks[5]) 
     96                        dzvals.append(toks[3]) 
     97                        lamvals.append(toks[4]) 
     98                        dlamvals.append(toks[5]) 
     99                        Pvals.append(toks[1]) 
     100                        dPvals.append(toks[2]) 
    129101                    else: 
    130102                        continue 
     
    140112                default_z_unit = "A" 
    141113                data_conv_P = None 
    142                 default_p_unit = " " 
     114                default_p_unit = " " # Adjust unit for axis (L^-3) 
    143115                lam_unit = lam_header[1].replace("[","").replace("]","") 
     116                if lam_unit == 'AA': 
     117                    lam_unit = 'A' 
    144118                varheader=[zvals[0],dzvals[0],lamvals[0],dlamvals[0],Pvals[0],dPvals[0]] 
    145119                valrange=range(1, len(zvals)) 
     
    161135                output.x, output.x_unit = self._unit_conversion(x, lam_unit, default_z_unit) 
    162136                output.y = y 
     137                output.y_unit = '\AA^{-2} cm^{-1}' # output y_unit erbij 
    163138                output.dx, output.dx_unit = self._unit_conversion(dx, lam_unit, default_z_unit) 
    164139                output.dy = dy 
     
    166141                output.dlam, output.dlam_unit = self._unit_conversion(dlam, lam_unit, default_z_unit) 
    167142 
    168                 output.xaxis("\rm{z}", output.x_unit) 
    169                 output.yaxis("\\rm{P/P0}", output.y_unit) 
     143                output.xaxis("\\rm{z}", output.x_unit) 
     144                output.yaxis("\\rm{ln(P)/(t \lambda^2)}", output.y_unit) # Adjust label to ln P/(lam^2 t), remove lam column refs 
    170145                # Store loading process information 
    171146                output.meta_data['loader'] = self.type_name 
    172                 output.sample.thickness = float(paramvals[6]) 
     147                #output.sample.thickness = float(paramvals[6]) 
    173148                output.sample.name = paramvals[1] 
    174149                output.sample.ID = paramvals[0] 
    175150                zaccept_unit_split = paramnames[7].split("[") 
    176151                zaccept_unit = zaccept_unit_split[1].replace("]","") 
    177                 if zaccept_unit.strip() == '\AA^-1': 
     152                if zaccept_unit.strip() == '\AA^-1' or zaccept_unit.strip() == '\A^-1': 
    178153                    zaccept_unit = "1/A" 
    179154                output.sample.zacceptance=(float(paramvals[7]),zaccept_unit) 
  • src/sas/sascalc/fit/AbstractFitEngine.py

    rfc18690 r7988501  
    131131        a way to get residuals from data. 
    132132    """ 
    133     def __init__(self, x, y, dx=None, dy=None, smearer=None, data=None): 
     133    def __init__(self, x, y, dx=None, dy=None, smearer=None, data=None, lam=None, dlam=None): 
    134134        """ 
    135135            :param smearer: is an object of class QSmearer or SlitSmearer 
     
    152152                 
    153153        """ 
    154         Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 
     154        Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy, lam=lam,dlam=dlam) 
    155155        self.num_points = len(x) 
    156156        self.sas_data = data 
  • src/sas/sascalc/fit/BumpsFitting.py

    r1a5d5f2 rf668101  
    2727from bumps import parameter 
    2828from bumps.fitproblem import FitProblem 
    29  
    3029 
    3130from sas.sascalc.fit.AbstractFitEngine import FitEngine 
Note: See TracChangeset for help on using the changeset viewer.