<jupyter_start><jupyter_text>Exploring matching quad patterns in arc line spectra<jupyter_code># imports
import json
import pdb 

import arclines
from arclines import io as arcl_io
from arclines.holy import patterns as arch_patt

from pypit import pyputils
msgs = pyputils.get_dummy_logger()
from pypit import arutils<jupyter_output><empty_output><jupyter_text>LRISr -- R600/7500 Idealized as the loaded spectrum is the one used to generate the current line lists We assume that the wavelength of a given feature is known to +/- 200 Ang<jupyter_code>swv_uncertainty = 200.<jupyter_output><empty_output><jupyter_text>Load<jupyter_code>lrisr_file = arclines.__path__[0]+'/data/sources/lrisr_600_7500_PYPIT.json'
with open(lrisr_file,'r') as f:
    lrisr = json.load(f)
npix = len(lrisr['spec'])<jupyter_output><empty_output><jupyter_text>Setup<jupyter_code># Wavelengths
def get_wave(pypit_fit):
    npix = len(pypit_fit['spec'])
    wave = arutils.func_val(pypit_fit['fitc'],
                        np.array(pypit_fit['tcent'])/(npix-1),
                        pypit_fit['function'],
                        minv=pypit_fit['fmin'], maxv=pypit_fit['fmax'])
    return wave
wave = get_wave(lrisr)
# Line list
reload(arcl_io)
llist = arcl_io.load_line_lists(['ArI','HgI','KrI','NeI','XeI'], unknown=True)
# Cut
gdwv = (llist['wave'] > 5400.) & (llist['wave'] < 9000.)
cut_llist = llist[gdwv]
wvdata = cut_llist['wave'].data
wvdata.sort()<jupyter_output><empty_output><jupyter_text>Match<jupyter_code>reload(arch_patt)
tcent = np.array(pypit_fit['tcent'])
nlin = tcent.size
# init
final_idx = {}
for ii in range(nlin):
    final_idx[ii] = []
#
for idx in range(nlin-4):
    # Setup
    spec_lines = np.array(tcent[idx:idx+4])
    wvmnx = [wave[idx]-swv_uncertainty, wave[idx]+swv_uncertainty]
    # Run
    #pdb.set_trace()
    matches = arch_patt.match_quad_to_list(spec_lines, wvdata, wvmnx, 1.6, tol=1)
    # Save
    for match in matches:
        for ii in range(4):
            final_idx[idx+ii].append(match[ii])
final_idx<jupyter_output><empty_output><jupyter_text>LRISb -- B600  Load<jupyter_code>lrisb_file = arclines.__path__[0]+'/data/sources/lrisb_600_4000_PYPIT.json'
with open(lrisb_file,'r') as f:
    lrisb = json.load(f)
npix = len(lrisb['spec'])<jupyter_output><empty_output><jupyter_text>Setup<jupyter_code>wave = get_wave(lrisb)
# Line list
reload(arcl_io)
llist = arcl_io.load_line_lists(['CdI','HgI','ZnI'], unknown=True)
# Cut
gdwv = (llist['wave'] > 3000.) & (llist['wave'] < 5600.)
cut_llist = llist[gdwv]
wvdata = cut_llist['wave'].data
wvdata.sort()<jupyter_output><empty_output><jupyter_text>Run<jupyter_code>reload(arch_patt)
pypit_fit = lrisb
tcent = np.array(pypit_fit['tcent'])
nlin = tcent.size
# init
final_idx = {}
for ii in range(nlin):
    final_idx[ii] = []
#
for idx in range(nlin-4):
    # Setup
    spec_lines = np.array(tcent[idx:idx+4])
    wvmnx = [wave[idx]-swv_uncertainty, wave[idx]+swv_uncertainty]
    # Run
    #pdb.set_trace()
    matches = arch_patt.match_quad_to_list(spec_lines, wvdata, wvmnx, 1.26, tol=1)
    # Save
    for match in matches:
        for ii in range(4):
            final_idx[idx+ii].append(match[ii])
final_idx<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14049844236760126, 'fraction_numerical': 0.019314641744548288, 'mean_word_length': 4.9025735294117645, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '135340', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1304, 'n_words': 220, 'path': 'docs/holy/Quad_Match.ipynb', 'repo_name': 'pypeit/arclines', 'size': '3210'}