BAL Templates

The purpose of this notebook is to demonstrate how to include BALs into QSO templates.


In [1]:
import os
import numpy as np
import matplotlib.pyplot as plt

In [2]:
from desisim.io import read_basis_templates
from desisim.templates import QSO, SIMQSO
from desisim.bal import BAL

In [3]:
%matplotlib inline

In [4]:
seed = 555
rand = np.random.RandomState(seed)

Plot a random subset of the BAL templates.


In [5]:
nplot = 5

In [6]:
balflux, balwave, balmeta = read_basis_templates('BAL')


INFO:io.py:895:read_basis_templates: Reading /Users/ioannis/work/desi/spectro/templates/basis_templates/v2.6/bal_templates_v2.0.fits

In [7]:
these = rand.choice(len(balmeta), nplot)
for ii in these:
    plt.plot(balwave, balflux[ii, :], label='Index {}'.format(ii))
    plt.legend(loc='lower right')
    plt.show()


Build example QSO spectra with and without BALs.


In [8]:
nmodel = 10
zrange = (1.8, 3.0)

In [9]:
qso = QSO()
flux, wave, meta = qso.make_templates(nmodel, seed=seed, zrange=zrange, 
                                      lyaforest=False, nocolorcuts=True)
meta


Out[9]:
Table length=10
OBJTYPESUBTYPETEMPLATEIDSEEDREDSHIFTMAGFLUX_GFLUX_RFLUX_ZFLUX_W1FLUX_W2OIIFLUXHBETAFLUXEWOIIEWHBETAD4000VDISPOIIDOUBLETOIIIHBETAOIIHBETANIIHBETASIIHBETAZMETALAGETEFFLOGGFEH
nanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggieserg / (cm2 s)erg / (cm2 s)AngstromAngstromkm / sDexDexDexDexGyrKm / s2
str10str10int64int64float64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32
QSO030830739461.971214339233965421.3611722.33148482.85450844.613619348.2460390.68837-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO112994525902.93510301714897220.1029877.65149939.095059.38525528.528181122.165985-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO22055362332.207988703954483421.1704167.3064943.402778110.20174330.762573237.674-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO37079455052.5445225497990222.2218671.45647531.29197282.243286612.21743231.441158-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO440564762282.343551573314299821.1906473.47044373.33995915.26603549.51687164.44705-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO542619119332.087720903521069521.0312233.60025883.86821588.24649283.02113178.89035-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO629479798141.841405509104188821.5402662.14483452.4204362.863134437.48036670.45209-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO720272347101.978311735594341120.8035413.6725094.77071575.8674765111.29061232.06288-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO824962664732.773039409343008621.4521732.4058442.62500832.44575024.404820451.648075-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO938323722212.583726451713885420.9915353.71253444.0122314.2105649.61566867.84074-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0

In [10]:
qso_bal = QSO(balqso=True)
flux_bal, _, meta_bal = qso_bal.make_templates(nmodel, seed=seed, balprob=1, zrange=zrange, 
                                               lyaforest=False, nocolorcuts=True)
meta_bal


INFO:io.py:895:read_basis_templates: Reading /Users/ioannis/work/desi/spectro/templates/basis_templates/v2.6/bal_templates_v2.0.fits
Out[10]:
Table length=10
OBJTYPESUBTYPETEMPLATEIDSEEDREDSHIFTMAGFLUX_GFLUX_RFLUX_ZFLUX_W1FLUX_W2OIIFLUXHBETAFLUXEWOIIEWHBETAD4000VDISPOIIDOUBLETOIIIHBETAOIIHBETANIIHBETASIIHBETAZMETALAGETEFFLOGGFEH
nanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggieserg / (cm2 s)erg / (cm2 s)AngstromAngstromkm / sDexDexDexDexGyrKm / s2
str10str10int64int64float64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32
QSOBAL030830739461.971214339233965421.3611722.25202732.85450843.478601742.48101479.711815-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL112994525902.93510301714897220.1029879.1951739.0950514.79203971.00738167.19891-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL22055362332.207988703954483421.1704163.45146063.40277814.730237552.4169146.18277-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL37079455052.5445225497990222.2218671.15848771.29197281.35072573.58962621.92136-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL440564762282.343551573314299821.1906473.6084043.33995913.813422431.952965127.547356-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL542619119332.087720903521069521.0312233.54913073.86821584.50568475.91279177.0667-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL629479798141.841405509104188821.5402662.30063822.4204362.84508364.330414126.95421-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL720272347101.978311735594341120.8035414.17364264.77071575.270684795.959435195.50069-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL824962664732.773039409343008621.4521732.38361672.62500832.894157411.80965652.68473-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSOBAL938323722212.583726451713885420.9915354.49000454.0122318.17044535.149246138.3646-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0

Not sure why the templates are not reproducible...


In [11]:
for ii in range(nmodel):
    plt.plot(wave, flux[ii, :], label='QSO')
    plt.plot(wave, flux_bal[ii, :], label='BAL QSO')
    plt.xlim(balwave.min()*(1+zrange[0]), balwave.max()*(1+zrange[1]))
    plt.legend(loc='upper right')
    plt.show()


What about adding BALs separately (e.g., as part of quickquasars)?

Instead of using the BAL code in desisim.templates itself, one can easily include BALs separately. Here, we demonstrate how to do so using the SIMQSO class to build QSO spectra.


In [12]:
nsimmodel = 20
simqq = SIMQSO()
simflux, simwave, simmeta = simqq.make_templates(nsimmodel, zrange=(1.8, 3), seed=seed,
                                                 nocolorcuts=True, lyaforest=False)
simmeta


Out[12]:
Table length=20
OBJTYPESUBTYPETEMPLATEIDSEEDREDSHIFTMAGFLUX_GFLUX_RFLUX_ZFLUX_W1FLUX_W2OIIFLUXHBETAFLUXEWOIIEWHBETAD4000VDISPOIIDOUBLETOIIIHBETAOIIHBETANIIHBETASIIHBETAZMETALAGETEFFLOGGFEH
magnanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggieserg / (cm2 s)erg / (cm2 s)AngstromAngstromkm / sDexDexDexDexGyrKm / s2
str10str10int64int64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32
QSO030830739462.087720921.7654571.95247481.96705642.89909464.9433468.880149-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO130830739461.841405519.3885918.78227417.5615919.52872338.80905584.24881-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO230830739461.978311819.48334718.24974616.09388717.13502128.53419941.578354-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO330830739462.773039320.4816746.31247436.41697266.96854939.05515213.342611-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO430830739462.583726421.5109482.86020042.48668432.67470772.72822173.905749-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO530830739462.453362520.049411.8543569.55519511.26807812.39679819.639875-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO630830739461.849433722.635880.911815050.882365051.10435812.45309074.6772423-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO730830739462.361799520.7324686.2471195.09345966.11592537.277426210.5539-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO830830739462.86649622.9578550.51851580.65593010.833760741.8271612.907373-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO930830739462.371510322.412531.24071621.0838961.41280232.01969863.3609607-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1030830739462.294986720.1854539.5372578.42982611.22737515.32926621.629114-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1130830739462.539327921.4401382.59538942.65427063.84577476.87270512.216707-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1230830739462.185722.3488771.203821.14934271.62628053.7117255.409975-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1330830739462.497043121.0970573.99248153.6406344.89327868.7931313.496968-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1430830739462.275936821.9478471.73866091.66288152.53287124.64284857.205031-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1530830739461.824109722.3672391.14000631.13006831.42758212.11810452.8727849-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1630830739462.31767522.5247691.35173940.977445361.04941231.07713021.6218448-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1730830739462.293493522.9620970.76739590.65337320.80737680.90755351.5166544-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1830830739462.554874220.9197864.1292024.286336.1083267.28050610.707948-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0
QSO1930830739462.403026321.1653774.01382353.41860944.3433365.86031310.180962-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0-1.0

In [13]:
bal = BAL()
simflux_bal, balmeta = bal.insert_bals(simwave, simflux, simmeta['REDSHIFT'], balprob=0.5, seed=seed)
balmeta


INFO:io.py:895:read_basis_templates: Reading /Users/ioannis/work/desi/spectro/templates/basis_templates/v2.6/bal_templates_v2.0.fits
Out[13]:
Table length=20
TEMPLATEIDREDSHIFT
int32float32
-12.0877209
2091.8414055
-11.9783118
-12.7730393
-12.5837264
2602.4533625
-11.8494337
1052.3617995
-12.866496
4492.3715103
2642.2949867
202.5393279
2882.1857
-12.4970431
-12.2759368
-11.8241097
3692.317675
5322.2934935
-12.5548742
2352.4030263

In [14]:
for ii in range(nmodel):
    plt.plot(simwave, simflux[ii, :], label='QSO')
    plt.plot(simwave, simflux_bal[ii, :], label='BAL QSO (ID={})'.format(balmeta['TEMPLATEID'][ii]))
    plt.xlim(3400, 5500)
    plt.legend(loc='upper right')
    plt.show()