def main(sensor_id, infile, output_dir='./', cti=None, do_trapping=False, do_electronics=False): processed_file = os.path.join(output_dir, '{0}_processed.fits'.format(sensor_id)) corrected_file = os.path.join(output_dir, '{0}_corrected.fits'.format(sensor_id)) ## CTI parameters if cti is None: do_cti = False cti = 0.0 else: do_cti = True cti_dict = {amp : cti for amp in range(1, 17)} ## Trapping parameters if do_trapping: # traps = [LinearTrap(4.0, 0.4, 1, 0.08), # LogisticTrap(1000.0, 0.4, 1, 60000., 0.0002)] traps = [LinearTrap(4.0, 0.4, 1, 0.08), LogisticTrap(40.0, 0.4, 1, 17500., 0.001)] else: traps = None traps_dict = {amp : traps for amp in range(1, 17)} ## Electronics parameters if do_electronics: scale = 0.0002 decay_time = 2.5 output_amps = {amp : FloatingOutputAmplifier(1.0, scale, decay_time) for amp in range(1, 17)} else: output_amps = {amp : BaseOutputAmplifier(1.0) for amp in range(1, 17)} ## Process infile imsim = ImageSimulator.from_image_fits(infile, output_amps, cti=cti_dict, traps=traps_dict) imarr_results = imsim.image_readout(infile, outfile=processed_file) ccd = MaskedCCD(processed_file) hdulist = fits.HDUList() with fits.open(infile) as template: hdulist.append(template[0]) hdulist[0].header['ORIGFILE'] = hdulist[0].header['FILENAME'] hdulist[0].header['FILENAME'] = corrected_file for amp in range(1, 17): imarr = ccd.bias_subtracted_image(amp).getImage().getArray() ## Electronics Correction if do_electronics: E = electronics_operator(imarr, scale, decay_time, num_previous_pixels=15) corrected_imarr = imarr - E else: corrected_imarr = imarr ## Trap Correction if do_trapping: T = trap_operator(imarr, *traps) corrected_imarr = corrected_imarr - (1-cti)*T else: pass ## CTI Correction if do_cti: Dinv_cti = cti_inverse_operator(cti, imarr.shape[1]) for i in range(imarr.shape[0]): corrected_imarr[i, :] = Dinv_cti*corrected_imarr[i, :] else: pass hdulist.append(fits.ImageHDU(data=corrected_imarr, header=template[amp].header)) with warnings.catch_warnings(): for warning in (UserWarning, AstropyWarning, AstropyUserWarning): warnings.filterwarnings('ignore', category=warning, append=True) fitsWriteto(hdulist, corrected_file, overwrite=True)
def main(sensor_id, infile, main_dir, gain_file=None, output_dir='./', no_bias=False): ## Get existing parameter results param_file = join(main_dir, '{0}_parameter_results.fits'.format(sensor_id)) param_results = OverscanParameterResults.from_fits(param_file) cti_results = param_results.cti_results drift_scales = param_results.drift_scales decay_times = param_results.decay_times trap_files = [ join(main_dir, '{0}_amp{1}_trap.pkl'.format(sensor_id, i)) for i in range(1, 17) ] ## Get gains if gain_file is not None: with open(gain_file, 'rb') as f: gain_results = pickle.load(f) gains = gain_results.get_amp_gains(sensor_id) else: gains = {i: 1.0 for i in range(1, 17)} ## Output filename base = splitext(os.path.basename(infile))[0] outfile = join(output_dir, '{0}_corrected.fits'.format(base)) ## Include bias frame for calibration if no_bias: bias_frame = None else: bias_frame = join(main_dir, '{0}_superbias.fits'.format(sensor_id)) ccd = MaskedCCD(infile, bias_frame=bias_frame) hdulist = fits.HDUList() with fits.open(infile) as template: hdulist.append(template[0]) ## Perform correction amp by amp for amp in range(1, 17): imarr = ccd.bias_subtracted_image( amp).getImage().getArray() * gains[amp] ## Electronics Correction if drift_scales[amp] > 0.: Linv = electronics_inverse_operator(imarr, drift_scales[amp], decay_times[amp], num_previous_pixels=15) corrected_imarr = imarr - Linv else: corrected_imarr = imarr ## Trap Correction spltrap = pickle.load(open(trap_files[amp], 'rb')) Tinv = trap_inverse_operator(corrected_imarr, spltrap) corrected_imarr = corrected_imarr - (1 - cti_results[amp]) * Tinv ## Reassemble HDUList hdulist.append( fits.ImageHDU(data=corrected_imarr / gains[amp], header=template[amp].header)) with warnings.catch_warnings(): for warning in (UserWarning, AstropyWarning, AstropyUserWarning): warnings.filterwarnings('ignore', category=warning, append=True) fitsWriteto(hdulist, outfile, overwrite=True)