Changeset 975


Ignore:
Timestamp:
04/03/06 16:38:48 (18 years ago)
Author:
mar637
Message:

Completed Ticket #7 - storing of fits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapfitter.py

    r943 r975  
    157157            pars = list(self.fitter.getparameters())
    158158            fixed = list(self.fitter.getfixedparameters())
    159             self.data._addfit(self._fittedrow, pars, fixed,
    160                               self.fitfuncs, self.components)
     159            from asap.asapfit import asapfit
     160            fit = asapfit()
     161            fit.setparameters(pars)
     162            fit.setfixedparameters(fixed)
     163            fit.setfunctions(self.fitfuncs)
     164            fit.setcomponents(self.components)
     165            fit.setframeinfo(self.data._getcoordinfo())
     166            self.data._addfit(fit,self._fittedrow)
    161167
    162168    def set_parameters(self, params, fixed=None, component=None):
     
    232238                raise ValueError(msg)
    233239
     240    def get_area(self, component=None):
     241        """
     242        Return the area under the fitted gaussian component.
     243        Parameters:
     244              component:   the gaussian component selection,
     245                           default (None) is the sum of all components
     246        Note:
     247              This will only work for gaussian fits.
     248        """
     249        if not self.fitted: return
     250        if self.fitfunc == "gauss":
     251            pars = list(self.fitter.getparameters())
     252            from math import log,pi,sqrt
     253            fac = sqrt(pi/log(16.0))
     254            areas = []
     255            for i in range(len(self.components)):
     256                j = i*3
     257                cpars = pars[j:j+3]
     258                areas.append(fac * cpars[0] * cpars[2])
     259        else:
     260            return None
     261        if component is not None:
     262            return areas[component]
     263        else:
     264            return sum(areas)
     265
    234266    def get_parameters(self, component=None):
    235267        """
     
    259291            cpars = pars
    260292            cfixed = fixed
    261         fpars = self._format_pars(cpars, cfixed)
     293        fpars = self._format_pars(cpars, cfixed, self.get_area(component))
    262294        if rcParams['verbose']:
    263295            print fpars
    264296        return cpars, cfixed, fpars
    265297
    266     def _format_pars(self, pars, fixed):
     298    def _format_pars(self, pars, fixed, area):
    267299        out = ''
    268300        if self.fitfunc == 'poly':
     
    283315                ounit = self.data.get_fluxunit()
    284316            while i < len(pars):
    285                 out += '  %d: peak = %3.3f %s , centre = %3.3f %s, FWHM = %3.3f %s \n' % (c,pars[i],ounit,pars[i+1],aunit,pars[i+2],aunit)
     317                out += '  %2d: peak = %3.3f %s , centre = %3.3f %s, FWHM = %3.3f %s\n      area = %3.3f %s %s\n' % (c,pars[i],ounit,pars[i+1],aunit,pars[i+2],aunit, area,ounit,aunit)
    286318                c+=1
    287319                i+=3
     
    352384            else:
    353385                raise RuntimeError(msg)
    354         if self.data is not scantable:
     386        from asap import scantable
     387        if not isinstance(self.data, scantable):
    355388            msg = "Not a scantable"
    356389            if rcParams['verbose']:
Note: See TracChangeset for help on using the changeset viewer.