DESI Throughput

The attached figure shows an estimate of the throughput derived from the fiber giving the highest throughput (presumably because closest to its target; this is fiber #307) on exposure #29181. Compared to simulations, we are still missing a factor 2.

This is very preliminary. Alternative analyses are more than welcome. The spectra are there: /project/projectdirs/desi/spectro/redux/daily/exposures/20191117/00029181/ (look at b3,r3,z3) And the fiberassign file is here : /project/projectdirs/desi/spectro/data/20191116/00028818/fiberassign-063064.fits (several copies of the same file in different exposures)


In [19]:
import os, pdb
import numpy as np
import fitsio

In [2]:
from astropy.table import Table

In [3]:
import desimodel.io

In [4]:
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(context='talk', style='ticks', font_scale=1.1)
colors = sns.color_palette()
%matplotlib inline

In [5]:
allnight = '20200102'
outdir = os.path.join(os.getenv('DESI_ROOT'), 'ioannis', 'throughput')

In [205]:
datadir = os.path.join(os.getenv('DESI_ROOT'), 'spectro', 'data')
reduxdir = os.path.join(os.getenv('DESI_ROOT'), 'spectro', 'redux', 'daily', 'exposures')

In [7]:
fiberfile = os.path.join(datadir, '20200102', '00037738', 'fiberassign-063511.fits')
#Table(fitsio.read(fiberfile))

In [198]:
import json
requestsfile = '/Users/ioannis/work/desi/spectro/data/20200102/00037742/request-00037742.json'
with open(requestsfile) as ff:
    jj = json.load(ff)
print(jj.keys())
print(jj['PASSTHRU'])
int(jj['PASSTHRU'].split(':')[3].split(',')[0])


dict_keys(['SEQUENCE', 'FLAVOR', 'OBSTYPE', 'CORRECT_FOR_ADC', 'USETEMP', 'USELUT', 'EXPTIME', 'PASSTHRU', 'PROGRAM', 'DELTARA', 'DELTADEC', 'TRACK', 'OFFSET_TYPE', 'INVALID', 'EXCLUDED', 'REQUIRED', 'EPOCH', 'GUIDER_MODE', 'WAIT', 'COUNT', 'MANIFEST', 'OBJECT', 'PM_STEP', 'SIMULATEMOVES', 'LEAD', 'PROPID', 'OBSERVER', 'DISPLAY', 'SEQNUM', 'ID', 'UID'])
{ OFFSTRA:1, OFFSTDEC:1, TILEID:63511, TILERA:122, TILEDEC:39.5 }
Out[198]:
63511

In [8]:
desimodel.io.load_focalplane()[0]


Out[8]:
<Table length=5430>
PETALDEVICELOCATIONPETAL_IDDEVICE_IDDEVICE_TYPESLITBLOCKBLOCKFIBERCABLECONDUITFIBERFWHMFRDABSOFFSET_XOFFSET_YOFFSET_TOFFSET_PLENGTH_R1LENGTH_R2MAX_TMIN_TMAX_PMIN_P
mmmmdegreesdegreesmmmmdegreesdegreesdegreesdegrees
int32int32int32int32str6str3int32int32int32str2int32float64float64float64float64float64float64float64float64float64float64float64float64float64
7070002M03139POS18200A039702.1390.95102.25-25.8185154604460612.328919779295408-12.798896202115827-7.3329980434807143.04995124083610673.0906526593725245196.29145210382842-196.29145210382842185.0-6.510237122851066
7170012M03621POS1840A039541.4893.0199.23-34.2459880441451118.45182341820423561.966170695770344-3.62524902922430672.89737883089779523.10304676910012197.48776528205983-197.48776528205983185.0-3.7366336014804347
7270022M03500POS18210A039711.4693.08100.44-35.353363765726038.067607832475183153.95265866761594-9.2982528537484092.98911091276056953.0094555955645257196.09305773538108-196.09305773538108185.0-9.904784808313366
7370032M03730POS18130A039631.8192.0101.8-42.6733720025282924.574660194916063-24.713956513725556.79608585259572352.92262277138225953.1353688539582794196.25296894295718-196.25296894295718185.0-3.200058547407167
7470042M03430POS18170A039671.9491.5999.71-43.7821464143515614.188635165735029254.14859696481045-5.9428134752566853.04129553033278873.074251001486179196.97921998660289-196.97921998660289185.0-2.108507464073625
7570052M02702POS1900A039752.390.3898.4-51.10067373182156630.69742981228919309.08985695604093-5.2697750146909643.03169711716696273.1440202897681977196.32101187186942-196.32101187186942185.0-3.9369307553631074
7670062M02813POS19230A039981.9791.4997.91-52.20986780488862420.31094455877104280.4442706858896-5.9594873400281192.99772191038834153.105887840846827195.01387036492014-195.01387036492014185.0-7.822787584932598
7770072M03426POS18220A039722.191.0799.56-53.33730307136269.895378215863193323.59993756026404-2.27342987571199732.9877179703622633.075180781273822195.45337276363483-195.45337276363483185.0-5.811631484441932
7870082M03567POS19120A039872.0291.3198.35-59.5269885297935236.8194737296092996.68133174545841-6.0814961393510323.01616010607466433.068778634595168196.52388512919305-196.52388512919305185.0-6.711182559036899
........................................................................
6533653311NONEOPT-1-1-1NA-10.00.00.0-274.69548309170284303.0000967441942108.00.00.00.00.00.00.00.0
6534653411NONEFIF-1-1-1NA-10.00.00.0-281.66326747466223295.2340116999037108.00.00.00.00.00.00.00.0
6535653511NONENON-1-1-1NA-10.00.00.0-288.6363428456453287.4734215917123108.00.00.00.00.00.00.00.0
6536653611NONENON-1-1-1NA-10.00.00.0-295.6314492612104279.7330237985845108.00.00.00.00.00.00.00.0
6537653711NONENON-1-1-1NA-10.00.00.0-302.635372754202271.99861447526564108.00.00.00.00.00.00.00.0
6538653811NONENON-1-1-1NA-10.00.00.0-309.65155212377755264.2799778485191108.00.00.00.00.00.00.00.0
6539653911NONENON-1-1-1NA-10.00.00.0-316.6678254335998256.5554235617426108.00.00.00.00.00.00.00.0
6540654011NONENON-1-1-1NA-10.00.00.0-323.70233078561887248.80362061998403108.00.00.00.00.00.00.00.0
6541654111NONEGIF-1-1-1NA-10.00.00.0-288.6338385655965216.99658663345753108.00.00.00.00.00.00.00.0
6542654211NONEGIF-1-1-1NA-10.00.00.0-303.14911967490735277.108328133109108.00.00.00.00.00.00.00.0

In [260]:
def read_and_stack_nightwatch(allnight, verbose=False, overwrite=False):
    """Read and stack all the nightwatch QA files for a given (input) set of nights.
    
    """
    from glob import glob
    import astropy.table
    
    nightmin, nightmax = np.min(int(allnight)), np.max(int(allnight))
    stackwatchfile = os.path.join(outdir, 'qa-nightwatch-{}-{}.fits'.format(str(nightmin), str(nightmax)))
    if os.path.isfile(stackwatchfile) and not overwrite:
        print('Reading {}'.format(stackwatchfile))
        allqa = Table(fitsio.read(stackwatchfile))
    else:
        print('Reading the focal plane model.')
        fp = desimodel.io.load_focalplane()[0]
        fp = fp['PETAL', 'FIBER', 'OFFSET_X', 'OFFSET_Y']
        
        nightwatchdir = os.path.join(os.getenv('DESI_ROOT'), 'spectro', 'nightwatch', 'kpno')
        for night in np.atleast_1d(allnight):
            nightdir = os.path.join(nightwatchdir, night)
            allexpiddir = glob(os.path.join(nightdir, '????????'))
            
            # Need to assign fiberassign files algorithmically...
            #tilefile = os.path.join(datadir, night, os.path.basename(exp)
            #                         '00037738', 'fiberassign-063511.fits')
            #tile = Table(fitsio.read(fiberfile))

            allqa = []
            for expiddir in allexpiddir:
                expid = os.path.basename(expiddir)
                qafile = os.path.join(expiddir, 'qa-{}.fits'.format(expid))
                
                # Hack!
                requestfile = os.path.join(datadir, night, 'request-{}.fits'.format(expid))
                tileid = int(jj['PASSTHRU'].split(':')[3].split(',')[0])
                tilefile = glob(os.path.join(datadir, night, '????????', 'fiberassign-{:06d}.fits'.format(tileid)))[0]
                #print(fitsio.FITS(tilefile)['FIBERASSIGN'])
                if verbose:
                    print('Reading {}'.format(tilefile))
                tile = Table(fitsio.FITS(tilefile)['FIBERASSIGN'].read())
                
                if verbose:
                    print('Reading {}'.format(qafile))
                qa = Table(fitsio.read(qafile, 'PER_CAMFIBER'))
                
                # Add the fiberassign info - hack!
                qa = astropy.table.join(qa, tile, keys='FIBER')

                allqa.append(qa)
            allqa = astropy.table.vstack(allqa)

            # Need to update the data model to 'f4'.
            if False:
                print('Updating the data model.')
                for col in allqa.colnames:
                    if allqa[col].dtype == '>f8':
                        allqa[col] = allqa[col].astype('f4')
                    
            # Add the x/y offsets from the focal plane model
            allqa = astropy.table.join(allqa, fp, keys='FIBER')
                    
        print('Writing {}'.format(stackwatchfile))
        fitsio.write(stackwatchfile, allqa.as_array(), clobber=True)
            
    return allqa

In [261]:
allqa = read_and_stack_nightwatch(allnight, verbose=True, overwrite=True)
allqa


Reading the focal plane model.
Reading /Users/ioannis/work/desi/spectro/data/20200102/00037738/fiberassign-063511.fits
Reading /Users/ioannis/work/desi/spectro/nightwatch/kpno/20200102/00037742/qa-00037742.fits
Writing /Users/ioannis/work/desi/ioannis/throughput/qa-nightwatch-20200102-20200102.fits
Out[261]:
<Table length=12000>
NIGHTEXPIDSPECTROCAMFIBERINTEG_RAW_FLUXMEDIAN_RAW_FLUXMEDIAN_RAW_SNRINTEG_CALIB_FLUXMEDIAN_CALIB_FLUXMEDIAN_CALIB_SNRTARGETIDPETAL_LOCDEVICE_LOCLOCATIONFIBERSTATUSTARGET_RATARGET_DECPMRAPMDECPMRA_IVARPMDEC_IVARREF_EPOCHLAMBDA_REFFA_TARGETFA_TYPEOBJTYPEFIBERASSIGN_XFIBERASSIGN_YNUMTARGETPRIORITYSUBPRIORITYOBSCONDITIONSNUMOBS_MORERELEASEBRICKIDBRICKNAMEBRICK_OBJIDMORPHTYPETARGET_RA_IVARTARGET_DEC_IVAREBVFLUX_GFLUX_RFLUX_ZFLUX_IVAR_GFLUX_IVAR_RFLUX_IVAR_ZMW_TRANSMISSION_GMW_TRANSMISSION_RMW_TRANSMISSION_ZFRACFLUX_GFRACFLUX_RFRACFLUX_ZFRACMASKED_GFRACMASKED_RFRACMASKED_ZFRACIN_GFRACIN_RFRACIN_ZNOBS_GNOBS_RNOBS_ZPSFDEPTH_GPSFDEPTH_RPSFDEPTH_ZGALDEPTH_GGALDEPTH_RGALDEPTH_ZFLUX_W1FLUX_W2FLUX_W3FLUX_W4FLUX_IVAR_W1FLUX_IVAR_W2FLUX_IVAR_W3FLUX_IVAR_W4MW_TRANSMISSION_W1MW_TRANSMISSION_W2MW_TRANSMISSION_W3MW_TRANSMISSION_W4ALLMASK_GALLMASK_RALLMASK_ZFRACDEVFRACDEV_IVARSHAPEDEV_RSHAPEDEV_E1SHAPEDEV_E2SHAPEDEV_R_IVARSHAPEDEV_E1_IVARSHAPEDEV_E2_IVARSHAPEEXP_RSHAPEEXP_E1SHAPEEXP_E2SHAPEEXP_R_IVARSHAPEEXP_E1_IVARSHAPEEXP_E2_IVARFIBERFLUX_GFIBERFLUX_RFIBERFLUX_ZFIBERTOTFLUX_GFIBERTOTFLUX_RFIBERTOTFLUX_ZWISEMASK_W1WISEMASK_W2MASKBITSREF_IDREF_CATGAIA_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_EXCESS_NOISEGAIA_DUPLICATED_SOURCEGAIA_ASTROMETRIC_SIGMA5D_MAXGAIA_ASTROMETRIC_PARAMS_SOLVEDPARALLAXPARALLAX_IVARPHOTSYSCMX_TARGETPRIORITY_INITNUMOBS_INITHPXPIXELBLOBDISTFIBERFLUX_IVAR_GFIBERFLUX_IVAR_RFIBERFLUX_IVAR_ZDESI_TARGETBGS_TARGETMWS_TARGETPETALOFFSET_XOFFSET_Y
mmmm
int64int64int64str1int64float64float64float64float64float64float64int64int16int32int32int32float64float64float32float32float32float32float32float32int64uint8str3float32float32int16int32float64int32int32int16int32str8int32str4float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16int16int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16int16int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32uint8uint8int16int64str2float32float32float32float32float32float32float32float32boolfloat32boolfloat32float32str1int64int64int64int64float32float32float32float32int64int64int64int32float64float64
20200102377420Z0391828.3864471774456.026401519775394.714122394036555-5361.510412569263-5.775402545928955-0.4425851439309107561165176856405714903113110121.5861105967704838.354585325635010.00.00.00.00.05400.042949672964SKY81.47378-284.72614000.934260681484314463080015355181214p38210850.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.0-0.030039852-0.007944582-0.1169948950.00.00.000000.00.00.00.00.00.00.00.0False0.0False0.00.000-1645813.08140.62352272.019254.82726429496729600083.21897551257103-286.66372294035915
20200102377420R088728.219164253936.721496582031253.0719017985521577-2497.8392680841266-1.2976044416427612-0.1080678413422251961165176856405714903113110121.5861105967704838.354585325635010.00.00.00.00.05400.042949672964SKY81.47378-284.72614000.934260681484314463080015355181214p38210850.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.0-0.030039852-0.007944582-0.1169948950.00.00.000000.00.00.00.00.00.00.00.0False0.0False0.00.000-1645813.08140.62352272.019254.82726429496729600083.21897551257103-286.66372294035915
20200102377420B026085.0261837123613.2217569351196290.94154438580768021525.01275790387560.6321676373481750.0391110949952193861165176856405714903113110121.5861105967704838.354585325635010.00.00.00.00.05400.042949672964SKY81.47378-284.72614000.934260681484314463080015355181214p38210850.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.0-0.030039852-0.007944582-0.1169948950.00.00.000000.00.00.00.00.00.00.00.0False0.0False0.00.000-1645813.08140.62352272.019254.82726429496729600083.21897551257103-286.66372294035915
20200102377420B135046.71602267463517.8983678817749021.26496733354113879524.3941701322074.8202989101409910.30648257189277693519102101697367202722720121.7171729258662538.39572497385273-0.5779923-0.431732251.700798149.445652015.55400.05451TGT55.6956-273.963560600.16849440918919534655351980015366521218p385360PSF2933461600000000.05864034000000000.00.04934796173.91609244.02437257.848149.20730610.52934314.6265660.864088540.906284750.9464460.000155187330.000459379370.00059792468.032038e-070.48728470.29135091.00000150.99999780.99999756443970.334118.0950478.38449664.780690.7885438.4008560.9437835.128334-20.055567371.57122.05056760.41322560.00090115791.2386049e-050.991671860.994877160.998905240.999586460000.00.00.00.00.00.00.00.00.00.00.00.00.00.0135.41406190.00157200.76497135.41408190.00159200.765030024908909813928685312G216.6120031332.805816.878317175.0316.163536149.917161.21758440.0False0.13458464True0.1705923101.60748N54560164580.00.00.00.0000059.10957630308695-273.27394550682914
20200102377420Z1542282.7675879552121.679847717285168.498503318980475114273.0379326587450.451999664306643.3357974248144263519102101697367202722720121.7171729258662538.39572497385273-0.5779923-0.431732251.700798149.445652015.55400.05451TGT55.6956-273.963560600.16849440918919534655351980015366521218p385360PSF2933461600000000.05864034000000000.00.04934796173.91609244.02437257.848149.20730610.52934314.6265660.864088540.906284750.9464460.000155187330.000459379370.00059792468.032038e-070.48728470.29135091.00000150.99999780.99999756443970.334118.0950478.38449664.780690.7885438.4008560.9437835.128334-20.055567371.57122.05056760.41322560.00090115791.2386049e-050.991671860.994877160.998905240.999586460000.00.00.00.00.00.00.00.00.00.00.00.00.00.0135.41406190.00157200.76497135.41408190.00159200.765030024908909813928685312G216.6120031332.805816.878317175.0316.163536149.917161.21758440.0False0.13458464True0.1705923101.60748N54560164580.00.00.00.0000059.10957630308695-273.27394550682914
20200102377420R1132565.5998808216560.318319320678714.67667320767465532832.1213644678217.595225334167481.44889037800342953519102101697367202722720121.7171729258662538.39572497385273-0.5779923-0.431732251.700798149.445652015.55400.05451TGT55.6956-273.963560600.16849440918919534655351980015366521218p385360PSF2933461600000000.05864034000000000.00.04934796173.91609244.02437257.848149.20730610.52934314.6265660.864088540.906284750.9464460.000155187330.000459379370.00059792468.032038e-070.48728470.29135091.00000150.99999780.99999756443970.334118.0950478.38449664.780690.7885438.4008560.9437835.128334-20.055567371.57122.05056760.41322560.00090115791.2386049e-050.991671860.994877160.998905240.999586460000.00.00.00.00.00.00.00.00.00.00.00.00.00.0135.41406190.00157200.76497135.41408190.00159200.765030024908909813928685312G216.6120031332.805816.878317175.0316.163536149.917161.21758440.0False0.13458464True0.1705923101.60748N54560164580.00.00.00.0000059.10957630308695-273.27394550682914
20200102377420Z2411302.4190068652459.9613952636718754.999607258209256-6173.1092611931135-5.087680816650391-0.38290405022174913519102101697398902522520121.8261085306784438.41140623252497-0.23474923-2.3085866.16631315.0190642015.55400.05451TGT34.44208-269.88140540.9265374706782393655351980015366521218p385677PSF320729670000000.0559962570000000.00.04865395717.1776441.5260362.55488203.8171140.8548653.898230.86586560.90753980.94717890.00.00.00.00276477820.438408850.0133927320.999455870.99973290.998991333738.1529101.7128898.25073486.6472872.30389453.37515323.77772912.2364193.7876365553.86562.02152180.41709510.000862693361.1026802e-050.99178850.994949040.99892060.99959230000.00.00.00.00.00.00.00.00.00.00.00.00.00.013.37839832.34156448.71938313.37839832.34156448.719383000908899776589315072G218.602545387.9693319.0510626.15240917.86603442.572561.32457750.0False0.38792026True0.228862210.656103N54554164580.00.00.00.0000031.75186728761004-269.8043577836922
20200102377420R293285.069727499338.66063308715823.2076033407922155-1596.3107361797045-0.7938481569290161-0.066607518342780683519102101697398902522520121.8261085306784438.41140623252497-0.23474923-2.3085866.16631315.0190642015.55400.05451TGT34.44208-269.88140540.9265374706782393655351980015366521218p385677PSF320729670000000.0559962570000000.00.04865395717.1776441.5260362.55488203.8171140.8548653.898230.86586560.90753980.94717890.00.00.00.00276477820.438408850.0133927320.999455870.99973290.998991333738.1529101.7128898.25073486.6472872.30389453.37515323.77772912.2364193.7876365553.86562.02152180.41709510.000862693361.1026802e-050.99178850.994949040.99892060.99959230000.00.00.00.00.00.00.00.00.00.00.00.00.00.013.37839832.34156448.71938313.37839832.34156448.719383000908899776589315072G218.602545387.9693319.0510626.15240917.86603442.572561.32457750.0False0.38792026True0.228862210.656103N54554164580.00.00.00.0000031.75186728761004-269.8043577836922
20200102377420B227922.93298799194614.4078435897827151.0140578342578322559.92614124972171.4057654142379760.087730086264409733519102101697398902522520121.8261085306784438.41140623252497-0.23474923-2.3085866.16631315.0190642015.55400.05451TGT34.44208-269.88140540.9265374706782393655351980015366521218p385677PSF320729670000000.0559962570000000.00.04865395717.1776441.5260362.55488203.8171140.8548653.898230.86586560.90753980.94717890.00.00.00.00276477820.438408850.0133927320.999455870.99973290.998991333738.1529101.7128898.25073486.6472872.30389453.37515323.77772912.2364193.7876365553.86562.02152180.41709510.000862693361.1026802e-050.99178850.994949040.99892060.99959230000.00.00.00.00.00.00.00.00.00.00.00.00.00.013.37839832.34156448.71938313.37839832.34156448.719383000908899776589315072G218.602545387.9693319.0510626.15240917.86603442.572561.32457750.0False0.38792026True0.228862210.656103N54554164580.00.00.00.0000031.75186728761004-269.8043577836922
...........................................................................................................................................................................................................................................................................................................................................................................................................................
20200102377429B499631630.5246802337615.2775516510009771.26410733557476072011.88889021828030.66817349195480350.05095957537964982611651773328785950925692560122.4940411483065838.4846802681387250.00.00.00.00.05400.042949672964SKY-95.278435-251.6835000.966729190538015163080015366541224p3855420.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00000.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00138135820.0226523990.0676776250.00.00.000000.00.00.00.00.00.00.00.0False0.0False0.00.000-1645629.63421610623.7672964.6320.17254294967296009-94.84918901585382-253.99419533106322
20200102377429R499787365.0626979828836.654026031494143.19947029841811453866.39190268047241.73770296573638920.1471418571495603235191025760731922920192010122.7088321122329738.672250469551145-5.537341-3.3909776521.89496975.07032015.55400.0321TGT-136.27711-204.350520680.17803456395672945655351980015377831226p387786PSF2.6612124e+163.9439375e+160.04475706956.212461324.07481676.05270.0607458650.00644986150.074600160.87591170.91461930.95130485.060286e-061.6734075e-058.790108e-050.966288860.99126760.927637340.99999921.00000130.99999983330.00.00.00.00.00.0447.91367244.96924115.45208-375.76742.5959380.52646960.00099647141.29265745e-050.99244370.99535270.999007050.999624972220.00.00.00.00.00.00.00.00.00.00.00.00.00.0744.101751030.36341304.2642744.101751030.36341304.2642002300908826972599319040G214.5861312986.526114.911454650.4081414.104276868.88281.2073430.0False0.04916116True0.6198921258.9479N3268164570.00.00.00.00009-136.1389175359281-205.8594370064533
20200102377429Z4997440600.9313788523457.4192676544189455.086579033132189-4622.248246301126-6.965609550476074-0.607379736427952835191025760731922920192010122.7088321122329738.672250469551145-5.537341-3.3909776521.89496975.07032015.55400.0321TGT-136.27711-204.350520680.17803456395672945655351980015377831226p387786PSF2.6612124e+163.9439375e+160.04475706956.212461324.07481676.05270.0607458650.00644986150.074600160.87591170.91461930.95130485.060286e-061.6734075e-058.790108e-050.966288860.99126760.927637340.99999921.00000130.99999983330.00.00.00.00.00.0447.91367244.96924115.45208-375.76742.5959380.52646960.00099647141.29265745e-050.99244370.99535270.999007050.999624972220.00.00.00.00.00.00.00.00.00.00.00.00.00.0744.101751030.36341304.2642744.101751030.36341304.2642002300908826972599319040G214.5861312986.526114.911454650.4081414.104276868.88281.2073430.0False0.04916116True0.6198921258.9479N3268164570.00.00.00.00009-136.1389175359281-205.8594370064533
20200102377429B499733530.9184836688417.155011177062991.41033960135711462380.3160271507261.31140834093093870.1122817650427585535191025760731922920192010122.7088321122329738.672250469551145-5.537341-3.3909776521.89496975.07032015.55400.0321TGT-136.27711-204.350520680.17803456395672945655351980015377831226p387786PSF2.6612124e+163.9439375e+160.04475706956.212461324.07481676.05270.0607458650.00644986150.074600160.87591170.91461930.95130485.060286e-061.6734075e-058.790108e-050.966288860.99126760.927637340.99999921.00000130.99999983330.00.00.00.00.00.0447.91367244.96924115.45208-375.76742.5959380.52646960.00099647141.29265745e-050.99244370.99535270.999007050.999624972220.00.00.00.00.00.00.00.00.00.00.00.00.00.0744.101751030.36341304.2642744.101751030.36341304.2642002300908826972599319040G214.5861312986.526114.911454650.4081414.104276868.88281.2073430.0False0.04916116True0.6198921258.9479N3268164570.00.00.00.00009-136.1389175359281-205.8594370064533
20200102377429R499889682.7369843692937.933385848999023.30044635122258974243.60355001210251.8191533684730530.1535700076444251335191021029559518923492340122.6950224744662838.5730742935746351.0588794-7.6429410.04738417.3134022015.55400.05451TGT-134.10658-229.499910550.7009371009529836655351980015366551228p3853294PSF456364870000000.0561231060000000.00.0436604714.691545548.769115101.95871207.1512654.20843545.803340.87875960.91662150.952469051.9609124e-061.2156763e-063.2892287e-060.00170857020.099794450.0075983550.99984610.99983290.9992528333538.4712231.8346121.838104402.85947144.2132676.32780554.46859731.751041100.4827152.075942.4895780.50232770.00099308591.2972958e-050.992628160.99546630.999031360.999634150000.00.00.00.00.00.00.00.00.00.00.00.00.00.011.41086337.8787779.190911.41086337.8787779.1909000908819443520495872G218.369087486.7573519.23583245.34946417.47649498.887681.29929950.0False0.30125436True0.148490521.33051N54555164570.00.00.00.00009-133.9693737890163-226.5787893784174
20200102377429Z4998451549.2060246495557.09411621093755.071195803303129-4956.186230569942-7.49458646774292-0.672446950978680635191021029559518923492340122.6950224744662838.5730742935746351.0588794-7.6429410.04738417.3134022015.55400.05451TGT-134.10658-229.499910550.7009371009529836655351980015366551228p3853294PSF456364870000000.0561231060000000.00.0436604714.691545548.769115101.95871207.1512654.20843545.803340.87875960.91662150.952469051.9609124e-061.2156763e-063.2892287e-060.00170857020.099794450.0075983550.99984610.99983290.9992528333538.4712231.8346121.838104402.85947144.2132676.32780554.46859731.751041100.4827152.075942.4895780.50232770.00099308591.2972958e-050.992628160.99546630.999031360.999634150000.00.00.00.00.00.00.00.00.00.00.00.00.00.011.41086337.8787779.190911.41086337.8787779.1909000908819443520495872G218.369087486.7573519.23583245.34946417.47649498.887681.29929950.0False0.30125436True0.148490521.33051N54555164570.00.00.00.00009-133.9693737890163-226.5787893784174
20200102377429B499834261.6204533112817.3884868621826171.41840683293350532480.2718397604691.10653996467590330.0959529474136051235191021029559518923492340122.6950224744662838.5730742935746351.0588794-7.6429410.04738417.3134022015.55400.05451TGT-134.10658-229.499910550.7009371009529836655351980015366551228p3853294PSF456364870000000.0561231060000000.00.0436604714.691545548.769115101.95871207.1512654.20843545.803340.87875960.91662150.952469051.9609124e-061.2156763e-063.2892287e-060.00170857020.099794450.0075983550.99984610.99983290.9992528333538.4712231.8346121.838104402.85947144.2132676.32780554.46859731.751041100.4827152.075942.4895780.50232770.00099308591.2972958e-050.992628160.99546630.999031360.999634150000.00.00.00.00.00.00.00.00.00.00.00.00.00.011.41086337.8787779.190911.41086337.8787779.1909000908819443520495872G218.369087486.7573519.23583245.34946417.47649498.887681.29929950.0False0.30125436True0.148490521.33051N54555164570.00.00.00.00009-133.9693737890163-226.5787893784174
20200102377429Z4999435894.3245725814555.2471275329589844.957725611698963-827.2139022723658-6.111640453338623-0.54493457621789735191025764926240921492140122.8530744615651738.6732228247294-1.3922821-9.509771351.42413596.41892015.55400.0331TGT-164.47572-204.396380660.27663722920538514655351980015377841229p387800PSF1.8567927e+162.4659774e+160.04179378544.29736846.4139907.27835.31114051.62240120.205391750.88362890.92003980.9544542-1.3066556e-102.596168e-097.594065e-090.47296520.557374360.90043560.999999760.9999970.9999998223182.5951154.6319050.0147.5737843.355210.0253.15396135.0026157.007866526.032042.42520360.48981940.00086265311.11049685e-050.99294220.99565970.999072730.999649760020.00.00.00.00.00.00.00.00.00.00.00.00.00.0423.07584657.9074705.21655423.07584657.9074705.21655002204908826216685068544G215.2938672312.966315.640473656.969214.786645718.54841.21249210.0False0.057392165True0.69519705789.4053N3366164570.00.00.00.00009-163.62647911990257-203.44238681708185
20200102377429B499934651.796520153917.7100553512573241.46865697884132285173.8738623708692.75036525726318360.2206065727384144435191025764926240921492140122.8530744615651738.6732228247294-1.3922821-9.509771351.42413596.41892015.55400.0331TGT-164.47572-204.396380660.27663722920538514655351980015377841229p387800PSF1.8567927e+162.4659774e+160.04179378544.29736846.4139907.27835.31114051.62240120.205391750.88362890.92003980.9544542-1.3066556e-102.596168e-097.594065e-090.47296520.557374360.90043560.999999760.9999970.9999998223182.5951154.6319050.0147.5737843.355210.0253.15396135.0026157.007866526.032042.42520360.48981940.00086265311.11049685e-050.99294220.99565970.999072730.999649760020.00.00.00.00.00.00.00.00.00.00.00.00.00.0423.07584657.9074705.21655423.07584657.9074705.21655002204908826216685068544G215.2938672312.966315.640473656.969214.786645718.54841.21249210.0False0.057392165True0.69519705789.4053N3366164570.00.00.00.00009-163.62647911990257-203.44238681708185
20200102377429R499985398.2009385240536.2112998962402343.16591817235681465263.4834554533232.5697138309478760.2025858142324408835191025764926240921492140122.8530744615651738.6732228247294-1.3922821-9.509771351.42413596.41892015.55400.0331TGT-164.47572-204.396380660.27663722920538514655351980015377841229p387800PSF1.8567927e+162.4659774e+160.04179378544.29736846.4139907.27835.31114051.62240120.205391750.88362890.92003980.9544542-1.3066556e-102.596168e-097.594065e-090.47296520.557374360.90043560.999999760.9999970.9999998223182.5951154.6319050.0147.5737843.355210.0253.15396135.0026157.007866526.032042.42520360.48981940.00086265311.11049685e-050.99294220.99565970.999072730.999649760020.00.00.00.00.00.00.00.00.00.00.00.00.00.0423.07584657.9074705.21655423.07584657.9074705.21655002204908826216685068544G215.2938672312.966315.640473656.969214.786645718.54841.21249210.0False0.057392165True0.69519705789.4053N3366164570.00.00.00.00009-163.62647911990257-203.44238681708185

Find fibers with high S/N spectra.


In [262]:
def select_spectra_snr(data, thiscam='Z', snrcut=10, qaplot=False):
    """Select spectra based on S/N."""
    
    #wcam = np.where(data['CAM'] == thiscam)[0]
    #wgood = np.where((data['MEDIAN_CALIB_SNR'] > snrcut) * (data['CAM'] == thiscam))[0]
    wsnr = np.where((data['MEDIAN_CALIB_SNR'] > snrcut))[0]
    
    isnr = np.where(np.isin(data['FIBER'], data['FIBER'][wsnr]))[0]
    print('Found {} high S/N spectra in {}/{} unique fibers.'.format(
        len(isnr), len(set(data['FIBER'][isnr])), len(set(data['FIBER']))))
    
    #for fib in set(star['FIBER']):
    #    if np.sum(star['FIBER'] == fib) != 3:
    #        print('Problem with fiber {}'.format(fib))    

    if qaplot:
        col = iter(colors)
        fig, ax = plt.subplots(figsize=(7, 7))
        ax.plot(data['OFFSET_X'], data['OFFSET_Y'], 'k.',
                ms=1, alpha=0.5, label='')
        for petal in sorted(set(data['PETAL'][isnr])):
            ii = data['PETAL'][isnr] == petal
            ax.scatter(data['OFFSET_X'][isnr][ii], data['OFFSET_Y'][isnr][ii], 
                       marker='o', s=20, color=next(col), label='Petal {}'.format(petal))
        ax.legend(frameon=True, fontsize=12, ncol=1)
        ax.axis('off')
    
    return data[isnr]

In [263]:
star = select_spectra_snr(allqa, snrcut=10, qaplot=True)
star
#star[star['FIBER'] == 3525]
#star[star['FIBER'] == 7]


Found 222 high S/N spectra in 74/4000 unique fibers.
Out[263]:
<Table length=222>
NIGHTEXPIDSPECTROCAMFIBERINTEG_RAW_FLUXMEDIAN_RAW_FLUXMEDIAN_RAW_SNRINTEG_CALIB_FLUXMEDIAN_CALIB_FLUXMEDIAN_CALIB_SNRTARGETIDPETAL_LOCDEVICE_LOCLOCATIONFIBERSTATUSTARGET_RATARGET_DECPMRAPMDECPMRA_IVARPMDEC_IVARREF_EPOCHLAMBDA_REFFA_TARGETFA_TYPEOBJTYPEFIBERASSIGN_XFIBERASSIGN_YNUMTARGETPRIORITYSUBPRIORITYOBSCONDITIONSNUMOBS_MORERELEASEBRICKIDBRICKNAMEBRICK_OBJIDMORPHTYPETARGET_RA_IVARTARGET_DEC_IVAREBVFLUX_GFLUX_RFLUX_ZFLUX_IVAR_GFLUX_IVAR_RFLUX_IVAR_ZMW_TRANSMISSION_GMW_TRANSMISSION_RMW_TRANSMISSION_ZFRACFLUX_GFRACFLUX_RFRACFLUX_ZFRACMASKED_GFRACMASKED_RFRACMASKED_ZFRACIN_GFRACIN_RFRACIN_ZNOBS_GNOBS_RNOBS_ZPSFDEPTH_GPSFDEPTH_RPSFDEPTH_ZGALDEPTH_GGALDEPTH_RGALDEPTH_ZFLUX_W1FLUX_W2FLUX_W3FLUX_W4FLUX_IVAR_W1FLUX_IVAR_W2FLUX_IVAR_W3FLUX_IVAR_W4MW_TRANSMISSION_W1MW_TRANSMISSION_W2MW_TRANSMISSION_W3MW_TRANSMISSION_W4ALLMASK_GALLMASK_RALLMASK_ZFRACDEVFRACDEV_IVARSHAPEDEV_RSHAPEDEV_E1SHAPEDEV_E2SHAPEDEV_R_IVARSHAPEDEV_E1_IVARSHAPEDEV_E2_IVARSHAPEEXP_RSHAPEEXP_E1SHAPEEXP_E2SHAPEEXP_R_IVARSHAPEEXP_E1_IVARSHAPEEXP_E2_IVARFIBERFLUX_GFIBERFLUX_RFIBERFLUX_ZFIBERTOTFLUX_GFIBERTOTFLUX_RFIBERTOTFLUX_ZWISEMASK_W1WISEMASK_W2MASKBITSREF_IDREF_CATGAIA_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_EXCESS_NOISEGAIA_DUPLICATED_SOURCEGAIA_ASTROMETRIC_SIGMA5D_MAXGAIA_ASTROMETRIC_PARAMS_SOLVEDPARALLAXPARALLAX_IVARPHOTSYSCMX_TARGETPRIORITY_INITNUMOBS_INITHPXPIXELBLOBDISTFIBERFLUX_IVAR_GFIBERFLUX_IVAR_RFIBERFLUX_IVAR_ZDESI_TARGETBGS_TARGETMWS_TARGETPETALOFFSET_XOFFSET_Y
mmmm
int64int64int64str1int64float64float64float64float64float64float64int64int16int32int32int32float64float64float32float32float32float32float32float32int64uint8str3float32float32int16int32float64int32int32int16int32str8int32str4float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16int16int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16int16int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32uint8uint8int16int64str2float32float32float32float32float32float32float32float32boolfloat32boolfloat32float32str1int64int64int64int64float32float32float32float32int64int64int64int32float64float64
20200102377420Z72273099.9546530987966.114074707031229.8822774835389351783463.3184410015840.737609863281226.7760165200264243519102101697603401721720121.9126391519777138.5774916051219853.4899554-4.8368735515.92431252.85252015.55400.010561TGT17.38503-227.423170630.9907091125611919655351980015366521218p3852722PSF2.7918383e+165.6341166e+160.05124505521.33746433.11671837.56363.66134645.4876240.010479430.859249650.902862850.94444553.5336534e-069.044815e-061.3710386e-060.660393060.668133140.99005981.00000081.00000060.9999977334391.841357.167120.0229.340936.871030.03107.25121616.2418296.37604-169.084842.23641060.473887260.00082245671.1158377e-050.99135310.994680760.998863160.99957060020.00.00.00.00.00.00.00.00.00.00.00.00.00.0405.1669336.604521428.096405.16733336.60551428.0968002206908924451177213952G213.27419953599.18113.807784356.626212.605047850.11721.2375230.0False0.049399763True0.243952361350.9738N105663164580.00.00.00.0000017.3582260537263-226.77521067093966
20200102377420B7612491.7974485368371.5316772460937515.883330827468674638926.6682708646389.65747070312515.232370312820943519102101697603401721720121.9126391519777138.5774916051219853.4899554-4.8368735515.92431252.85252015.55400.010561TGT17.38503-227.423170630.9907091125611919655351980015366521218p3852722PSF2.7918383e+165.6341166e+160.05124505521.33746433.11671837.56363.66134645.4876240.010479430.859249650.902862850.94444553.5336534e-069.044815e-061.3710386e-060.660393060.668133140.99005981.00000081.00000060.9999977334391.841357.167120.0229.340936.871030.03107.25121616.2418296.37604-169.084842.23641060.473887260.00082245671.1158377e-050.99135310.994680760.998863160.99957060020.00.00.00.00.00.00.00.00.00.00.00.00.00.0405.1669336.604521428.096405.16733336.60551428.0968002206908924451177213952G213.27419953599.18113.807784356.626212.605047850.11721.2375230.0False0.049399763True0.243952361350.9738N105663164580.00.00.00.0000017.3582260537263-226.77521067093966
20200102377420R71309762.4024102066750.966339111328125.6868481758616871101407.152604938634.513763427734424.0175213899382243519102101697603401721720121.9126391519777138.5774916051219853.4899554-4.8368735515.92431252.85252015.55400.010561TGT17.38503-227.423170630.9907091125611919655351980015366521218p3852722PSF2.7918383e+165.6341166e+160.05124505521.33746433.11671837.56363.66134645.4876240.010479430.859249650.902862850.94444553.5336534e-069.044815e-061.3710386e-060.660393060.668133140.99005981.00000081.00000060.9999977334391.841357.167120.0229.340936.871030.03107.25121616.2418296.37604-169.084842.23641060.473887260.00082245671.1158377e-050.99135310.994680760.998863160.99957060020.00.00.00.00.00.00.00.00.00.00.00.00.00.0405.1669336.604521428.096405.16733336.60551428.0968002206908924451177213952G213.27419953599.18113.807784356.626212.605047850.11721.2375230.0False0.049399763True0.243952361350.9738N105663164580.00.00.00.0000017.3582260537263-226.77521067093966
20200102377420Z101487536.7419663672611.86108398437523.255303373643771020198.4531951103490.222290039062518.627783008111163519102101697485202162160121.9610192362894638.469950302307346-4.6321177-12.084589443.96744998.82742015.55400.0401TGT8.161446-254.848770670.394980853150539655351980015366521218p3851540PSF2.3630266e+163.9112837e+160.0503801551441.47691021.62331060.84330.0116735520.00411346280.0193323680.861452340.90442130.9453577.4426176e-104.720715e-092.7774899e-080.988497850.99546260.97946311.0000010.999992250.99999983330.00.00.00.00.00.0678.77747368.654658.22123104.445942.31587360.478560840.00091777851.1967853e-050.99149840.99477030.998882350.99957782220.00.00.00.00.00.00.00.00.00.00.00.00.00.01118.3177792.58954823.01691118.3177792.58954823.0169002300908922870629250560G214.0522623867.820814.338994625.6108413.598441717.399351.21007810.0False0.054589853True0.7447993994.8439N4067164580.00.00.00.000007.630807235750595-256.4649954419215
20200102377420B10780574.1185196852449.0004272460937517.944829269482423841080.3039229654489.291778564453117.361421064027913519102101697485202162160121.9610192362894638.469950302307346-4.6321177-12.084589443.96744998.82742015.55400.0401TGT8.161446-254.848770670.394980853150539655351980015366521218p3851540PSF2.3630266e+163.9112837e+160.0503801551441.47691021.62331060.84330.0116735520.00411346280.0193323680.861452340.90442130.9453577.4426176e-104.720715e-092.7774899e-080.988497850.99546260.97946311.0000010.999992250.99999983330.00.00.00.00.00.0678.77747368.654658.22123104.445942.31587360.478560840.00091777851.1967853e-050.99149840.99477030.998882350.99957782220.00.00.00.00.00.00.00.00.00.00.00.00.00.01118.3177792.58954823.01691118.3177792.58954823.0169002300908922870629250560G214.0522623867.820814.338994625.6108413.598441717.399351.21007810.0False0.054589853True0.7447993994.8439N4067164580.00.00.00.000007.630807235750595-256.4649954419215
20200102377420R101385112.4831799406796.51831054687526.5609027902408351184073.7897069217683.904602050781224.9426201580875643519102101697485202162160121.9610192362894638.469950302307346-4.6321177-12.084589443.96744998.82742015.55400.0401TGT8.161446-254.848770670.394980853150539655351980015366521218p3851540PSF2.3630266e+163.9112837e+160.0503801551441.47691021.62331060.84330.0116735520.00411346280.0193323680.861452340.90442130.9453577.4426176e-104.720715e-092.7774899e-080.988497850.99546260.97946311.0000010.999992250.99999983330.00.00.00.00.00.0678.77747368.654658.22123104.445942.31587360.478560840.00091777851.1967853e-050.99149840.99477030.998882350.99957782220.00.00.00.00.00.00.00.00.00.00.00.00.00.01118.3177792.58954823.01691118.3177792.58954823.0169002300908922870629250560G214.0522623867.820814.338994625.6108413.598441717.399351.21007810.0False0.054589853True0.7447993994.8439N4067164580.00.00.00.000007.630807235750595-256.4649954419215
20200102377420Z104874986.2399915823288.625274658203114.997667097412442399473.5241874554188.7171325683593810.5519274517725735191030470936400041410122.097226685097938.991512697541830.00.00.00.00.05400.012801TGT-18.156332-124.201590660.41575925742400965655351980015389061220p3901872COMP0.00.00.052230783316.64948842.84441940.23834.64706131.11905671.06336530.8567460.901089970.943407650.0234195780.0177929940.000873996640.0852516140.0832074060.074917750.64089020.62930570.9302929224514.3204399.25394147.72905348.395468.9866479.274463019.632055.618210341.85214120.6810.439328160.0956154240.000267409545.7911525e-060.99118750.99457870.99884130.99956230000.86468655730279.511.438962-0.18850727-0.290427716495.8572949369.83762479.810.04132-0.48837346-0.680962152144.6341659013.41862391.815.26310140.62668693.5231315.26434640.6281493.523160040961013908L20.00.00.00.00.00.00.00.0False0.0False0.00.0N128066164590.00.00.00.00000-15.489741827321861-123.11415097916169
20200102377420R104374737.45868653513199.9433975219726611.4616900713081229528.99693978042129.691902160644538.68632495503223535191030470936400041410122.097226685097938.991512697541830.00.00.00.00.05400.012801TGT-18.156332-124.201590660.41575925742400965655351980015389061220p3901872COMP0.00.00.052230783316.64948842.84441940.23834.64706131.11905671.06336530.8567460.901089970.943407650.0234195780.0177929940.000873996640.0852516140.0832074060.074917750.64089020.62930570.9302929224514.3204399.25394147.72905348.395468.9866479.274463019.632055.618210341.85214120.6810.439328160.0956154240.000267409545.7911525e-060.99118750.99457870.99884130.99956230000.86468655730279.511.438962-0.18850727-0.290427716495.8572949369.83762479.810.04132-0.48837346-0.680962152144.6341659013.41862391.815.26310140.62668693.5231315.26434640.6281493.523160040961013908L20.00.00.00.00.00.00.00.0False0.0False0.00.0N128066164590.00.00.00.00000-15.489741827321861-123.11415097916169
20200102377420B104120722.32603024568.262058258056644.32763505661924393347.231875189753.484407424926763.343710440507307335191030470936400041410122.097226685097938.991512697541830.00.00.00.00.05400.012801TGT-18.156332-124.201590660.41575925742400965655351980015389061220p3901872COMP0.00.00.052230783316.64948842.84441940.23834.64706131.11905671.06336530.8567460.901089970.943407650.0234195780.0177929940.000873996640.0852516140.0832074060.074917750.64089020.62930570.9302929224514.3204399.25394147.72905348.395468.9866479.274463019.632055.618210341.85214120.6810.439328160.0956154240.000267409545.7911525e-060.99118750.99457870.99884130.99956230000.86468655730279.511.438962-0.18850727-0.290427716495.8572949369.83762479.810.04132-0.48837346-0.680962152144.6341659013.41862391.815.26310140.62668693.5231315.26434640.6281493.523160040961013908L20.00.00.00.00.00.00.00.0False0.0False0.00.0N128066164590.00.00.00.00000-15.489741827321861-123.11415097916169
...........................................................................................................................................................................................................................................................................................................................................................................................................................
20200102377427Z39886516959.5870231883182.85327148437555.8315727289740455122615.1125879442621.19067382812553.0465450604134653519103985779194471370130122.3571816114300839.62391380079282-0.29606575-4.4776807416.17731213.95352015.55400.0401TGT-67.0744830.1506160680.4871241531947763655351980015411441223p3955064PSF2.6551398e+164.683677e+160.047543171396.39261388.98671524.66810.0182515330.0109409261.43766880.86871740.909552160.94835321.429628e-107.592344e-101.9260161e-080.98638440.99256820.60355570.99999891.0000011.00000153420.00.026.8437080.00.019.673319706.6692381.2554672.18537721.81682.5848340.50412360.000933203031.2063772e-050.99197520.99506410.998945240.99960162200.00.00.00.00.00.00.00.00.00.00.00.00.00.01085.03641079.28191184.71011085.03641079.28191184.71011281282940909131090643454080G214.1217293903.99814.457446455.9887713.634583632.64291.20541040.0False0.05486336True1.0256228816.73627N4068164590.00.00.00.00007-69.053885542005832.56720034100107
20200102377427R3989669271.947910733371.846755981445317.579197247512383589993.7569474559339.271148681640615.6954481787653413519103985778965872070200122.4248659064694639.520308490282980.00.00.00.00.05400.02561TGT-79.849384.9445030620.941603414070289655351980015411441223p3952778DEV0.00.00.04803045129.74727392.19162812.9972511.6294025.59106162.43235280.86746520.90866880.94783780.81855230.47197060.417790920.0451871230.04313770.043838650.731526260.78020210.7335368343785.5997412.79764178.05736516.082249.9097391.29684587.933259.6555-394.470215.6880180.83724410.175074280.000423494767.951936e-060.99189330.99501360.998934450.99959750001.01.04.593193-0.045493145-0.10068387558497.561663366.92441497.80.00.00.00.00.00.013.51689640.85799884.6969626.84382665.550385128.24716000819261L20.00.00.00.00.00.00.00.0False0.0False0.00.0N25662164590.00.00.00.00007-80.790068328138437.529393989661827
20200102377427Z39891593606.7274203778621.744323730468823.658241429987461025136.4901575088489.236907958984420.194302081125733519103985778965872070200122.4248659064694639.520308490282980.00.00.00.00.05400.02561TGT-79.849384.9445030620.941603414070289655351980015411441223p3952778DEV0.00.00.04803045129.74727392.19162812.9972511.6294025.59106162.43235280.86746520.90866880.94783780.81855230.47197060.417790920.0451871230.04313770.043838650.731526260.78020210.7335368343785.5997412.79764178.05736516.082249.9097391.29684587.933259.6555-394.470215.6880180.83724410.175074280.000423494767.951936e-060.99189330.99501360.998934450.99959750001.01.04.593193-0.045493145-0.10068387558497.561663366.92441497.80.00.00.00.00.00.013.51689640.85799884.6969626.84382665.550385128.24716000819261L20.00.00.00.00.00.00.00.0False0.0False0.00.0N25662164590.00.00.00.00007-80.790068328138437.529393989661827
20200102377427B3989283920.5955875573176.953414916992210.37555921607753240144.24201665615151.277107238769539.2258652336645943519103985778965872070200122.4248659064694639.520308490282980.00.00.00.00.05400.02561TGT-79.849384.9445030620.941603414070289655351980015411441223p3952778DEV0.00.00.04803045129.74727392.19162812.9972511.6294025.59106162.43235280.86746520.90866880.94783780.81855230.47197060.417790920.0451871230.04313770.043838650.731526260.78020210.7335368343785.5997412.79764178.05736516.082249.9097391.29684587.933259.6555-394.470215.6880180.83724410.175074280.000423494767.951936e-060.99189330.99501360.998934450.99959750001.01.04.593193-0.045493145-0.10068387558497.561663366.92441497.80.00.00.00.00.00.013.51689640.85799884.6969626.84382665.550385128.24716000819261L20.00.00.00.00.00.00.00.0False0.0False0.00.0N25662164590.00.00.00.00007-80.790068328138437.529393989661827
20200102377428Z4481777088.8488049404257.943145751953114.317864204702117448707.05047239584213.9493484497070310.2798934256447835191039878758687839683960123.9594946971308939.394367700340595-2.5850542-5.308147151.82965296.050932015.55400.0331TGT-382.48364-23.4435230650.04863148218010371655351980015411491239p395287PSF7062896600000000.01.3674056e+160.03889923496.6975712.94336959.140565.4700340.0426351580.149553090.89123280.925365450.957540631.3669493e-061.8723716e-067.1847703e-060.642802950.973137140.91052011.00000071.00.99999976333178.875060.00.0145.009380.00.0307.72504166.269299.441146361.3672.64236550.52135340.00077005471.1141383e-050.99342940.99595970.99913690.9996740220.00.00.00.00.00.00.00.00.00.00.00.00.00.0385.75177553.69543744.9004385.75177553.69543744.9004002268909218776695736960G215.2994892292.261215.681414266.5543814.750475718.97891.22211160.13838711False0.07790159True0.59802413330.29535N3365164600.00.00.00.00008-382.863296-23.247052999999955
20200102377428B448148875.3922703096625.7404670715332032.11923697674001634352.40618558103618.419364929199221.187129638023378235191039878758687839683960123.9594946971308939.394367700340595-2.5850542-5.308147151.82965296.050932015.55400.0331TGT-382.48364-23.4435230650.04863148218010371655351980015411491239p395287PSF7062896600000000.01.3674056e+160.03889923496.6975712.94336959.140565.4700340.0426351580.149553090.89123280.925365450.957540631.3669493e-061.8723716e-067.1847703e-060.642802950.973137140.91052011.00000071.00.99999976333178.875060.00.0145.009380.00.0307.72504166.269299.441146361.3672.64236550.52135340.00077005471.1141383e-050.99342940.99595970.99913690.9996740220.00.00.00.00.00.00.00.00.00.00.00.00.00.0385.75177553.69543744.9004385.75177553.69543744.9004002268909218776695736960G215.2994892292.261215.681414266.5543814.750475718.97891.22211160.13838711False0.07790159True0.59802413330.29535N3365164600.00.00.00.00008-382.863296-23.247052999999955
20200102377428R4481207276.08692260436104.544029235839847.7848556366428046175735.7742189408294.587493896484385.5324928711831535191039878758687839683960123.9594946971308939.394367700340595-2.5850542-5.308147151.82965296.050932015.55400.0331TGT-382.48364-23.4435230650.04863148218010371655351980015411491239p395287PSF7062896600000000.01.3674056e+160.03889923496.6975712.94336959.140565.4700340.0426351580.149553090.89123280.925365450.957540631.3669493e-061.8723716e-067.1847703e-060.642802950.973137140.91052011.00000071.00.99999976333178.875060.00.0145.009380.00.0307.72504166.269299.441146361.3672.64236550.52135340.00077005471.1141383e-050.99342940.99595970.99913690.9996740220.00.00.00.00.00.00.00.00.00.00.00.00.00.0385.75177553.69543744.9004385.75177553.69543744.9004002268909218776695736960G215.2994892292.261215.681414266.5543814.750475718.97891.22211160.13838711False0.07790159True0.59802413330.29535N3365164600.00.00.00.00008-382.863296-23.247052999999955
20200102377429Z48666381500.8930545233029.5620117187554.464639292360485128838.276704682572.70043945312552.10062366261153519103047513105195990590122.3925985407227739.016115372328820.67177314-5.178719264.8563616.79572015.55400.0321TGT-74.279564-118.2942660670.5576965941025963655351980015389071224p3902219PSF1.5713219e+162.2679044e+160.050946586717.5331128.64181304.49480.1046130360.0196168141.99879050.860009130.903400360.944759967.5761946e-087.645858e-084.973772e-070.959891440.97574280.60546151.00000020.99999920.99922513330.00.012.450670.00.09.93624366.12628191.52966-13.042578-277.254972.58511640.50988410.000864557461.1279003e-050.99140320.99471170.99886980.99957312200.00.00.00.00.00.00.00.00.00.00.00.00.00.0557.11633876.31481012.85284557.11633876.31481012.85284002172909036979320176000G214.8787972448.426315.228558286.818614.366785668.25161.21395210.0False0.064177155True0.7113468558.7687N3267164590.00.00.00.00009-73.10650147490375-115.48023473329823
20200102377429R48665204291.62812122994.88647460937553.9264916570210254500879.4346297082600.15405273437553.003172566969613519103047513105195990590122.3925985407227739.016115372328820.67177314-5.178719264.8563616.79572015.55400.0321TGT-74.279564-118.2942660670.5576965941025963655351980015389071224p3902219PSF1.5713219e+162.2679044e+160.050946586717.5331128.64181304.49480.1046130360.0196168141.99879050.860009130.903400360.944759967.5761946e-087.645858e-084.973772e-070.959891440.97574280.60546151.00000020.99999920.99922513330.00.012.450670.00.09.93624366.12628191.52966-13.042578-277.254972.58511640.50988410.000864557461.1279003e-050.99140320.99471170.99886980.99957312200.00.00.00.00.00.00.00.00.00.00.00.00.00.0557.11633876.31481012.85284557.11633876.31481012.85284002172909036979320176000G214.8787972448.426315.228558286.818614.366785668.25161.21395210.0False0.064177155True0.7113468558.7687N3267164590.00.00.00.00009-73.10650147490375-115.48023473329823
20200102377429B48663252910.9244606681948.776794433593842.840563507215122832770.13556002361702.387817382812542.39107177863853519103047513105195990590122.3925985407227739.016115372328820.67177314-5.178719264.8563616.79572015.55400.0321TGT-74.279564-118.2942660670.5576965941025963655351980015389071224p3902219PSF1.5713219e+162.2679044e+160.050946586717.5331128.64181304.49480.1046130360.0196168141.99879050.860009130.903400360.944759967.5761946e-087.645858e-084.973772e-070.959891440.97574280.60546151.00000020.99999920.99922513330.00.012.450670.00.09.93624366.12628191.52966-13.042578-277.254972.58511640.50988410.000864557461.1279003e-050.99140320.99471170.99886980.99957312200.00.00.00.00.00.00.00.00.00.00.00.00.00.0557.11633876.31481012.85284557.11633876.31481012.85284002172909036979320176000G214.8787972448.426315.228558286.818614.366785668.25161.21395210.0False0.064177155True0.7113468558.7687N3267164590.00.00.00.00009-73.10650147490375-115.48023473329823

In [300]:
def read_one_spectrocam(night, expid, spectrocam, fibers=None, verbose=False):
    """Read a single-camera spectrum for a given night, expid, 
    and spectrograph+camera combination.
    
    """
    import desispec.io
    
    strnight = str(night)
    strexpid = '{:08d}'.format(expid)
    
    specfile = os.path.join(reduxdir, strnight, strexpid, 'sframe-{}-{}.fits'.format(
        spectrocam, strexpid))
    if verbose:
        print('Reading {}'.format(specfile))
        
    spec = desispec.io.read_frame(specfile)
    if fibers is not None:
        #print('Selecting {} fibers'.format(len(fibers)))
        wfiber = np.where(np.isin(spec.fibers, fibers))[0]
        spec.flux = spec.flux[wfiber, :]
        spec.ivar = spec.ivar[wfiber, :]
        spec.mask = spec.mask[wfiber, :]
        spec.resolution_data = spec.resolution_data[wfiber, :, :]
        spec.fibermap = spec.fibermap[wfiber]
        spec.fibers = fibers
    
    return spec

def read_all_spectra(data, verbose=False):
    """Pack all the spectra for a given night and expid into a single 
    dictionary.
    
    """
    from astropy.table import Table, Column
    
    # Night and expid better be unique!
    night, expid = data['NIGHT'][0], data['EXPID'][0]
    
    # Build an output dictionary with one key per fiber.
    fibers, uindx = np.unique(star['FIBER'].data, return_index=True)
    #fibers = sorted(set(data['FIBER']))
    nspec = len(fibers)
    print('Reading {} spectra.'.format(nspec))
    
    out = Table()    
    #out.add_column(Column(name='FIBER', data=np.array(fibers).reshape(1, nspec)))
    #out.add_column(Column(name='OFFSET_X', data=data['OFFSET_X'][uindx].reshape(1, nspec)))
    #out.add_column(Column(name='OFFSET_Y', data=data['OFFSET_Y'][uindx].reshape(1, nspec)))
    out['FIBER'] = fibers
    out['OFFSET_X'] = data['OFFSET_X'][uindx].data
    out['OFFSET_Y'] = data['OFFSET_Y'][uindx].data
    out['PETAL'] = data['PETAL'][uindx].data
    out['TARGET_RA'] = data['TARGET_RA'][uindx].data
    out['TARGET_DEC'] = data['TARGET_DEC'][uindx].data
    
    waveout = Table()

    offset = 0
    for ispectro, spectro in enumerate(sorted(set(data['SPECTRO']))):
        wspectro = np.where(data['SPECTRO'] == spectro)[0]
            
        # I think this assumes that all cameras are operational.
        thesefibers = np.array(sorted(set(data['FIBER'][wspectro])))
        
        for icam, cam in enumerate(sorted(set(data['CAM'][wspectro]))):
            spectrocam = '{}{:d}'.format(cam.lower(), spectro)
            #print(spectrocam, offset, len(thesefibers))
            
            onespec = read_one_spectrocam(night, expid, spectrocam, 
                                          fibers=thesefibers, verbose=verbose)
            if ispectro == 0:
                waveout['WAVE_{}'.format(cam)] = onespec.wave
                here!
                out['FLUX_{}'.format(cam)] = np.zeros((nspec, onespec.nwave), dtype='f4')
            out['FLUX_{}'.format(cam)][offset:offset+len(thesefibers), :] = onespec.flux
            
        offset = offset + len(thesefibers)
            
    return waveout, out

def plot_all_spectra(allspec, nplot=None):
    """Plot the data given the output of read_all_spectra.
    
    """
    from IPython.display import Image
    
    if nplot is None:
        nplot = len(allspec['FIBER'])
    
    for ifib, fib in enumerate(allspec['FIBER'][:nplot]):
        fig, ax = plt.subplots(figsize=(6, 4))
        #fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
        #for cam in ('B', 'R', 'Z'):
        #    ax.plot(allspec['WAVE_{}'.format(cam)], allspec['FLUX_{}'.format(cam)][ifib, :])
            
        url = "http://legacysurvey.org/viewer-dev/jpeg-cutout?ra={:.6f}&dec={:.6f}&layer=dr8&size=100".format(
            allspec['TARGET_RA'][ifib], allspec['TARGET_DEC'][ifib])
        print(url)
        Image(url=url)
    #ax.plot(bcam.wave, bthru.photons(bcam.wave, bcam.flux[fiberid, :]))

In [301]:
#jj = read_one_spectrocam(20200102, 37742, 'b0', fibers=[7, 10, 144])
#jj.flux.shape

In [302]:
%time allspec = read_all_spectra(star, verbose=False)
print(allspec.keys())


Reading 74 spectra.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<timed exec> in <module>

<ipython-input-300-519e79125aff> in read_all_spectra(data, verbose)
     70                                           fibers=thesefibers, verbose=verbose)
     71             if ispectro == 0:
---> 72                 waveout['WAVE_{}'.format(cam)] = onespec.wave
     73                 out['FLUX_{}'.format(cam)] = np.zeros((nspec, onespec.nwave), dtype='f4')
     74             out['FLUX_{}'.format(cam)][offset:offset+len(thesefibers), :] = onespec.flux

/usr/local/anaconda3/envs/desi/lib/python3.6/site-packages/astropy/table/table.py in __setitem__(self, item, value)
   1302                                        shape=value.shape[1:],
   1303                                        unit=getattr(value, 'unit', None))
-> 1304                 new_column[:] = value
   1305 
   1306             # Now add new column to the table

/usr/local/anaconda3/envs/desi/lib/python3.6/site-packages/astropy/table/column.py in __setitem__(self, index, value)
    913         # Set items using a view of the underlying data, as it gives an
    914         # order-of-magnitude speed-up. [#2994]
--> 915         self.data[index] = value
    916 
    917     if six.PY2:

ValueError: could not broadcast input array from shape (2326) into shape (2751)
dict_keys(['FIBER', 'OFFSET_X', 'OFFSET_Y', 'PETAL', 'TARGET_RA', 'TARGET_DEC', 'WAVE_B', 'FLUX_B', 'WAVE_R', 'FLUX_R', 'WAVE_Z', 'FLUX_Z'])

In [292]:
from astropy.table import Table, Column
bb = Table()
bb.add_column(Column(name='bob', data=np.array([1, 2]).reshape(1, 2)))#, shape=(1, 2), length=1))
bb


Out[292]:
<Table length=1>
bob [2]
int64
1 .. 2

In [267]:
plot_all_spectra(allspec, nplot=2)


http://legacysurvey.org/viewer-dev/jpeg-cutout?ra=121.912639&dec=38.577492&layer=dr8&size=100
http://legacysurvey.org/viewer-dev/jpeg-cutout?ra=121.961019&dec=38.469950&layer=dr8&size=100

In [ ]:
def 
bthru = desimodel.io.load_throughput('b')
rthru = desimodel.io.load_throughput('r')
zthru = desimodel.io.load_throughput('z')

In [ ]:


In [ ]:


In [ ]:
night, expid = 20191117, 29181
night, expid = 20191117, 29181

In [ ]:


In [ ]:
def read_fibermap(night=20191116, expid=28818, fiberassignid=63064):
    strexpid = '{:08d}'.format(expid)
    strfiberassignid = '{:06d}'.format(fiberassignid)
                  
    fiberassignfile = os.path.join(datadir, str(night), strexpid, 'fiberassign-{}.fits'.format(
        strfiberassignid))
    sr = desispec.io.read_frame(specfile)
    return sr

In [ ]:
dir(bthru)

In [ ]:
help(bthru.thru)

In [ ]: