Changeset 25427d9 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Mar 21, 2016 8:32:15 AM (8 years ago)
Author:
awashington
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:
cf92b1f, 5757bbe
Parents:
1c0e3b0 (diff), bb0c836 (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' of github.com:SasView/sasview

Location:
src/sas/sascalc
Files:
1 added
3 edited
11 moved

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/calculator/BaseComponent.py

    r79492222 r9e531f2  
    11#!/usr/bin/env python 
    22 
    3 """  
     3""" 
    44Provide base functionality for all model components 
    55""" 
    66 
    7 # imports    
     7# imports 
    88import copy 
    99import numpy 
    1010#TO DO: that about a way to make the parameter 
    11 #is self return if it is fittable or not   
     11#is self return if it is fittable or not 
    1212 
    1313class BaseComponent: 
    14     """  
     14    """ 
    1515    Basic model component 
    16      
     16 
    1717    Since version 0.5.0, basic operations are no longer supported. 
    1818    """ 
     
    2020    def __init__(self): 
    2121        """ Initialization""" 
    22          
     22 
    2323        ## Name of the model 
    2424        self.name = "BaseComponent" 
    25          
     25 
    2626        ## Parameters to be accessed by client 
    2727        self.params = {} 
     
    4949        self.output_name = "Intensity" 
    5050        self.output_unit = "cm^{-1}" 
    51          
     51 
    5252    def __str__(self): 
    53         """  
     53        """ 
    5454        :return: string representatio 
    55  
    5655        """ 
    5756        return self.name 
    58     
     57 
    5958    def is_fittable(self, par_name): 
    6059        """ 
    6160        Check if a given parameter is fittable or not 
    62          
    63         :param par_name: the parameter name to check  
    64          
     61 
     62        :param par_name: the parameter name to check 
     63 
    6564        """ 
    6665        return par_name.lower() in self.fixed 
    6766        #For the future 
    6867        #return self.params[str(par_name)].is_fittable() 
    69     
    70     def run(self, x):  
     68 
     69    def run(self, x): 
    7170        """ 
    7271        run 1d 
    7372        """ 
    7473        return NotImplemented 
    75      
    76     def runXY(self, x):  
     74 
     75    def runXY(self, x): 
    7776        """ 
    7877        run 2d 
    7978        """ 
    80         return NotImplemented   
    81      
    82     def calculate_ER(self):  
     79        return NotImplemented 
     80 
     81    def calculate_ER(self): 
    8382        """ 
    8483        Calculate effective radius 
    8584        """ 
    86         return NotImplemented   
    87      
    88     def calculate_VR(self):  
     85        return NotImplemented 
     86 
     87    def calculate_VR(self): 
    8988        """ 
    9089        Calculate volume fraction ratio 
    9190        """ 
    92         return NotImplemented  
    93      
     91        return NotImplemented 
     92 
    9493    def evalDistribution(self, qdist): 
    9594        """ 
    9695        Evaluate a distribution of q-values. 
    97          
     96 
    9897        * For 1D, a numpy array is expected as input: :: 
    99          
     98 
    10099            evalDistribution(q) 
    101              
     100 
    102101          where q is a numpy array. 
    103          
    104          
     102 
     103 
    105104        * For 2D, a list of numpy arrays are expected: [qx_prime,qy_prime], 
    106105          where 1D arrays, :: 
    107          
     106 
    108107              qx_prime = [ qx[0], qx[1], qx[2], ....] 
    109  
    110108          and :: 
    111  
    112               qy_prime = [ qy[0], qy[1], qy[2], ....]  
    113          
     109              qy_prime = [ qy[0], qy[1], qy[2], ....] 
     110 
    114111        Then get :: 
    115  
    116112            q = numpy.sqrt(qx_prime^2+qy_prime^2) 
    117          
     113 
    118114        that is a qr in 1D array; :: 
    119  
    120             q = [q[0], q[1], q[2], ....]  
    121          
     115            q = [q[0], q[1], q[2], ....] 
     116 
    122117        ..note:: 
    123           Due to 2D speed issue, no anisotropic scattering  
     118          Due to 2D speed issue, no anisotropic scattering 
    124119          is supported for python models, thus C-models should have 
    125120          their own evalDistribution methods. 
    126          
     121 
    127122        The method is then called the following way: :: 
    128          
     123 
    129124            evalDistribution(q) 
    130  
    131125        where q is a numpy array. 
    132          
     126 
    133127        :param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays 
    134128        """ 
     
    140134                msg = "evalDistribution expects a list of 2 ndarrays" 
    141135                raise RuntimeError, msg 
    142                  
     136 
    143137            # Extract qx and qy for code clarity 
    144138            qx = qdist[0] 
    145139            qy = qdist[1] 
    146              
     140 
    147141            # calculate q_r component for 2D isotropic 
    148142            q = numpy.sqrt(qx**2+qy**2) 
     
    153147 
    154148            return iq_array 
    155                  
     149 
    156150        elif qdist.__class__.__name__ == 'ndarray': 
    157151            # We have a simple 1D distribution of q-values 
     
    159153            iq_array = v_model(qdist) 
    160154            return iq_array 
    161              
     155 
    162156        else: 
    163157            mesg = "evalDistribution is expecting an ndarray of scalar q-values" 
    164158            mesg += " or a list [qx,qy] where qx,qy are 2D ndarrays." 
    165159            raise RuntimeError, mesg 
    166          
    167      
    168      
     160 
     161 
     162 
    169163    def clone(self): 
    170164        """ Returns a new object identical to the current object """ 
    171165        obj = copy.deepcopy(self) 
    172166        return self._clone(obj) 
    173      
     167 
    174168    def _clone(self, obj): 
    175169        """ 
     
    182176        obj._persistency_dict = copy.deepcopy( self._persistency_dict) 
    183177        return obj 
    184      
     178 
    185179    def set_dispersion(self, parameter, dispersion): 
    186180        """ 
    187181        model dispersions 
    188         """  
     182        """ 
    189183        ##Not Implemented 
    190184        return None 
    191          
     185 
    192186    def getProfile(self): 
    193187        """ 
    194         Get SLD profile  
    195          
     188        Get SLD profile 
     189 
    196190        : return: (z, beta) where z is a list of depth of the transition points 
    197                 beta is a list of the corresponding SLD values  
     191                beta is a list of the corresponding SLD values 
    198192        """ 
    199193        #Not Implemented 
    200194        return None, None 
    201              
     195 
    202196    def setParam(self, name, value): 
    203         """  
     197        """ 
    204198        Set the value of a model parameter 
    205      
     199 
    206200        :param name: name of the parameter 
    207201        :param value: value of the parameter 
    208          
     202 
    209203        """ 
    210204        # Look for dispersion parameters 
     
    223217                    self.params[item] = value 
    224218                    return 
    225              
     219 
    226220        raise ValueError, "Model does not contain parameter %s" % name 
    227          
     221 
    228222    def getParam(self, name): 
    229         """  
     223        """ 
    230224        Set the value of a model parameter 
    231  
    232225        :param name: name of the parameter 
    233          
     226 
    234227        """ 
    235228        # Look for dispersion parameters 
     
    246239                if item.lower()==name.lower(): 
    247240                    return self.params[item] 
    248              
     241 
    249242        raise ValueError, "Model does not contain parameter %s" % name 
    250       
     243 
    251244    def getParamList(self): 
    252         """  
     245        """ 
    253246        Return a list of all available parameters for the model 
    254         """  
     247        """ 
    255248        list = self.params.keys() 
    256249        # WARNING: Extending the list with the dispersion parameters 
    257250        list.extend(self.getDispParamList()) 
    258251        return list 
    259      
     252 
    260253    def getDispParamList(self): 
    261         """  
     254        """ 
    262255        Return a list of all available parameters for the model 
    263         """  
     256        """ 
    264257        list = [] 
    265          
     258 
    266259        for item in self.dispersion.keys(): 
    267260            for p in self.dispersion[item].keys(): 
    268261                if p not in ['type']: 
    269262                    list.append('%s.%s' % (item.lower(), p.lower())) 
    270                      
     263 
    271264        return list 
    272      
     265 
    273266    # Old-style methods that are no longer used 
    274     def setParamWithToken(self, name, value, token, member):  
     267    def setParamWithToken(self, name, value, token, member): 
    275268        """ 
    276269        set Param With Token 
    277270        """ 
    278271        return NotImplemented 
    279     def getParamWithToken(self, name, token, member):  
     272    def getParamWithToken(self, name, token, member): 
    280273        """ 
    281274        get Param With Token 
    282275        """ 
    283276        return NotImplemented 
    284      
    285     def getParamListWithToken(self, token, member):  
     277 
     278    def getParamListWithToken(self, token, member): 
    286279        """ 
    287280        get Param List With Token 
    288281        """ 
    289282        return NotImplemented 
    290     def __add__(self, other):  
     283    def __add__(self, other): 
    291284        """ 
    292285        add 
    293286        """ 
    294287        raise ValueError, "Model operation are no longer supported" 
    295     def __sub__(self, other):  
     288    def __sub__(self, other): 
    296289        """ 
    297290        sub 
    298291        """ 
    299292        raise ValueError, "Model operation are no longer supported" 
    300     def __mul__(self, other):  
     293    def __mul__(self, other): 
    301294        """ 
    302295        mul 
    303296        """ 
    304297        raise ValueError, "Model operation are no longer supported" 
    305     def __div__(self, other):  
     298    def __div__(self, other): 
    306299        """ 
    307300        div 
    308301        """ 
    309302        raise ValueError, "Model operation are no longer supported" 
    310          
  • src/sas/sascalc/calculator/c_extensions/libfunc.c

    r79492222 r9e531f2  
    33#include <math.h> 
    44 
    5 #include "libmultifunc/libfunc.h" 
     5#include "libfunc.h" 
    66 
    77#include <stdio.h> 
  • src/sas/sascalc/calculator/c_extensions/librefl.c

    ra6d2e3b r9e531f2  
    44 
    55#include <math.h> 
    6 #include "libmultifunc/librefl.h" 
     6#include "librefl.h" 
    77#include <stdio.h> 
    88#include <stdlib.h> 
    99#if defined(_MSC_VER) 
    10 #include "../libigor/winFuncs.h" 
     10#include "winFuncs.h" 
    1111#endif 
    1212 
  • src/sas/sascalc/calculator/c_extensions/sld2i.cpp

    r79492222 r9e531f2  
    77using namespace std; 
    88extern "C" { 
    9         #include "libmultifunc/libfunc.h" 
    10         #include "libmultifunc/librefl.h" 
     9        #include "libfunc.h" 
     10        #include "librefl.h" 
    1111} 
    1212/** 
  • src/sas/sascalc/calculator/sas_gen.py

    r06aaa75d r9e531f2  
    33SAS generic computation and sld file readers 
    44""" 
    5 from sas.models.BaseComponent import BaseComponent 
    6 import sas.models.sas_extension.sld2i as mod 
     5from sas.sascalc.calculator.BaseComponent import BaseComponent 
     6import sas.sascalc.calculator.core.sld2i as mod 
    77from periodictable import formula 
    88from periodictable import nsf 
  • src/sas/sascalc/data_util/qsmearing.py

    • Property mode changed from 100755 to 100644
    r8cb0692 rf8aa738  
    1919def smear_selection(data, model = None): 
    2020    """ 
    21     Creates the right type of smearer according  
     21    Creates the right type of smearer according 
    2222    to the data. 
    23  
    2423    The canSAS format has a rule that either 
    2524    slit smearing data OR resolution smearing data 
    26     is available.  
    27      
     25    is available. 
     26 
    2827    For the present purpose, we choose the one that 
    2928    has none-zero data. If both slit and resolution 
    30     smearing arrays are filled with good data  
     29    smearing arrays are filled with good data 
    3130    (which should not happen), then we choose the 
    32     resolution smearing data.  
    33      
     31    resolution smearing data. 
     32 
    3433    :param data: Data1D object 
    3534    :param model: sas.model instance 
     
    4342            return None 
    4443        return Pinhole2D(data) 
    45      
     44 
    4645    if  not hasattr(data, "dx") and not hasattr(data, "dxl")\ 
    4746         and not hasattr(data, "dxw"): 
    4847        return None 
    49      
     48 
    5049    # Look for resolution smearing data 
    5150    _found_resolution = False 
    5251    if data.dx is not None and len(data.dx) == len(data.x): 
    53          
     52 
    5453        # Check that we have non-zero data 
    5554        if data.dx[0] > 0.0: 
     
    6564    if data.dxl is not None and len(data.dxl) == len(data.x) \ 
    6665        and data.dxw is not None and len(data.dxw) == len(data.x): 
    67          
     66 
    6867        # Check that we have non-zero data 
    6968        if data.dxl[0] > 0.0 or data.dxw[0] > 0.0: 
    7069            _found_slit = True 
    71          
     70 
    7271        # Sanity check: all data should be the same as a function of Q 
    7372        for item in data.dxl: 
     
    7574                _found_resolution = False 
    7675                break 
    77              
     76 
    7877        for item in data.dxw: 
    7978            if data.dxw[0] != item: 
     
    9897        """ 
    9998        Apply the resolution function to the data. 
    100  
    10199        Note that this is called with iq_in matching data.x, but with 
    102100        iq_in[first_bin:last_bin] set to theory values for these bins, 
    103101        and the remainder left undefined.  The first_bin, last_bin values 
    104102        should be those returned from get_bin_range. 
    105  
    106103        The returned value is of the same length as iq_in, with the range 
    107104        first_bin:last_bin set to the resolution smeared values. 
     
    123120        """ 
    124121        For a given q_min, q_max, find the corresponding indices in the data. 
    125  
    126122        Returns first, last. 
    127  
    128123        Note that these are indexes into q from the data, not the q_calc 
    129124        needed by the resolution function.  Note also that these are the 
  • src/sas/sascalc/fit/pluginmodel.py

    r79492222 r9e531f2  
    1  
    2 from sas.models.BaseComponent import BaseComponent 
     1from sas.sascalc.calculator.BaseComponent import BaseComponent 
    32import math 
    43 
    54class Model1DPlugin(BaseComponent): 
    65    ## Name of the model 
    7     
     6 
    87    def __init__(self , name="Plugin Model" ): 
    98        """ Initialization """ 
     
    1312        self.params  = {} 
    1413        self.description = 'plugin model' 
    15          
     14 
    1615    def function(self, x): 
    1716        """ 
     
    1918        """ 
    2019        return x 
    21          
     20 
    2221    def run(self, x = 0.0): 
    23         """  
     22        """ 
    2423        Evaluate the model 
    25          
     24 
    2625        :param x: input x, or [x, phi] [radian] 
    27          
     26 
    2827        :return: function value 
    29          
     28 
    3029        """ 
    3130        if x.__class__.__name__ == 'list': 
     
    3736        else: 
    3837            return self.function(x) 
    39          
    40     
     38 
     39 
    4140    def runXY(self, x = 0.0): 
    42         """  
     41        """ 
    4342        Evaluate the model 
    44          
    45         :param x: input x, or [x, y]  
    46          
     43 
     44        :param x: input x, or [x, y] 
     45 
    4746        :return: function value 
    48          
     47 
    4948        """ 
    5049        if x.__class__.__name__ == 'list': 
     
    5453        else: 
    5554            return self.function(x) 
    56          
     55 
    5756    def set_details(self): 
    5857        """ 
     
    6160        if not self.params: 
    6261            return {} 
    63              
     62 
    6463        for key in self.params.keys(): 
    6564            self.details[key] = ['', None, None] 
  • src/sas/sascalc/dataloader/readers/sesans_reader.py

    r3689302 r1c0e3b0  
    142142                default_p_unit = " " 
    143143                lam_unit = lam_header[1].replace("[","").replace("]","") 
    144                 for i,x_val in output.x: 
    145                     output.x[i], output.x_unit = self._unit_conversion(x_val, lam_unit, default_z_unit) 
    146                 for i,y_val in output.y: 
    147                     output.y[i], output.y_unit = self._unit_conversion(y_val, " ", default_p_unit) 
    148144                varheader=[zvals[0],dzvals[0],lamvals[0],dlamvals[0],Pvals[0],dPvals[0]] 
    149145                valrange=range(1, len(zvals)) 
     
    163159                input_f.close() 
    164160 
    165                 #Data 
    166                 output.x = x #[x != 0] 
    167                 output.y = y #[x != 0] 
     161                output.x, output.x_unit = self._unit_conversion(x, lam_unit, default_z_unit) 
     162                output.y = y 
     163                output.dx, output.dx_unit = self._unit_conversion(dx, lam_unit, default_z_unit) 
    168164                output.dy = dy 
    169                 output.dx = dx 
    170                 output.lam = lam 
    171                 output.dlam = dlam 
     165                output.lam, output.lam_unit = self._unit_conversion(lam, lam_unit, default_z_unit) 
     166                output.dlam, output.dlam_unit = self._unit_conversion(dlam, lam_unit, default_z_unit) 
    172167 
    173168                output.xaxis("\rm{z}", output.x_unit) 
     
    182177                if zaccept_unit.strip() == '\AA^-1': 
    183178                    zaccept_unit = "1/A" 
    184                 output.sample.zacceptance=float(paramvals[7]) 
    185                 output.sample.zacceptance=self._unit_conversion(output.sample.zacceptance, 
    186                                                                 zaccept_unit, "1/" + default_z_unit) 
     179                output.sample.zacceptance=(float(paramvals[7]),zaccept_unit) 
    187180                output.vars=varheader 
    188181 
Note: See TracChangeset for help on using the changeset viewer.