Package: astro-bifrost
BIFRÖSTBlack hole Investigations of Forbidden-line Radiation in Optical SpecTraThis code aims to connect galaxy spectra to coronal line detections, just as
the burning rainbow bridge it is named after connects Asgard and Midgard,
by providing a means of searching for them via a framework for analyzing spectra
with simple tests and a stacking procedure.InstallationAfter cloning the repository, you can install locally via pip:pip install .Or alternatively,python setup.py installAll of the dependencies are listed in therequirements.txtfile, and should be installed automatically.  These dependencies are:numpy < 1.21, >= 1.17numba >= 0.53.1pandas >= 1.3.2tqdm >= 4.61.2matplotlib >= 3.4.2plotly >= 4.14.3astropy >= 4.2.1astroquery >= 0.4.2spectres >= 2.1.1scipy >= 1.7.0joblib >= 1.0.1PyAstronomy >= 0.16.0kaleido >= 0.2.1I can't guarantee this package will work  for any versions of these requirements
outside the suggestions above.Documentation SummaryMost of the functions of this module are built around three core objects:Spectrum,Spectra,
andStack.
Please see the source code for more detailed docstrings for each class and method.SpectrumThe Spectrum class stores a single object's spectrum, including an array of wavelengths, fluxes, and 1-sigma errors.
Information about redshift, coordinates, and extinction can also be stored and (if available) used to apply corrections to
the spectrum.  The basic constructor is:class Spectrum(wave, flux, error, redshift=None, velocity=None, ra=None, dec=None, ebv=None, name='Generic', output_path=None, **data)There are also constructors available for creating an object directly from an SDSS-formatted FITS file:Spectrum.from_fits, and from completely simulated data:Spectrum.simulated.As a side note, basic arithmetic operators (+, -, *, /) may be performed between Spectrum objects.  Doing so will create a new
Spectrum object with the flux combined as expected, and the error will be propagated as well.  This is only possible if the two
objects being added have identical wavelength arrays and are both corrected, and they must also either both or neither be normalized.SpectraThe Spectra object is a child of both Spectrum and dict.  It is a convenient way of storing many Spectrum objects together
in a dictionary, with methods for correcting and plotting each Spectrum in the dictionary.  Also as a convenience, the object
can be indexed like a list or a dictionary.  i.e. if the first element in the dictionary has a key 'Spectrum A', it can be
obtained either using the key 'Spectrum A', or the index 0.  There is also a method calledto_numpyfor converting any attributes
into numpy arrays.  Its basic constructor is no different from a typical dictionary:class Spectra()and items can be added with theadd_specmethod:Spectra.add_spec(SpectrumA)StackThe main attraction, the Stack object, is a child of the Spectra object, thus making it also dictionary-like. This class
has methods for stacking all the spectra inside it together, binning the spectra and then stacking each bin, calculating line flux
ratios, and many plotting methods.To perform the stacking procedure, (which corrects all spectra in the Stack for redshift and extinction, normalizes them,
resamples their fluxes over a uniform wavelength grid, and then coadds them using a weighted mean, with inverse variances used
as weights), one must call the Stack object instance directly, i.e. if we have two Spectrum objects A and B:# Create the stack objectstack=bifrost.Stack()# Create spectrum objectsA=bifrost.Spectrum(wave1,flux1,error1,redshift1)B=bifrost.Spectrum(wave2,flux2,error2,redshift2)# Append Spectrum objects to the stackstack.add_spec(A)stack.add_spec(B)# Call the stacking procedure with the default argumentsstack()ExamplesSee the example files in the examples folder to get a sense of how to use the code.
Feel free to also run the unit tests located inunit_test.py.