Registration¶
PySpecKit is made extensible by allowing user-registered modules for reading, writing, and fitting data.
For examples of registration in use, look at the source code of pyspeckit.spectrum.__init__ and pyspeckit.spectrum.fitters.
The registration functions can be accessed directly:
pyspeckit.register_reader
pyspeckit.register_writer
However, models are bound to individual instances of the Spectrum class, so they must be accessed via a specfit instance
sp = pyspeckit.Spectrum('myfile.fits')
sp.specfit.register_fitter
Alternatively, you can access and edit the default Registry
pyspeckit.fitters.default_Registry.add_fitter
If you’ve already loaded a Spectrum instance, but then you want to reload fitters from the default_Registry, or if you want to make your own Registry, you can use the semi-private method
MyRegistry = pyspeckit.fitters.Registry()
sp._register_fitters(registry=MyRegistry)
API¶
- pyspeckit.spectrum.__init__.register_reader(filetype, function, suffix, default=False) [github] [bitbucket]¶
Register a reader function.
Parameters: filetype: str :
The file type name
function: function :
The reader function. Should take a filename as input and return an X-axis object (see units.py), a spectrum, an error spectrum (initialize it to 0’s if empty), and a pyfits header instance
suffix: int :
What suffix should the file have?
- pyspeckit.spectrum.__init__.register_writer(filetype, function, suffix, default=False) [github] [bitbucket]¶
Register a writer function.
Parameters: filetype: string :
The file type name
function: function :
The writer function. Will be an attribute of Spectrum object, and called as spectrum.Spectrum.write_hdf5(), for example.
suffix: int :
What suffix should the file have?
- class pyspeckit.spectrum.fitters.Registry [github] [bitbucket]¶
This class is a simple wrapper to prevent fitter properties from being globals
- add_fitter(name, function, npars, override=False, key=None, multisingle=None) [github] [bitbucket]¶
Register a fitter function.
Parameters: name: string :
The fit function name.
function: function :
The fitter function. Single-fitters should take npars + 1 input parameters, where the +1 is for a 0th order baseline fit. They should accept an X-axis and data and standard fitting-function inputs (see, e.g., gaussfitter). Multi-fitters should take N * npars, but should also operate on X-axis and data arguments.
npars: int :
How many parameters does the function being fit accept?