Mean spectra over multiple pixels from datacube

382 views Asked by At

I have a fits datacube with galactic longitude, latitude and velocity in the 3 axis. To extract the spectrum from the datacube at a particular pixel value of longitude and latitude, I use the function

cube[:, 1935, 1407].quicklook()
plt.show()

and the image is extracted with the function

cube.to_pvextractor()
plt.show()

A sample spectrum spectrum and a zoomed image image is attached here.

The bright spots are the detections. How do I use several pixels and average the spectra to get a mean spectrum so that I reduce the noise and analyze the peak? I have been trying to code this but I don't know how to proceed as I am new to python. Can anybody please give a hint?

1

There are 1 answers

0
Enric Grau-Luque On

You can use spectrapepper for this:

import spectrapepper as spep
import matplotlib.pyplot as plt

# load sample data from library
x, y = spep.load_spectras()

# calculate the average spectra of the set
avg = spep.avg(y)

# plot the result compared to the data set
for i in y:
    plt.plot(x, i, lw=0.5)
plt.plot(x, avg, c='red', lw=1)
plt.show()

The library has also other tools for data set analysis. Check example 6 included in the docs for more options of similar nature.