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)¶
Register a reader function.
Required Arguments:
- filetype: [ string ]
- 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?
Optional Keyword Arguments:
- pyspeckit.spectrum.__init__.register_writer(filetype, function, suffix, default=False)¶
Register a writer function.
Required Arguments:
- 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?
Optional Keyword Arguments:
- class pyspeckit.spectrum.fitters.Registry¶
This class is a simple wrapper to prevent fitter properties from being globals
- add_fitter(name, function, npars, multisingle='single', override=False, key=None)¶
Register a fitter function.
Required Arguments:
- 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?
Optional Keyword Arguments:
- multisingle: [ ‘multi’ | ‘single’ ]
- Is the function a single-function fitter (with a background), or does it allow N copies of the fitting function?
- override: [ True | False ]
- Whether to override any existing type if already present.
- key: [ char ]
- Key to select the fitter in interactive mode