def calibrate_scan(scan,beam,basedir): #load ccal module ccal = apercal.ccal() ccal.crosscal_transfer_to_target = False #there is no target ccal.fluxcal = "WSRTA{0}_B{1:0>3}.MS".format(scan,beam) ccal.basedir = "{0}/{1}/".format(basedir,scan) #basedir for Apercal is different than my basedir, plus trailing slash #print "Setting fluxcal to WSRTA{0}_B{1:0>3}.MS".format(scan,beam) #print "Calibrating data set {2}00/raw/WSRTA{0}_B{1:0>3}.MS".format(scan,beam,ccal.basedir) ccal.go()
def get_bpsols(cfgfile): #function to read solutions and return arrays of values and freqs #now read solutions and put into array to return ccal = apercal.ccal(cfgfile) values, freqs = subs.readmirlog.get_bp(ccal.crosscaldir + '/' + ccal.fluxcal) #replace all zeros with nans before returning. values[values == 0] = np.nan print 'read calibration solutions into numpy array' return values, freqs
def cal_mult_bp(scanlist, cfgfile, basedir, sourcename, gainint='60', gapint='60', bpint='60'): #now do the bandpass solutions - the point of all of this! #define intervals by default #numbers don't matter overly much - will be full solution of short scan #sourcename is important! Make sure it's a recognized calibrator format!!!! #read cfgfile, not sure this will actually matter here since I set basedir manually ccal = apercal.ccal(cfgfile) #set-up utilities for bandpass calibration mfcal = lib.miriad('mfcal') # Comment the next line out if you don't want to solve for delays mfcal.options = 'delay' mfcal.stokes = 'XX' mfcal.interval = gainint + ',' + gapint + ',' + bpint mfcal.tol = 0.1 # Set the tolerance a bit lower. Otherwise mfcal takes a long time to finsh #IMPORTANT! source names have beam number, need to make sure miriad canrecongize #these parts are global, and I do specific scans below puthd = lib.miriad('puthd') puthd.value = sourcename #Now iterate and # Execute the bandpass calibration #reading into different arrays #now iterate through scans and do calibration for i, scan in enumerate(scanlist): print i, scan ccal.basedir = basedir + '_' + str(i) + '/' ccal.crosscaldir = ccal.basedir + '00/crosscal/' #print ccal.basedir #print ccal.fluxcal #print ccal.crosscaldir puthdstring = ccal.crosscaldir + sourcename + '.mir/source' #print puthdstring puthd.in_ = puthdstring #extra underscore because python has a global in puthd.go() #convert.show() #print ccal.crosscaldir if os.path.exists(ccal.crosscaldir): print 'doing calibration' mfcal.vis = ccal.crosscaldir + ccal.fluxcal mfcal.go()
def do_bp(cfgfile, inttime='30'): #function to do the bandpass solution, for given interval #inttime is the solution interval for bandpass, in minutes ccal = apercal.ccal(cfgfile) #change to working directory #workaround for long path names ccal.director('ch', ccal.crosscaldir) gainint = inttime gapint = inttime bpint = inttime mfcal = lib.miriad('mfcal') mfcal.vis = ccal.fluxcal print mfcal.vis #print mfcal.vis # Comment the next line out if you don't want to solve for delays mfcal.options = 'delay' mfcal.stokes = 'XX' mfcal.interval = gainint + ',' + gapint + ',' + bpint mfcal.tol = 0.1 # Set the tolerance a bit lower. Otherwise mfcal takes a long time to finsh mfcal.go() print 'calibration finished'
def get_bp_sols_mult_bp(scanlist, cfgfile, basedir): ccal = apercal.ccal(cfgfile) all_values = [] for i, scan in enumerate(scanlist): print i, scan ccal.basedir = basedir + '_' + str(i) + '/' ccal.crosscaldir = ccal.basedir + '00/crosscal/' #print ccal.basedir #print ccal.fluxcal #print ccal.crosscaldir #convert.show() #print ccal.crosscaldir if os.path.exists(ccal.crosscaldir): #print ccal.crosscaldir + ccal.fluxcal values, freqs = subs.readmirlog.get_bp(ccal.crosscaldir + ccal.fluxcal) #create master array if len(all_values) == 0: all_values = np.copy(values) else: all_values = np.append(all_values, values, axis=2) return all_values
#I am getting two different datasets: #180216005 (Dwingeloo 1) #180302009 (DR21) #Will create almost empty configuration files for both cfg1 = '/home/adams/apertif/AAF/180216005.cfg' cfg2 = '/home/adams/apertif/AAF/180302009.cfg' #Now in miriad need to use uvimage to create image cube #Want to limit number of channels #Want to include near 9330, 20 subbands #Subbands start at multiples of 64 #take subbands 130-149 #channels 8320, 9599 #move to directory where data is ccal = apercal.ccal(cfg1) ccal.director('ch', ccal.crosscaldir) uvimage = lib.miriad('uvimage') uvimage.vis = ccal.target + 'mir' #uvaver.out uvimage.view = 'amplitude' targetname = ccal.target uvimage.out = targetname + '_amp_freq.im' #still too much data so also select a time range #parentheses in command so need double quote uvimage.select = "'-auto,time(11:00:00,12:00:00)'" uvimage.line = 'channel,1280,8320,1' uvimage.options = 'freq' uvimage.mode = 3 uvimage.go()