source: sasview/src/sas/fit/Fitting.py @ 25f223b

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 25f223b was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[792db7d5]1"""
[aa36f96]2Class Fit contains ScipyFit and ParkFit methods declaration
3allows to create instance of type ScipyFit or ParkFit to perform either
4a park fit or a scipy fit.
[792db7d5]5"""
[d8a2e31]6
[89f3b66]7#from scipy import optimize
[79492222]8from sas.fit.ScipyFitting import ScipyFit
9from sas.fit.ParkFitting import ParkFit
10from sas.fit.BumpsFitting import BumpsFit
[7705306]11
[6fe5100]12ENGINES={
13    'scipy': ScipyFit,
14    'park': ParkFit,
15    'bumps': BumpsFit,
16}
[7705306]17
[06e7c26]18class Fit(object):
[7705306]19    """
[aa36f96]20    Wrap class that allows to select the fitting type.this class
21    can be used as follow : ::
22   
[79492222]23        from sas.fit.Fitting import Fit
[792db7d5]24        fitter= Fit()
25        fitter.fit_engine('scipy') or fitter.fit_engine('park')
26        engine = fitter.returnEngine()
[c4d6900]27        engine.set_data(data,id)
[792db7d5]28        engine.set_param( model,model.name, pars)
[c4d6900]29        engine.set_model(model,id)
[393f0f3]30       
[792db7d5]31        chisqr1, out1, cov1=engine.fit(pars,qmin,qmax)
[aa36f96]32       
[7705306]33    """ 
[e3efa6b3]34    def __init__(self, engine='scipy', *args, **kw):
[792db7d5]35        """
36        """
[aa36f96]37        #self._engine will contain an instance of ScipyFit or ParkFit
[20d30e9]38        self._engine = None
[06e7c26]39        self.fitter_id = None
[e3efa6b3]40        self.set_engine(engine, *args, **kw)
[7705306]41         
[06e7c26]42    def __setattr__(self, name, value):
43        """
44        set fitter_id and its engine at the same time
45        """
46        if name == "fitter_id":
47            self.__dict__[name] = value
48            if hasattr(self, "_engine") and self._engine is not None:
49                self._engine.fitter_id = value   
50        elif name == "_engine":
51            self.__dict__[name] = value
52            if hasattr(self, "fitter_id") and self.fitter_id is not None:
53                self._engine.fitter_id = self.fitter_id
54        else:
55            self.__dict__[name] = value
56               
[e3efa6b3]57    def set_engine(self, word, *args, **kw):
[7705306]58        """
[aa36f96]59        Select the type of Fit
60       
61        :param word: the keyword to select the fit type
62       
63        :raise: if the user does not enter 'scipy' or 'park',
64             a valueError is raised
65             
[7705306]66        """
[6fe5100]67        try:
[e3efa6b3]68            self._engine = ENGINES[word](*args, **kw)
[6fe5100]69        except KeyError, exc:
70            raise KeyError("fit engine should be one of scipy, park or bumps")
[aa36f96]71
[ba7dceb]72    def fit(self, msg_q=None, q=None, handler=None, 
[7db52f1]73                        curr_thread=None, 
74                        ftol=1.49012e-8,
75                        reset_flag=False):
[792db7d5]76        """Perform the fit """
[ba7dceb]77        return self._engine.fit(msg_q=msg_q, 
78                                q=q, handler=handler, curr_thread=curr_thread,
[7db52f1]79                                ftol=ftol, reset_flag=reset_flag)
[511c6810]80     
[634ca14]81    def set_model(self, model, id, pars=[], constraints=[], data=None):
[20d30e9]82        """
[c4d6900]83        store a model model to fit at the position id of the fit engine
[20d30e9]84        """
[634ca14]85        self._engine.set_model(model, id, pars, constraints, data=data)
[20d30e9]86   
[c4d6900]87    def set_data(self, data, id, smearer=None, qmin=None, qmax=None):
[20d30e9]88        """
[c4d6900]89        Store data to fit at the psotion id of the fit engine
[aa36f96]90       
91        :param data: data to fit
92        :param smearer: smearerobject to smear data
93        :param qmin: the minimum q range to fit
94        :param qmax: the minimum q range to fit
95       
[20d30e9]96        """
[c4d6900]97        self._engine.set_data(data, id, smearer, qmin, qmax)
[ca6d914]98       
[c4d6900]99    def get_model(self, id):
[7705306]100        """ return list of data"""
[c4d6900]101        self._engine.get_model(id)
[9855699]102
[20d30e9]103
[c4d6900]104    def remove_fit_problem(self, id):
105        """remove fitarrange in id"""
106        self._engine.remove_fit_problem(id)
[ca6d914]107       
[c4d6900]108    def select_problem_for_fit(self, id, value):
[a9e04aa]109        """
[c4d6900]110        select a couple of model and data at the id position in dictionary
[aa36f96]111        and set in self.selected value to value
112       
113        :param value: the value to allow fitting.
114             can only have the value one or zero
[a9e04aa]115        """
[c4d6900]116        self._engine.select_problem_for_fit(id, value)
[20d30e9]117       
[c4d6900]118    def get_problem_to_fit(self, id):
[a9e04aa]119        """
[c4d6900]120        return the self.selected value of the fit problem of id
[aa36f96]121           
[c4d6900]122        :param id: the id of the problem
[aa36f96]123       
[a9e04aa]124        """
[c4d6900]125        return self._engine.get_problem_to_fit(id)
Note: See TracBrowser for help on using the repository browser.