Semi-automated multi-COmponent Universal Spectral-line fitting Engine
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.eggs stage_2 - pretty much completed Dec 20, 2017
astropy_helpers @ 9f82aac astropy _underscore_ helpers Feb 11, 2019
docs updating docs Feb 11, 2019
.gitignore updating documentation Feb 11, 2019
.readthedocs.yml ditch the conda build and go all-in on pip Feb 11, 2019
.rtd-environment.yml updating documentation Feb 11, 2019
.travis.yml initial commit for scousepy Nov 23, 2017
LICENSE stats tweaks Mar 9, 2018 updating documentation Feb 11, 2019 initial commit for scousepy Nov 23, 2017 initial commit for scousepy Nov 23, 2017
pip-requirements updated documentation Jun 12, 2018
setup.cfg tweaks to help installation Jun 12, 2018 initial commit for scousepy Nov 23, 2017


The scousepy package provides a method by which a large amount of complex astronomical spectral line data can be fitted in a systematic way. A description of the method and original IDL version of the code can be found in Henshaw et al. 2016. For a more comprehensive description of scousepy, including a simple tutorial, please head here. The example scripts and data required for the tutorials can be found in the scousepy_tutorials repo.

Installing scousepy


scousepy requires the following packages:

Note that for interactive fitting with pyspeckit you may need to customise your matplotlib configuration. Namely, if you're using scousepy on a Mac you will most likely need to change your backend from 'macosx' to 'Qt5Agg' (or equiv.). You can find some information about how to do this here.


(Available soon - stick to developer version for now - see below)

To install the latest stable release, you can type::

pip install scousepy

or you can download the latest tar file from PyPI and install it using::

python install

Developer version

If you want to install the latest developer version of the scousepy, you can do so from the git repository::

git clone
cd scousepy
python install

You may need to add the --user option to the last line if you do not have root access.

Reporting issues and getting help

Please help to improve this package by reporting issues via GitHub. Alternatively, you can get in touch here.


This package was developed by:

  • Jonathan Henshaw

Contributors include:

  • Adam Ginsburg
  • Manuel Reiner

Citing scousepy

If you make use of this package in a publication, please consider the following acknowledgement...

   author = {{Henshaw}, J.~D. and {Ginsburg}, A. and {Haworth}, T.~J. and
	{Longmore}, S.~N. and {Kruijssen}, J.~M.~D. and {Mills}, E.~A.~C. and
	{Sokolov}, V. and {Walker}, D.~L. and {Barnes}, A.~T. and {Contreras}, Y. and
	{Bally}, J. and {Battersby}, C. and {Beuther}, H. and {Butterfield}, N. and
	{Dale}, J.~E. and {Henning}, T. and {Jackson}, J.~M. and {Kauffmann}, J. and
	{Pillai}, T. and {Ragan}, S. and {Riener}, M. and {Zhang}, Q.
    title = "{'The Brick' is not a brick: A comprehensive study of the structure and dynamics of the Central Molecular Zone cloud G0.253+0.016}",
  journal = {arXiv e-prints},
archivePrefix = "arXiv",
   eprint = {1902.02793},
 keywords = {Astrophysics - Astrophysics of Galaxies},
     year = 2019,
    month = feb,
   adsurl = {},
  adsnote = {Provided by the SAO/NASA Astrophysics Data System}

Please also consider acknowledgements to the required packages in your work.


The method has been updated slightly from the original IDL version of the code. It is now more interactive than before which should hopefully speed things up a bit for the user. The method is broken down into six stages in total. Each stage is summarised below.

Stage 1

Here scousepy identifies the spatial area over which to fit the data. It generates a grid of spectral averaging areas (SAAs). The user is required to provide the width of the spectral averaging area. Extra refinement of spectral averaging areas (i.e. for complex regions) can be controlled using the keyword refine_grid.

Stage 2

User-interactive fitting of the spatially averaged spectra output from stage 1. scousepy makes use of the pyspeckit package and is fully interactive.

Stage 3

Non user-interactive fitting of individual spectra contained within all SAAs. The user is required to input several tolerance levels to scousepy. Please refer to Henshaw et al. 2016 for more details on each of these.

Stage 4

Here scousepy selects the best-fits that are output in stage 3.


Unfortunately there is no one-size-fits-all method to selecting a best-fitting solution when multiple choices are available (stage 4). SCOUSE uses the Akaike Information Criterion, which weights the chi-squared value of a best-fitting solution according to the number of free-parameters.

While AIC does a good job of returning the best-fitting solutions, there are areas where the best-fitting solutions can be improved. As such the following stages are optional but highly recommended.

This part of the process has changed significantly from the original code. The user is now presented with several diagnostic plots (see below), selecting different regions will display the corresponding spectra, allowing the user to check the fit quality.

Depending on the data a user may wish to perform a few iterations of Stages 5-6.

Stage 5

Checking the fits. Here the user is required to check the best-fitting solutions to the spectra. This stage is now fully interactive. The user is first presented with several diagnostic plots namely: rms, residstd, redchi2, ncomps, aic, chi2. These can be used to assess the quality of fits throughout the map. Clicking on a particular region will show the spectra associated with that location. The user can then select spectra for closer inspection or refitting as required.

Stage 6

Re-analysing the identified spectra. In this stage the user is required to either select an alternative solution or re-fit completely the spectra identified in stage 5.