<p>The average signal-to-noise would be the average level of the spectrum signal divided by the RMS difference of the fit to the polynomial. i.e. You want
<span class="math-container">$${\rm RMS} =  \left(\frac{1}{N}\sum_i^{N} (y_p - y_i)^2 \right)^{1/2} \ , $$</span>
where <span class="math-container">$y_i$</span> are the pixel data values and <span class="math-container">$y_p$</span> is the polynomial model value at that pixel.</p>
<p>The signal-to-noise ratio of a spectrum is in general wavelength-dependent. The way you have done this could give you a wavelength-dependent value if you split the spectrum into smaller pieces and fit a polynomial to the continuum of each piece.</p>
<p>You cannot get a pixel-by-pixel value using this method, since the RMS is not well-defined for single pixels (or even for a few pixels). For that you should have propagated the uncertainty  of each pixel during all the spectrum extraction steps.</p>

CC BY-SA 4.0
2023-02-19T08:07:37.140Z
2023-02-19T08:07:37.140Z
ProfRob
<p>I want to calculate the S/N of an galaxy absorption spectrum. <a href="https://i.sstatic.net/3lyQw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3lyQw.png" alt="enter image description here" /></a></p>
<p>I therefore chose a part of the spectrum which contains very little to none absorption features and should be only made up of noise and the continuum flux (see the region in next plot).<a href="https://i.sstatic.net/mpm8g.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mpm8g.png" alt="enter image description here" /></a>.</p>
<p>I then fitted a 4th degree polynomial to that data using np.polyfit().
<a href="https://i.sstatic.net/ywg0W.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ywg0W.png" alt="enter image description here" /></a></p>
<p>If I understand the situation correctly the signal should be the fitted polynomial, since this is the spectral continuum in this region. And the noise would correspond to the deviations from that continuum (blue curve in plot). Then I would calculate the S/N = polynom / flux. Is this the right approach ? And how do I get only one value for the S/N since just dividing the polynom by the flux will give me a S/N value for each pixel. Maybe I mixed something up but I can not get my head arround it. I am grateful for any tips.</p>

<observational-astronomy><galaxy><data-analysis><spectra><python>
How to calculate S/N in galaxy absorption spectra?
trynerror
# How to calculate S/N in galaxy absorption spectra?

(Asked by: username_0 on 2021-09-25)

I want to calculate the S/N of an galaxy absorption spectrum. [![enter image description here](https://i.sstatic.net/3lyQw.png)](https://i.sstatic.net/3lyQw.png)

I therefore chose a part of the spectrum which contains very little to none absorption features and should be only made up of noise and the continuum flux (see the region in next plot).[![enter image description here](https://i.sstatic.net/mpm8g.png)](https://i.sstatic.net/mpm8g.png).

I then fitted a 4th degree polynomial to that data using np.polyfit().
[![enter image description here](https://i.sstatic.net/ywg0W.png)](https://i.sstatic.net/ywg0W.png)

If I understand the situation correctly the signal should be the fitted polynomial, since this is the spectral continuum in this region. And the noise would correspond to the deviations from that continuum (blue curve in plot). Then I would calculate the S/N = polynom / flux. Is this the right approach ? And how do I get only one value for the S/N since just dividing the polynom by the flux will give me a S/N value for each pixel. Maybe I mixed something up but I can not get my head arround it. I am grateful for any tips.

**Tags:** observational-astronomy, galaxy, data-analysis, spectra, python

---

## 1 answers

### Answer by username_1 on 2023-02-19. Score: 1 | Accepted answer

The average signal-to-noise would be the average level of the spectrum signal divided by the RMS difference of the fit to the polynomial. i.e. You want
$${\rm RMS} = \left(\frac{1}{N}\sum\_i^{N} (y\_p - y\_i)^2 \right)^{1/2} \ , $$
where $y\_i$ are the pixel data values and $y\_p$ is the polynomial model value at that pixel.

The signal-to-noise ratio of a spectrum is in general wavelength-dependent. The way you have done this could give you a wavelength-dependent value if you split the spectrum into smaller pieces and fit a polynomial to the continuum of each piece.

You cannot get a pixel-by-pixel value using this method, since the RMS is not well-defined for single pixels (or even for a few pixels). For that you should have propagated the uncertainty of each pixel during all the spectrum extraction steps.


---

