musevlt / mpdaf

MUSE Python Data Analysis Framework
BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Bug in error calculation in Spectrum.mean #13

Closed jzabl closed 3 years ago

jzabl commented 3 years ago

The appears to be a bug in the error propagation in Spectrum.mean().

https://github.com/musevlt/mpdaf/blob/983428674ce44cd2595b0b90e952aa333c75e32c/lib/mpdaf/obj/spectrum.py#L766

It is currently:

flux, wsum = np.ma.average(self.data[lambda_slice], returned=True)
if self.var is not None:
     err_flux = np.sqrt(np.ma.sum(self.var[lambda_slice])) / wsum**2

But it should be:

    err_flux = np.sqrt(np.ma.sum(self.var[lambda_slice])) / wsum

or

    err_flux = np.sqrt(np.ma.sum(self.var[lambda_slice]) / wsum**2.)

This indirectly also affects Spectrum.abmag_band

RolandBacon commented 3 years ago

Thanks for the check. Correction implemented.