Changeset 1230 for tags


Ignore:
Timestamp:
09/01/06 10:45:58 (18 years ago)
Author:
mar637
Message:

small fix to _format_pars to test for length. Ticket #44 - fit can be saved as ASCII via fitter.store_fit.

Location:
tags/Release2.1.0b/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tags/Release2.1.0b/python/asapfit.py

    r974 r1230  
    5555                  }
    5656            comp.append(d)
     57            k+=1
    5758        out.append(comp)
    5859        return out
     60
     61    def save(self, filename):
     62        f = file(filename, 'w')
     63        parstr = ""
     64        for i in xrange(self.getcomponents()[0]):
     65            pname = "P%d"% (i)
     66            parstr += "%-12s " % (pname)
     67        header = "#%-12s %s\n" % ("Function", parstr)
     68        f.write(header)
     69        i = 0
     70        funcs=self.getfunctions()
     71        pars=self.getparameters()
     72        for c in self.getcomponents():
     73            line = " %-12s " % (funcs[i])
     74            for j in xrange(c):
     75                line += "%3.8f " % (pars[i*c+j])
     76            i+=1
     77            f.write(line+"\n")
     78        f.close()
    5979
    6080    def _format_pars(self, pars, ftype, unit):
     
    6383            i = 0
    6484            for p in pars:
    65                 out += ' p%d = %3.3f %s,' % (i,p,unit)
     85                out += ' p%d = %3.6f %s,' % (i,p,unit)
    6686                i+=1
    6787            out = out[1:-1]
    6888        elif ftype == 'gauss':
    69             out += 'peak = %3.3f , centre = %3.3f %s, FWHM = %3.3f %s' % (pars[0],pars[1],unit,pars[2],unit)
     89            out += 'peak = %3.6f , centre = %3.6f %s, FWHM = %3.6f %s' % (pars[0],pars[1],unit,pars[2],unit)
    7090        return out
  • tags/Release2.1.0b/python/asapfitter.py

    r1228 r1230  
    156156        return
    157157
    158     def store_fit(self):
    159         """
    160         Store the fit parameters in the scantable.
     158    def store_fit(self, filename=None):
     159        """
     160        Save the fit parameters.
     161        Parameters:
     162            filename:    if specified save as an ASCII file, if None (default)
     163                         store it in the scnatable
    161164        """
    162165        if self.fitted and self.data is not None:
     
    170173            fit.setcomponents(self.components)
    171174            fit.setframeinfo(self.data._getcoordinfo())
    172             self.data._addfit(fit,self._fittedrow)
     175            if filename is not None:
     176                import os
     177                filename = os.path.expandvars(os.path.expanduser(filename))
     178                if os.path.exists(filename):
     179                    raise IOError("File '%s' exists." % filename)
     180                fit.save(filename)
     181            else:
     182                self.data._addfit(fit,self._fittedrow)
    173183
    174184    #def set_parameters(self, params, fixed=None, component=None):
     
    353363            for i in range(len(pars)):
    354364                fix = ""
    355                 if fixed[i]: fix = "(fixed)"
     365                if len(fixed) and fixed[i]: fix = "(fixed)"
    356366                if errors :
    357367                    out += '  p%d%s= %3.6f (%1.6f),' % (c,fix,pars[i], errors[i])
Note: See TracChangeset for help on using the changeset viewer.