"""
This script creates a new linelist file based on an atlas for a specific element of the gas lamp
used in the wavelength calibration. The best match between the atlas and the observed spectrum
is found using MCMC.
"""

from os.path import dirname, join

import numpy as np

from pyreduce.instruments import instrument_info
from pyreduce.wavelength_calibration import WavelengthCalibrationInitialize

# Load ThAr data generated by wavecal_master
thar_data = np.load(join(dirname(__file__), "harps_red.thar.npz"))
thar_spec = thar_data["thar"]

# Load Instrument Info to get the wavelength range for each order
# alternatively, create this in some other way
instrument = instrument_info.load_instrument("HARPS")
wave_range = instrument.get_wavelength_range(None, "red")

# Run the linelist module
module = WavelengthCalibrationInitialize(element="thar", medium="vac", plot=True)
linelist = module.execute(thar_spec, wave_range)

# Save the linelist
linelist.save("linelist.npy")
