<jupyter_start><jupyter_text>Add GAMA emission lines to template spectra<jupyter_code>import numpy as np 
# -- local -- 
import env
from feasibgs import util as UT
from feasibgs import catalogs as Cat
from feasibgs import forwardmodel as FM
import matplotlib as mpl 
import matplotlib.pyplot as pl 
mpl.rcParams['text.usetex'] = True
mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['axes.linewidth'] = 1.5
mpl.rcParams['axes.xmargin'] = 1
mpl.rcParams['xtick.labelsize'] = 'x-large'
mpl.rcParams['xtick.major.size'] = 5
mpl.rcParams['xtick.major.width'] = 1.5
mpl.rcParams['ytick.labelsize'] = 'x-large'
mpl.rcParams['ytick.major.size'] = 5
mpl.rcParams['ytick.major.width'] = 1.5
mpl.rcParams['legend.frameon'] = False
%matplotlib inline<jupyter_output><empty_output><jupyter_text>read in GAMA-legacy catalog<jupyter_code>cata = Cat.GamaLegacy()
gleg = cata.Read()<jupyter_output><empty_output><jupyter_text>calculate absolute magnitude with `k-correct` to $z = 0.1$<jupyter_code>redshift = gleg['gama-spec']['z_helio']
absmag_ugriz = cata.AbsMag(gleg, kcorr=0.1, H0=70, Om0=0.3)
i_rand = np.random.choice(range(absmag_ugriz.shape[1]), size=10)
fig = plt.figure()#figsize=(8,4))
sub = fig.add_subplot(111)
sub.scatter(absmag_ugriz[2,:], absmag_ugriz[1,:] - absmag_ugriz[2,:], c='k', s=2)
sub.scatter(absmag_ugriz[2,i_rand], absmag_ugriz[1,i_rand] - absmag_ugriz[2,i_rand], s=30, marker='s')
sub.set_xlabel('$M_{0.1r}$', fontsize=20)
sub.set_xlim([-14., -24])
sub.set_ylabel('$^{0.1}(g-r)$', fontsize=20)
sub.set_ylim([-0.2, 1.2])

# compile z, M_r0.1, 0.1(g-r)
gleg_meta = np.vstack([
    redshift[i_rand], 
    absmag_ugriz[2,i_rand], 
    absmag_ugriz[1,i_rand] - absmag_ugriz[2,i_rand]]).T
bgs3 = FM.BGStree()
match, _ = bgs3.Query(gleg_meta)
bgstemp = FM.BGStemplates(wavemin=1500., wavemax=2e4)
vdisp = np.repeat(100.0, len(i_rand))
flux_temp, wave_temp, meta_temp = bgstemp.Spectra(
    gleg['gama-photo']['modelmag_r'][i_rand], redshift[i_rand], vdisp, seed=1, templateid=match)
fig = plt.figure()
sub = fig.add_subplot(111)
for i in range(flux_temp.shape[0]): 
    sub.plot(wave_temp, flux_temp[i].T)
sub.set_xlabel('Wavelength (A)', fontsize=20)
sub.set_xlim([1500., 2e4])
sub.set_ylabel(r'$f(\lambda) \,\,[10^{-17} erg/s/cm^2/A]$', fontsize=20)
print gleg['gama-spec']['z_helio'][i_rand]
print gleg['gama-spec']['iha'][i_rand]
print gleg['gama-spec']['ha'][i_rand]
print gleg['gama-spec']['hasig'][i_rand]
print gleg['gama-spec']['haew'][i_rand]
L_ha = 6563. # rest frame H-alpha
gauss_norm = gleg['gama-spec']['ha'][i_rand]/np.sqrt(2.*np.pi*gleg['gama-spec']['hasig'][i_rand]**2)
def gauss(x, mu, sig): 
    return np.exp(-(x-mu)**2/(2.*sig**2))
fig = plt.figure(figsize=(8,4))
sub1 = fig.add_subplot(121)
sub2 = fig.add_subplot(122)
sub1.scatter(absmag_ugriz[2,:], absmag_ugriz[1,:] - absmag_ugriz[2,:], c='k', s=2)
sub1.scatter(absmag_ugriz[2,i_rand[0]], absmag_ugriz[1,i_rand[0]] - absmag_ugriz[2,i_rand[0]],
             s=30, marker='s')
sub2.plot(wave_temp, flux_temp[0].T + 
          gauss_norm[0] * gauss(wave_temp, L_ha*(1.+redshift[i_rand][0]), gleg['gama-spec']['hasig'][i_rand][0]))
sub1.set_xlabel('$M_{0.1r}$', fontsize=20)
sub1.set_xlim([-14., -24])
sub1.set_ylabel('$^{0.1}(g-r)$', fontsize=20)
sub1.set_ylim([-0.2, 1.2])
sub2.set_xlabel('Wavelength (A)', fontsize=20)
sub2.set_xlim([3600., 9800.])
sub2.set_ylabel(r'$f(\lambda) \,\,[10^{-17} erg/s/cm^2/A]$', fontsize=20)
#sub.set_ylim([2., 12.])
print redshift[i_rand][3]
fig = plt.figure(figsize=(8,4))
sub1 = fig.add_subplot(121)
sub2 = fig.add_subplot(122)
sub1.scatter(absmag_ugriz[2,:], absmag_ugriz[1,:] - absmag_ugriz[2,:], c='k', s=2)
sub1.scatter(absmag_ugriz[2,i_rand[3]], absmag_ugriz[1,i_rand[3]] - absmag_ugriz[2,i_rand[3]],
             s=30, marker='s')
sub2.plot(wave_temp, flux_temp[3].T + gauss_norm[3] * gauss(wave_temp, L_ha*(1.+redshift[i_rand][3]), gleg['gama-spec']['hasig'][i_rand][3]))
sub1.set_xlabel('$M_{0.1r}$', fontsize=20)
sub1.set_xlim([-14., -24])
sub1.set_ylabel('$^{0.1}(g-r)$', fontsize=20)
sub1.set_ylim([-0.2, 1.2])
sub2.set_xlabel('Wavelength (A)', fontsize=20)
sub2.set_xlim([3600., 9800.])
sub2.set_ylabel(r'$f(\lambda) \,\,[10^{-17} erg/s/cm^2/A]$', fontsize=20)
#sub.set_ylim([2., 12.])
ii = 4
print redshift[i_rand][ii]
fig = plt.figure(figsize=(8,4))
sub1 = fig.add_subplot(121)
sub2 = fig.add_subplot(122)
sub1.scatter(absmag_ugriz[2,:], absmag_ugriz[1,:] - absmag_ugriz[2,:], c='k', s=2)
sub1.scatter(absmag_ugriz[2,i_rand[ii]], absmag_ugriz[1,i_rand[ii]] - absmag_ugriz[2,i_rand[ii]],
             s=30, marker='s')
sub2.plot(wave_temp, flux_temp[ii].T + 
          gauss_norm[ii] * gauss(wave_temp, L_ha*(1.+redshift[i_rand][ii]), gleg['gama-spec']['hasig'][i_rand][ii]))
sub1.set_xlabel('$M_{0.1r}$', fontsize=20)
sub1.set_xlim([-14., -24])
sub1.set_ylabel('$^{0.1}(g-r)$', fontsize=20)
sub1.set_ylim([-0.2, 1.2])
sub2.set_xlabel('Wavelength (A)', fontsize=20)
sub2.set_xlim([3600., 9800.])
sub2.set_ylabel(r'$f(\lambda) \,\,[10^{-17} erg/s/cm^2/A]$', fontsize=20)
#sub.set_ylim([2., 12.])
ii = 5
print redshift[i_rand][ii]
fig = plt.figure(figsize=(8,4))
sub1 = fig.add_subplot(121)
sub2 = fig.add_subplot(122)
sub1.scatter(absmag_ugriz[2,:], absmag_ugriz[1,:] - absmag_ugriz[2,:], c='k', s=2)
sub1.scatter(absmag_ugriz[2,i_rand[ii]], absmag_ugriz[1,i_rand[ii]] - absmag_ugriz[2,i_rand[ii]],
             s=30, marker='s')
sub2.plot(wave_temp, flux_temp[ii].T + 
          gauss_norm[ii] * gauss(wave_temp, L_ha*(1.+redshift[i_rand][ii]), gleg['gama-spec']['hasig'][i_rand][ii]))
sub1.set_xlabel('$M_{0.1r}$', fontsize=20)
sub1.set_xlim([-14., -24])
sub1.set_ylabel('$^{0.1}(g-r)$', fontsize=20)
sub1.set_ylim([-0.2, 1.2])
sub2.set_xlabel('Wavelength (A)', fontsize=20)
sub2.set_xlim([3600., 9800.])
sub2.set_ylabel(r'$f(\lambda) \,\,[10^{-17} erg/s/cm^2/A]$', fontsize=20)
#sub.set_ylim([2., 12.])
ii = 9
print redshift[i_rand][ii]
fig = plt.figure(figsize=(8,4))
sub1 = fig.add_subplot(121)
sub2 = fig.add_subplot(122)
sub1.scatter(absmag_ugriz[2,:], absmag_ugriz[1,:] - absmag_ugriz[2,:], c='k', s=2)
sub1.scatter(absmag_ugriz[2,i_rand[ii]], absmag_ugriz[1,i_rand[ii]] - absmag_ugriz[2,i_rand[ii]],
             s=30, marker='s')
sub2.plot(wave_temp, flux_temp[ii].T + 
          gauss_norm[ii] * gauss(wave_temp, L_ha*(1.+redshift[i_rand][ii]), gleg['gama-spec']['hasig'][i_rand][ii]))
sub1.set_xlabel('$M_{0.1r}$', fontsize=20)
sub1.set_xlim([-14., -24])
sub1.set_ylabel('$^{0.1}(g-r)$', fontsize=20)
sub1.set_ylim([-0.2, 1.2])
sub2.set_xlabel('Wavelength (A)', fontsize=20)
sub2.set_xlim([3600., 9800.])
sub2.set_ylabel(r'$f(\lambda) \,\,[10^{-17} erg/s/cm^2/A]$', fontsize=20)
#sub.set_ylim([2., 12.])<jupyter_output>0.29762
{'fraction_non_alphanumeric': 0.23267326732673269, 'fraction_numerical': 0.06810681068106811, 'mean_word_length': 6.199784017278618, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '449633', 'license': 'MIT', 'n_tokens_mistral': 3353, 'n_tokens_neox': 3145, 'n_words': 397, 'path': 'notebook/notes_template_lines.ipynb', 'repo_name': 'changhoonhahn/feasiBGS', 'size': '6666'}