Closed andycasey closed 2 years ago
I'm fairly sure this is a direct consequence of the nonlinear relationship between air and vacuum wavelengths, i.e. working as intended. The range object 15004.099625020779 : 0.01 : 15504.245608304296
itself has 50015 elements just by the nature of its bounds and step size.
For very small wavelength ranges, converting starting and stopping wavelengths and keeping the step the same is a reasonable approximation. For large ones it will fail, so for the best possible comparisons between synthesized air and vacuum spectra, interpolation is required at some level. However, for the 15000-15500 \AA range, we are actually in a middle regime where the relationship between air and vacuum wavelengths is linear-ish, as long you adapt both the step size and the range endpoints.
I've opened a PR, which I will try to merge soon, that will do this conversion automatically for you, raising a warning if the approximation becomes inaccurate. This overlaps with some other things I've been thinking about, and will make it easier to change the internals later, e.g. to use frequencies instead of wavelengths.
That's great! I thought that could be the case, but I could not find a .wavelength
property (or similar) in the outputted spectrum
object to check for sure. Sorry for the noise! I'll leave this open until it gets closed by your pull request.
I have encountered some strange behaviour with Korg v0.4.1. Maybe it is a bug in how Julia is handling floating points, or it might not be a bug: it might just be how things should be. This is low priority as I have found a workaround. A minimum reproducible example is below.
Let me describe the example. I want to synthesize between 15,000 and 15,500 Angstroms (air wavelengths), at 0.01 Angstrom spacings.
Case A Since Korg works in vacuum wavelengths I first convert 15,000 and 15,500 Angstroms to vacuum wavelengths and then supply those bounds to Korg, with 0.01 Angstrom spacings:
15004.099625020779:0.01:15504.245608304296
.Korg returns a spectrum with length 50,014 but I expected 50,001 (+/- 1, depending on how the array is constructed). For now I will just trim the edge of the spectrum to match the number of points.
Case B Now for the comparison. I will now do the synthesis where I supply fewer significant digits to Korg:
15004.09:0.01:15504.24
. This will give me a few more flux calculations than what I need, but I can use it to interpolate or trim it down, etc.Below you can see the plotted spectra for Case A (red, bad) and Case B (blue, good). I say that Case B is "good" because when I compare to other radiative transfer codes, Case B looks correct but Case A looks incorrect. You can see that both spectra agree in the blue end of the spectra, but by the right end of the spectra there is significant shifting going on.
Is this something to do with how Julia constructs the wavelength array differently to how Python would? Is there some rounding bug going on?
To compare with other radiative transfer codes I have switched to using Case B and interpolating the Korg spectrum to the comparison spectra.
Minimum reproducible example
Run
example.jl
thenexample.py
for plotting. Files for the minimum reproducible example:example.jl
code:example.py
code: