%load_ext autoreload
%autoreload 2
%matplotlib inline
import mpld3
mpld3.enable_notebook()

import warnings
warnings.filterwarnings("ignore")

import numpy as N
from spectrogrism import spectrogrism as S
from spectrogrism import snifs

"""
Explanation: SNIFS R-channel
Author: Yannick Copin &#121;&#46;&#99;&#111;&#112;&#105;&#110;&#64;&#105;&#112;&#110;&#108;&#46;&#105;&#110;&#50;&#112;&#51;&#46;&#102;&#114;
We construct a very simple optical model mimicking the red channel of the Supernova Integral Field Spectrograph.
End of explanation
"""


optcfg = snifs.SNIFS_R
print(optcfg)

"""
Explanation: Load the SNIFS-R channel optical configuration:
End of explanation
"""


simcfg = snifs.SNIFS_SIMU
print(simcfg)

"""
Explanation: Load the simulation configuration:
End of explanation
"""


spectro = S.Spectrograph(optcfg)
print(spectro)

"""
Explanation: Create a Spectrograph instance from optical configuration:
End of explanation
"""


if not spectro.test(simcfg.get_wavelengths(optcfg), verbose=False):
    print "ERROR: backward modeling does not match."
else:
    print " SUCCESSFUL ROUND-TRIP TEST ".center(70, '-')

"""
Explanation: Test the optical model:
End of explanation
"""


detector = spectro.predict_positions(simcfg)
ax = detector.plot(modes=(-1, 0, 1, 2), blaze=True)
ax.set_aspect('auto')
ax.axis(N.array([-2000, 2000, -4000, 4000]) *
        spectro.detector.pxsize / 1e-3)  # [mm]
ax.figure.set_size_inches(12, 10)

"""
Explanation: Simulate spectra on the detector and plot:
End of explanation
"""


