Accessing and Querying the Survey Class

The survey HDF5 file is a master look up table for each observation made by VIRUS for HETDEX. It can be accessed directly through the HDF5 survey file, or through the Survey class API. The Survey class includes information for each three dither set HETDEX observation in HDR1. It includes both science and calibration shots. Any quantity related to an individual dither is provided in an array of length three. Fundamental properties of a shot and quality assessment values for seeing (fwhm), astrometry, flux limits and transparency (response_4540) are tabulated to allow for querying of desired shots.

We first introduce the basic API to query the Survey Class by sky coordinates to get a list of shots where fibers are located within that region. Later on in this notebook we show some basic querying of the Survey class and demonstrate a few examples.

Initiate the Survey class

%matplotlib inline
import tables as tb
import numpy as np
import matplotlib.pyplot as plt

from astropy.table import Table
import astropy.units as u
from astropy.coordinates import SkyCoord

from hetdex_api.survey import Survey, FiberIndex
S = Survey('pdr1')
# convert to an astropy table format. Can remove any flagged shots if desired by setting return_good=True.
survey_table = S.return_astropy_table(return_good=False) 
survey_table
Table length=3502
shotidfieldobjiddateobsidradecpan_ifufwhm_virusfwhm_virus_errresponse_4540ambtempdatevobsdewpointexptimehumiditymjdnstars_fit_fwhmobsindpressurestructaztimetrajcdectrajcpatrajcrashot_flag
int64bytes12bytes18int32int32float64float64float64int32float32float32float32float32bytes12float32float32float32float32int32int32float32float32bytes7float32float32float32bool
20170920008dex-fallDEX00068_0_000_E20170920824.5887020.000469154.144974211.66565760.401027770.121220.42277720170920v00810.840555367.0995252.57258016.30581802.2015147.7671407175620.0152.6967224.5895True
20170920009dex-fallDEX00094_0_000_E20170920931.6085690.000689154.184946211.98485230.182024260.100620.37222320170920v00910.787222367.5993752.33758016.32441802.2015147.7894107452680.0152.7149531.6095True
20170921018dex-fallDEX00001_020170921186.4981220.000526154.177847181.75783220.56476130.137420.89666720170921v0189.74367.16646.67358017.2571803.082147.7318905591860.0152.667856.4995True
20170921020dex-fallDEX00046_0_000_E201709212018.6492920.001456154.126565181.69577730.272837880.11320.47222120170921v02010.080556367.0658349.73758017.285121803.082147.7524606475480.0152.684718.6495True
20170921021dex-fallDEX00070_0_000_E201709212125.1277790.000856154.16784181.64490380.182977660.11820.04333320170921v02110.283889366.549351.74158017.341803.0481147.7695307122810.0152.6986725.1295True
20170921022dex-fallDEX00070_0_000_E201709212231.3389450.000353154.178197181.97675250.58307540.127719.63833420170921v02210.735556367.1989454.85758017.31671803.0481147.7894107365860.0152.7149531.3395True
20170921025dex-fallDEX00017_1_000_W201709212510.8208150.000884208.837196181.73739620.148833230.089219.42611120170921v02510.836667366.9664656.02558017.3641802.91266212.268708382790.0207.3326610.8195True
20170921026dex-fallDEX00041_1_000_W201709212617.3006090.001184208.919681181.79941810.0137203590.11618.89055620170921v02610.827222367.5495658.00958017.3851802.7095212.2498209050280.0207.3171817.2995True
20170921029dex-fallDEX00095_1_000_W201709212931.8789350.000924208.749334181.89899480.8984370.121318.76277720170921v02910.489445367.1495757.42558017.4261802.1676212.2086310063760.0207.2834631.8795True
20170922021dex-fallDEX00015_0_000_E201709222110.2783990.001199154.164499211.83253570.54711630.135620.0661120170922v02111.661667366.782757.3358018.26101801.38873147.7349906165630.0152.6703810.2795True
.................................................................................
20210810022dex-fallDEXfl1201202108102215.7473451.386349150.335036771.68564630.246440430.13720.4411120210810v02212.118889368.4777856.00859436.383221806.0958143.1271809093891.386358148.9229715.74763True
20210810023dex-fallDEXfl0547202108102320.7510321.387937150.333082771.47813010.217661740.15520.30166620210810v02312.070556427.6072755.98959436.4311806.0958143.1271809324801.387939148.9229720.75196True
20210810024dex-fallDEXfl1831202108102427.7504621.383569150.305894771.54405010.200467020.14120.01888820210810v02411.161111367.3658453.70659436.418241806.23126143.1271809592451.383825148.9229727.750586True
20210818008dex-fallDEXfl069520210818824.497572.359227147.751397771.70269630.479754630.13316.93666620210818v00813.848889368.3314581.19259444.383111803.556139.9612109083162.359597146.3780724.49788True
20210818009dex-fallDEXfl196620210818930.501762.358941147.778205771.62963770.199678840.15717.47277820210818v00913.051666428.27573.84759444.4201803.556139.9612109323112.359597146.3780730.502125True
20210818010dex-fallDEXfl1901202108181034.9973931.803343147.794806771.38667150.200806870.12217.56277820210818v01012.544444368.1998671.30459444.418281803.6915139.9612109591801.803569146.3780734.997623True
20210818011dex-fallDEXfl079120210818118.751763-1.662152202.591086771.43172160.232611940.1418.20611220210818v01111.935555428.208466.2159444.434211803.6915204.775331023392-1.662814201.134318.75208True
20210826008dex-springDEXsp6607202108268240.07134452.579344295.52774781.42783070.157773440.15820.91555620210826v00812.225367.310454.51959452.12371807.3488319.74277025141752.57897293.8813240.07066True
20210828007dex-springDEXsp6643202108287240.80150152.778936295.966469781.35698770.142283290.14621.44166820210828v00711.168889367.740448.03759454.117391804.5042320.1262024729152.778416294.31314240.80075True
20210830013dex-springDEXsp66492021083013244.69245450.99492293.60186781.52505970.286028060.14519.72166620210830v01314.098333487.777167.07859456.137311805.24927317.97006031603650.9942291.92062244.69333True

It also converts RA and DEC into astropy coordinate objects.

S.coords
<SkyCoord (ICRS): (ra, dec) in deg
    [( 24.588702, 4.6900000e-04), ( 31.608569, 6.8900000e-04),
     (  6.498122, 5.2600000e-04), ..., (240.071344, 5.2579344e+01),
     (240.801501, 5.2778936e+01), (244.692454, 5.0994920e+01)]>

Shots are labeled based on their observation date and observation ID:

S.date
array([20170920, 20170920, 20170921, ..., 20210826, 20210828, 20210830],
      dtype=int32)
S.obsid
array([ 8,  9, 18, ...,  8,  7, 13], dtype=int32)

A specific shot can be linked either by an integer combination of these two values, called shotid, or the DATEvOBS form:

S.datevobs
array(['20170920v008', '20170920v009', '20170921v018', ...,
       '20210826v008', '20210828v007', '20210830v013'], dtype='<U12')
S.shotid
array([20170920008, 20170920009, 20170921018, ..., 20210826008,
       20210828007, 20210830013])

Searching for shots near a sky coordinate wiht get_shotlist

Most users searching for observations will want to get a list of observations/shots at a specific sky position. Each shot has a single associated sky coordinate. We can retrieve a list of shots that may contain fibers in a specific region. However, because of the varying and non-contiguous footprint of VIRUS, this is not an immediate guarantee a region has been observed. You must further query fibers in each shot to determine this. See Notebook 02 to learn how to query with the Fibers Class API.

This function which operates on the Survey class object. An astropy coordinates object is required as input.

coords = SkyCoord(11.628530 * u.deg, 0.081790 * u.deg, frame='icrs')

We can either search a rectangular region, width and height in degrees:

shotlist = S.get_shotlist(coords, width=0.5, height=0.2)
shotlist
array([20171119003, 20180106004, 20181003009, 20181005017, 20181107014,
       20191222012])

or we can search a circular aperture with a radius given in degress, or in an astropy quantity object:

shotlist = S.get_shotlist(coords, radius=10*u.arcmin)
shotlist
array([20171119003, 20180106004, 20181003009, 20181107014, 20191222012])

From here a user can take their shotlist and query the position on the Fibers class and see if their region of interest is observed in the survey.

Basic querying for the Survey Class

The Survey HDF5 itself contains information about the quality of each observation. A user can query different parameters and plot up general shot quantities. For example, we can compare the distribution of throughput values (technically the response at 4540 AA) between the HETDEX spring and HETDEX fall fields:

Example: Plotting up the canonical throughput value at 4540 AA

idx_spring = np.where( (S.field == 'dex-spring') * np.isfinite(S.response_4540) )
idx_fall = np.where( (S.field == 'dex-fall') * np.isfinite(S.response_4540))
plt.figure(figsize=(8,6))
plt.hist(S.response_4540[idx_spring], label = 'DEX-Spring', bins=20)
plt.hist(S.response_4540[idx_fall], label = 'DEX-Fall', bins=20)
plt.xlabel('Throughput at 4540 AA')
plt.ylabel('N OBS')
plt.legend()
<matplotlib.legend.Legend at 0x15045f2d7d90>

Access the survey H5 file

The hdfile attribute contains the link to the survey HDF5 file. Calling it will show you all the information in the HDF5 file. You may interact with this directly rather than using the Survey class initiation.

S.hdfile
File(filename=/scratch/projects/hetdex/pdr1/survey/survey_pdr1.h5, title='PDR1 Survey File', mode='r', root_uep='/', filters=Filters(complevel=0, shuffle=False, bitshuffle=False, fletcher32=False, least_significant_digit=None))
/ (RootGroup) 'PDR1 Survey File'
/Survey (Table(3502,)) ''
  description := {
  "shotid": Int64Col(shape=(), dflt=0, pos=0),
  "field": StringCol(itemsize=12, shape=(), dflt=b'', pos=1),
  "objid": StringCol(itemsize=18, shape=(), dflt=b'', pos=2),
  "date": Int32Col(shape=(), dflt=0, pos=3),
  "obsid": Int32Col(shape=(), dflt=0, pos=4),
  "ra": Float64Col(shape=(), dflt=0.0, pos=5),
  "dec": Float64Col(shape=(), dflt=0.0, pos=6),
  "pa": Float64Col(shape=(), dflt=0.0, pos=7),
  "n_ifu": Int32Col(shape=(), dflt=0, pos=8),
  "fwhm_virus": Float32Col(shape=(), dflt=0.0, pos=9),
  "fwhm_virus_err": Float32Col(shape=(), dflt=0.0, pos=10),
  "response_4540": Float32Col(shape=(), dflt=0.0, pos=11),
  "ambtemp": Float32Col(shape=(), dflt=0.0, pos=12),
  "datevobs": StringCol(itemsize=12, shape=(), dflt=b'', pos=13),
  "dewpoint": Float32Col(shape=(), dflt=0.0, pos=14),
  "exptime": Float32Col(shape=(), dflt=0.0, pos=15),
  "humidity": Float32Col(shape=(), dflt=0.0, pos=16),
  "mjd": Float32Col(shape=(), dflt=0.0, pos=17),
  "nstars_fit_fwhm": Int32Col(shape=(), dflt=0, pos=18),
  "obsind": Int32Col(shape=(), dflt=0, pos=19),
  "pressure": Float32Col(shape=(), dflt=0.0, pos=20),
  "structaz": Float32Col(shape=(), dflt=0.0, pos=21),
  "time": StringCol(itemsize=7, shape=(), dflt=b'', pos=22),
  "trajcdec": Float32Col(shape=(), dflt=0.0, pos=23),
  "trajcpa": Float32Col(shape=(), dflt=0.0, pos=24),
  "trajcra": Float32Col(shape=(), dflt=0.0, pos=25),
  "shot_flag": BoolCol(shape=(), dflt=False, pos=26)}
  byteorder := 'little'
  chunkshape := (425,)

Close the Survey H5 file after use

It is good practice to close any h5 files that are open when you no longer need to access new data from the h5 file

S.close()