[792db7d5] | 1 | """ |
---|
[aa36f96] | 2 | Class Fit contains ScipyFit and ParkFit methods declaration |
---|
| 3 | allows to create instance of type ScipyFit or ParkFit to perform either |
---|
| 4 | a park fit or a scipy fit. |
---|
[792db7d5] | 5 | """ |
---|
[d8a2e31] | 6 | |
---|
[89f3b66] | 7 | #from scipy import optimize |
---|
[c4d6900] | 8 | from sans.fit.ScipyFitting import ScipyFit |
---|
| 9 | from sans.fit.ParkFitting import ParkFit |
---|
[7705306] | 10 | |
---|
| 11 | |
---|
| 12 | class Fit: |
---|
| 13 | """ |
---|
[aa36f96] | 14 | Wrap class that allows to select the fitting type.this class |
---|
| 15 | can be used as follow : :: |
---|
| 16 | |
---|
[792db7d5] | 17 | from sans.fit.Fitting import Fit |
---|
| 18 | fitter= Fit() |
---|
| 19 | fitter.fit_engine('scipy') or fitter.fit_engine('park') |
---|
| 20 | engine = fitter.returnEngine() |
---|
[c4d6900] | 21 | engine.set_data(data,id) |
---|
[792db7d5] | 22 | engine.set_param( model,model.name, pars) |
---|
[c4d6900] | 23 | engine.set_model(model,id) |
---|
[393f0f3] | 24 | |
---|
[792db7d5] | 25 | chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) |
---|
[aa36f96] | 26 | |
---|
[7705306] | 27 | """ |
---|
[93f0a586] | 28 | def __init__(self, engine='scipy'): |
---|
[792db7d5] | 29 | """ |
---|
| 30 | """ |
---|
[aa36f96] | 31 | #self._engine will contain an instance of ScipyFit or ParkFit |
---|
[20d30e9] | 32 | self._engine = None |
---|
[93f0a586] | 33 | self.set_engine(engine) |
---|
[7705306] | 34 | |
---|
[89f3b66] | 35 | def set_engine(self, word): |
---|
[7705306] | 36 | """ |
---|
[aa36f96] | 37 | Select the type of Fit |
---|
| 38 | |
---|
| 39 | :param word: the keyword to select the fit type |
---|
| 40 | |
---|
| 41 | :raise: if the user does not enter 'scipy' or 'park', |
---|
| 42 | a valueError is raised |
---|
| 43 | |
---|
[7705306] | 44 | """ |
---|
[89f3b66] | 45 | if word == "scipy": |
---|
| 46 | self._engine = ScipyFit() |
---|
| 47 | elif word == "park": |
---|
[c4d6900] | 48 | self._engine = ParkFit() |
---|
[7705306] | 49 | else: |
---|
| 50 | raise ValueError, "enter the keyword scipy or park" |
---|
[aa36f96] | 51 | |
---|
| 52 | def fit(self, q=None, handler=None, curr_thread=None): |
---|
[792db7d5] | 53 | """Perform the fit """ |
---|
[c4d6900] | 54 | return self._engine.fit(q, handler, curr_thread=curr_thread) |
---|
[511c6810] | 55 | |
---|
[c4d6900] | 56 | def set_model(self, model, id, pars=[], constraints=[]): |
---|
[20d30e9] | 57 | """ |
---|
[c4d6900] | 58 | store a model model to fit at the position id of the fit engine |
---|
[20d30e9] | 59 | """ |
---|
[c4d6900] | 60 | self._engine.set_model(model, id, pars, constraints) |
---|
[20d30e9] | 61 | |
---|
[c4d6900] | 62 | def set_data(self, data, id, smearer=None, qmin=None, qmax=None): |
---|
[20d30e9] | 63 | """ |
---|
[c4d6900] | 64 | Store data to fit at the psotion id of the fit engine |
---|
[aa36f96] | 65 | |
---|
| 66 | :param data: data to fit |
---|
| 67 | :param smearer: smearerobject to smear data |
---|
| 68 | :param qmin: the minimum q range to fit |
---|
| 69 | :param qmax: the minimum q range to fit |
---|
| 70 | |
---|
[20d30e9] | 71 | """ |
---|
[c4d6900] | 72 | self._engine.set_data(data, id, smearer, qmin, qmax) |
---|
[ca6d914] | 73 | |
---|
[c4d6900] | 74 | def get_model(self, id): |
---|
[7705306] | 75 | """ return list of data""" |
---|
[c4d6900] | 76 | self._engine.get_model(id) |
---|
[9855699] | 77 | |
---|
[20d30e9] | 78 | |
---|
[c4d6900] | 79 | def remove_fit_problem(self, id): |
---|
| 80 | """remove fitarrange in id""" |
---|
| 81 | self._engine.remove_fit_problem(id) |
---|
[ca6d914] | 82 | |
---|
[c4d6900] | 83 | def select_problem_for_fit(self, id, value): |
---|
[a9e04aa] | 84 | """ |
---|
[c4d6900] | 85 | select a couple of model and data at the id position in dictionary |
---|
[aa36f96] | 86 | and set in self.selected value to value |
---|
| 87 | |
---|
| 88 | :param value: the value to allow fitting. |
---|
| 89 | can only have the value one or zero |
---|
[a9e04aa] | 90 | """ |
---|
[c4d6900] | 91 | self._engine.select_problem_for_fit(id, value) |
---|
[20d30e9] | 92 | |
---|
[c4d6900] | 93 | def get_problem_to_fit(self, id): |
---|
[a9e04aa] | 94 | """ |
---|
[c4d6900] | 95 | return the self.selected value of the fit problem of id |
---|
[aa36f96] | 96 | |
---|
[c4d6900] | 97 | :param id: the id of the problem |
---|
[aa36f96] | 98 | |
---|
[a9e04aa] | 99 | """ |
---|
[c4d6900] | 100 | return self._engine.get_problem_to_fit(id) |
---|