def __init__(self, ms, pred_path, fpath, pset_loc): self.ms = ms self.DEBUG = False self.pred_path = pred_path self.fpath = fpath self.pset_loc = pset_loc self.log = jp.Locker(fpath+'log')
def main(fpath, redsteps, nlist): logger = jp.Locker(fpath + 'log') logger.add_calls('quality_check') dirlist = rebuild_dirlist(redsteps, nlist) rms = [] maxmin = [] snrs = [] for run in dirlist: try: data = fits.getdata(fpath + run + '/ws-image.fits')[0, 0, :, :] except: data = fits.getdata(fpath + run + '/ws-MFS-image.fits')[0, 0, :, :] rms.append(calcrms(data)) maxmin.append(max_min(data)) snrs.append(snr(data)) copy_images(fpath, redsteps) logger.rms = rms logger.maxmin = maxmin logger.snrs = snrs plotter('RMS', dirlist, rms, fpath + 'rms.pdf') plotter('I_max/I_min', dirlist, maxmin, fpath + 'maxmin.pdf') plotter('Signal to noise (max/rms)', dirlist, snrs, fpath + 'snr.pdf') logger.save()
def __init__(self, n, ms, fpath, pset_loc='./'): self.n = n self.ms = ms self.fpath = fpath self.initialized = False self.pset_loc = pset_loc self.log = jp.Locker(fpath + 'log') self.DEBUG = False assert fpath[-1] == '/' assert ms[-1] == '/' assert pset_loc[-1] == '/'
def __init__(self, n, ms, fpath, pset_loc = './', predict_path = './model.fits'): self.ms = ms self.fpath = fpath self.initialized = False self.pset_loc = pset_loc self.log = jp.Locker(fpath+'log') self.predict_path = predict_path self.DEBUG = False assert fpath[-1] == '/' assert ms[-1] == '/' assert pset_loc[-1] == '/' assert n == 1
def main(parsed, cwd): os.environ['OMP_NUM_THREADS'] = '1' if parsed.s == 'h': print(''' The following reduction steps have (so far) been implemented: p | Phase only calibration d | Diagonal calibration, meaning one phase and one diagonal calibration t | TEC calibration for the ionosphere, basically a constraint on the | phase-only calibration u | Phase-up: mash all short baselines together to one single base station | Requires a model. m | Predict using a new model - requires a model a | Solve for both TEC and Phase at the same time l | Apply lin2circ: converts from linear to circular basis _____________________________________________________________________________ ''') # Load the sequence of reductions redsteps = list(parsed.s) uni_redsteps = np.unique(redsteps) nlist = np.zeros(len(redsteps)) for chara in uni_redsteps: mask = chara == np.asarray(redsteps) nlist[mask] = np.arange(1, int(1 + sum(mask))) if 'u' in redsteps and not parsed.y: print( "This reduction strings contains a phase-up. Phase-ups are destructive - so please make sure that you have backed your system up. Type 'ok' to continue: " ) ans = raw_input() if ans != 'ok': sys.exit() if 'u' in redsteps or 'm' in redsteps: assert parsed.m != None # Load all ms if parsed.multims: mslist = [parsed.ms + ms + '/' for ms in os.listdir(parsed.ms)] else: mslist = [parsed.ms] pool = mp.Pool(4) # Maybe make this a function or something? # Perform the reductions # TODO: need to fix all the necessary reductions, at least 'd' and 'm' for red, n in zip(redsteps, nlist): n = int(n) if red == 'p': callist = [ pc.PhaseCalibrator(n, ms, parsed.p, '{}/parsets/'.format(cwd)) for ms in mslist ] pool.map(executeCalibration, callist) imgcall = callist[0].prep_img() imgcall += ' '.join(mslist) callist[0].pickle_and_call(imgcall) elif red == 'd': callist = [ dc.DiagonalCalibrator(n, ms, parsed.p, '{}/parsets/'.format(cwd)) for ms in mslist ] pool.map(executeCalibration, callist) callist[0].run_img(mslist) elif red == 't': callist = [ tc.TecCalibrator(n, ms, parsed.p, '{}/parsets/'.format(cwd)) for ms in mslist ] pool.map(executeCalibration, callist) imgcall = callist[0].prep_img() imgcall += ' '.join(mslist) callist[0].pickle_and_call(imgcall) elif red == 'u': for ms in mslist: cal = pu.PhaseUp(n, ms, parsed.p, '{}/parsets/'.format(cwd), parsed.m) cal.initialize() cal.execute() elif red == 'm': callist = [ pr.Predictor(ms, parsed.m, parsed.p, '{}/parsets/'.format(cwd)) for ms in mslist ] pool.map(executePredict, callist) elif red == 'a': callist = [ tp.TecPhaseCalibrator(n, ms, parsed.p, '{}/parsets/'.format(cwd)) for ms in mslist ] pool.map(executeCalibration, callist) imgcall = callist[0].prep_img() imgcall += ' '.join(mslist) callist[0].pickle_and_call(imgcall) elif red == 'l': callist = [ lc.LinToCirc(n, ms, parsed.p, '{}/parsets/'.format(cwd)) for ms in mslist ] pool.map(executeCalibration, callist) else: print("Reduction step {} not implemented".format(red)) if parsed.d: cal.DEBUG = True #if not parsed.multims: # cal.initialize() # cal.execute() qc.main(parsed.p, redsteps, nlist) log = jp.Locker(parsed.p + 'log') log['ms'] = parsed.ms log['last_edit'] = datetime.datetime.now().strftime("%Y_%m_%d_%H_$M") log.save()