Connecting Spectra to Mocks

The purpose of this notebook is to demonstrate how to generate spectra and apply target selection cuts for various mock catalogs and target types. Here we generate spectra for targets in a single healpixel with no constraints on the target density (relative to the expected target density) or contaminants.

For code to generate large numbers of spectra over significant patches of sky and to create a representative DESI dataset (with parallelism), see desitarget/bin/select_mock_targets (as well as its MPI-parallelized cousin, desitarget/bin/select_mock_targets) and desitarget.mock.build.targets_truth.

Finally, note that the various python Classes instantiated here (documented in desitarget.mock.mockmaker) are easily extensible to other mock catalogs and galaxy/QSO/stellar physics. Please contact @desi-data if you have specific suggestions, requirements, or desired features.

John Moustakas
Siena College
2018 September


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

In [2]:
from desiutil.log import get_logger, DEBUG
log = get_logger()

In [3]:
import seaborn as sns
sns.set(style='white', font_scale=1.1, palette='Set2')

In [4]:
%matplotlib inline

To keep the calculations below manageable we specify a single nside=64 healpixel in an arbitrary location of the DESI footprint.


In [5]:
healpixel = 26030
nside = 64

Specifying the random seed makes our calculations reproducible.


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

Define a couple wrapper routines we will use below several times.


In [7]:
def plot_subset(wave, flux, truth, objtruth, nplot=16, ncol=4, these=None, 
                xlim=None, loc='right', targname='', objtype=''):
    """Plot a random sampling of spectra."""
    
    nspec, npix = flux.shape
    if nspec < nplot:
        nplot = nspec
    
    nrow = np.ceil(nplot / ncol).astype('int')

    if loc == 'left':
        xtxt, ytxt, ha = 0.05, 0.93, 'left'
    else:
        xtxt, ytxt, ha = 0.93, 0.93, 'right'
    
    if these is None:
        these = rand.choice(nspec, nplot, replace=False)
        these = np.sort(these)
        
    ww = (wave > 5500) * (wave < 5550)

    fig, ax = plt.subplots(nrow, ncol, figsize=(2.5*ncol, 2*nrow), sharey=False, sharex=True)
    for thisax, indx in zip(ax.flat, these):
        thisax.plot(wave, flux[indx, :] / np.median(flux[indx, ww]))
        if objtype == 'STAR' or objtype == 'WD':
            thisax.text(xtxt, ytxt, r'$T_{{eff}}$={:.0f} K'.format(objtruth['TEFF'][indx]), 
                        ha=ha, va='top', transform=thisax.transAxes, fontsize=13)
        else:
            thisax.text(xtxt, ytxt, 'z={:.3f}'.format(truth['TRUEZ'][indx]), 
                        ha=ha, va='top', transform=thisax.transAxes, fontsize=13)
            
        thisax.xaxis.set_major_locator(plt.MaxNLocator(3))
        if xlim:
            thisax.set_xlim(xlim)
    for thisax in ax.flat:
        thisax.yaxis.set_ticks([])
        thisax.margins(0.2)
        
    fig.suptitle(targname)
    fig.subplots_adjust(wspace=0.05, hspace=0.05, top=0.93)

Tracer QSOs

Both tracer and Lya QSO spectra contain an underlying QSO spectrum, but the Lya QSOs (which we demonstrate below) also include the Lya forest (here, based on the v2.0 of the "London" mocks).

Every target class has its own dedicated "Maker" class.


In [8]:
from desitarget.mock.mockmaker import QSOMaker

In [9]:
QSO = QSOMaker(seed=seed)


WARNING:templates.py:2366:__init__: Using default SIMQSO model

The various read methods return a dictionary with (hopefully self-explanatory) target- and mock-specific quantities.

Because most mock catalogs only come with (cosmologically accurate) 3D positions (RA, Dec, redshift), we use Gaussian mixture models trained on real data to assign other quantities like shapes, magnitudes, and colors, depending on the target class. For more details see the gmm-dr7.pynb Python notebook.


In [10]:
dir(QSOMaker)


Out[10]:
['FFA',
 'GMM_BGS',
 'GMM_ELG',
 'GMM_LRG',
 'GMM_QSO',
 'KDTree_build',
 'KDTree_query',
 'KDTree_rescale',
 '__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_nospectra_photometry',
 '_qaplot_scatter_photometry',
 '_sample_vdisp',
 'get_fiberfraction',
 'imaging_depth',
 'is_south',
 'make_spectra',
 'mock_density',
 'mw_dust_extinction',
 'mw_transmission',
 'populate_targets_truth',
 'qamock_sky',
 'read',
 'read_GMM',
 'remove_north_south_bits',
 'sample_GMM',
 'scatter_photometry',
 'select_targets',
 'template_maker',
 'wave']

In [11]:
data = QSO.read(healpixels=healpixel, nside=nside)


INFO:mockmaker.py:231:_get_radec: Reading /global/project/projectdirs/desi/mocks/DarkSky/v1.0.1/qso_0_inpt.fits
INFO:mockmaker.py:236:_get_radec: Assigning healpix pixels with nside = 64.
INFO:mockmaker.py:1349:readmock: Trimmed to 294 QSOs in 1 healpixel(s)
INFO:mockmaker.py:1389:readmock: Sampling from QSO Gaussian mixture model.

In [12]:
for key in sorted(list(data.keys())):
    print('{:>20}'.format(key))


             BRICKID
           BRICKNAME
                 DEC
                 EBV
             FRACDEV
        FRACDEV_IVAR
          GALDEPTH_G
          GALDEPTH_R
          GALDEPTH_Z
                  GR
             HEALPIX
                 MAG
           MAGFILTER
          MOCKFORMAT
              MOCKID
   MW_TRANSMISSION_G
   MW_TRANSMISSION_R
  MW_TRANSMISSION_W1
  MW_TRANSMISSION_W2
  MW_TRANSMISSION_W3
  MW_TRANSMISSION_W4
   MW_TRANSMISSION_Z
               NSIDE
          PSFDEPTH_G
          PSFDEPTH_R
         PSFDEPTH_W1
         PSFDEPTH_W2
          PSFDEPTH_Z
                  RA
                  RZ
         SHAPEDEV_E1
    SHAPEDEV_E1_IVAR
         SHAPEDEV_E2
    SHAPEDEV_E2_IVAR
          SHAPEDEV_R
     SHAPEDEV_R_IVAR
         SHAPEEXP_E1
    SHAPEEXP_E1_IVAR
         SHAPEEXP_E2
    SHAPEEXP_E2_IVAR
          SHAPEEXP_R
     SHAPEEXP_R_IVAR
               SOUTH
         TARGET_NAME
                TYPE
                W1W2
              WEIGHT
                   Z
                 ZW1
             Z_NORSD

Now we can generate the spectra as well as the targeting catalogs (targets) and corresponding truth table.


In [13]:
%time flux, wave, targets, truth, objtruth = QSO.make_spectra(data)


CPU times: user 10.6 s, sys: 332 ms, total: 11 s
Wall time: 11 s

In [14]:
print(flux.shape, wave.shape)


(294, 32001) (32001,)

The truth catalog contains the target-type-agnostic, known properties of each object (including the noiseless photometry), while the objtruth catalog contains different information depending on the type of target.


In [15]:
truth


Out[15]:
<Table length=294>
TARGETIDMOCKIDTRUEZTRUESPECTYPETEMPLATETYPETEMPLATESUBTYPETEMPLATEIDSEEDMAGMAGFILTERFLUX_GFLUX_RFLUX_ZFLUX_W1FLUX_W2FLUX_W3FLUX_W4
magnanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggies
int64int64float32bytes10bytes10bytes10int32int64float32bytes15float32float32float32float32float32float32float32
038980802.14468QSOQSO0308307394622.310131decam2014-r1.24593631.19109821.65897693.53530535.22208930.00.0
138980812.1017907QSOQSO1308307394621.74744decam2014-r2.15068911.99997042.64416863.79032546.6087710.00.0
238980822.0933137QSOQSO2308307394619.97554decam2014-r9.88922710.2278414.64179224.7166241.6464270.00.0
338980842.130867QSOQSO3308307394620.975834decam2014-r4.73554664.0706734.74454555.19291078.4643550.00.0
438980862.1383474QSOQSO4308307394620.517382decam2014-r6.89393766.2093627.60697948.03003910.6820.00.0
538980892.1134171QSOQSO5308307394622.452776decam2014-r1.16018941.04445541.33181971.82193862.7614290.00.0
638980902.0968761QSOQSO6308307394622.112696decam2014-r1.52831521.42863661.90992.39848043.9917840.00.0
738980912.1031346QSOQSO7308307394622.21616decam2014-r1.25654241.29878061.99570054.74365147.46042350.00.0
838980922.0873334QSOQSO8308307394622.323217decam2014-r1.23094381.17682891.61229423.01031044.8997270.00.0
...................................................
28444507750.24762678QSOQSO284308307394620.089771decam2014-r9.0528639.20644110.14663455.06562866.362660.00.0
28544510810.2423425QSOQSO285308307394621.177752decam2014-r3.0229333.3798683.347517314.15165418.6767790.00.0
28644510830.24200284QSOQSO286308307394622.461763decam2014-r0.903576731.0358441.16755387.2282688.9566050.00.0
28744550110.20584077QSOQSO287308307394622.305737decam2014-r0.982120931.19592941.21976056.27385238.925630.00.0
28844550160.19950642QSOQSO288308307394620.231005decam2014-r7.7227468.0834787.241641549.633167.1914140.00.0
28944735090.16963921QSOQSO289308307394621.611774decam2014-r1.88307792.26615642.2550288.58432412.1543180.00.0
29044735480.15938476QSOQSO290308307394617.577793decam2014-r82.92615593.0857290.83878541.8383817.99110.00.0
29144737200.15224007QSOQSO291308307394618.585546decam2014-r29.49887736.79439537.847224.73984283.023350.00.0
29244741290.12352133QSOQSO292308307394620.065584decam2014-r8.2186419.4138369.50912345.0635152.2615050.00.0
29344741300.12371948QSOQSO293308307394620.324472decam2014-r7.23830377.4167127.139540749.4589264.290190.00.0

In [16]:
objtruth


Out[16]:
<Table length=294>
TARGETIDMABS_1450SLOPES [5]EMLINES [62,3]BAL_TEMPLATEIDDLATRUEZ_NORSD
mag
int64float32float32float32int16boolfloat32
0-22.276962-1.2975354 .. -1.0743971034.4368 .. 269.5846-1False2.1437433
1-22.839176-1.5567551 .. -0.6927671033.4977 .. 336.0061-1False2.097336
2-24.496473-1.5177195 .. -0.873076441034.3599 .. 287.68607-1False2.0972614
3-23.766111-1.6437727 .. -1.55605551034.6467 .. 278.66608-1False2.131041
4-24.178185-1.3443806 .. -1.09389221033.722 .. 352.3445-1False2.1416454
5-22.192215-1.455469 .. -1.3223031034.206 .. 316.65164-1False2.1126738
6-22.458462-1.9528524 .. -0.95689891033.9252 .. 273.11548-1False2.098513
7-22.216278-1.1239568 .. -1.05187751033.6422 .. 304.71652-1False2.1042516
8-22.207693-1.9601669 .. -1.11278361033.569 .. 324.69693-1False2.0873556
.....................
284-19.91731-0.8349316 .. -0.58915121034.0177 .. 372.9634-1False0.2479765
285-18.317102-1.5567272 .. -0.876727341034.4933 .. 345.76453-1False0.24319886
286-16.899096-1.300528 .. -0.677067041035.0283 .. 287.5509-1False0.24232832
287-16.35727-1.8036945 .. -1.11473761035.0691 .. 310.82388-1False0.20747599
288-19.120567-2.1154327 .. -0.95734911034.7297 .. 281.1522-1False0.19969091
289-16.58561-1.7432963 .. -1.09955291035.0902 .. 291.54092-1False0.17022586
290-20.830135-1.2727911 .. -1.3030321033.9381 .. 340.8922-1False0.15847993
291-19.151999-0.99189305 .. -0.72838211034.7849 .. 362.28397-1False0.15142709
292-17.500885-1.3504946 .. -0.467766051034.242 .. 281.00714-1False0.124221675
293-17.938726-1.8114623 .. -0.82867271034.293 .. 418.2334-1False0.124556065

Next, let's run target selection, after which point the targets catalog should look just like an imaging targeting catalog (here, using the DR7 data model).


In [17]:
QSO.select_targets(targets, truth)

In [18]:
targets


Out[18]:
<Table length=294>
RELEASEBRICKIDBRICKNAMEOBJIDTYPERADECRA_IVARDEC_IVARDCHISQ [5]FLUX_GFLUX_RFLUX_ZFLUX_W1FLUX_W2FLUX_W3FLUX_W4FLUX_IVAR_GFLUX_IVAR_RFLUX_IVAR_ZFLUX_IVAR_W1FLUX_IVAR_W2FLUX_IVAR_W3FLUX_IVAR_W4MW_TRANSMISSION_GMW_TRANSMISSION_RMW_TRANSMISSION_ZMW_TRANSMISSION_W1MW_TRANSMISSION_W2MW_TRANSMISSION_W3MW_TRANSMISSION_W4NOBS_GNOBS_RNOBS_ZFRACFLUX_GFRACFLUX_RFRACFLUX_ZFRACMASKED_GFRACMASKED_RFRACMASKED_ZFRACIN_GFRACIN_RFRACIN_ZALLMASK_GALLMASK_RALLMASK_ZWISEMASK_W1WISEMASK_W2PSFDEPTH_GPSFDEPTH_RPSFDEPTH_ZGALDEPTH_GGALDEPTH_RGALDEPTH_ZFRACDEVFRACDEV_IVARSHAPEDEV_RSHAPEDEV_R_IVARSHAPEDEV_E1SHAPEDEV_E1_IVARSHAPEDEV_E2SHAPEDEV_E2_IVARSHAPEEXP_RSHAPEEXP_R_IVARSHAPEEXP_E1SHAPEEXP_E1_IVARSHAPEEXP_E2SHAPEEXP_E2_IVARFIBERFLUX_GFIBERFLUX_RFIBERFLUX_ZFIBERTOTFLUX_GFIBERTOTFLUX_RFIBERTOTFLUX_ZREF_CATREF_IDGAIA_PHOT_G_MEAN_MAGGAIA_PHOT_G_MEAN_FLUX_OVER_ERRORGAIA_PHOT_BP_MEAN_MAGGAIA_PHOT_BP_MEAN_FLUX_OVER_ERRORGAIA_PHOT_RP_MEAN_MAGGAIA_PHOT_RP_MEAN_FLUX_OVER_ERRORGAIA_PHOT_BP_RP_EXCESS_FACTORGAIA_ASTROMETRIC_SIGMA5D_MAXGAIA_ASTROMETRIC_PARAMS_SOLVEDGAIA_ASTROMETRIC_EXCESS_NOISEGAIA_DUPLICATED_SOURCEPARALLAXPARALLAX_IVARPMRAPMRA_IVARPMDECPMDEC_IVARMASKBITSEBVPHOTSYSDESI_TARGETBGS_TARGETMWS_TARGET
degdeg1 / deg21 / deg2nanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggiesnanomaggies1/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**21/nanomaggies**2arcsec1 / arcsec2arcsec1 / arcsec2
int16int32bytes8int32bytes4float64float64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16int16int16float32float32float32float32float32float32float32float32float32float32float32float32uint8uint8float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32bytes2int64float32float32float32float32float32float32float32float32int64float32boolfloat32float32float32float32float32float32int16float32bytes1int64int64int64
99993383872048p0120PSF204.830627441406251.2483211755752563100000000.0100000000.00.0 .. 400.01.16559791.19636341.75018175.52927642.64067050.00.01312.0187193.1701546.767050.738866270.293091240.00.00.93245710.9539850.973782540.99600440.99754430.99947580.9998022220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.75000130.814671931.26923850.75000130.814671931.2692385-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.02362411S000
99993383862046p0120PSF204.71549987792971.1373358964920044100000000.0100000000.00.0 .. 400.02.01596831.95835822.61431075.15629535.2586070.00.01312.0187193.1701546.767050.73851880.292957040.00.00.933125140.95444530.974047540.996045230.997569440.999481140.9998042220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.01.29717021.33355751.89590811.29717021.33355751.8959081-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023382172S400
99993383882051p0120PSF205.075576782226561.353391408920288100000000.0100000000.00.0 .. 400.09.1710339.7214114.037930524.07425342.1795960.00.01312.0187193.1701546.767050.739321770.29326710.00.00.930199560.95242850.97288620.995866240.99745930.99945760.999795142220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.05.901086.61986110.1803615.901086.61986110.180361-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024442965S400
99993398262046p0150PSF204.7402343751.561166524887085100000000.0100000000.00.0 .. 400.04.41804463.8839584.67567873.50959047.4546830.00.01312.0187193.1701546.767050.739493850.293333530.00.00.93161150.95340210.973446970.995952670.997512460.9994690.999799432220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.02.84278062.6448083.390822.84278062.6448083.39082-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023930596S000
99993369442041p0100PSF204.067047119140621.0969563722610474100000000.0100000000.00.0 .. 400.06.37647965.8034347.33307177.04343411.6680690.00.01312.0187193.1701546.767050.73787250.29270750.00.00.925521430.94919930.97102460.99557880.99728250.99941980.99978092220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.04.1029313.95188835.31797174.1029313.95188835.3179717-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.026146166S400
99993369462046p0100PSF204.55952453613281.0726839303970337100000000.0100000000.00.0 .. 400.01.09200671.05699031.27667121.96318664.12214470.00.01312.0187193.1701546.767050.73824190.292850140.00.00.93154260.95335460.97341960.99594850.99750990.99946840.999799252220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.70264920.71976480.92584680.70264920.71976480.9258468-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023955569S000
99993369442041p0100PSF204.247863769531251.121935248374939100000000.0100000000.00.0 .. 400.01.39208141.33552661.79785362.8023862.4512110.00.01312.0187193.1701546.767050.73808080.292787940.00.00.92499990.948838950.97081660.99554670.99726270.99941560.99977932220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.895731570.909436051.30381020.895731570.909436051.3038102-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.0263366S000
99993369462046p0100PSF204.62829589843751.0127018690109253100000000.0100000000.00.0 .. 400.01.22459191.29551641.96439724.45937547.11819740.00.01312.0187193.1701546.767050.738170560.29282260.00.00.930289450.95249050.972921970.99587170.99746270.99945830.999795442220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.78796080.88219081.42458830.78796080.88219081.4245883-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024410317S000
99993383872048p0120PSF204.765930175781251.210925817489624100000000.0100000000.00.0 .. 400.01.15645351.12560431.49963333.41661173.877570.00.01312.0187193.1701546.767050.738725840.2930370.00.00.9324940.95401040.97379720.996006670.997545660.99947610.99980212220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.74411730.7664881.08753980.74411730.7664881.0875398-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023610726S000
.........................................................................................................................................................................................................................................................................................................
99993398272048p0150PSF204.75398254394531.6244542598724365100000000.0100000000.00.0 .. 400.08.4768378.8437189.95178752.38645665.318080.00.01312.0187193.1701546.767050.73965190.293394570.00.00.932584350.954072650.9738330.99601220.997549060.99947680.99980242220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.05.45440156.02219067.2170745.45440156.02219067.217074-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023578001S400
99993383872048p0120PSF204.761444091796881.2100533246994019100000000.0100000000.00.0 .. 400.02.85323933.29283523.341884112.51018117.8806150.00.01312.0187193.1701546.767050.738720.293034730.00.00.93249490.954010960.973797560.99600670.99754570.99947610.99980212220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.01.83591022.24227882.4235471.83591022.24227882.423547-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023610417S400
99993398272048p0150PSF204.759170532226561.518020749092102100000000.0100000000.00.0 .. 400.00.804205540.96297381.11413857.852626310.1377870.00.01312.0187193.1701546.767050.739412250.293302030.00.00.93117570.95310170.9732740.9959260.997496070.999465470.99979812220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.51746420.655743660.80797750.51746420.655743660.8079775-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024088643S400
99993398252043p0150PSF204.46943664550781.5930354595184326100000000.0100000000.00.0 .. 400.00.920372371.07003551.04033597.566840612.3382270.00.01312.0187193.1701546.767050.73932160.2932670.00.00.928907930.95153750.972372830.9957870.997410540.999447170.99979122220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.00.59221150.7286480.754455570.59221150.7286480.75445557-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024912357S400
99993398262046p0150PSF204.685073852539061.4230129718780518100000000.0100000000.00.0 .. 400.07.18898967.73316436.810820651.29592566.596190.00.01312.0187193.1701546.767050.739129660.293192920.00.00.92964040.95204280.9726640.99583190.99743820.999453070.999793472220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.04.62573865.26595164.9392334.62573865.26595164.939233-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024646092S400
99993383872048p0120PSF204.889831542968751.1543452739715576100000000.0100000000.00.0 .. 400.01.7379662.16973112.1182397.768984313.1396280.00.01312.0187193.1701546.767050.738708850.293030440.00.00.934103970.95511960.974435570.9961050.99760620.9994890.9998072220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.01.11829021.47749341.5361551.11829021.47749341.536155-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.023027996S400
99993398262046p0150PSF204.696884155273441.4177831411361694100000000.0100000000.00.0 .. 400.077.20161488.74274488.45273539.708816.18930.00.01312.0187193.1701546.767050.73912840.293192450.00.00.931202770.953120350.97328470.99592770.99749710.999465640.99979822220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.049.675260.42998564.14625549.675260.42998564.146255-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024078833S400
99993355062046p0070PSF204.543792724609380.8182441592216492100000000.0100000000.00.0 .. 400.027.26280435.072836.88496223.99428281.276730.00.01312.0187193.1701546.767050.737680850.29263350.00.00.923956930.948118150.970400630.99548240.997223140.99940710.999776072220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.017.54218923.88306426.74911317.54218923.88306426.749113-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.026717706S000
99993383862046p0120PSF204.58634948730471.228458046913147100000000.0100000000.00.0 .. 400.07.6552819.0378499.26846444.6427650.946450.00.01312.0187193.1701546.767050.73860720.29299120.00.00.928744140.95142440.97230770.995776950.99740440.999445860.99979072220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.04.9257736.1543866.72152574.9257736.1543866.7215257-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.02497194S400
99993383872048p0120PSF204.980468751.3565109968185425100000000.0100000000.00.0 .. 400.06.75089456.99914267.01236248.27980460.1619150.00.01312.0187193.1701546.767050.73924350.293236880.00.00.93081720.952854450.97313160.9959040.997482540.999462540.999797052220.00.00.00.00.00.01.01.01.00.00.00.00052.4807477.72680571.870682157.54399513.1825682.51188640.00.00.00.00.00.00.00.00.00.00.00.00.00.04.34384784.76611475.08539154.34384784.76611475.0853915-10.00.00.00.00.00.00.00.000.0False0.01.00.01.00.01.000.024218742S400

And indeed, we can see that only a subset of the QSOs were identified as targets (the rest scattered out of the QSO color selection boxes).


In [19]:
from desitarget.targetmask import desi_mask
isqso = (targets['DESI_TARGET'] & desi_mask.QSO) != 0
print('Identified {} / {} QSO targets.'.format(np.count_nonzero(isqso), len(targets)))


Identified 212 / 294 QSO targets.

Finally, let's plot some example spectra.


In [20]:
plot_subset(wave, flux, truth, objtruth, targname='QSO')


Generating QSO spectra with cosmological Lya skewers proceeds along similar lines.

Here, we also include BALs with 25% probability.


In [21]:
from desitarget.mock.mockmaker import LYAMaker

In [22]:
mockfile='/project/projectdirs/desi/mocks/lya_forest/london/v9.0/v9.0.0/master.fits'

In [23]:
LYA = LYAMaker(seed=seed, balprob=0.25)


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/bal_templates_v3.0.fits
WARNING:templates.py:2366:__init__: Using default SIMQSO model

In [24]:
lyadata = LYA.read(mockfile=mockfile,healpixels=healpixel, nside=nside)


INFO:mockmaker.py:2178:readmock: Reading /project/projectdirs/desi/mocks/lya_forest/london/v9.0/v9.0.0/master.fits
INFO:mockmaker.py:2199:readmock: Assigning healpix pixels with nside = 64
INFO:mockmaker.py:2215:readmock: Trimmed to 170 LYAs in 1 healpixel(s)
INFO:mockmaker.py:2294:readmock: Sampling from LYA Gaussian mixture model.

In [25]:
%time lyaflux, lyawave, lyatargets, lyatruth, lyaobjtruth = LYA.make_spectra(lyadata)


CPU times: user 8.31 s, sys: 492 ms, total: 8.8 s
Wall time: 8.8 s

In [26]:
lyaobjtruth


Out[26]:
<Table length=170>
TARGETIDMABS_1450SLOPES [5]EMLINES [62,3]BAL_TEMPLATEIDDLATRUEZ_NORSD
mag
int64float32float32float32int16boolfloat32
0-22.906696-2.3944457 .. -1.2179691034.3647 .. 320.135-1False2.0183415
1-24.242075-1.5030277 .. -0.9156341033.3444 .. 272.70781191False1.8446927
2-26.16369-1.2548411 .. -1.14267751034.1617 .. 300.59125-1False1.898226
3-23.72464-1.5543343 .. -1.2424361034.6519 .. 341.757-1False2.2047193
4-22.081312-1.1508446 .. -0.9901971033.948 .. 324.45157-1False1.9178948
5-23.29512-1.5320792 .. -0.69532731034.0862 .. 309.977661244False1.897785
6-24.113333-1.4432797 .. -1.0312591033.747 .. 284.6498-1False2.2173119
7-22.56924-1.6487641 .. -1.04219321033.6038 .. 347.671-1False2.2149906
8-22.811445-1.1508201 .. -1.16585081033.5029 .. 275.93246-1False1.977837
.....................
160-24.185734-1.557274 .. -0.47837081034.0641 .. 318.52765-1False2.9441462
161-21.991577-1.4187244 .. -1.12775041034.046 .. 314.7326-1False2.196323
162-24.172369-1.8801084 .. -1.00810711034.6393 .. 312.21511273False3.2347643
163-23.117832-0.92458373 .. -0.968899851034.0422 .. 281.50415-1False2.1256657
164-26.677013-1.313339 .. -1.32692281034.0491 .. 279.05722-1False3.1653585
165-23.608818-1.0223213 .. -1.24696641033.6888 .. 275.84964-1False2.277878
166-23.883997-1.71898 .. -1.0102771033.9664 .. 343.27838-1False3.2356553
167-26.911806-2.003809 .. -0.811448751032.9304 .. 258.21564-1False3.2324107
168-22.896101-1.5177834 .. -0.8501331034.515 .. 239.30566-1False2.9437847
169-22.919933-1.1982878 .. -1.24960081033.6097 .. 311.61578-1False3.485869

In [27]:
plot_subset(lyawave, lyaflux, lyatruth, lyaobjtruth, xlim=(3500, 5500), targname='LYA')



In [28]:
#Now lets generate the same spectra but including the different features and the new continum model.
#For this we need to reload the desitarget module, for some reason it seems not be enough with defining a diferen variable for the LYAMaker
del sys.modules['desitarget.mock.mockmaker']

In [29]:
from desitarget.mock.mockmaker import LYAMaker

In [30]:
LYA = LYAMaker(seed=seed,sqmodel='lya_simqso_model_develop',balprob=0.25)


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/bal_templates_v3.0.fits
WARNING:templates.py:2358:__init__: Using simqso.sqmodel under development defined in desisim.scripts.lya_simqso_model

In [31]:
lyadata_continum = LYA.read(mockfile=mockfile,healpixels=healpixel, nside=nside)


INFO:mockmaker.py:2178:readmock: Reading /project/projectdirs/desi/mocks/lya_forest/london/v9.0/v9.0.0/master.fits
INFO:mockmaker.py:2199:readmock: Assigning healpix pixels with nside = 64
INFO:mockmaker.py:2215:readmock: Trimmed to 170 LYAs in 1 healpixel(s)
INFO:mockmaker.py:2294:readmock: Sampling from LYA Gaussian mixture model.

In [32]:
%time lyaflux_cont, lyawave_cont, lyatargets_cont, lyatruth_cont, lyaobjtruth_cont = LYA.make_spectra(lyadata_continum)


CPU times: user 8.21 s, sys: 359 ms, total: 8.57 s
Wall time: 8.56 s

Lets plot together some of the spectra with the old and new continum model


In [33]:
plt.figure(figsize=(20, 10))
indx=rand.choice(len(lyaflux),9)
for i in range(9):
    plt.subplot(3, 3, i+1)
    plt.plot(lyawave,lyaflux[indx[i]],label="Old Continum")
    plt.plot(lyawave_cont,lyaflux_cont[indx[i]],label="New Continum")
plt.legend()


Out[33]:
<matplotlib.legend.Legend at 0x2aaaea432898>

And finally we compare the colors, for the two runs with the new and old continum


In [34]:
plt.plot(lyatruth["FLUX_W1"],lyatruth_cont["FLUX_W1"]/lyatruth["FLUX_W1"]-1,'.')
plt.xlabel("FLUX_W1")
plt.ylabel(r"FLUX_W1$^{new}$/FLUX_W1-1")


Out[34]:
Text(0,0.5,'FLUX_W1$^{new}$/FLUX_W1-1')

In [35]:
plt.plot(lyatruth["FLUX_W2"],lyatruth_cont["FLUX_W2"]/lyatruth["FLUX_W2"]-1,'.')
plt.xlabel("FLUX_W2")
plt.ylabel(r"(FLUX_W2$^{new}$/FLUX_W2)-1")


Out[35]:
Text(0,0.5,'(FLUX_W2$^{new}$/FLUX_W2)-1')

In [46]:
plt.hist(lyatruth["FLUX_W1"],bins=100,label="Old Continum",alpha=0.7)
plt.hist(lyatruth_cont["FLUX_W1"],bins=100,label="New Continum",histtype='step',linestyle='--')
plt.xlim(0,100)   #Limiting to 100 to see it better.
plt.xlabel("FLUX_W1")
plt.legend()


Out[46]:
<matplotlib.legend.Legend at 0x2aaaea75f320>

In [47]:
plt.hist(lyatruth["FLUX_W2"],bins=100,label="Old Continum",alpha=0.7)
plt.hist(lyatruth_cont["FLUX_W2"],bins=100,label="New Continum",histtype='step',linestyle='--')
plt.xlim(0,100)   #Limiting to 100 to see it better.
plt.xlabel("FLUX_W2")
plt.legend()


Out[47]:
<matplotlib.legend.Legend at 0x2aaaea8819e8>

Conclusion: Colors are slightly affected by changing the continum model.

To Finalize the LYA section, lets generate another set of spectra now including DLAs, metals, LYB, etc.


In [48]:
del sys.modules['desitarget.mock.mockmaker']
from desitarget.mock.mockmaker import LYAMaker  ##Done in order to reload the desitarget, it doesn't seem to be enough with initiating a  diferent variable for the LYAMaker class.

In [49]:
LYA = LYAMaker(seed=seed,sqmodel='lya_simqso_model',balprob=0.25,add_dla=True,add_metals="all",add_lyb=True)
lyadata_all= LYA.read(mockfile=mockfile,healpixels=healpixel, nside=nside)
%time lyaflux_all, lyawave_all, lyatargets_all, lyatruth_all, lyaobjtruth_all = LYA.make_spectra(lyadata_all)


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/bal_templates_v3.0.fits
WARNING:templates.py:2362:__init__: Using modified simqso.sqmodel defined in desisim.scripts.lya_simqso_model
INFO:mockmaker.py:2178:readmock: Reading /project/projectdirs/desi/mocks/lya_forest/london/v9.0/v9.0.0/master.fits
INFO:mockmaker.py:2199:readmock: Assigning healpix pixels with nside = 64
INFO:mockmaker.py:2215:readmock: Trimmed to 170 LYAs in 1 healpixel(s)
INFO:mockmaker.py:2294:readmock: Sampling from LYA Gaussian mixture model.
INFO:lya_spectra.py:114:read_lya_skewers: Added LYB from transmission file
INFO:lya_spectra.py:128:read_lya_skewers: Added F_Metals from transmision file
INFO:lya_spectra.py:162:read_lya_skewers: Read DLAs from transmision file
CPU times: user 7.33 s, sys: 380 ms, total: 7.71 s
Wall time: 7.71 s

In [50]:
plot_subset(lyawave_all, lyaflux_all, lyatruth_all, lyaobjtruth_all, xlim=(3500, 5500), targname='LYA')


Demonstrate the other extragalactic target classes: LRG, ELG, and BGS.

For simplicity let's write a little wrapper script that does all the key steps.


In [51]:
def demo_mockmaker(Maker, seed=None, nrand=16, loc='right'):

    TARGET = Maker(seed=seed)
    
    log.info('Reading the mock catalog for {}s'.format(TARGET.objtype))
    tdata = TARGET.read(healpixels=healpixel, nside=nside)
    
    log.info('Generating {} random spectra.'.format(nrand))
    indx = rand.choice(len(tdata['RA']), np.min( (nrand, len(tdata['RA'])) ) )
    tflux, twave, ttargets, ttruth, tobjtruth = TARGET.make_spectra(tdata, indx=indx)
    
    log.info('Selecting targets')
    TARGET.select_targets(ttargets, ttruth)
    
    plot_subset(twave, tflux, ttruth, tobjtruth, loc=loc, 
                targname=tdata['TARGET_NAME'], objtype=TARGET.objtype)

LRGs


In [52]:
from desitarget.mock.mockmaker import LRGMaker

In [53]:
%time demo_mockmaker(LRGMaker, seed=seed, loc='left')


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/lrg_templates_v2.2.fits
INFO:<ipython-input-51-4a2e37d4263e>:5:demo_mockmaker: Reading the mock catalog for LRGs
INFO:mockmaker.py:231:_get_radec: Reading /global/project/projectdirs/desi/mocks/DarkSky/v1.0.1/lrg_0_inpt.fits
INFO:mockmaker.py:236:_get_radec: Assigning healpix pixels with nside = 64.
INFO:mockmaker.py:1349:readmock: Trimmed to 646 LRGs in 1 healpixel(s)
INFO:mockmaker.py:1389:readmock: Sampling from LRG Gaussian mixture model.
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
WARNING:cuts.py:282:isLRG_colors: Setting zfiberflux to zflux!!!
INFO:<ipython-input-51-4a2e37d4263e>:8:demo_mockmaker: Generating 16 random spectra.
INFO:<ipython-input-51-4a2e37d4263e>:12:demo_mockmaker: Selecting targets
CPU times: user 8.25 s, sys: 759 ms, total: 9.01 s
Wall time: 9.48 s

ELGs


In [54]:
from desitarget.mock.mockmaker import ELGMaker

In [55]:
%time demo_mockmaker(ELGMaker, seed=seed, loc='left')


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/elg_templates_v2.2.fits
INFO:<ipython-input-51-4a2e37d4263e>:5:demo_mockmaker: Reading the mock catalog for ELGs
INFO:mockmaker.py:231:_get_radec: Reading /global/project/projectdirs/desi/mocks/DarkSky/v1.0.1/elg_0_inpt.fits
INFO:mockmaker.py:236:_get_radec: Assigning healpix pixels with nside = 64.
INFO:mockmaker.py:1349:readmock: Trimmed to 3939 ELGs in 1 healpixel(s)
INFO:mockmaker.py:1389:readmock: Sampling from ELG Gaussian mixture model.
INFO:<ipython-input-51-4a2e37d4263e>:8:demo_mockmaker: Generating 16 random spectra.
INFO:<ipython-input-51-4a2e37d4263e>:12:demo_mockmaker: Selecting targets
CPU times: user 21.4 s, sys: 3.39 s, total: 24.8 s
Wall time: 26.1 s

BGS


In [56]:
from desitarget.mock.mockmaker import BGSMaker

In [57]:
%time demo_mockmaker(BGSMaker, seed=seed)


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/bgs_templates_v2.3.fits
INFO:<ipython-input-51-4a2e37d4263e>:5:demo_mockmaker: Reading the mock catalog for BGSs
INFO:mockmaker.py:2415:_read_mockfile: Assigning healpix pixels with nside = 64
INFO:mockmaker.py:2450:readmock: Trimmed to 2338 BGSs in 1 healpixel(s).
INFO:mockmaker.py:2491:readmock: Sampling from BGS Gaussian mixture model.
INFO:<ipython-input-51-4a2e37d4263e>:8:demo_mockmaker: Generating 16 random spectra.
INFO:<ipython-input-51-4a2e37d4263e>:12:demo_mockmaker: Selecting targets
CPU times: user 15.8 s, sys: 1.4 s, total: 17.2 s
Wall time: 18.2 s

Next, demonstrate how to generate spectra of stars...

MWS_MAIN


In [58]:
from desitarget.mock.mockmaker import MWS_MAINMaker

In [59]:
%time demo_mockmaker(MWS_MAINMaker, seed=seed, loc='left')


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/star_templates_v3.1.fits
INFO:<ipython-input-51-4a2e37d4263e>:5:demo_mockmaker: Reading the mock catalog for STARs
WARNING:mockmaker.py:1875:readmock: Galaxia top-level directory /global/project/projectdirs/desi/mocks/mws/galaxia/alpha/v0.0.5/healpix/8 not found!
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<timed eval> in <module>

<ipython-input-51-4a2e37d4263e> in demo_mockmaker(Maker, seed, nrand, loc)
      4 
      5     log.info('Reading the mock catalog for {}s'.format(TARGET.objtype))
----> 6     tdata = TARGET.read(healpixels=healpixel, nside=nside)
      7 
      8     log.info('Generating {} random spectra.'.format(nrand))

~/desi/code/desitarget/py/desitarget/mock/mockmaker.py in read(self, mockfile, mockformat, healpixels, nside, nside_galaxia, target_name, magcut, faintstar_mockfile, faintstar_magcut, **kwargs)
   4440                                    faintstar_mockfile=faintstar_mockfile,
   4441                                    faintstar_magcut=faintstar_magcut,
-> 4442                                    seed=self.seed)
   4443 
   4444         return data

~/desi/code/desitarget/py/desitarget/mock/mockmaker.py in readmock(self, mockfile, healpixels, nside, nside_galaxia, target_name, magcut, faintstar_mockfile, faintstar_magcut, seed)
   1874         if not os.path.isdir(mockfile_nside):
   1875             log.warning('Galaxia top-level directory {} not found!'.format(mockfile_nside))
-> 1876             raise IOError
   1877 
   1878         rand = np.random.RandomState(seed)

OSError: 

MWS_NEARBY


In [60]:
from desitarget.mock.mockmaker import MWS_NEARBYMaker

In [61]:
%time demo_mockmaker(MWS_NEARBYMaker, seed=seed, loc='left')


INFO:<ipython-input-51-4a2e37d4263e>:5:demo_mockmaker: Reading the mock catalog for STARs
INFO:mockmaker.py:231:_get_radec: Reading /global/project/projectdirs/desi/mocks/mws/100pc/v0.0.4/mock_100pc.fits
INFO:mockmaker.py:236:_get_radec: Assigning healpix pixels with nside = 64.
INFO:mockmaker.py:2897:readmock: Trimmed to 7 MWS_NEARBYs in 1 healpixel(s).
INFO:<ipython-input-51-4a2e37d4263e>:8:demo_mockmaker: Generating 16 random spectra.
INFO:<ipython-input-51-4a2e37d4263e>:12:demo_mockmaker: Selecting targets
CPU times: user 3.31 s, sys: 156 ms, total: 3.47 s
Wall time: 3.61 s

White dwarfs (WDs)


In [62]:
from desitarget.mock.mockmaker import WDMaker

In [63]:
%time demo_mockmaker(WDMaker, seed=seed, loc='right')


INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/wd_templates_v2.2.fits
INFO:io.py:956:read_basis_templates: Reading /global/project/projectdirs/desi/spectro/templates/basis_templates/v3.2/wd_templates_v2.2.fits
INFO:<ipython-input-51-4a2e37d4263e>:5:demo_mockmaker: Reading the mock catalog for WDs
INFO:mockmaker.py:231:_get_radec: Reading /global/project/projectdirs/desi/mocks/mws/wd/v0.0.2/mock_wd.fits
INFO:mockmaker.py:236:_get_radec: Assigning healpix pixels with nside = 64.
INFO:mockmaker.py:2738:readmock: Trimmed to 12 WDs in 1 healpixel(s).
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/global/common/software/desi/cori/desiconda/20190804-1.3.0-spec/conda/lib/python3.6/site-packages/fitsio/fitslib.py in _extract_colnum(self, col)
   2629                     mess="column name '%s' not found (case insensitive)" % col
-> 2630                     colnum = self._colnames_lower.index(colstr.lower())
   2631             except ValueError:

ValueError: 'phot_g_mean_mag' is not in list

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<timed eval> in <module>

<ipython-input-51-4a2e37d4263e> in demo_mockmaker(Maker, seed, nrand, loc)
      4 
      5     log.info('Reading the mock catalog for {}s'.format(TARGET.objtype))
----> 6     tdata = TARGET.read(healpixels=healpixel, nside=nside)
      7 
      8     log.info('Generating {} random spectra.'.format(nrand))

~/desi/code/desitarget/py/desitarget/mock/mockmaker.py in read(self, mockfile, mockformat, healpixels, nside, mock_density, **kwargs)
   4908         data = MockReader.readmock(mockfile, target_name=self.objtype,
   4909                                    healpixels=healpixels, nside=nside,
-> 4910                                    mock_density=mock_density)
   4911 
   4912         return data

~/desi/code/desitarget/py/desitarget/mock/mockmaker.py in readmock(self, mockfile, healpixels, nside, target_name, mock_density)
   2748                 'PMRA', 'PMDEC', 'PARALLAX', 'PARALLAX_ERROR',
   2749                 'ASTROMETRIC_EXCESS_NOISE', 'RA']
-> 2750         data = fitsio.read(mockfile, columns=cols, upper=True, ext=1, rows=cut)
   2751 
   2752         zz = (data['RADIALVELOCITY'] / C_LIGHT).astype('f4')

/global/common/software/desi/cori/desiconda/20190804-1.3.0-spec/conda/lib/python3.6/site-packages/fitsio/fitslib.py in read(filename, ext, extver, **keys)
     99         item=_make_item(ext, extver=extver)
    100 
--> 101         data = fits[item].read(**keys)
    102         if header:
    103             h = fits[item].read_header()

/global/common/software/desi/cori/desiconda/20190804-1.3.0-spec/conda/lib/python3.6/site-packages/fitsio/fitslib.py in read(self, **keys)
   1811             if 'columns' in keys:
   1812                 del keys['columns']
-> 1813             data = self.read_columns(columns, **keys)
   1814         elif rows is not None:
   1815             if 'rows' in keys:

/global/common/software/desi/cori/desiconda/20190804-1.3.0-spec/conda/lib/python3.6/site-packages/fitsio/fitslib.py in read_columns(self, columns, **keys)
   1993 
   1994         # if columns is None, returns all.  Guaranteed to be unique and sorted
-> 1995         colnums = self._extract_colnums(columns)
   1996         if isinstance(colnums,int):
   1997             # scalar sent, don't read as a recarray

/global/common/software/desi/cori/desiconda/20190804-1.3.0-spec/conda/lib/python3.6/site-packages/fitsio/fitslib.py in _extract_colnums(self, columns)
   2605         colnums = numpy.zeros(len(columns), dtype='i8')
   2606         for i in xrange(colnums.size):
-> 2607             colnums[i] = self._extract_colnum(columns[i])
   2608 
   2609         # returns unique sorted

/global/common/software/desi/cori/desiconda/20190804-1.3.0-spec/conda/lib/python3.6/site-packages/fitsio/fitslib.py in _extract_colnum(self, col)
   2630                     colnum = self._colnames_lower.index(colstr.lower())
   2631             except ValueError:
-> 2632                 raise ValueError(mess)
   2633         return int(colnum)
   2634 

ValueError: column name 'PHOT_G_MEAN_MAG' not found (case insensitive)

Finally demonstrate how to generate (empyt) SKY spectra.


In [64]:
from desitarget.mock.mockmaker import SKYMaker

In [65]:
SKY = SKYMaker(seed=seed)

In [66]:
skydata = SKY.read(healpixels=healpixel, nside=nside)


INFO:mockmaker.py:231:_get_radec: Reading /global/project/projectdirs/desi/mocks/uniformsky/0.2/uniformsky-2048-0.2.fits
INFO:mockmaker.py:236:_get_radec: Assigning healpix pixels with nside = 64.
INFO:mockmaker.py:1771:readmock: Trimmed to 1024 SKYs in 1 healpixel(s).

In [67]:
skyflux, skywave, skytargets, skytruth, objtruth = SKY.make_spectra(skydata)

In [68]:
SKY.select_targets(skytargets, skytruth)

In [ ]: