<jupyter_start><jupyter_text>Barycentric correction function<jupyter_code>def get_barycorr(time, ra, dec):
    global LATITUDE, LONGITUDE, ALTITUDE

    aat = EarthLocation.from_geodetic(lat=LATITUDE, 
                                      lon=LONGITUDE,
                                      height=ALTITUDE)
    sc = SkyCoord(ra, dec, unit=(u.deg, u.deg))
    barycorr = sc.radial_velocity_correction('heliocentric',
                                             obstime=Time(time, format='mjd'), 
                                             location=aat)
    bc = barycorr.to(u.km/u.s) 
        
    return bc.value * u.km / u.s<jupyter_output><empty_output><jupyter_text>Dealing with x pixels<jupyter_code># interpolates xpixel value with wavelength
interp_wave = interp1d(halphatab['pixel'], halphatab['vac_ref_wl[A]'])

fitx = np.arange(300,4000,1)

newfitx = np.logspace(np.log10(halphatab['pixel'].min()+0.01), 
                      np.log10(halphatab['pixel'].max()-0.01), 5000, base=10.0)
n = interp1d(halphatab['pixel'], halphatab['air_ref_wl[A]'])

plt.plot(newfitx, interp_wave(newfitx), 'k', lw=3)
plt.plot(newfitx, n(newfitx), 'darkorange')

print(interp_wave(newfitx)[-1]/10, n(newfitx)[-1]/10)
orders
wavelength_fns = []

for j in range(len(orders)):
    
    flux = np.load(orders[j])
    interp_flux = interp1d(fitx, flux)
    
    date_dir = int(orders[j].split('/')[-1].split('n')[0])
    
    filename = str(orders[j].split('/')[-1].split('.')[0].split('_')[0])
    
    row = [i for i in log['Filename'] if filename in i]
    if len(row) == 0:
        ra, dec = locations[tics[-1]][0], locations[tics[-1]][-1]
    else:
        arg = np.where(log['Filename']==row)[0]
        t = log['TIC'][arg].data[0]
        ra, dec = locations[t][0], locations[t][-1]

    
    fits_fn = np.sort([i for i in os.listdir(path.format(date_dir)) if 
                       filename in i and i.endswith('.fits')])[0]
    fits_fn = os.path.join(path.format(date_dir), fits_fn)
    
    hdu = fits.open(fits_fn)
    time = hdu[0].header['UTMJD']
    
    if j == 0:
        LATITUDE = hdu[0].header['LAT_OBS'] * u.deg
        LONGITUDE = hdu[0].header['LONG_OBS'] * u.deg
        ALTITUDE = hdu[0].header['ALT_OBS'] * u.m

    wavelength = interp_wave(newfitx) * u.AA
    speedlight = 2.998e8 * u.m / u.s
    barycorr = get_barycorr(time, ra, dec)
    dopshift = ((wavelength * barycorr) / speedlight).to(u.nm)
    wavelength = (wavelength - dopshift).to(u.nm)
        
    hdu.close()

    outname = os.path.join(path_orders, '{0}_with_wavelength.npy'.format(filename))
    np.save(outname,
            [wavelength*1.005, interp_flux(newfitx)])
    wavelength_fns.append(outname)
wavelength
plt.figure(figsize=(14,4))
plt.plot(wavelength*1.005, interp_flux(newfitx), 'k')
plt.vlines(849.8, 0, 2, color='darkorange', alpha=0.5, lw=4)
plt.vlines(854.2, 0, 2, color='darkorange', alpha=0.5, lw=4)
plt.xlim(867, 845)
plt.ylim(0.7, 1.2)
plt.figure(figsize=(14,4))
plt.plot(wavelength*1.005, interp_flux(newfitx), 'k')
plt.vlines(656.23, 0, 10, color='darkorange', alpha=0.5, lw=4)
#plt.vlines(854.2, 0, 2, color='darkorange', alpha=0.5, lw=4)
plt.xlim(660, 652)
plt.ylim(0.7, 4.0)<jupyter_output><empty_output><jupyter_text>Measure Equivalent Widths<jupyter_code>master = Table.read('/Users/arcticfox/Documents/youngStars/veloce/master_log.tab',
                    format='ascii')
path = '/Users/arcticfox/Documents/youngStars/veloce/spectra/'
tab = Table.read(os.path.join(path, '{0}_orders.tab'.format(element)), format='ascii')
ew = {}
for t in tics:
    ew[t] = []

for i in range(len(wavelength_fns)):
    dat = np.load(wavelength_fns[i])
    
    wave = dat[0] +0.0#* 1.005
    
    if element == 'halpha':
        line_inds = np.where((wave >= 656.05) & (wave <= 656.4))[0]
        continuum_inds = np.where( ( ( wave>=655.4) & (wave<=656.0)  ) |
                                   ( (wave>=656.45) & (wave<=656.85) ) )[0]
    elif element == 'calcium':
        line_inds = np.where((wave>=849.5) & (wave<=850.3))[0]
        continuum_inds = np.where( ( (wave>=848.4) & (wave<=849.3) ) |
                                   ( (wave>=850.5) & (wave<=852) ) )[0]
    
    string = wavelength_fns[i].split('/')[-1]
    date = string.split('n')[0]
    file = string.split('_')[0]
    
    line_area = np.abs(np.trapz(dat[1][line_inds], x=dat[0][line_inds]))
    continuum = np.nanmedian(dat[1][continuum_inds])
    
    frac = (dat[1][line_inds][1:]-continuum)/continuum
    dx = np.diff(dat[0][line_inds])
    summed_ew = (np.nansum(frac * dx)*u.nm).to(u.AA)
    
    if int(date) < 20:
        ew[333680372].append(summed_ew.value)
    else:
        fn = [i for i in tab['Filename'] if file in i][0]
        tic = tab[tab['Filename']==fn]['TIC'].data[0]
        ew[tic].append(summed_ew.value)
    
    """
    plt.plot(wave, dat[1], 'k')
    plt.plot(wave[line_inds], dat[1][line_inds], c='darkorange')
    plt.plot(wave[continuum_inds], dat[1][continuum_inds], c='skyblue')
    plt.xlim(860,845)
    plt.ylim(0,4)
    plt.show()
    """
for t in tics:
    plt.title(t)
    plt.plot(ew[t], '.')
    plt.show()
for tic in tics:
    np.save(os.path.join(path, 'ew_{0}_{1}.npy'.format(element, tic)), ew[tic])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18691588785046728, 'fraction_numerical': 0.04463093648674423, 'mean_word_length': 2.9076005961251865, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '368777', 'license': 'MIT', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2105, 'n_words': 316, 'path': 'feinstein_notebooks/wavelength_solution_and_ews.ipynb', 'repo_name': 'afeinstein20/veloce-spectra-reduction', 'size': '5243'}