1
$\begingroup$

it's my first time processing spectra from a black body radiation experiment, I'm using Python and having some troubles... I have this spectra with 2 peaks and uneven background noise which I want to normalize, I tried using specutils 1.1 "continuum-fitting" (documentation here: https://specutils.readthedocs.io/en/stable/fitting.html#continuum-fitting )

My implementation is this:

import matplotlib.pyplot as plt import numpy as np 
from astropy.modeling import models
from astropy import units as u
from specutils.spectra import Spectrum1D, SpectralRegion
from specutils.fitting import fit_generic_continuum

...

x = data[:, 0]
y = data[:, 1]
plt.plot(x, y, label = 'My Data', c='C0')

spectrum = Spectrum1D(flux=y*u.Jy, spectral_axis=x*u.um)
g1_fit = fit_generic_continuum(spectrum)
y_fit = g1_fit(x*u.um)

plt.plot(x, y_fit, label = ' Specutils Continuum Fit', c='C1')

plt.legend()

But the result is somewhat disappointing

enter image description here

Am I doing something wrong? Do you have any other way to normalize the background noise in python? any suggestion at all?

$\endgroup$
  • $\begingroup$ What is your purpose? Removing the peaks only? $\endgroup$ – Laurent Duval Nov 22 '20 at 11:35
  • $\begingroup$ Yes, at the end I used a median filtering technique $\endgroup$ – Alessandro Romancino Nov 23 '20 at 12:03
0
$\begingroup$

At the end I settled on using a median filter from scipy (medfilt) and with a high enough kernel it removed the spikes completely.

The problem on my specutils implementation was that I needed to exclude the peaks in the spectrum window by doing this, althought I found this too hard to implement on 100-120 data measurement I had:

...
from specutils import SpectralRegion

spectrum = Spectrum1D(flux=y*u.Jy, spectral_axis=x*u.um)
g1_fit = fit_generic_continuum(spectrum, exclude_regions=[SpectralRegion(2 * u.um, 6 * u.um), SpectralRegion(58 * u.um, 65 * u.um)])
y_fit = g1_fit(x*u.um)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.