def dark_current(n, T, tag='', amb_temp=''): int_times = np.round(np.linspace(5, 500, n), 0) cam.printProgressBar(0, sum(int_times)) y = 0 for j in int_times: cam.set_int_time(j) cam.set_frame_time(j + 20) cap, _ = cam.img_cap(routine, img_dir, 'f') hdu_img = fits.open(unsorted_img) data = hdu_img[0].data dark_header = fits.getheader(unsorted_img) dark_header.append(('FPATEMP', T, 'Temperature of detector')) dark_header.append(('TEMPAMB', amb_temp, 'Ambient Temperature')) hdu_img.close() os.remove(unsorted_img) #Delete image after data retrieval fits.writeto(unsorted_img, data, dark_header) cam.file_sorting(img_dir, j, j + 20, tag=tag) y += j cam.printProgressBar(y, sum(int_times)) print('PROGRAM HAS COMPLETED')
def full_well(n, int_t, tag=''): dit = cam.set_int_time(int_t) cam.set_frame_time(int_t + 20) cam.printProgressBar(0, n) for j in range(n): cap, _ = cam.img_cap(routine, img_dir, 'f') cam.file_sorting(img_dir, dit, dit + 20, tag=tag) cam.printProgressBar(j, n)
def read_ramp(n): int_times = np.round(np.linspace(0.033, 0.5, n), 3) RNs = [] bias_level = [] cam.printProgressBar(0, n) y = 0 for j in int_times: int_t = cam.set_int_time(j) if int_t < (j + 1): cam.set_frame_time(20.33) bias_1, _ = cam.simple_cap() bias_2, _ = cam.simple_cap() bias_1 = np.asarray(bias_1, dtype=np.int32) bias_2 = np.asarray(bias_2, dtype=np.int32) bias_dif = bias_2 - bias_1 dif_clipped = bias_dif.flatten() RNs.append(np.std(dif_clipped) / np.sqrt(2)) bias_level.append(np.median(bias_1)) else: RNs.append(RNs[-1]) bias_level.append(bias_level[-1]) y += 1 cam.printProgressBar(y, n) RNs = 3.22 * np.array(RNs) bias_level = 3.22 * np.array(bias_level) int_times *= 1E3 fig, ax1 = plt.subplots() color = 'tab:red' ax1.set_xlabel('Integration Time ($\mu$s)') ax1.set_ylabel('Median $e^-$/pixel', color=color) ax1.scatter(int_times, bias_level, color=color) ax1.tick_params(axis='y', labelcolor=color) ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis color = 'tab:blue' ax2.set_ylabel('$\sigma$', color=color) # we already handled the x-label with ax1 ax2.scatter(int_times, RNs, color=color) ax2.tick_params(axis='y', labelcolor=color) fig.tight_layout() # otherwise the right y-label is slightly clipped plt.grid(True) plt.title('Read-noise/Bias as function of Integration Time') plt.show()
def master_bias(n, tag, T): ''' Enter docstring here ''' cam.set_int_time(0.033) cam.set_frame_time(100.033) cam.printProgressBar(0, n, prefix='Progress:', suffix='Complete', length=50) stack = np.zeros((naxis1, naxis2), dtype=np.uint16) for j in range(n): cap, _ = cam.img_cap(routine, img_dir, 'f') hdu_img = fits.open(unsorted_img) fits_img = hdu_img[0] data = fits_img.data hdu_img.close() #Close image so it can be sorted stack = np.dstack((stack, data)) cam.printProgressBar(j,n, prefix = 'Progress:', \ suffix = 'Complete', length = 50) if j == n - 1: #On final frame grab header bias_header = fits.getheader(unsorted_img) os.remove(unsorted_img) #Delete image after data retrieval bias_header.append(('NDIT', n, 'Number of integrations')) bias_header.append(('TYPE', 'MASTER_BIAS', '0s exposure frame')) bias_header.append(('FPATEMP', T, 'Temperature of detector')) #Median Stack stack = stack[:, :, 1:] #Slice off base layer master_bias = np.median(stack, axis=2) master_bias = master_bias.astype(np.uint16) #Write master frame to fits master_path = read_path + 'master_bias_' \ + tag + '.fits' fits.writeto(master_path, master_bias, bias_header) print('PROGRAM HAS COMPLETED')
def read_noise_estimate(n): ''' Capture n pairs of bias frames (520REFCLKS) Produce difference image from each pair and store read noise estimate from sigma/sqrt(2) of difference Output histogram of final pair with RN estimate as average of all pairs ''' cam.set_int_time(0.033) cam.set_frame_time(100) cam.printProgressBar(0, 2 * n, prefix='Progress:', suffix='Complete', length=50) y = 0 RNs = [] for j in range(n): bias_1, _ = cam.simple_cap() y += 1 cam.printProgressBar(y, 2 * n) bias_2, _ = cam.simple_cap() y += 1 cam.printProgressBar(y, 2 * n) bias_1 = np.asarray(bias_1, dtype=np.int32) bias_2 = np.asarray(bias_2, dtype=np.int32) #save max mean dif, max absolute dif bias_dif = bias_2 - bias_1 dif_clipped = bias_dif.flatten() RNs.append(np.std(dif_clipped) / np.sqrt(2)) dev = np.std(dif_clipped) RNs = np.array(RNs) RN = round(np.median(RNs), 3) uncert = round(3 * np.std(RNs), 2) sample_hist, _, _ = stats.sigmaclip(dif_clipped, 5, 5) N, bins, _ = plt.hist(sample_hist,bins = 265,facecolor='blue', alpha=0.75,\ label = 'Bias Difference Image') def fit_function(x, B, sigma): return (B * np.exp(-1.0 * (x**2) / (2 * sigma**2))) popt, _ = optimize.curve_fit(fit_function, xdata=bins[0:-1]+0.5, \ ydata=N, p0=[0, dev]) xspace = np.linspace(bins[0], bins[-1], 100000) fit_dev = round(popt[1], 3) delta_sig = round(abs(fit_dev - dev), 2) plt.plot(xspace+0.5, fit_function(xspace, *popt), color='darkorange', \ linewidth=2.5, label='Gaussian fit, $\Delta\sigma$:{}'.format(delta_sig)) plt.ylabel('No. of Pixels') plt.xlabel('ADUs') plt.title( 'Read Noise Estimate:${}\pm{}$ ADUs ($n={}$, FPA:$-40^\circ$C)'.format( RN, uncert, n)) plt.legend(loc='best') plt.show() print('PROGRAM HAS COMPLETED')
def master_dark(i, n, T, tag=''): ''' DIT and NDIT are inputs Function can also take tag for sorting individual frames onto local drive T is the FPA temperature used to record temperature of FPA for this dark which is written to file name and FITS header Program also outputs a .npy binary file containing 3D datacube of central (100,100) window for studying temporal variance over stack ''' cam.set_int_time(i) cam.set_frame_time(i + 20) bias = cam.get_master_bias(T) cam.printProgressBar(0, n, prefix='Progress:', suffix='Complete', length=50) stack = np.zeros((naxis1, naxis2), dtype=np.uint16) window = np.zeros((100, 100), dtype=np.uint16) for j in range(n): _, _ = cam.img_cap(routine, img_dir, 'f') hdu_img = fits.open(unsorted_img) data = hdu_img[0].data hdu_img.close() #Close image so it can be sorted data = data - bias stack = np.dstack((stack, data)) data_window = cam.window(data, 100) window = np.dstack((window, data_window)) cam.printProgressBar(j,n, prefix = 'Progress:', \ suffix = 'Complete', length = 50) if j == n - 1: #On final frame grab header dark_header = fits.getheader(unsorted_img) #Save single frame to local drive cam.file_sorting(local_img_dir, i, i + 20, tag=tag) #Median stack stack = stack[:, :, 1:] #Slice off base layer master_dark = np.median(stack, axis=2) #Prepare window for temporal analysis window = window[:, :, 1:] #Slice off base layer temp_var = np.median(np.var(stack, axis=2)) temp_path = master_darks + 'dark_cube' \ + str(i/1000) + '_' +str(T) +'C.npy' np.save(temp_path, window) dark_header.append(('NDIT', n, 'Number of integrations')) dark_header.append(('TYPE', 'MASTER_DARK', 'Median stack of dark frames')) dark_header.append(('FPATEMP', T, 'Temperature of detector')) dark_header.append( ('TEMPVAR', temp_var, 'Median temporal variance of central (100,100) window')) #Output master frame to fits master_path = master_darks + 'master_dark_' \ + str(i/1000) + '_' +str(T) +'C.fits' fits.writeto(master_path, master_dark, dark_header) print('PROGRAM HAS COMPLETED')