-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Photon counting step function #260
Open
kjl0025
wants to merge
11
commits into
main
Choose a base branch
from
photon_counting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
62a928b
photon counting, fixed an err estimation from converting with k gain,…
f181cce
unit tests done, a few other small improvements
7ef22a9
linting
01482b6
lint
0d9f6f8
lint
948ccd2
eliminated potential division by 0
8cabe71
make a detectornoisemaps cal file for CI's sake
87f6d95
had to add nonlin calib as well
569ae0c
oops, forgot the dummy dataset
e995bf3
fewer full frames simulated in hopes that the CI will not cancel the …
3b1b969
oops, forgot to actually change the number
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
from pathlib import Path | ||
import numpy as np | ||
import warnings | ||
import scipy.ndimage | ||
import pandas as pd | ||
import astropy.io.fits as fits | ||
|
@@ -166,7 +167,7 @@ def create_synthesized_master_dark_calib(detector_areas): | |
# image area, including "shielded" rows and cols: | ||
imrows, imcols, imr0c0 = imaging_area_geom('SCI', detector_areas) | ||
prerows, precols, prer0c0 = unpack_geom('SCI', 'prescan', detector_areas) | ||
|
||
np.random.seed(4567) | ||
frame_list = [] | ||
for i in range(len(EMgain_arr)): | ||
for l in range(N): #number of frames to produce | ||
|
@@ -1857,3 +1858,91 @@ def add_defect(sch_imgs, prob, ori, temp): | |
hdul.writeto(str(filename)[:-4]+'_'+str(mult_counter)+'.fits', overwrite = True) | ||
else: | ||
hdul.writeto(filename, overwrite = True) | ||
|
||
def create_photon_countable_frames(Nbrights=30, Ndarks=40, EMgain=5000, kgain=7, exptime=0.1, cosmic_rate=0, full_frame=True): | ||
'''This creates mock Dataset containing frames with large gain and short exposure time, illuminated and dark frames. | ||
Used for unit tests for photon counting. | ||
|
||
Args: | ||
Nbrights (int): number of illuminated frames to simulate | ||
Ndarks (int): number of dark frames to simulate | ||
EMgain (float): EM gain | ||
kgain (float): k gain (e-/DN) | ||
exptime (float): exposure time (in s) | ||
cosmic_rate: (float) simulated cosmic rays incidence, hits/cm^2/s | ||
full_frame: (bool) If True, simulated frames are SCI full frames. If False, 50x50 images are simulated. Defaults to True. | ||
|
||
Returns: | ||
dataset (corgidrp.data.Dataset): Dataset containing both the illuminated and dark frames | ||
ill_mean (float): mean electron count value simulated in the illuminated frames | ||
dark_mean (float): mean electron count value simulated in the dark frames | ||
''' | ||
np.random.seed(1234) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment with seeding as above. |
||
pix_row = 1024 #number of rows and number of columns | ||
fluxmap = np.ones((pix_row,pix_row)) #photon flux map, photons/s | ||
|
||
emccd = EMCCDDetect( | ||
em_gain=EMgain, | ||
full_well_image=60000., # e- | ||
full_well_serial=100000., # e- | ||
dark_current=8.33e-4, # e-/pix/s | ||
cic=0.01, # e-/pix/frame | ||
read_noise=100., # e-/pix/frame | ||
bias=2000, # e- | ||
qe=0.9, # quantum efficiency, e-/photon | ||
cr_rate=cosmic_rate, # cosmic rays incidence, hits/cm^2/s | ||
pixel_pitch=13e-6, # m | ||
eperdn=kgain, | ||
nbits=64, # number of ADU bits | ||
numel_gain_register=604 #number of gain register elements | ||
) | ||
|
||
thresh = emccd.em_gain/10 # threshold | ||
|
||
if np.average(exptime*fluxmap) > 0.1: | ||
warnings.warn('average # of photons/pixel is > 0.1. Decrease frame ' | ||
'time to get lower average # of photons/pixel.') | ||
|
||
if emccd.read_noise <=0: | ||
warnings.warn('read noise should be greater than 0 for effective ' | ||
'photon counting') | ||
if thresh < 4*emccd.read_noise: | ||
warnings.warn('thresh should be at least 4 or 5 times read_noise for ' | ||
'accurate photon counting') | ||
|
||
avg_ph_flux = np.mean(fluxmap) | ||
# theoretical electron flux for brights | ||
ill_mean = avg_ph_flux*emccd.qe*exptime + emccd.dark_current*exptime + emccd.cic | ||
# theoretical electron flux for darks | ||
dark_mean = emccd.dark_current*exptime + emccd.cic | ||
|
||
frame_e_list = [] | ||
frame_e_dark_list = [] | ||
prihdr, exthdr = create_default_headers() | ||
for i in range(Nbrights): | ||
# Simulate bright | ||
if full_frame: | ||
frame_dn = emccd.sim_full_frame(fluxmap, exptime) | ||
else: | ||
frame_dn = emccd.sim_sub_frame(fluxmap[:50,:50], exptime) | ||
frame = data.Image(frame_dn, pri_hdr=prihdr, ext_hdr=exthdr) | ||
frame.ext_hdr['CMDGAIN'] = EMgain | ||
frame.ext_hdr['EXPTIME'] = exptime | ||
frame.pri_hdr["VISTYPE"] = "TDEMO" | ||
frame_e_list.append(frame) | ||
|
||
for i in range(Ndarks): | ||
# Simulate dark | ||
if full_frame: | ||
frame_dn_dark = emccd.sim_full_frame(np.zeros_like(fluxmap), exptime) | ||
else: | ||
frame_dn_dark = emccd.sim_sub_frame(np.zeros_like(fluxmap[:50,:50]), exptime) | ||
frame_dark = data.Image(frame_dn_dark, pri_hdr=prihdr.copy(), ext_hdr=exthdr.copy()) | ||
frame_dark.ext_hdr['CMDGAIN'] = EMgain | ||
frame_dark.ext_hdr['EXPTIME'] = exptime | ||
frame_dark.pri_hdr["VISTYPE"] = "DARK" | ||
frame_e_dark_list.append(frame_dark) | ||
|
||
dataset = data.Dataset(frame_e_list+frame_e_dark_list) | ||
|
||
return dataset, ill_mean, dark_mean |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally, seeding should be done by the function that calls this function, not this function itself (by doing it here, it will always produce the same result and can't be overridden).