Preproc Fussing


In [1]:
#%matplotlib notebook
%matplotlib inline

In [2]:
# imports
from importlib import reload
import os
from matplotlib import pyplot as plt

from astropy.io import fits
from desispec import preproc
# You may wish to comment this out
#from pypeit import ginga


/home/xavier/anaconda3/lib/python3.7/site-packages/desispec-0.29.0.dev3381-py3.7.egg/desispec/maskbits.py:73: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  """)

Init


In [3]:
exp_path = '/home/xavier/DESI/Commissioning/exposures'

In [4]:
night = '20190619'

Methods


In [5]:
def add_gain(header):
    header['GAINA'] = 1.21763880607
    header['GAINB'] = 1.26599257375
    header['GAINC'] = 1.37207665312
    header['GAIND'] = 1.28793077884

In [6]:
def show_boundary(img, vmin=-400, vmax=1673):
    plt.clf()
    plt.figure(figsize=(13,7))
    plt.imshow(img.pix[1800:2200,500:1000], vmin=vmin, vmax=vmax)
    plt.show()

Try one (0.5s)


In [7]:
iid = 16322
ifile_05 = os.path.join(exp_path, night, '000{}'.format(iid), 'desi-000{}.fits.fz'.format(iid))
ifile_05


Out[7]:
'/home/xavier/DESI/Commissioning/exposures/20190619/00016322/desi-00016322.fits.fz'

In [8]:
hdulist = fits.open(ifile_05)
z2_hdu = hdulist['z2']

Show it (you may wish to comment this out)


In [9]:
#ginga.show_image(z2_hdu.data)

Run preproc!


In [10]:
## Add in gain
add_gain(z2_hdu.header)

In [11]:
reload(preproc)
img = preproc.preproc(z2_hdu.data, z2_hdu.header, None, bias=False, pixflat=False, mask=False, 
                      nocrosstalk=True, ccd_calibration_filename=False, dark=False, overscan_per_row=True)


WARNING:preproc.py:447:preproc: Missing keyword SATURLEVA in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier A of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.064272 2006.687500
INFO:preproc.py:517:preproc: Measured readnoise for AMP A = 2.064272
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVB in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier B of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.097935 2007.593750
INFO:preproc.py:517:preproc: Measured readnoise for AMP B = 2.097935
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVC in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier C of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.620456 2009.734375
INFO:preproc.py:517:preproc: Measured readnoise for AMP C = 2.620456
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVD in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier D of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.315711 2004.109375
INFO:preproc.py:517:preproc: Measured readnoise for AMP D = 2.315711
INFO:cosmics.py:357:reject_cosmic_rays_ala_sdss: starting with nsig=6.0 cfudge=3.0 c2fudge=0.5
INFO:cosmics.py:394:reject_cosmic_rays_ala_sdss: first pass: 12155 pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 0: 23166 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 1: 21197 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 2: 18347 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 3: 15309 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 4: 13010 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 5: 11314 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 6: 10022 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 7: 9059 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 8: 8342 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 9: 7983 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 10: 7422 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 11: 6918 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 12: 6490 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 13: 6264 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 14: 6129 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 15: 5939 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 16: 5666 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 17: 5497 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 18: 5531 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 19: 5351 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 20: 5207 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 21: 5066 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 22: 4898 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 23: 4817 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 24: 4623 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 25: 4539 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 26: 4522 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 27: 4428 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 28: 4339 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 29: 4317 new pixels rejected
INFO:cosmics.py:448:reject_cosmic_rays_ala_sdss: end : 535216 pixels rejected in 6.2 sec

View it


In [12]:
#ginga.show_image(img.pix)
show_boundary(img)


<Figure size 432x288 with 0 Axes>

Original


In [13]:
reload(preproc)
img_orig = preproc.preproc(z2_hdu.data, z2_hdu.header, None, bias=False, pixflat=False, mask=False, 
                      nocrosstalk=True, ccd_calibration_filename=False, dark=False, orig_over=True,
                          overscan_per_row=True)


WARNING:preproc.py:447:preproc: Missing keyword SATURLEVA in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier A of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.064272 2006.687500
INFO:preproc.py:517:preproc: Measured readnoise for AMP A = 2.064272
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVB in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier B of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.097935 2007.593750
INFO:preproc.py:517:preproc: Measured readnoise for AMP B = 2.097935
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVC in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier C of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.620456 2009.734375
INFO:preproc.py:517:preproc: Measured readnoise for AMP C = 2.620456
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVD in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier D of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.315711 2004.109375
INFO:preproc.py:517:preproc: Measured readnoise for AMP D = 2.315711
INFO:cosmics.py:357:reject_cosmic_rays_ala_sdss: starting with nsig=6.0 cfudge=3.0 c2fudge=0.5
INFO:cosmics.py:394:reject_cosmic_rays_ala_sdss: first pass: 193 pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 0: 44 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 1: 0 new pixels rejected
INFO:cosmics.py:448:reject_cosmic_rays_ala_sdss: end : 1093 pixels rejected in 1.2 sec

In [14]:
show_boundary(img_orig)


<Figure size 432x288 with 0 Axes>

Long exposure (10s)


In [15]:
iid = 16287
ifile = os.path.join(exp_path, night, '000{}'.format(iid), 'desi-000{}.fits.fz'.format(iid))
ifile


Out[15]:
'/home/xavier/DESI/Commissioning/exposures/20190619/00016287/desi-00016287.fits.fz'

In [16]:
hdulist = fits.open(ifile)
z2_hdu_10 = hdulist['z2']

In [17]:
## Add in gain
add_gain(z2_hdu_10.header)

In [18]:
reload(preproc)
img_10 = preproc.preproc(z2_hdu_10.data, z2_hdu.header, None, bias=False, pixflat=False, mask=False, 
                      nocrosstalk=True, ccd_calibration_filename=False, dark=False, overscan_per_row=True)


WARNING:preproc.py:447:preproc: Missing keyword SATURLEVA in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier A of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.088590 2006.609375
INFO:preproc.py:517:preproc: Measured readnoise for AMP A = 2.088590
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVB in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier B of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.126005 2007.546875
INFO:preproc.py:517:preproc: Measured readnoise for AMP B = 2.126005
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVC in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier C of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.927955 2009.625000
INFO:preproc.py:517:preproc: Measured readnoise for AMP C = 2.927955
WARNING:preproc.py:447:preproc: Missing keyword SATURLEVD in header and nothing in calib data; using 200000
INFO:preproc.py:461:preproc: nrows in overscan=2064
INFO:preproc.py:465:preproc: Subtracting overscan per row for amplifier D of camera z2
INFO:preproc.py:483:preproc: Median rdnoise and overscan= 2.393622 2004.218750
INFO:preproc.py:517:preproc: Measured readnoise for AMP D = 2.393622
INFO:cosmics.py:357:reject_cosmic_rays_ala_sdss: starting with nsig=6.0 cfudge=3.0 c2fudge=0.5
INFO:cosmics.py:394:reject_cosmic_rays_ala_sdss: first pass: 1585 pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 0: 2923 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 1: 2942 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 2: 2972 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 3: 2933 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 4: 2959 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 5: 2923 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 6: 3101 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 7: 3057 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 8: 3050 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 9: 3085 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 10: 3135 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 11: 3103 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 12: 3112 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 13: 3106 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 14: 2975 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 15: 2997 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 16: 2945 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 17: 2912 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 18: 2900 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 19: 2759 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 20: 2720 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 21: 2809 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 22: 2710 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 23: 2690 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 24: 2676 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 25: 2699 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 26: 2600 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 27: 2582 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 28: 2520 new pixels rejected
INFO:cosmics.py:424:reject_cosmic_rays_ala_sdss: at iter 29: 2536 new pixels rejected
INFO:cosmics.py:448:reject_cosmic_rays_ala_sdss: end : 179258 pixels rejected in 4.8 sec

In [19]:
show_boundary(img_10, vmin=None, vmax=None)


<Figure size 432x288 with 0 Axes>