<p>If your limits in wavelength are <span class="math-container">$\lambda_1$</span> and <span class="math-container">$\lambda_2$</span>, then take the log of these and then divide your x-axis into <span class="math-container">$n$</span> bins with equal steps in log wavelength.</p>
<p>If you already have your spectra binned in linear wavelength then you have to decide how much of each pixel to allocate to the newly created log wavelength pixel array.</p>
<p>There are a number of ways to do this. The simplest is to allocate a fraction of the flux equal to the fraction of the pixel that lies within the log wavelength pixel. This correctly conserves flux.</p>
<p>A more complicated scheme would fit a line, or some other function, to the pixels spanning each log wavelength pixel and then integrate that function between the boundaries of the log wavelength pixels.</p>
<p>There are some examples of python code <a href="https://scipy-cookbook.readthedocs.io/items/Rebinning.html" rel="nofollow noreferrer">here</a>.</p>
<p>Even better, there is a python spectrum analysis package called specutils and it has &quot;resampling&quot; functions ready to go.
<a href="https://specutils.readthedocs.io/en/stable/manipulation.html#resampling" rel="nofollow noreferrer">https://specutils.readthedocs.io/en/stable/manipulation.html#resampling</a></p>

CC BY-SA 4.0
2022-03-09T19:25:51.390Z
2022-03-09T19:32:33.430Z
2022-03-09T19:32:33.430Z
ProfRob
<p>I want to write a function that cross correlates a spectrum with a quasar template</p>
<p>I’d like to ask you how can I convert my flux density vs wavelength spectrum to log-wavelength. It’s not clear to me if I should just take wavelength axis -&gt; log-wavelength axis. Or should I do something else?</p>
<p>From what I understand from reading here other people's questions, I need the spectra to be binned linearly in log-wavelength.</p>
<p>Sorry for my ignorance, but what does it mean? I understand how it helps but not the action itself. And how do I do that (let's say on Matlab or Python)? I know it's related to interpolation but I do not understand how to do it and why.</p>

<observational-astronomy><data-analysis><spectra><quasars>
How to convert spectra to log-wavelength and interpolate them into linear spacing in log-wavelength
Q Wolf
# How to convert spectra to log-wavelength and interpolate them into linear spacing in log-wavelength

(Asked by: username_0 on 2022-03-09)

I want to write a function that cross correlates a spectrum with a quasar template

I’d like to ask you how can I convert my flux density vs wavelength spectrum to log-wavelength. It’s not clear to me if I should just take wavelength axis -> log-wavelength axis. Or should I do something else?

From what I understand from reading here other people's questions, I need the spectra to be binned linearly in log-wavelength.

Sorry for my ignorance, but what does it mean? I understand how it helps but not the action itself. And how do I do that (let's say on Matlab or Python)? I know it's related to interpolation but I do not understand how to do it and why.

**Tags:** observational-astronomy, data-analysis, spectra, quasars


---

## 1 answers

### Answer by username_1 on 2022-03-09. Score: 3 | Accepted answer

If your limits in wavelength are $\lambda\_1$ and $\lambda\_2$, then take the log of these and then divide your x-axis into $n$ bins with equal steps in log wavelength.

If you already have your spectra binned in linear wavelength then you have to decide how much of each pixel to allocate to the newly created log wavelength pixel array.

There are a number of ways to do this. The simplest is to allocate a fraction of the flux equal to the fraction of the pixel that lies within the log wavelength pixel. This correctly conserves flux.

A more complicated scheme would fit a line, or some other function, to the pixels spanning each log wavelength pixel and then integrate that function between the boundaries of the log wavelength pixels.

There are some examples of python code [here](https://scipy-cookbook.readthedocs.io/items/Rebinning.html).

Even better, there is a python spectrum analysis package called specutils and it has "resampling" functions ready to go.
<https://specutils.readthedocs.io/en/stable/manipulation.html#resampling>


---

