source: sasview/sansmodels/src/sans/models/dispersion_models.py @ 40945a3

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 40945a3 was 988130c6, checked in by Gervaise Alina <gervyh@…>, 16 years ago

self.fixed field added in models but need to change wrapper generator

  • Property mode set to 100644
File size: 3.7 KB
Line 
1"""
2    This software was developed by the University of Tennessee as part of the
3    Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4    project funded by the US National Science Foundation.
5
6    If you use DANSE applications to do scientific research that leads to
7    publication, we ask that you acknowledge the use of the software with the
8    following sentence:
9
10    "This work benefited from DANSE software developed under NSF award DMR-0520547."
11
12    copyright 2008, University of Tennessee
13"""
14
15"""
16    Class definitions for python dispersion model for
17    model parameters. These classes are bridges to the C++
18    dispersion object.
19   
20    The ArrayDispersion class takes in numpy arrays only.
21   
22    Usage:
23    These classes can be used to set the dispersion model of a SANS model
24    parameter:
25   
26        cyl = CylinderModel()
27        cyl.set_dispersion('radius', GaussianDispersion())
28   
29   
30    After the dispersion model is set, you can access it's
31    parameter through the dispersion dictionary:
32   
33        cyl.dispersion['radius']['width'] = 5.0
34   
35    TODO: For backward compatibility, the model parameters are still kept in
36    a dictionary. The next iteration of refactoring work should involve moving
37    away from value-based parameters to object-based parameter. We want to
38    store parameters as objects so that we can unify the 'params' and 'dispersion'
39    dictionaries into a single dictionary of parameter objects that hold the
40    complete information about the parameter (units, limits, dispersion model, etc...). 
41   
42   
43"""
44import sans_extension.c_models as c_models 
45
46
47
48class DispersionModel:
49    """
50        Python bridge class for a basic dispersion model
51        class with a constant parameter value distribution
52    """
53    def __init__(self):
54        self.cdisp = c_models.new_dispersion_model()
55       
56    def set_weights(self, values, weights):
57        """
58            Set the weights of an array dispersion
59        """
60        message = "set_weights is not available for DispersionModel.\n"
61        message += "  Solution: Use an ArrayDispersion object"
62        raise "RuntimeError", message
63       
64class GaussianDispersion(DispersionModel):
65    """
66        Python bridge class for a dispersion model based
67        on a Gaussian distribution.
68    """
69    def __init__(self):
70        self.cdisp = c_models.new_gaussian_model()
71       
72    def set_weights(self, values, weights):
73        """
74            Set the weights of an array dispersion
75        """
76        message = "set_weights is not available for GaussiantDispersion.\n"
77        message += "  Solution: Use an ArrayDispersion object"
78        raise "RuntimeError", message
79       
80class ArrayDispersion(DispersionModel):
81    """
82        Python bridge class for a dispersion model based on arrays.
83        The user has to set a weight distribution that
84        will be used in the averaging the model parameter
85        it is applied to.
86    """
87    def __init__(self):
88        self.cdisp = c_models.new_array_model()
89       
90    def set_weights(self, values, weights):
91        """
92            Set the weights of an array dispersion
93            Only accept numpy arrays.
94            @param values: numpy array of values
95            @param weights: numpy array of weights for each value entry
96        """
97        if len(values) != len(weights):
98            raise ValueError, "ArrayDispersion.set_weights: given arrays are of different lengths"
99       
100        c_models.set_dispersion_weights(self.cdisp, values, weights)
101 
102models = {GaussianDispersion:"GaussianModel", ArrayDispersion:"MyModel"}       
103       
Note: See TracBrowser for help on using the repository browser.