Changes in / [0c3e5d2:c5b7d07] in sasmodels


Ignore:
Files:
1 added
5 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • compare.py

    r373d1b6 r87fce00  
    301301    ] 
    302302 
    303 def get_demo_pars(name): 
    304     import sasmodels.models 
    305     __import__('sasmodels.models.'+name) 
    306     model = getattr(sasmodels.models, name) 
    307     pars = getattr(model, 'demo', None) 
    308     if pars is None: pars = dict((p[0],p[2]) for p in model.parameters) 
    309     return pars 
    310  
    311303def main(): 
    312304    opts = [arg for arg in sys.argv[1:] if arg.startswith('-')] 
     
    330322    # if model does not define demo parameters 
    331323    name = args[0] 
    332     pars = get_demo_pars(name) 
     324    import sasmodels.models 
     325    __import__('sasmodels.models.'+name) 
     326    model = getattr(sasmodels.models, name) 
     327    pars = getattr(model, 'demo', None) 
     328    if pars is None: pars = dict((p[0],p[2]) for p in model.parameters) 
    333329 
    334330    Nopencl = int(args[1]) if len(args) > 1 else 5 
  • sasmodels/bumps_model.py

    rc97724e rf786ff3  
    44import sys, os 
    55import datetime 
    6  
    7 from sasmodels import sesans 
    86 
    97# CRUFT python 2.6 
     
    215213    #plt.axhline(-1, color='black', ls='--',lw=1, hold=True) 
    216214 
    217 def _plot_sesans(data, theory, view): 
    218     import matplotlib.pyplot as plt 
    219     resid = (theory - data.data)/data.err_data 
    220     plt.subplot(121) 
    221     plt.errorbar(data.SElength, data.data, yerr=data.err_data) 
    222     plt.plot(data.SElength, theory, '-', hold=True) 
    223     plt.xlabel('spin echo length (A)') 
    224     plt.ylabel('polarization') 
    225     plt.subplot(122) 
    226     plt.plot(data.SElength, resid, 'x') 
    227     plt.xlabel('spin echo length (A)') 
    228     plt.ylabel('residuals') 
    229215 
    230216def _plot_result2D(data, theory, view): 
     
    244230    plt.colorbar() 
    245231 
     232def plot_result(data, theory, view='log'): 
     233    """ 
     234    Plot the data and residuals. 
     235    """ 
     236    if hasattr(data, 'qx_data'): 
     237        _plot_result2D(data, theory, view) 
     238    else: 
     239        _plot_result1D(data, theory, view) 
     240 
     241 
    246242class BumpsModel(object): 
    247243    """ 
     
    267263        self.model = model 
    268264        self.cutoff = cutoff 
    269         if hasattr(data, 'SElength'): 
    270             self.data_type = 'sesans' 
    271         elif hasattr(data, 'qx_data'): 
    272             self.data_type = 'Iqxy' 
    273         else: 
    274             self.data_type = 'Iq' 
    275265 
    276266        partype = model.info['partype'] 
    277267 
    278268        # interpret data 
    279         if self.data_type == 'sesans': 
    280             q = sesans.make_q(data.q_zmax, data.Rmax) 
    281             self.index = slice(None,None) 
    282             self.iq = data.data 
    283             self.diq = data.err_data 
    284             self._theory = np.zeros_like(q) 
    285             q_vectors = [q] 
    286         elif self.data_type == 'Iqxy': 
     269        if hasattr(data, 'qx_data'): 
    287270            self.index = (data.mask==0) & (~np.isnan(data.data)) 
    288271            self.iq = data.data[self.index] 
     
    293276            else: 
    294277                q_vectors = [data.qx_data, data.qy_data] 
    295         elif self.data_type == 'Iq': 
     278        else: 
    296279            self.index = (data.x>=data.qmin) & (data.x<=data.qmax) & ~np.isnan(data.y) 
    297280            self.iq = data.y[self.index] 
     
    299282            self._theory = np.zeros_like(data.y) 
    300283            q_vectors = [data.x] 
    301         else: 
    302             raise ValueError("Unknown data type") # never gets here 
    303284 
    304285        # Remember function inputs so we can delay loading the function and 
     
    352333            self._theory[self.index] = self._fn(pars, pd_pars, self.cutoff) 
    353334            #self._theory[:] = self._fn.eval(pars, pd_pars) 
    354             if self.data_type == 'sesans': 
    355                 P = sesans.hankel(self.data.SElength, self.data.wavelength, 
    356                                   self.data.thickness, self._fn_inputs[0], 
    357                                   self._theory) 
    358                 self._cache['theory'] = P 
    359             else: 
    360                 self._cache['theory'] = self._theory 
     335            self._cache['theory'] = self._theory 
    361336        return self._cache['theory'] 
    362337 
     
    374349 
    375350    def plot(self, view='log'): 
    376         """ 
    377         Plot the data and residuals. 
    378         """ 
    379         data, theory = self.data, self.theory() 
    380         if self.data_type == 'Iq': 
    381             _plot_result1D(data, theory, view) 
    382         elif self.data_type == 'Iqxy': 
    383             _plot_result2D(data, theory, view) 
    384         elif self.data_type == 'sesans': 
    385             _plot_sesans(data, theory, view) 
    386         else: 
    387             raise ValueError("Unknown data type") 
    388  
    389     def simulate_data(self, noise=None): 
    390         print "noise", noise 
    391         if noise is None: 
    392             noise = self.diq[self.index] 
    393         else: 
    394             noise = 0.01*noise 
    395             self.diq[self.index] = noise 
    396         y = self.theory() 
    397         y += y*np.random.randn(*y.shape)*noise 
    398         if self.data_type == 'Iq': 
    399             self.data.y[self.index] = y 
    400         elif self.data_type == 'Iqxy': 
    401             self.data.data[self.index] = y 
    402         elif self.data_type == 'sesans': 
    403             self.data.data[self.index] = y 
    404         else: 
    405             raise ValueError("Unknown model") 
     351        plot_result(self.data, self.theory(), view=view) 
    406352 
    407353    def save(self, basename): 
  • sasmodels/generate.py

    r3271e20 ra503bfd  
    722722        parameters = COMMON_PARAMETERS + kernel_module.parameters, 
    723723        source = getattr(kernel_module, 'source', []), 
    724         oldname = kernel_module.oldname, 
    725         oldpars = kernel_module.oldpars, 
    726724        ) 
    727725    # Fill in attributes which default to None 
  • sasmodels/sasview_model.py

    r0a82216 r250fa25  
    3232 
    3333 
    34 def make_class(kernel_module, dtype='single', namestyle='name'): 
     34def make_class(kernel_module, dtype='single'): 
    3535    """ 
    3636    Load the sasview model defined in *kernel_module*. 
    3737 
    3838    Returns a class that can be used directly as a sasview model. 
    39  
    40     Defaults to using the new name for a model. Setting namestyle='name' 
    41     will produce a class with a name compatible with SasView 
    4239    """ 
    4340    model =  load_model(kernel_module, dtype=dtype) 
     
    4542        SasviewModel.__init__(self, model) 
    4643    attrs = dict(__init__=__init__) 
    47     ConstructedModel = type(model.info[namestyle],  (SasviewModel,), attrs) 
     44    ConstructedModel = type(model.info['name'],  (SasviewModel,), attrs) 
    4845    return ConstructedModel 
    4946 
     
    5754 
    5855        self.name = model.info['name'] 
    59         self.oldname = model.info['oldname'] 
    6056        self.description = model.info['description'] 
    6157        self.category = None 
  • sesansdemo.py

    rc97724e r10576d1  
    1010 
    1111# q-range parameters 
    12  
    1312q = arange(0.0003, 1.0, 0.0003);    # [nm^-1] range wide enough for  Hankel transform 
    1413dq=(q[1]-q[0])*1e9;   # [m^-1] step size in q, needed for integration 
     
    3534 
    3635clf() 
    37 subplot(211)  # plot the SANS calculation 
     36subplot(1,2,1)  # plot the SANS calculation 
    3837plot(q,I,'k') 
    3938loglog(q,I) 
     
    5655PP=exp(th*Lambda**2/4/pi/pi*(G-G[0])); 
    5756 
    58 subplot(212) 
     57subplot(1,2,2) 
    5958plot(zz,PP,'k',label="Hankel transform") # Hankel transform 1D 
    6059xlabel('spin-echo length [nm]') 
     
    6362 
    6463# Cosine transformation of 2D scattering patern 
    65 if False: 
     64if True: 
    6665    qy,qz = meshgrid(q,q) 
    6766    qr=R*sqrt(qy**2 + qz**2); # reuse variable names Hankel transform, but now 2D 
Note: See TracChangeset for help on using the changeset viewer.