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

from astropy.table import Table, Column
from astropy.io import fits

import seaborn as sns
from desisim.templates import STAR

sns.set(style='white', font_scale=1.6, palette='deep')
%matplotlib inline

LIGHT = 2.99792458E5  #- speed of light in km/s


:0: FutureWarning: IPython widgets are experimental and may change in the future.

In [2]:
cat = fits.getdata('allsky_galaxia_desi_3250p100.fits', ext=1)[:1000]
print(cat.columns)
nstar = len(cat)


ColDefs(
    name = 'X'; format = 'E'; unit = 'kpc'
    name = 'Y'; format = 'E'; unit = 'kpc'
    name = 'Z'; format = 'E'; unit = 'kpc'
    name = 'l'; format = 'E'; unit = 'deg'
    name = 'b'; format = 'E'; unit = 'deg'
    name = 'RA'; format = 'D'; unit = 'deg'
    name = 'DEC'; format = 'D'; unit = 'deg'
    name = 'pm_l'; format = 'E'
    name = 'pm_b'; format = 'E'
    name = 'pm_RA'; format = 'E'
    name = 'pm_DEC'; format = 'E'
    name = 'pm_l_kms'; format = 'E'; unit = 'km s-1'
    name = 'pm_b_kms'; format = 'E'; unit = 'km s-1'
    name = 'pm_RA_kms'; format = 'E'; unit = 'km s-1'
    name = 'pm_DEC_kms'; format = 'E'; unit = 'km s-1'
    name = 'v_helio'; format = 'E'; unit = 'km s-1'
    name = 'd_helio'; format = 'E'; unit = 'kpc'
    name = 'DM'; format = 'E'; unit = 'mag'
    name = 'ABV'; format = 'E'; unit = 'mag'
    name = 'SDSSu_true_nodust'; format = 'E'; unit = 'mag'
    name = 'SDSSu_true'; format = 'E'; unit = 'mag'
    name = 'SDSSu_obs'; format = 'E'; unit = 'mag'
    name = 'SDSSg_true_nodust'; format = 'E'; unit = 'mag'
    name = 'SDSSg_true'; format = 'E'; unit = 'mag'
    name = 'SDSSg_obs'; format = 'E'; unit = 'mag'
    name = 'SDSSr_true_nodust'; format = 'E'; unit = 'mag'
    name = 'SDSSr_true'; format = 'E'; unit = 'mag'
    name = 'SDSSr_obs'; format = 'E'; unit = 'mag'
    name = 'SDSSi_true_nodust'; format = 'E'; unit = 'mag'
    name = 'SDSSi_true'; format = 'E'; unit = 'mag'
    name = 'SDSSi_obs'; format = 'E'; unit = 'mag'
    name = 'SDSSz_true_nodust'; format = 'E'; unit = 'mag'
    name = 'SDSSz_true'; format = 'E'; unit = 'mag'
    name = 'SDSSz_obs'; format = 'E'; unit = 'mag'
    name = 'FeH'; format = 'E'
    name = 'age'; format = 'E'
    name = 'teff'; format = 'E'
    name = 'logg'; format = 'E'
    name = 'mtip'; format = 'E'
    name = 'mact'; format = 'E'
    name = 'smass'; format = 'E'
    name = 'popid'; format = 'J'
    name = 'brickname'; format = '8A'
    name = 'brickid'; format = 'K'
    name = 'vRcyl'; format = 'E'; unit = 'km s-1'
    name = 'vPHIcyl'; format = 'E'; unit = 'km s-1'
    name = 'vZcyl'; format = 'E'; unit = 'km s-1'
    name = 'vX'; format = 'E'; unit = 'km s-1'
    name = 'vY'; format = 'E'; unit = 'km s-1'
    name = 'vZ'; format = 'E'; unit = 'km s-1'
    name = 'vU'; format = 'E'; unit = 'km s-1'
    name = 'vV'; format = 'E'; unit = 'km s-1'
    name = 'vW'; format = 'E'; unit = 'km s-1'
    name = 'objid'; format = 'K'
)

In [3]:
# Build the input Table needed by desisim.templates.
star_properties = Table()
star_properties.add_column(Column(name='REDSHIFT', length=nstar, dtype='f4'))
star_properties.add_column(Column(name='MAG', length=nstar, dtype='f4'))
star_properties.add_column(Column(name='TEFF', length=nstar, dtype='f4'))
star_properties.add_column(Column(name='LOGG', length=nstar, dtype='f4'))
star_properties.add_column(Column(name='FEH', length=nstar, dtype='f4'))

normfilter = 'sdss2010-r'
star_properties['REDSHIFT'] = cat['v_helio'] / LIGHT
star_properties['MAG'] = cat['SDSSr_true_nodust']
star_properties['TEFF'] = 10**cat['teff']
star_properties['LOGG'] = cat['logg']
star_properties['FEH'] = cat['FeH']

print(star_properties)


  REDSHIFT     MAG     TEFF    LOGG      FEH    
------------ ------- ------- ------- -----------
 6.01848e-05 15.8917 3282.58 5.13229  -0.0315856
 7.99531e-06 15.8664 3312.49 5.14478 -0.00470402
 1.74716e-05 15.5964  3334.0 5.10969    0.125893
 5.70486e-05 15.3146  3410.2 5.09782  0.00320513
 9.38985e-05 15.8247 3458.58 5.05803     0.09498
 6.27923e-07 16.7426 3363.57 5.13803  -0.0633323
  6.7137e-05 15.4234 3541.03 5.01888    0.117763
 1.90811e-05 15.9689 3328.64 5.12838   0.0616664
 -3.0621e-05 16.0427 3437.96 5.08739   0.0287824
 4.54792e-05 16.8698 3183.28 5.06934   0.0716745
         ...     ...     ...     ...         ...
-2.19293e-05 15.5301 4670.36 4.63824    0.134668
 1.39156e-05  15.633 4796.29 4.66383   -0.198207
 0.000101043 16.0687 4532.31 4.69746   -0.137685
 7.15131e-05 16.0526 4577.26 4.69566   -0.176918
 4.90442e-05 15.5463 4729.08 4.61933    0.174833
 5.23339e-05 16.9829 4197.07 4.78854   -0.110437
 0.000110215 16.7676 4273.42 4.73282    0.130931
 0.000110136 16.7092 4342.24 4.74698   -0.126916
 3.05512e-05  16.383 4447.55 4.70958  -0.0844261
 4.06572e-05 16.2816 4470.27 4.69687  -0.0361054
 8.89215e-06    15.9 4604.76 4.63764    0.216518
Length = 1000 rows

In [4]:
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))
_, _, _ = ax1.hist(star_properties['MAG'])
ax1.set_ylabel('Number of Stars per bin')
ax1.set_xlabel('SDSS r (AB mag)')

_, _, _ = ax2.hist(star_properties['REDSHIFT'] * LIGHT)
ax2.set_xlabel('Heliocentric Redshift')

fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(6, 8))
ax1.scatter(star_properties['TEFF'], star_properties['LOGG'])
ax1.set_ylabel('log $(g / cm s^{-2})$')
ax1.margins(0.05)

ax2.scatter(star_properties['TEFF'], star_properties['FEH'])
ax2.set_xlabel('T$_{eff}$ (K)')
ax2.set_ylabel('[Fe/H]')
ax2.margins(0.05)
fig.subplots_adjust(hspace=0.04)



In [5]:
seed = 123
star = STAR(normfilter=normfilter)
flux, wave, meta = star.make_templates(seed=seed, star_properties=star_properties)


INFO:io.py:611:read_basis_templates: Reading /Users/ioannis/research/projects/desi/spectro/templates/basis_templates/v2.2/star_templates_v2.1.fits
INFO:DESI:Reading /Users/ioannis/research/projects/desi/spectro/templates/basis_templates/v2.2/star_templates_v2.1.fits
WARNING:templates.py:1296:make_star_templates: 35 spectra could not be computed given the input priors!
WARNING:DESI:35 spectra could not be computed given the input priors!

In [6]:
print(meta)


OBJTYPE TEMPLATEID    SEED      REDSHIFT  ... AGE    TEFF    LOGG      FEH    
                                          ... Gyr     K     m / s2            
------- ---------- ---------- ----------- ... ---- ------- ------- -----------
   STAR          0 2991312382 6.01848e-05 ... -1.0 3282.58 5.13229  -0.0315856
   STAR          1 3062119789 7.99531e-06 ... -1.0 3312.49 5.14478 -0.00470402
   STAR          2 1228959102 1.74716e-05 ... -1.0  3334.0 5.10969    0.125893
   STAR          3 1840268610 5.70486e-05 ... -1.0  3410.2 5.09782  0.00320513
   STAR          4  974319580 9.38985e-05 ... -1.0 3458.58 5.05803     0.09498
   STAR          5 2967327842 6.27923e-07 ... -1.0 3363.57 5.13803  -0.0633323
   STAR          6 2367878886  6.7137e-05 ... -1.0 3541.03 5.01888    0.117763
   STAR          7 3088727057 1.90811e-05 ... -1.0 3328.64 5.12838   0.0616664
   STAR          8 3090095699 -3.0621e-05 ... -1.0 3437.96 5.08739   0.0287824
   STAR          9 2109339754 4.54792e-05 ... -1.0 3183.28 5.06934   0.0716745
    ...        ...        ...         ... ...  ...     ...     ...         ...
   STAR        990 4211633505 1.39156e-05 ... -1.0 4796.29 4.66383   -0.198207
   STAR        991 1436232733 0.000101043 ... -1.0 4532.31 4.69746   -0.137685
   STAR        992 3791223403 7.15131e-05 ... -1.0 4577.26 4.69566   -0.176918
   STAR        993 1211957270 4.90442e-05 ... -1.0 4729.08 4.61933    0.174833
   STAR        994 3949104175 5.23339e-05 ... -1.0 4197.07 4.78854   -0.110437
   STAR        995 1670951350 0.000110215 ... -1.0 4273.42 4.73282    0.130931
   STAR        996 1784574163 0.000110136 ... -1.0 4342.24 4.74698   -0.126916
   STAR        997 2445381101 3.05512e-05 ... -1.0 4447.55 4.70958  -0.0844261
   STAR        998 3198099070 4.06572e-05 ... -1.0 4470.27 4.69687  -0.0361054
   STAR        999 2423849465 8.89215e-06 ... -1.0 4604.76 4.63764    0.216518
Length = 1000 rows

In [7]:
plt.plot(wave, flux[0, :])
plt.xlabel('Observed Wavelength ($\AA$)')
plt.ylabel('F$_{\lambda}$ (erg / s / cm$^{2}$ / $\AA$)')


Out[7]:
<matplotlib.text.Text at 0x11e044e90>

In [ ]: