Starfish-develop / Starfish

Tools for Flexible Spectroscopic Inference
https://starfish.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
68 stars 22 forks source link

air=True in grid_tools causing weird wavelength bug #65

Open iancze opened 8 years ago

iancze commented 8 years ago

Steps to reproduce:

import numpy as np
import Starfish
from Starfish.grid_tools import PHOENIXGridInterfaceNoAlpha

grid = PHOENIXGridInterfaceNoAlpha(wl_range=[900, 50000], air=False)
wl = grid.wl

print("Air is {}: Maximum change in wavelength {:.3f} AA".format(False, np.max(np.diff(wl))))
print("Air is {}: Minimum change in wavelength {:.3f} AA".format(False, np.min(np.diff(wl))))
print()

grid = PHOENIXGridInterfaceNoAlpha(wl_range=[900, 50000], air=True)
wl = grid.wl

print("Air is {}: Maximum change in wavelength {:.3f} AA".format(True, np.max(np.diff(wl))))
print("Air is {}: Minimum change in wavelength {:.3f} AA".format(True, np.min(np.diff(wl))))

Output

Air is False: Maximum change in wavelength 0.225 AA
Air is False: Minimum change in wavelength 0.006 AA

Air is True: Maximum change in wavelength 743.863 AA
Air is True: Minimum change in wavelength -1293.716 AA

Obviously, the wavelength grid should be monotonic. I'm not really sure what's causing this, but it seems to be related to applying the vacuum_to_air method to a larger range of wavelengths than just the optical.

gully commented 7 years ago

It seems like there's a resonance feature that reorders the wavelengths at one index location:

vac_air_demo

Not sure how to handle this, though these are exceptionally short wavelengths, so it's unlikely that you have data there. Still it's problematic if you're trying to integrate the function or something.

iancze commented 7 years ago

Ah, your plot makes the issue clearer. I think the problem is that the vacuum to air conversion we are using is not valid outside of optical wavelengths.

jason-neal commented 7 years ago

The Ciddor 1996 formula used is valid for the wavelength range between 0.23 and 1.7μm. Found in the conclusion here as the actual paper is behind a paywall.