QA_Prod (v2.0)

v2.0 -- First S/N prod plot

In [1]:
%matplotlib notebook

In [2]:
# imports
import os
from imp import reload
from desispec.qa import qa_prod as dqap
from desispec.qa import qa_plots as dqqp

from matplotlib import pyplot as plt


/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/desispec-0.26.0.dev3104-py3.6.egg/desispec/util.py:335: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was *originally* set to 'nbAgg' by the following code:
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/tornado/ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
    self._handle_recv()
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
    self._run_callback(callback, msg)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
    callback(*args, **kwargs)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
    handler(stream, idents, msg)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
    user_expressions, allow_stdin)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel/ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/ipykernel/zmqshell.py", line 533, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2698, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2808, in run_ast_nodes
    if self.run_code(code, result):
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-2c924c9481ae>", line 1, in <module>
    get_ipython().magic('matplotlib notebook')
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2146, in magic
    return self.run_line_magic(magic_name, magic_arg_s)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2067, in run_line_magic
    result = fn(*args,**kwargs)
  File "<decorator-gen-107>", line 2, in matplotlib
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/magics/pylab.py", line 99, in matplotlib
    gui, backend = self.shell.enable_matplotlib(args.gui)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2930, in enable_matplotlib
    pt.activate_matplotlib(backend)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 307, in activate_matplotlib
    matplotlib.pyplot.switch_backend(backend)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/pyplot.py", line 229, in switch_backend
    matplotlib.use(newbackend, warn=False, force=True)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/__init__.py", line 1305, in use
    reload(sys.modules['matplotlib.backends'])
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/importlib/__init__.py", line 166, in reload
    _bootstrap._exec(spec, module)
  File "/home/xavier/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 14, in <module>
    line for line in traceback.format_stack()


  matplotlib.use(_matplotlib_backend)

Init


In [3]:
os.environ['DESI_SPECTRO_REDUX'] = '/home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux'
os.environ['SPECPROD'] = 'mini'

In [4]:
reload(dqap)
qa_prod = dqap.QA_Prod()

Remake

Script

desi_qa_prod --remake_frameqa 3  

Slurp

In Python


In [5]:
#qa_prod.slurp(remove=False)

Script

desi_qa_prod --slurp

Parsing QA Data


In [10]:
reload(dqap)
qa_prod = dqap.QA_Prod()

Load QA


In [11]:
qa_prod.load_data()


INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200316_qa.json
INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200323_qa.json
INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200324_qa.json
INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200325_qa.json

One entry


In [12]:
qa_prod.data['20200316']['10']['b0']['FLUXCALIB']


Out[12]:
{'METRICS': {'MAX_ZP_OFF': [0.0, 63],
  'NSTARS_FIBER': 10,
  'RMS_ZP': 0.0,
  'ZP': 18.1748373412697},
 'PARAMS': {'MAX_ZP_OFF': 0.2, 'ZP_WAVE': 4800.0}}

Grab a Table of QA values


In [13]:
qa_tbl = qa_prod.get_qa_table('SKYSUB', 'RESID', channels=['b'])
qa_tbl


Out[13]:
Table length=170
RESIDEXPIDCAMERADATE-OBSNIGHTEXPTIMEAIRMASSFLAVOR
float64str2str2str23str8float64float64str7
-0.0297860858175944546b72020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.086186904666163856b82020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.065845132782099476b92020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.063765112960708416b32020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.090850496971942366b02020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.089064292367350366b52020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.062213295727485026b12020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.070038665725226326b62020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.081637810904535266b42020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
-0.0137639207169630856b22020-03-17T02:33:36.69120200316327.46580626132441.359901419566095science
........................
-0.1034053881025371940b12020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.0723904186424206840b02020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.1670904443676608540b22020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.0577943646498937440b52020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.1251802891300286540b42020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.1608340084556800840b92020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.0991148991241317440b72020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.1199210381653443840b82020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.02004692330302049240b32020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science
-0.126408940199411340b62020-03-26T02:59:11.96420200325912.06202171409781.135584511184822science

Histogram


In [14]:
plt.clf()
ax = plt.gca()
ax.hist(qa_tbl['RESID'])
ax.set_xlim(-1,1)
ax.set_xlabel('SKY_RESID')


Out[14]:
Text(0.5,0,'SKY_RESID')

Camera Histograms

In Python


In [11]:
reload(dqqp)
dqqp.prod_channel_hist(qa_prod, 'SKYSUB', 'RESID', xlim=(-1,1))


Script

 desi_qa_prod --channel_hist=default

Time Series plot


In [12]:
qatype = 'SKYSUB'
metric = 'RESID'

In Python


In [13]:
reload(dqqp)
dqqp.prod_time_series(qa_prod, qatype, metric)


Script

desi_qa_prod --time_series=SKYSUB-RESID

<S/N>

Script

desi_qa_prod --S2N_plot --xaxis texp

Load up


In [15]:
reload(dqap)
qa_prod = dqap.QA_Prod()
qa_prod.load_data()


INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200316_qa.json
INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200323_qa.json
INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200324_qa.json
INFO:qa.py:220:load_qa_multiexp: Loading QA prod file: /home/xavier/DESI/DESI_SCRATCH/18.11/spectro/redux/mini/QA/20200325_qa.json

In [18]:
# This takes ~0.1s per exposure
qa_prod.load_exposure_s2n()

In [19]:
len(qa_prod.qa_exps)


Out[19]:
17

Plots


In [20]:
#reload(dqqp)

Standard


In [21]:
dqqp.prod_avg_s2n(qa_prod, optypes=['ELG', 'LRG', 'QSO'])#, outfile='S2N_MJD.png')


Exposure ID


In [19]:
dqqp.prod_avg_s2n(qa_prod, optypes=['ELG', 'LRG'], xaxis='expid')


$t_{\rm exposure}$


In [20]:
dqqp.prod_avg_s2n(qa_prod, optypes=['ELG', 'LRG', 'QSO'], xaxis='texp') # , outfile='S2N_texp.png')



ZP Plot

Script

desi_qa_prod --ZP_plot --xaxis texp

In code


In [34]:
reload(dqqp)
dqqp.prod_ZP(qa_prod)



In [35]:
dqqp.prod_ZP(qa_prod, xaxis='texp')



In [ ]: