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:


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')

Alternatively, you can access and edit the default Registry


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()


If you want to register a new variable-optical-depth deuterated ammonia model, you could do the following:

sp.specfit.register_fitter(name=’nh2d’, function=nh2d.nh2d_vtau_fitter, npars=4)


pyspeckit.spectrum.__init__.register_reader(filetype, function, suffix, default=False)[source] [github] [bitbucket]

Register a reader function.


filetype: str :

The file type name

function: function :

The reader function. Should take a filename as input and return an X-axis object (see, 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)[source] [github] [bitbucket]

Register a writer function.


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[source] [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)[source] [github] [bitbucket]

Register a fitter function.


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?