Welcome to specstack’s documentation!¶
Change log¶
- 19.4.0:
- First version released
Content¶
Installation¶
specstack is written in python 3.7. It needs only the following libraries:
- Numpy v1.16: Numerical python
- catscii v1.3: catalog simple query tool
Other libraries are used, but they are all part of the standard python library. As such no extra installations are needed.
1-from the python repository¶
The last specstack version is v19.4.0 and is available in the main pypi repository. To install it:
pip install specstack --user
Using this command will allow you not to have to install any other package. Pip will install what is missing for you.
2-From the local the github repository¶
The installable package can be found in the github directory under the ‘’dist’’ directory. Take the last version and run:
pip install specstack-X.Y.Z.tar.gz --user
In the version number of specstack, X is the year, Y is the month, and Z is the number of revisions in that month. Therefore 19.4.3 means, third revision of April 2019.
This will install specstack.
Usage¶
The command line interface help¶
You start specstack from a terminal. specstack comes with a command line interface which includes a ‘help’ that you can display in your terminal using the help command. It must be called like this:
[user@machine]$ specstack --help
This command will display the help of the program:
usage: specstack [-h] [-s S] [-p] [--method METHOD] [-f F]
speclist normlimits bin
specstack V19.4.0, R. Thomas, 2018, ESO, This program comes with ABSOLUTELY NO
WARRANTY; and is distributed under the GPLv3.0 Licence terms.See the version
of this Licence distributed along this code for details.
positional arguments:
speclist File with col1 = spectra names, col2 = redshift
normlimits l1 and l2 in angstrom where the spectra will be normalised
bin Binning of the stacked spectrum
optional arguments:
-h, --help show this help message and exit
-s S Sigma we use for the clipping, default=3
-p If plot at the end
-f F Name of the final file
specstack has few optionnal arguments and 3 mandatory arguements. You can not start specstack without any argument:
Mandatory arguments¶
- speclist: This is the file that contains the list of spectra you want to stack. This files should have two columns:
- the spec column: name of the spectrum file to use
- the redshift column: redshift of the spectrum
- The header of the file should be ‘#redshift spec’. The names of the columns should be there.
Example:
#redshift spec
3.5 spec1.txt
3.7 spec2.txt
3.65 spec3.txt
. .
. .
. .
Warning
Each spectrum should be an ascii file with (wavelength-flux) columns. Wavelength should be in Angstrom.
- normlimits: This is where the spectra are going to be normalized. It consists of two wavelength in angstrom, separated by a coma. Example: 1020,1120.
- bin: This is the final binning, in angstrom, of the spectrum.
Optional arguments¶
- -h and ‘- -help’: Display this help in the terminal.
- -s: The program uses a simgal clipping algorithm to compute the stack. The default value is 3sigma but you can as well use a different number of sigma if you want too. Example: -s 4 will use a 4-sigma clipping.
- -p: If you want to see the result of the stacking as a plot directly after the computation.
- -f: By default the stacked spectrum is saved in a text file with wavelength-stackflux-standard deviation. The file is by default called ‘stacked.txt’. But if you want to give another name you can use that option. Example: -f final_stack.txt. This way the final file will be called final_stack.txt.
How does it work?¶
Brief decription¶
Specstack is reading the spectra file and is going to process each of them separaterly. First it deredshift the wavelenght grid and normalize the flux to the region given by the user using the ‘normlimits’ argument. In the region given by these limits, the mean of the flux is set to 1.
Once all the spectra are normalized and redshifted specstack is going to look at the maximal wavelength window where all the stacked spectrum can be computed with all the individual spectra. To do that it will look at all the de-redshifted grid and collect the starting-bluest and final-reddest wavelength. From the set of blue wavelengths it will take the maximal wavelength. From the set of red wavelength it will take the minimal wavelength. This define the final restframe window of the stacked spectrum (from Lb to Lr). This ensure that each point in the stack spectrum is computed with the same amount of individual flux points.
Then all the individual spectrum are regridded in a common wavelength grid of bin=1Angstrom and limits Lb and Lr. Once it is done the final stack spectrum flux is computed computing the mean of all the individual spectrum using a sigma-clipping algorithm (default is 3-sigma but can be easily changed from the command line interface).
Finally, the wavelength binning is changed a last time to the binning requested by the user, interpolating the spectrum to a new wavelength grid.
Final Result¶
You can see below an animation of the stack of z>4 galaxies with different anount of individual galaxies, from N=2 to N=163.

What is specstack?¶
specstack is a small project that stacks spectra of galaxies (but can also work with other types of object) into a single averaged spectrum.
Acknowldgements and citation¶
If you get to use specstack for your work, please quote the ASCL entry. Thanks!
Contribute! specstack is not perfect! It has been primarily developed for my private research and I decided to release i n the spirit of making the research process as transparent as possible and in the hope it can be used by other people. If you have any comment or anything you would like to be added to specstack, or, even better, if you want to modify it, you can either do it yourself or please feel free to contact me! —> rthomas@eso.org, the.spartan.proj@gmail.com. In any case, you can find the source code here.
Warning
Copyright
specstack is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
specstack is distributed without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the program. If not, see http://www.gnu.org/licenses/ .