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

# # Dark current and hot pixels

# Every image from a CCD contains *dark current*, which are counts in a raw image caused by thermal effects in the CCD. 
# the dark current is modern CCDs is extremely small if the camera is cooled in some way. Cameras cooled with liquid nitrogen have nearly zero dark current while thermo-electrically cooled CCDs have a somewhat larger dark current. The dark current in a CCD operating at room temperature will typically be very large.
#
# Even a camera in which the dark current is *typically* very small will have a small fraction of pixels, called hot pixels, in which the dark current is much higher.
#
# The next notebook walks through how to identify those pixels and how to decide the right way to remove dark current from your data. 

# # EVERYTHING BELOW MOVES INTO LATER NOTEBOOK 

# +
from astropy.nddata import CCDData
from astropy.visualization import hist
import matplotlib.pyplot as plt
import numpy as np

from convenience_functions import show_image
# -

dark_1000 = CCDData.read('master_dark_exposure_1000.0.fit')

show_image(dark_1000, cmap='gray')

plt.figure(figsize=(20, 10))
hist(dark_1000.data.flatten(), bins=100);
plt.semilogy()
plt.grid()
plt.xlabel('Counts')

plt.figure(figsize=(20, 10))
hist(dark_1000.data.flatten()/1000 * 1.5, bins=10000, density=True);
plt.semilogy()
plt.grid()
#plt.xlim(0, .1)
plt.xlabel('dark current, electrons per second')

bop = hist(dark_1000.data.flatten()/1000 * 1.5, bins=10000, density=True);
bop

print(len(bop[0]), len(bop[1]))

frac_pix = np.cumsum(bop[0] * (bop[1][1:] - bop[1][:-1]))

plt.figure(figsize=(20, 10))
plt.bar(bop[1][:-1], 1 - frac_pix, (bop[1][1:] - bop[1][:-1]));
plt.semilogy()
#plt.xlim(0, .2)
#plt.ylim(0.01, 1)
plt.grid()

(dark_1000.data.flatten()/1000 * 1.5).mean()



StarcoderdataJupyterScriptsDedupFiltered