Using the AnalyzeWLS Class
This notebook demonstrates how to use the diagnostic tools in the AnalyzeWLS and AnalyzeWLSDict classes. First, import packages.
[1]:
import os
import inspect
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from modules.quicklook.src.analyze_wls import *
from kpfpipe.models.level1 import KPF1
%matplotlib inline
Read Files and Instantiate Objects
[2]:
# for AnalyzeWLS
red_thar_wls_fn = '/testdata/WLS/20230731/kpf_20230731_master_WLS_/data/masters//20230731/kpf_20230731_master_arclamp_autocal-thar-all-morn_L1.fits'
red_thar_WLS_L1 = KPF1.from_fits(red_thar_wls_fn)
red_thar_WLS = AnalyzeWLS(red_thar_WLS_L1)
# for AnalyzeWLSDict and AnalyzeWLS2Dict
cal_type = 'thar' # 'lfc'
#red_lfc_dict_fn = '/testdata/WLS/20230731/kpf_20230731_master_WLS_/data/masters//20230731/kpf_20230731_master_arclamp_autocal-lfc-all-morn_RED_L1.json.gz'
#green_lfc_dict_fn = '/testdata/WLS/20230731/kpf_20230731_master_WLS_/data/masters//20230731/kpf_20230731_master_arclamp_autocal-lfc-all-morn_GREEN_L1.json.gz'
#red_thar_dict_fn = '/testdata/WLS/20230731/kpf_20230731_master_WLS_/data/masters//20230731/kpf_20230731_master_arclamp_autocal-thar-all-morn_RED_L1.json.gz'
#green_thar_dict_fn = '/testdata/WLS/20230731/kpf_20230731_master_WLS_/data/masters//20230731/kpf_20230731_master_arclamp_autocal-thar-all-morn_GREEN_L1.json.gz'
red_thar_dict_fn = '/testdata/WLS/20230430/KP.20230430.31963.46_L1.fits_WLS_RED_L1.json.gz'
green_thar_dict_fn = '/testdata/WLS/20230430/KP.20230430.31963.46_L1.fits_WLS_GREEN_L1.json.gz'
red_lfc_dict_fn = '/testdata/WLS/20230430/KP.20230430.56774.47_L1.fits_WLS_RED_L1.json.gz'
green_lfc_dict_fn = '/testdata/WLS/20230430/KP.20230430.56774.47_L1.fits_WLS_GREEN_L1.json.gz'
red_lfc_WLSDict = AnalyzeWLSDict(red_lfc_dict_fn)
green_lfc_WLSDict = AnalyzeWLSDict(green_lfc_dict_fn)
red_thar_WLSDict = AnalyzeWLSDict(red_thar_dict_fn)
green_thar_WLSDict = AnalyzeWLSDict(green_thar_dict_fn)
Examining WLS Dictionaries
Note that the dictionaries are huge (tens of MB) and running > print(red_lfc_WLSDict) will cause Jupyter Notebook to crash. Instead, you can use the print_dict method in modules.Utils.analyze_wls which limits the number depth in the heirarchy that is printed. The cell below explors one of the directories.
[3]:
print_dict(red_lfc_WLSDict.wls_dict['orderlets']['CAL']['orders'][3]['lines'][2], max_depth=1)
amp:
2415144344.5691915
mu:
3.1108221941336476
sig:
56.37729924207784
const:
-17063386.513751905
covar:
[[ 3.11250062e+24 -3.92019559e+10 2.42379535e+16 -1.46810540e+22]
[-3.92019836e+10 8.44129058e-03 -3.05255637e+02 1.84914621e+08]
[ 2.42379535e+16 -3.05255421e+02 1.88748044e+08 -1.14325665e+14]
[-1.46810540e+22 1.84914491e+08 -1.14325665e+14 6.92476483e+19]]
data:
[ 1809.52077636 13943.01161019 22047.67998789 25605.29642308
25584.00251777 20034.51550638 2122.20348951]
model:
[ 661.74603868 14683.99984687 23341.18166835 26625.12396104
24532.72779652 17065.96773344 4231.88871223]
quality:
good
chi2:
0.20885556372897557
rms:
1645.2473274168558
mu_diff:
0.11082219413364758
lambda_fit:
6240.667812386068
List Methods in AnalyzeWLS
This methods in this class operate on wavelength solution in Level 1 objects.
[4]:
for name, method in inspect.getmembers(red_thar_WLS, predicate=inspect.ismethod):
print(f"Method Name: {name}")
print(f"Doc String: {method.__doc__}\n")
Method Name: __init__
Doc String: None
Method Name: plot_WLS_orderlet_diff
Doc String:
Make a plot of differences between the wavelength solutions for the orders.
Args:
chip (string) - "green" or "red"
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
Returns:
PNG plot in fig_path or shows the plot it the current environment
(e.g., in a Jupyter Notebook).
Plot the WLS Difference Between Orderlets
[5]:
red_thar_WLS.plot_WLS_orderlet_diff(chip='red', show_plot=True)
List Methods in AnalyzeWLSDict
This methods in this class operate on JSON dictionaries generated during the process of a generating wavelength solution.
[6]:
for name, method in inspect.getmembers(green_thar_WLSDict, predicate=inspect.ismethod):
print(f"Method Name: {name}")
print(f"Doc String: {method.__doc__}\n")
Method Name: __init__
Doc String: None
Method Name: plot_WLS_line
Doc String:
Generate a plot of a single spectral line.
Args:
orderlet (string) - 'SCI1', 'SCI2', 'SCI3', 'CAL', or 'SKY'
order (integer) - order number
line (integer) - line number
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
Returns:
PNG plot in fig_path or shows the plot it in the current environment
(e.g., in a Jupyter Notebook).
Method Name: plot_WLS_lines_in_order
Doc String:
Generate an array plots of spectral lines.
Args:
orderlet (string) - 'SCI1', 'SCI2', 'SCI3', 'CAL', or 'SKY'
order (integer) - order number
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
Returns:
PNG plot in fig_path or shows the plot it in the current environment
(e.g., in a Jupyter Notebook).
Method Name: plot_WLS_lines_in_orderlet
Doc String:
Generate an array plots of spectral lines for all orders of a given orderlet.
Args:
orderlet (string) - 'SCI1', 'SCI2', 'SCI3', 'CAL', or 'SKY'
order (integer) - order number
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
Returns:
PNG plot in fig_path or shows the plot it in the current environment
(e.g., in a Jupyter Notebook).
Method Name: plot_wave_diff_final_initial
Doc String:
Generate an array of plots of the difference between initial and initial
wavelength solutions for the orders of a given orderlet.
Args:
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
warming_ms (double) - level in m/s where the orange 'warning' boxes start
default=10
alarm_ms (double) - level in m/s where the orange 'warning' boxes end
and the red 'alarm' boxes being
default=100
Returns:
PNG plot in fig_path or shows the plot it in the current environment
(e.g., in a Jupyter Notebook).
Plot a single line
[7]:
green_lfc_WLSDict.plot_WLS_line('SCI2', 12, 11, show_plot=True)
Plot all lines in an order
The annotations indicate fit parameters and statistics. The background shading indicates chi^2 of the fit (red = bad).
[8]:
green_thar_WLSDict.plot_WLS_lines_in_order('SCI2', 10, show_plot=True)
Plot all lines in an orderlet
The annotations indicate fit parameters and statistics. The background shading indicates chi^2 of the fit (red = bad). Note that the cell below takes a many minutes to execute becaues of the number of lines that need to be plotted.
[9]:
green_thar_WLSDict.plot_WLS_lines_in_orderlet('SCI2', show_plot=True)
List Methods in AnalyzeWLS2Dict
The methods in this class involve the wavelength solutions from two JSON dictionaries.
[10]:
orderlet = 'SCI2'
red_thar_LFC_2WLSDict = AnalyzeTwoWLSDict(red_lfc_dict_fn, red_thar_dict_fn, name1='LFC', name2='ThAr')
for name, method in inspect.getmembers(red_thar_LFC_2WLSDict, predicate=inspect.ismethod):
print(f"Method Name: {name}")
print(f"Doc String: {method.__doc__}\n")
Method Name: __init__
Doc String: None
Method Name: plot_wave_diff_wls
Doc String:
Generate an array of plots of the difference between two wavelength solutions
for the orders of a given orderlet.
Args:
orderlet (string) - 'SCI1', 'SCI2', 'SCI3', 'CAL', or 'SKY'
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
warming_ms (double) - level in m/s where the orange 'warning' boxes start
default=10
alarm_ms (double) - level in m/s where the orange 'warning' boxes end
and the red 'alarm' boxes being
default=100
Returns:
PNG plot in fig_path or shows the plot it in the current environment
(e.g., in a Jupyter Notebook).
Method Name: plot_wavelength_coverage
Doc String:
Generate a plot showing the coverage of fitted lines in a wavelength solution.
Args:
orderlet (string) - 'SCI1', 'SCI2', 'SCI3', 'CAL', or 'SKY'
fig_path (string) - set to the path for the file to be generated.
default=None
show_plot (boolean) - show the plot in the current environment.
default=False
Returns:
PNG plot in fig_path or shows the plot it in the current environment
(e.g., in a Jupyter Notebook).
Plot Differences Between Two Wavelength Solutions
Each panel is a spectral order. The bottom right corner shows the average offset as a function of order.
[11]:
two_dicts = AnalyzeTwoWLSDict(red_thar_dict_fn, red_lfc_dict_fn)
two_dicts.plot_wave_diff_wls('SCI2', show_plot=True)
Plot the Coverage of a Wavelengh Solution
[12]:
two_dicts = AnalyzeTwoWLSDict(green_thar_dict_fn, red_thar_dict_fn)
two_dicts.plot_wavelength_coverage(show_plot=True)
[13]:
two_dicts = AnalyzeTwoWLSDict(green_lfc_dict_fn, red_lfc_dict_fn)
two_dicts.plot_wavelength_coverage(show_plot=True)