Ejemplo n.º 1
0
    def test_raft_image_mosaic(self):
        """
        Test of raft-level mosaicking code.
        """
        infiles = sorted(
            glob.glob(
                os.path.join(_root_dir, 'S??', '*_lambda_flat_1000_*.fits')))
        infiles = OrderedDict([(filename.split('/')[-2], filename)
                               for filename in infiles])
        test_files = dict()
        step = 100
        level = step
        for slot, infile in list(infiles.items()):
            outfile = '%s_test_image_%05i.fits' % (slot, level)
            with fits.open(infile) as hdu_list:
                for hdu in hdu_list[1:17]:
                    hdu.data = np.ones(hdu.data.shape,
                                       dtype=np.float32) * level
                    level += step
                fitsWriteto(hdu_list, outfile, overwrite=True)
            test_files[slot] = outfile

        raft_mosaic = raftTest.RaftMosaic(test_files, bias_subtract=False)
        raft_mosaic.plot(title='Test pattern')
        plt.savefig(self.outfile)
Ejemplo n.º 2
0
def make_image(config, slot_names, mean_frame_pattern='_mean_bias_image.fits'):
    """
    Make the mosaic image of the entire raft, when illuminated by the CCOB 
    according to config. Returns:
    - the raw image of the raft
    - the corrected image where mean bias frame has been removed and gains applied
    """
    file_list = sorted(find_files(config))
    fits_files_dict = {slot_names[i] : file_list[i] for i in range(len(file_list))}
    ccd_dict = {}
    ccd_dict_wbias = {}
    gains_dict = {}
    for slot in slot_names:

        mean_bias_file = slot + mean_frame_pattern

        ccd_dict[slot] = sensorTest.MaskedCCD(fits_files_dict[slot])
        outfile = os.path.join(config['tmp_dir'],'ccd' + slot + '.fits')
        image={}
     
        ccd_dict_wbias[slot]=sensorTest.MaskedCCD(fits_files_dict[slot],\
                                                 bias_frame=os.path.join(config['tmp_dir'],mean_bias_file))
        outfile_wbias = os.path.join(config['tmp_dir'],'ccd' + slot + '_wbias.fits')
        image_wbias={}
        
        eotest_results_file = os.path.join(config['eo_data_path'],'{}_eotest_results.fits'.format(ccd_dict[slot].md('LSST_NUM')))
        gains_dict[slot] = gains(eotest_results_file)
        
        for amp in ccd_dict[slot]:
            image[amp] = ccd_dict[slot].bias_subtracted_image(amp)
            image[amp] *= gains_dict[slot][amp]
            image_wbias[amp] = ccd_dict_wbias[slot].bias_subtracted_image(amp)
            image_wbias[amp] *= gains_dict[slot][amp]
      
        imutils.writeFits({amp: image_wbias[amp].getImage() for amp in ccd_dict_wbias[slot]}, 
                          outfile_wbias, fits_files_dict[slot])
        imutils.writeFits({amp: image[amp].getImage() for amp in ccd_dict[slot]}, 
                          outfile, fits_files_dict[slot])

    fits_files_dict_corr={slot : os.path.join(config['tmp_dir'],'ccd'+slot+'.fits') for slot in slot_names}
    fits_files_dict_corr_wbias={slot : os.path.join(config['tmp_dir'],'ccd'+slot+'_wbias.fits') for slot in slot_names}
    
    im_corr = raft.RaftMosaic(fits_files_dict_corr, bias_subtract=False)
    im_corr_wbias = raft.RaftMosaic(fits_files_dict_corr_wbias, bias_subtract=False)
    im_raw = raft.RaftMosaic(fits_files_dict, bias_subtract=False)
    
    return im_raw, im_corr, im_corr_wbias
Ejemplo n.º 3
0
gains = dict()
for slot, res_file in results_files.items():
    results = sensorTest.EOTestResults(res_file)
    gains[slot] = dict([(amp, gain) for amp, gain
                        in zip(results['AMP'], results['GAIN'])])

# Collect super bias files for bias frame subtraction.
bias_frames = slot_dependency_glob('*median_bias.fits', 'dark_defects_raft')

title = '%s, %s' % (raft_id, run_number)
file_prefix = '%s_%s' % (raft_id, run_number)

# Raft-level mosaics of median darks, bias, superflats high and low.
dark_mosaic = raftTest.RaftMosaic(slot_dependency_glob('*median_dark_bp.fits',
                                                       'bright_defects_raft'),
                                  gains=gains, bias_frames=bias_frames)
dark_mosaic.plot(title='%s, medianed dark frames' % title,
                 annotation='e-/pixel, gain-corrected, bias-subtracted',
                 rotate180=True)
plt.savefig('%s_medianed_dark.png' % file_prefix)
del dark_mosaic

median_bias = raftTest.RaftMosaic(bias_frames, bias_subtract=False)
median_bias.plot(title='%s, median bias frames' % title, annotation='ADU/pixel',
                 rotate180=True)
plt.savefig('%s_median_bias.png' % file_prefix)
del median_bias

sflat_high = raftTest.RaftMosaic(slot_dependency_glob('*superflat_high.fits',
                                                      'cte_raft'),