Query the Fiber Database

import numpy as np
import time

import matplotlib.pyplot as plt

from astropy.table import Table, vstack, hstack
from astropy.coordinates import SkyCoord
import astropy.units as u

from hetdex_api.shot import get_fibers_table
from hetdex_api.survey import FiberIndex

Query a single coordinate:

coord = SkyCoord(ra=182.21303*u.deg, dec=50.915985*u.deg)
# Intiate the FiberIndex class from hetdex_api.survey:
F = FiberIndex('pdr1')

#help(F.query_region)

FiberIndex.Query_region() returns an astropy table of all fibers within the the aperture defined. Default is 3.5 arcsec radius. amp_flag, gal_flag, meteor, throughput flag populate whether the fiber would make it into the current catalog. 1 is good, 0 is removed. ‘flag’ combines the three flags

# This example was observed in multiple observations so there are many associated fibers
fibtab = F.query_region(coord, radius=3.5*u.arcsec)
fibtab.show_in_notebook()
Table length=19
idxmultiframeradecfiber_idhealpixampdatedatevobsexpnumfibidxfibnumfpxfpyifuidifuslotifuxifuyshotidspecidfieldflagamp_flagmeteor_flaggal_flagshot_flagthroughput_flag
0multi_047_092_075_RU182.2123450.91626720190407021_2_multi_047_092_075_RU_0121441630867RU2019040720190407v02121112245.993373.342075092-5.0824.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
1multi_047_092_075_RU182.2119150.91658420190407021_1_multi_047_092_075_RU_0111441630867RU2019040720190407v02111011247.318374.042075092-2.5424.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
2multi_047_092_075_RU182.2120850.91588620190407021_1_multi_047_092_075_RU_0311441630867RU2019040720190407v02113031246.048371.832075092-3.8122.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
3multi_047_092_075_RU182.2118550.91549320190407021_3_multi_047_092_075_RU_0511441630867RU2019040720190407v02135051245.993370.332075092-5.0819.8320190407021047dex-springTrueTrueTrueTrueTrueTrue
4multi_047_092_075_RU182.211750.9161920190407021_3_multi_047_092_075_RU_0311441630867RU2019040720190407v02133031247.263372.532075092-3.8122.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
5multi_047_092_075_RU182.2144350.9157520190407021_2_multi_047_092_075_RU_0141441630868RU2019040720190407v02121314240.903373.342075092-10.1724.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
6multi_047_092_075_RU182.21450.91606520190407021_1_multi_047_092_075_RU_0131441630868RU2019040720190407v02111213242.228374.042075092-7.6324.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
7multi_047_092_075_RU182.2125750.9166320190407021_3_multi_047_092_075_RU_0121441630868RU2019040720190407v02131112245.993374.742075092-5.0824.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
8multi_047_092_075_RU182.2136250.9163720190407021_3_multi_047_092_075_RU_0131441630868RU2019040720190407v02131213243.443374.742075092-7.6324.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
9multi_047_092_075_RU182.2122350.91518820190407021_1_multi_047_092_075_RU_0511441738261RU2019040720190407v02115051244.778369.632075092-5.0819.8320190407021047dex-springTrueTrueTrueTrueTrueTrue
10multi_047_092_075_RU182.2135550.91530620190407021_2_multi_047_092_075_RU_0331441738262RU2019040720190407v02123233242.173371.132075092-8.922.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
11multi_047_092_075_RU182.2125150.91556520190407021_2_multi_047_092_075_RU_0321441738262RU2019040720190407v02123132244.713371.132075092-6.3622.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
12multi_047_092_075_RU182.213450.91600820190407021_2_multi_047_092_075_RU_0131441738262RU2019040720190407v02121213243.443373.342075092-7.6324.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
13multi_047_092_075_RU182.2129550.91632520190407021_1_multi_047_092_075_RU_0121441738262RU2019040720190407v02111112244.778374.042075092-5.0824.2420190407021047dex-springTrueTrueTrueTrueTrueTrue
14multi_047_092_075_RU182.2141650.91536320190407021_1_multi_047_092_075_RU_0331441738262RU2019040720190407v02113233240.958371.832075092-8.922.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
15multi_047_092_075_RU182.2131250.91562320190407021_1_multi_047_092_075_RU_0321441738262RU2019040720190407v02113132243.498371.832075092-6.3622.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
16multi_047_092_075_RU182.212950.9152320190407021_3_multi_047_092_075_RU_0521441738262RU2019040720190407v02135152243.443370.332075092-7.6319.8320190407021047dex-springTrueTrueTrueTrueTrueTrue
17multi_047_092_075_RU182.2127450.91592820190407021_3_multi_047_092_075_RU_0321441738262RU2019040720190407v02133132244.713372.532075092-6.3622.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
18multi_047_092_075_RU182.2137850.9156720190407021_3_multi_047_092_075_RU_0331441738262RU2019040720190407v02133233242.173372.532075092-8.922.0320190407021047dex-springTrueTrueTrueTrueTrueTrue
# close the FiberIndex class (and associated open h5 files) when done
F.close()

Use get_fibers_table to access fiber spectra

Please use the get_fibers_table funtion to extract single fiber spectra. Calibration updates and adjustments are accessed through this function. For example, the raw h5 files are in native 2AA binning and do not have the white dwarf calibration correction applied. You may access those arrays by setting the option rawh5=True. Note that get_fibers_table offers the ability to retrieve fibers within a specified aperture (provide coords + radius option), a specified amp (multiframe option), a specified ifuslot. Please see help(get_fibers_table). The fiber_flux_offset is applicable to stacking analyses.

Note that when combining multiple fibers to perform a spectra extraction you will need to correctly apply the atmospheric diffraction correction. The API has several functions to do this extraction for you.

  1. To extract a PSF-weighted spectrum please see get_spectra.ipynb notebook.

  2. To generate line flux maps please see make_narrowband_image.ipynb.

  3. To make a data cube and display it please see make_data_cube.ipynb.

from hetdex_api.shot import get_fibers_table
wave = np.linspace(3470, 5540, 1036)
shotlist = list(np.unique( fibtab['shotid']))
print('Fiber coverage is available in the following shotids: {}'.format(shotlist))
Fiber coverage is available in the following shotids: [20190407021]
# example of grabbing all fibers in single shot:
spec_tab = get_fibers_table(shotlist[0], coord)
## More info on get_fibers_table
help( get_fibers_table)
Help on function get_fibers_table in module hetdex_api.shot:

get_fibers_table(shot, coords=None, ifuslot=None, multiframe=None, expnum=None, radius=<Quantity 3.5 arcsec>, survey='hdr4', astropy=True, verbose=False, rawh5=False, F=None, fiber_flux_offset=None, add_rescor=False, add_mask=False, mask_options=None, mask_version=None, ignore_mask=None, mask_in_place=False, mask_value=nan)
    Returns fiber specta for a given shot.
    
    Parameters
    ----------
    shot
        either shotid or datevobs
    coords
        astropy coordinate object
    radius
        an astropy quantity object
    astropy
        flag to make it an astropy table. Deprecated. Output is always an astropy table
    survey
        data release you want to access
    rawh5: bool
        if True, this will simply return the fibers from the specified shoth5
        file. If False (the default), any relevent correcctions
        are applied.
    verbose
        print out warnings. Default is False
    F   Fibers class object
        a pre-intiated fibers class object. This is used to limit I/O.
    fiber_flux_offset: 1036 array
        array of values in units of 10**-17 ergs/s/cm2/AA to add
        to each fiber spectrum used in the extraction. Defaults
        to None
    add_rescor
        option to add calfib_ffsky_rescor column generated by Maja Lujan Niemeyer.
        Defaults to False for now
    add_mask
        option to add mask column. Defaults to False for now.
    mask_options
        string array options to select to mask. Default None will select all flags.
        Set this to 'BITMASK' to return the full bitmask array
        Options are 'MAIN', 'FTF', 'CHI2FIB', 'BADPIX', 'BADAMP', 'LARGEGAL', 'METEOR',
        'BADSHOT', 'THROUGHPUT', 'BADFIB', 'SAT'
    ignore_mask
        Option to provide a list of flag names that should be ingored in the mask model
    mask_in_place
        Set to True to apply mask to calfib, calfibe, calfib_ffsky and calfib_ffsky_rescor
    mask_value
        value to fill masked values. Default is np.nan
    
    Returns
    -------
    A table of fibers within the defined aperture. Will be an astropy table
    object if astropy=True is set
spec_tab
Table length=19
multiframeradecfiber_idampcalfibcalfib_countscalfib_ffskycalfibecalfibe_countschi2contiderror1Dexpnumfiber_to_fiberfibidxfibnumfpxfpyifuidifuslotifuxifuyobsindrmssky_spectrumsky_subtractedspecidspectrumtracewavelength
degdeg1e-17 erg / (Angstrom s cm2)1e-17 erg / (Angstrom s cm2)1e-17 erg / (Angstrom s cm2)Angstrom
bytes20float32float32bytes38bytes2float32[1036]float32[1036]float32[1036]float32[1036]float32[1036]float32[1032]bytes8float32[1032]int32float32[1032]int32int32float32float32bytes3bytes3float32float32int32float32[1032]float32[1032]float32[1032]bytes3float32[1032]float32[1032]float32[1032]
multi_047_092_075_RU182.2119150.91658420190407021_1_multi_047_092_075_RU_011RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.81887656 .. 1.0159861S/N 005213.751459 .. 13.190371510.84478176 .. 0.903894071011247.318374.042075092-2.5424.2414.917628 .. 5.1587663121.020706 .. 107.6161830.544086 .. 28.88933047153.01169 .. 137.51656106.26733 .. 103.9737853481.7861 .. 5496.499
multi_047_092_075_RU182.2129550.91632520190407021_1_multi_047_092_075_RU_012RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.81769365 .. 0.498122S/N 005214.02096 .. 13.52092910.8829924 .. 0.93502551112244.778374.042075092-5.0824.2414.580227 .. 3.7110221126.494644 .. 118.5348214.5966 .. 10.112312047142.3144 .. 129.49612115.1998 .. 112.981613481.9663 .. 5497.051
multi_047_092_075_RU182.21450.91606520190407021_1_multi_047_092_075_RU_013RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.7905547 .. 0.49956927S/N 005213.9085455 .. 13.65460710.86432797 .. 0.91700461213242.228374.042075092-7.6324.2414.583771 .. 3.3264768123.82084 .. 119.404641.4037967 .. 12.229787047126.22407 .. 132.32137124.146416 .. 122.0117953482.1555 .. 5497.596
multi_047_092_075_RU182.2120850.91588620190407021_1_multi_047_092_075_RU_031RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.5663015 .. 0.5004975S/N 005213.815502 .. 13.54722810.95131093 .. 0.96437063031246.048371.832075092-3.8122.0315.3305473 .. 3.4207976122.74672 .. 121.12527-15.62719 .. -8.274664047106.55284 .. 112.40317285.2453 .. 283.43643485.471 .. 5506.621
multi_047_092_075_RU182.2131250.91562320190407021_1_multi_047_092_075_RU_032RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.8067379 .. 0.8620199S/N 005213.71839 .. 13.55197610.9418365 .. 0.97839943132243.498371.832075092-6.3622.0314.0777164 .. 5.0786114119.15543 .. 120.268863.1750033 .. 30.28142047121.76375 .. 150.10284294.14648 .. 292.214723485.6223 .. 5507.1123
multi_047_092_075_RU182.2141650.91536320190407021_1_multi_047_092_075_RU_033RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.2944099 .. 0.71716964S/N 005213.55041 .. 13.73405610.92882615 .. 0.97264523233240.958371.832075092-8.922.0312.6529367 .. 3.892724115.169556 .. 123.1447813.93148 .. -2.8704581047128.53435 .. 119.82689303.10278 .. 301.304383485.7737 .. 5507.603
multi_047_092_075_RU182.2122350.91518820190407021_1_multi_047_092_075_RU_051RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.3008631 .. 1.2362224S/N 005213.153173 .. 13.9685310.9987586 .. 0.970604665051244.778369.632075092-5.0819.8315.777974 .. 5.8537173106.05574 .. 131.27971-10.307098 .. 6.96620404795.18195 .. 137.79848471.64044 .. 470.10623488.444 .. 5514.905
multi_047_092_075_RU182.2125750.9166320190407021_3_multi_047_092_075_RU_012RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.20949575 .. 0.53787726S/N 005214.16332 .. 13.86771930.8829924 .. 0.93502551112245.993374.742075092-5.0824.2412.2965612 .. 3.5165098130.89207 .. 128.0368-1.5701933 .. -12.017702047129.58072 .. 116.31113115.33434 .. 113.001583481.723 .. 5497.0137
multi_047_092_075_RU182.2136250.9163720190407021_3_multi_047_092_075_RU_013RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.4315053 .. 1.1913637S/N 005214.045922 .. 13.61802330.86432797 .. 0.91700461213243.443374.742075092-7.6324.2414.2970266 .. 5.1780276128.12532 .. 118.37282-6.4042315 .. -15.828482047121.85992 .. 102.71937124.301025 .. 122.124933481.9294 .. 5497.556
multi_047_092_075_RU182.211750.9161920190407021_3_multi_047_092_075_RU_031RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.5849641 .. 0.61896884S/N 005213.649189 .. 13.63149730.95131093 .. 0.96437063031247.263372.532075092-3.8122.0313.4145186 .. 3.6732588119.1036 .. 123.49708-5.5495973 .. -4.9322453047112.85276 .. 117.92091285.41534 .. 283.47613485.4927 .. 5506.548
multi_047_092_075_RU182.2127450.91592820190407021_3_multi_047_092_075_RU_032RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.060439 .. 0.31985188S/N 005213.638253 .. 13.91589630.9418365 .. 0.97839943132244.713372.532075092-6.3622.0315.330388 .. 2.8250048116.874504 .. 130.3960619.553514 .. -6.547449047135.72678 .. 123.20469294.10834 .. 292.27413485.656 .. 5507.0376
multi_047_092_075_RU182.2137850.9156720190407021_3_multi_047_092_075_RU_033RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.0766742 .. 1.3291706S/N 005213.486258 .. 13.96097630.92882615 .. 0.97264523233242.173372.532075092-8.922.0315.7316694 .. 5.304574113.32992 .. 129.2168623.190355 .. -0.31247133047135.81903 .. 128.26047303.04004 .. 301.18453485.8196 .. 5507.527
multi_047_092_075_RU182.2118550.91549320190407021_3_multi_047_092_075_RU_051RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.8586132 .. 0.60621494S/N 005213.310113 .. 14.40681530.9987586 .. 0.970604665051245.993370.332075092-5.0819.8313.8591292 .. 4.1524324111.90196 .. 143.66246-39.244324 .. -7.66078404771.9564 .. 135.35776471.71622 .. 470.09583488.783 .. 5514.8423
multi_047_092_075_RU182.212950.9152320190407021_3_multi_047_092_075_RU_052RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.6403743 .. 1.1830976S/N 005213.228006 .. 14.47398931.0044304 .. 0.984302045152243.443370.332075092-7.6319.8315.9770164 .. 5.2285957110.2344 .. 146.0222315.220559 .. -14.7852955047124.753716 .. 130.59302480.45145 .. 478.888853488.971 .. 5515.2
multi_047_092_075_RU182.2123450.91626720190407021_2_multi_047_092_075_RU_012RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.72925425 .. 0.67011124S/N 005214.313326 .. 13.74549120.8829924 .. 0.93502551112245.993373.342075092-5.0824.2414.1634545 .. 4.437146134.7299 .. 124.65459-9.59449 .. 6.9940414047126.62801 .. 131.41603115.22805 .. 113.011363481.9744 .. 5496.923
multi_047_092_075_RU182.213450.91600820190407021_2_multi_047_092_075_RU_013RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.50302494 .. 1.5292405S/N 005214.191607 .. 14.00218720.86432797 .. 0.91700461213243.443373.342075092-7.6324.2413.3806987 .. 6.3608403131.88202 .. 128.8987-3.8954377 .. -11.337533047129.18425 .. 117.259575124.221275 .. 121.9978943482.1697 .. 5497.469
multi_047_092_075_RU182.2144350.9157520190407021_2_multi_047_092_075_RU_014RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.00.1330721 .. 0.26586938S/N 005214.200979 .. 14.00399920.8750727 .. 0.92121761314240.903373.342075092-10.1724.2412.2647963 .. 2.5130594133.5215 .. 129.0154-0.30778193 .. 7.565406047134.11646 .. 136.21022133.1792 .. 130.955493482.3875 .. 5498.018
multi_047_092_075_RU182.2125150.91556520190407021_2_multi_047_092_075_RU_032RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.3396385 .. 0.6383396S/N 005213.882472 .. 13.9188520.9418365 .. 0.97839943132244.713371.132075092-6.3622.0316.5420685 .. 3.6243832123.92002 .. 131.79446-1.133471 .. -33.757107047121.9197 .. 97.25282294.2214 .. 292.195073485.7527 .. 5507.031
multi_047_092_075_RU182.2135550.91530620190407021_2_multi_047_092_075_RU_033RU0.0 .. 0.00.0 .. 0.0-0.0 .. 0.00.0 .. 0.00.0 .. 0.01.1945068 .. 0.57079405S/N 005213.783499 .. 14.04945920.92882615 .. 0.97264523233242.173371.132075092-8.922.0314.839354 .. 3.1153224121.479805 .. 131.79068-17.410967 .. -39.62772047103.20199 .. 91.378426303.10196 .. 301.293823485.9094 .. 5507.525
%matplotlib inline
# Here is every fiber in the 3.5 arcsec aperture
plt.figure(figsize=(10,5))
for row in spec_tab:
    plt.plot(wave, row['calfib'], label='FiberID is {}'.format(row['fiber_id']))
    plt.xlim(3858-25, 3858+25)
#plt.legend()
../_images/8dce4dde2d6e3fcfa116c98ccc58fbc172f43e3ff1ad372c54139c6d0fde934a.png