def main(raft_id, database, main_dir, calib_dir, output_dir='./'): logfile = database.replace('.db', '.log') logging.basicConfig(filename=logfile, level=logging.INFO) sensor_list = ['S00', 'S01', 'S02', 'S10', 'S11', 'S12', 'S20', 'S21', 'S22'] sensor_ids = ['{0}_{1}'.format(raft_id, sensor_id) for sensor_id in sensor_list] ## Get bias frame bias_frames = {sensor_id : os.path.join(calib_dir, '{0}_superbias.fits'.format(sensor_id)) for sensor_id in sensor_ids} ## Get projector positions and exptimes camera = camMapper._makeCamera() lct = LsstCameraTransforms(camera) subdir_list = [x.path for x in os.scandir(main_dir) if isdir(x.path)] for subdir in sorted(subdir_list): base = basename(subdir) if "xtalk" not in base: continue xpos, ypos, exptime = base.split('_')[-4:-1] central_sensor, ccdX, ccdY = lct.focalMmToCcdPixel(float(ypos), float(xpos)) infiles = glob.glob(join(subdir, '*{0}.fits'.format(central_sensor))) ## Run crosstalk task for infile in infiles: crosstalk_task = CrosstalkSpotTask() crosstalk_task.config.database = database crosstalk_task.run(central_sensor, infile, bias_frame=bias_frames[central_sensor])
def __init__(self, ccdid, led, path_to_data, gainfile, biasfile=None, is_PTC=False): self.ccdid = ccdid self.gains = u.gains(gainfile, is_PTC=is_PTC) self.biasfile= biasfile self.led = led self.path_to_data = path_to_data self.data = {} camera = camMapper._makeCamera() self.lct = LsstCameraTransforms(camera)
def main(raft_id, main_dir, calib_dir, output_dir='./'): sensor_list = [ 'S00', 'S01', 'S02', 'S10', 'S11', 'S12', 'S20', 'S21', 'S22' ] sensor_ids = [ '{0}_{1}'.format(raft_id, sensor_id) for sensor_id in sensor_list ] for sensor_id in sensor_ids: print("Sensor: {0}".format(sensor_id)) ## Get calibration products bias_frame = join(calib_dir, '{0}_superbias.fits'.format(sensor_id)) dark_frame = join(calib_dir, '{0}_superdark.fits'.format(sensor_id)) ## Get projector positions and exptimes position_set = set() exptime_set = set() camera = camMapper._makeCamera() lct = LsstCameraTransforms(camera) subdir_list = [x.path for x in os.scandir(main_dir) if isdir(x.path)] for subdir in subdir_list: base = basename(subdir) if "xtalk" not in base: continue xpos, ypos, exptime = base.split('_')[-4:-1] central_ccd, ccdX, ccdY = lct.focalMmToCcdPixel( float(ypos), float(xpos)) if central_ccd == sensor_id: position_set.add((xpos, ypos)) exptime_set.add(exptime) ## For each exptime construct calibrated crosstalk image for exptime in exptime_set: for i, pos in enumerate(position_set): xpos, ypos = pos infiles = glob.glob( join(main_dir, '*{0}_{1}_{2}*'.format(xpos, ypos, exptime), '*{0}.fits'.format(sensor_id))) pos_output_dir = join( output_dir, 'xtalk_{0}_{1}_{2}_calibrated'.format(xpos, ypos, exptime)) os.mkdir(pos_output_dir) # add check if already existing base = basename(infiles[0]) outfile = join( pos_output_dir, base.replace(sensor_id, '{0}_calibrated'.format(sensor_id))) calibrated_stack(infiles, outfile, bias_frame=bias_frame, dark_frame=dark_frame)
def main(sensor_id, main_dir, calib_dir, output_dir='./'): gain_results = pickle.load(open(join(calib_dir, 'et_results.pkl'), 'rb')) gains = gain_results.get_amp_gains(sensor_id) ## Get projector positions and exptimes position_set = set() exptime_set = set() camera = camMapper._makeCamera() lct = LsstCameraTransforms(camera) subdir_list = [x.path for x in os.scandir(main_dir) if isdir(x.path)] for subdir in subdir_list: base = basename(subdir) if "xtalk" not in base: continue xpos, ypos, exptime = base.split('_')[-4:-1] central_sensor, ccdX, ccdY = lct.focalMmToCcdPixel( float(ypos), float(xpos)) if central_sensor == sensor_id: position_set.add((xpos, ypos)) exptime_set.add(exptime) ## For each exptime calculate crosstalk for exptime in exptime_set: outfile = join( output_dir, '{0}_{0}_{1}_crosstalk_matrix.fits'.format(sensor_id, exptime)) ## Get calibrated crosstalk infiles infiles = [] for i, pos in enumerate(position_set): xpos, ypos = pos infile = glob.glob( join(main_dir, '*{0}_{1}_{2}*'.format(xpos, ypos, exptime), '*{0}_calibrated.fits'.format(sensor_id)))[0] infiles.append(infile) ## Run crosstalk task crosstalk_task = CrosstalkTask() crosstalk_task.config.outfile = outfile crosstalk_task.run(sensor_id, infiles, gains)
xoffset = 5.0 # mm yoffset = -7.0 # mm # LED setup: current and exposure times led = ['uv', 'blue', 'red', 'nm750', 'nm850', 'nm960'] current = [0.1, 0.006, 0.009, 0.01, 0.01, 0.01] exp_time_orig = [0.02, 0.05, 0.05, 0.09, 0.06, 0.12] exp_time_corr_factor = [1.33, 1.69, 1.46, 1.4, 1.5, 2.7] exp_time = np.array(exp_time_orig) * np.array(exp_time_corr_factor) led_config = list(zip(led, current, np.around(exp_time, 2))) print(led_config) # Full focal plane pointings. # 5 pointings/CCD. One in the center and one in the center of each quadrant camera = camMapper._makeCamera() lct = LsstCameraTransforms(camera) raft_list = [ 'R01', 'R02', 'R03', 'R10', 'R11', 'R12', 'R13', 'R14', 'R20', 'R21', 'R22', 'R23', 'R24', 'R30', 'R31', 'R32', 'R33', 'R34', 'R41', 'R42', 'R43' ] sensor_list = ['S00', 'S01', 'S02', 'S10', 'S11', 'S12', 'S20', 'S21', 'S22'] fp_pos_e2v = [(1024, 3003), (3072, 3003), (2048, 2002), (1024, 1001), (3072, 1001)] fp_pos_itl = [(1018, 3000), (3054, 3000), (2036, 2000), (1018, 1000), (3054, 1000)] xall = np.zeros((len(raft_list), len(sensor_list) * len(fp_pos_e2v))) yall = np.zeros((len(raft_list), len(sensor_list) * len(fp_pos_e2v))) for i, raft in enumerate(raft_list): for j, sensor in enumerate(sensor_list):
led = ['uv', 'blue', 'red', 'nm750', 'nm850', 'nm960'] current = [0.1, 0.006, 0.009, 0.01, 0.01, 0.01] exp_time_orig = [0.02, 0.05, 0.05, 0.09, 0.06, 0.12] exp_time_corr_factor = [1.33, 1.69, 1.46, 1.4, 1.5, 2.7] exp_time = np.array(exp_time_orig) * np.array(exp_time_corr_factor) led_config = list(zip(led, current, np.around(exp_time,2))) print(led_config) # Find the scan center, in camera coordinates # Here, choosing the middle of Segment14 of R22_S11 raft = 'R22' sensor = 'S11' reb = 'Reb1' ccdid = raft + '_' + sensor camera = camMapper._makeCamera() lct = LsstCameraTransforms(camera) det = lct.getDetector(ccdid) ref_sensor = det.getSerial() print(ref_sensor) if 'E2V' in ref_sensor: ycenter, xcenter = lct.ccdPixelToFocalMm(2304,3003,ccdid) #e2V else: ycenter, xcenter = lct.ccdPixelToFocalMm(2286,3000,ccdid) #ITL print(xcenter, ycenter) # Scan boundaries xmin = xcenter - Delta_x / 2. xmax = xcenter + Delta_x / 2. ymin = ycenter - Delta_y / 2. ymax = ycenter + Delta_y / 2.
def main(configfile): config = yaml.load(open(configfile, 'rb'), Loader=yaml.FullLoader) print(config) plt.ioff() # turn off interactive mode to avoid problem with X forwarding path_to_beam = config['path_to_beam_model'] model_ccdid = config['model_ccdid'] model_ref_amp = config['model_ref_amp'] path_to_bias = config['path_to_bias'] led_beam = config['led_beam_model'] led = config['led_analysis'] raft_list = config['raft_list'] sensor_list = config['sensor_list'] outdir_figs = config['outdir_figs'] outdir_fits = config['outdir_fits'] basedir1 = '/gpfs/slac/lsst/fs3/g/data/jobHarness/jh_stage-test/LCA-10134_Cryostat/LCA-10134_Cryostat-0001/' basedir2 = '/gpfs/slac/lsst/fs3/g/data/jobHarness/jh_stage/LCA-10134_Cryostat/LCA-10134_Cryostat-0001/' path_to_data = { 'R01': basedir1 + '6848D/BOT_acq/v0/48087/', 'R02': basedir1 + '6849D/BOT_acq/v0/48093/', 'R10': None, 'R11': basedir1 + '6851D/BOT_acq/v0/48108/', 'R12': basedir1 + '6852D/BOT_acq/v0/48113/', 'R20': basedir1 + '6853D/BOT_acq/v0/48118/', 'R21': None, 'R22': basedir2 + '11974/BOT_acq/v0/93868/', 'R30': basedir1 + '6843D/BOT_acq/v0/48047/' } beam_model = load_beam_model(path_to_beam, led_name=led_beam, ref_amp=model_ref_amp, ccdid=model_ccdid) camera = camMapper._makeCamera() lct = LsstCameraTransforms(camera) delta_x, delta_y = compute_offsets(beam_model, lct, ccdid=model_ccdid, ref_pix_x=2304, ref_pix_y=3003) ccdid_list = sorted( [raft + '_' + sensor for sensor in sensor_list for raft in raft_list]) for data_ccdid in ccdid_list: print(data_ccdid) gainfile = '/gpfs/slac/lsst/fs3/g/data/jobHarness/jh_stage-test/LCA-10134_Cryostat/LCA-10134_Cryostat-0001/6801D/fe55_analysis_BOT/v0/47706/' + data_ccdid + '_6801D_eotest_results.fits' biasfile = os.path.join(path_to_bias, f'{data_ccdid}_sbias.fits') raft = data_ccdid.split('_')[0] data = qe_data.CcobQeData(data_ccdid, led, path_to_data[raft], gainfile, biasfile=biasfile) data.find_dir() for pos in data.pos_list: data.make_avg_mosaic_at_pos(pos, '/home/combet/tmp_9rafts/') mosaic = data.data[pos]['mosaic'] bbox = define_model_bbox(beam_model, mosaic, data.lct, pos, delta_x, delta_y) xarr = np.linspace(bbox[0], bbox[1], mosaic.shape[0]) yarr = np.linspace(bbox[2], bbox[3], mosaic.shape[1]) tmp = beam_model.beam_image['f_interp']( xarr, yarr) # interp works in cam coordinates tmp = np.flip(np.flip(tmp, axis=0), axis=1) # invert the model in x and in y model_eotestDef = np.flip( tmp.T, axis=1) # beam model followinf EOTest convention model_normalised = model_eotestDef / np.max( model_eotestDef.flatten()) qe = mosaic / model_normalised qe_norm = qe / np.median(qe.flatten()) outfile = os.path.join(outdir_fits, f'QE_{data_ccdid}_{led}_{pos}.fits') amp_coord = data.data[pos]['amp_coord'] make_fits(qe, amp_coord, outfile, data.template_file) figfile = os.path.join(outdir_figs, f'QE_{data_ccdid}_{led}_{pos}.png') plot_results(qe, model_eotestDef, mosaic, data_ccdid, data.lct, pos, delta_x, delta_y, figfile) figfile = os.path.join(outdir_figs, f'QE_{data_ccdid}_{led}_{pos}_norm.png') plot_results(qe_norm, model_normalised, mosaic, data_ccdid, data.lct, pos, delta_x, delta_y, figfile)
class CcobQeData: """ A class to compute and save the relative QE measurements perfomed using CCOB data Attributes ---------- ccdid: string Path to the file containing information necessary to the CCOB beam reconstruction led: string Path to the file containing information to read in the sensor data used to compute the CCOB QE path_to_data: CcobBeam object Contains all the properties of the CCOB beam reconstructed from the config_file_beam configuration file gainfile: 2D array Mosaic image of the CCOB-illuminated sensor to be used in the QE calculation biasfile: 2D array Mosaic image of the QE obtained from ccd/beam """ def __init__(self, ccdid, led, path_to_data, gainfile, biasfile=None, is_PTC=False): self.ccdid = ccdid self.gains = u.gains(gainfile, is_PTC=is_PTC) self.biasfile= biasfile self.led = led self.path_to_data = path_to_data self.data = {} camera = camMapper._makeCamera() self.lct = LsstCameraTransforms(camera) def find_dir(self): """ Finds all the CCOB positions that falls into the sensor identified by self.ccdid. The corresponding list of directories (for that particular self.led) and the list of positions are recorded in new attributes of the CcobQeData object. """ allfiles = glob.glob(os.path.join(self.path_to_data,'*'+self.led+'*')) filenames=[os.path.basename(f) for f in allfiles] fnames_comp=[f.split('_') for f in filenames] x_ccob = np.array(fnames_comp).T[2].astype(np.float) y_ccob = np.array(fnames_comp).T[3].astype(np.float) tmp = [self.lct.focalMmToCcdPixel(t[0],t[1]) for t in zip(y_ccob,x_ccob)] ccdid_list=np.array(tmp).T[0] flag = (ccdid_list == self.ccdid) self.dir_list = np.sort(np.array(allfiles)[flag]) dirnames=[os.path.basename(d) for d in self.dir_list] dnames_comp=[d.split('_') for d in dirnames] x_ccob = np.array(dnames_comp).T[2].astype(np.float) y_ccob = np.array(dnames_comp).T[3].astype(np.float) pos_str = [str(x_ccob[i])+'_'+str(y_ccob[i]) for i in np.arange(len(x_ccob))] self.pos_list = np.unique(pos_str) def make_avg_mosaic_at_pos(self, pos, outdir): """ Creates a mosaic image from a given sensor illuminated by the CCOB at a given position, by averaging all exposures made from this position. Parameters ---------- pos : string Position of the CCOB in the format "xpos_ypos", matching the name of the directories generated during acquisition outdir : string Directory where to save the temporary FITS file created when taking the mean. """ dirlist = [d for d in self.dir_list if pos in d] flist = np.reshape(np.array([glob.glob(os.path.join(d, '*'+self.ccdid+'*')) for d in dirlist]),(len(dirlist))) print('Averaging the following files:\n') print(flist) tmp_file = os.path.join(outdir,'tmp.fits') imutils.fits_mean_file(flist, os.path.join(outdir,tmp_file)) self.template_file = flist[0] mosaic, amp_coord = u.make_ccd_2d_array(tmp_file, gains=self.gains, biasfile=self.biasfile) self.data[pos] = {'mosaic':mosaic, 'amp_coord':amp_coord} def plot_mosaic(self, pos): """ Plots the mosaic image of the (mean) exposure and identifies the position of the CCOB on the figure. """ mosaic = self.data[pos]['mosaic'] xccob = float(pos.split('_')[0]) # CCS yccob = float(pos.split('_')[1]) # CCS ccdid, x_from_ccob_pos, y_from_ccob_pos = self.lct.focalMmToCcdPixel(yccob, xccob) # FP coord vmin = np.median(mosaic.flatten())*0.9 vmax = np.median(mosaic.flatten())*1.02 plt.imshow(mosaic, vmin=vmin, vmax=vmax) plt.plot([np.shape(mosaic)[1]-x_from_ccob_pos],[y_from_ccob_pos], marker='+',color='red') plt.colorbar() plt.show()