[AstroPy] Co-adding spectra

Jonathan Loveday j.loveday at sussex.ac.uk
Thu Jun 3 09:36:42 EDT 2021


Dear All

I would like to co-add a number of spectra, which won’t all cover the same wavelength range.  It seems that the spectrum.coadd_errorweighted() method (https://spectrum.readthedocs.io/en/latest/api/spectrum.coadd_errorweighted.html#spectrum.coadd_errorweighted) is ideal for this.  However, I am unclear how one initiates a Spectrum with this package; the documentation is unclear on this point.  I’m not sure if spectrum is still an affiliated astropy package, as it does not appear in the list on https://www.astropy.org/affiliated/, and the spectrum page above is >5 years old.

The built-in help function doesn’t bear much resemblance to the spectrum web page, so I wonder if 'pip install spectrum' has installed a different package?

>>> help(spectrum.Spectrum.__init__)
Help on function __init__ in module spectrum.psd:

__init__(self, data, data_y=None, sampling=1.0, detrend=None, scale_by_freq=True, NFFT=None)
    **Constructor**
    
    .. rubric:: Attributes:
    
    From the input parameters, the following attributes are set:
    
      * :attr:`data` (updates :attr:`N`, :attr:`df`, :attr:`datatype`)
      * :attr:`data_y` used for cross PSD only (correlogram)
      * :attr:`detrend`
      * :attr:`sampling` (updates :attr:`df`)
      * :attr:`scale_by_freq`
      * :attr:`NFFT` (reset :attr:`sides`, :attr:`df`)
    
    The following read-only attributes are set during the initialisation:
    
      * :attr:`datatype`
      * :attr:`df`
      * :attr:`N`
    
    And finally, additional read-write attributes are available:
    
      * :attr:`psd`: used to store the PSD data array, which size depends
        on :attr:`sides` i.e., one-sided for real data and two-sided for
        the complex data.
      * :attr:`sides`: if set, changed the :attr:`psd`.


————

I’ve tried using specutils to perform this task, but it is unclear to me how one would go about it.  The only way I could think of was to use specutils to rebin the spectra to a common wavelength range, pull out all the fluxes and errors into 2d numpy arrays, and then use np.average.  It seems like there should be an easier way though.

Any advice gratefully received!

Many thanks, Jon

Jon Loveday
Astronomy Centre, University of Sussex, Falmer, Brighton, BN1 9QH, UK
J.Loveday at sussex.ac.uk
+44 (0) 1273 877719





More information about the AstroPy mailing list