'Specutils FluxConservingResampler is not conserving flux

I have a synthetic spectrum that I need to resample while conserving the integrated flux (I am trying to calculate synthetic magnitudes). I have tried using Specutils FluxConservingResampler, which does resample the spectrum to the resolution I want but does not conserve the integrated flux.

Following the example code from the Specutils website, I did the following:

input_spectra = Spectrum1D(spectral_axis = wavelength*u.AA, flux = flux*u.erg/u.s/u.AA/(u.m**2)) #define the input spectrum

resample_grid = np.arange(start, end + 1, 1) * u.AA #define the wavelengths to resample to

fluxc_resample = FluxConservingResampler()

output_spectrum1D = fluxc_resample(input_spectra, resample_grid) #resample the spectrum

Plotting output_spectrum1D it looks like a resampled version of the spectrum, but when I integrate the resampled spectrum and the origional spectrum (using scipy.integrate.simps), the results are very different:

Integrated flux with no resampling:  2.0777298542784767e-18 
Integrated flux with FluxConservingResampler:  2.5622441715039887e-14 

I really don't know what it is that I'm doing wrong or how to make it conserve the flux. Am I missing something here, or should I be using something else to resample the spectrum?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source