# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# # Testing Bootcalib robustness to Cosmic Rays

# %matplotlib inline

# +
# imports
try:
    import seaborn as sns; sns.set(context="notebook",font_scale=2)
except:
    pass

from desispec import bootcalib as desiboot
from desiutil import funcfits as dufits
from astropy.io import fits
from astropy.stats import sigma_clip

import numpy as np
from astropy.modeling import models, fitting
# -

# ## r camera

# Read
fiberflat = '/Users/xavier/DESI/Wavelengths/CRs/pix-r0-00000000.fits.gz'
flat_hdu = fits.open(fiberflat)
header = flat_hdu[0].header
flat = flat_hdu[0].data
ny = flat.shape[0]

# Find Fibers
xpk, ypos, cut = desiboot.find_fiber_peaks(flat)

reload(desiboot)
desiboot.qa_fiber_peaks(xpk, cut)

# Crude first
xset, xerr = desiboot.trace_crude_init(flat,xpk,ypos)
# Polynomial fits
xfit, fdicts = desiboot.fit_traces(xset,xerr)

# QA
desiboot.qa_fiber_Dx(xfit, fdicts)

# Model the PSF
gauss = desiboot.fiber_gauss(flat,xfit,xerr)
desiboot.qa_fiber_gauss(gauss)



StarcoderdataJupyterScriptsDedupFiltered