def panelplot(sd, aipsname, intl_antennas, intl_name, times, refant, ra, dec): ny, nx = len(intl_antennas), 6 pltsquash = 0.5 * float(sd.shape[3]) / float(sd.shape[2]) for pol in [0, 1]: for i in range(ny): wdata = WizAIPSUVData(aipsname, 'FITS', 1, 1) d, uvw, tjunk = dget(wdata, np.array([intl_antennas[i], refant])) plt.subplot(nx, ny, i + 1, xticks=[], yticks=[]) # data if interesting(d): plt.imshow(np.arctan2(d[0][pol].imag, d[0][pol].real)) if i == 2: plt.title(aipsname + ' ' + ra + ' ' + dec) plt.subplot(nx, ny, i + 1 + ny, xticks=[], yticks=[]) #FT of data if interesting(d): d_display = np.sqrt(abs(fft.fftshift(fft.fft2(d[0][pol])))) plt.imshow(d_display, cmap=matplotlib.cm.gray_r) delays = sd[i, 0, 0, :, pol] if len(delays[~np.isnan(delays)]): plt.subplot(nx, ny, i + 1 + 2 * ny, xticks=[], yticks=[]) # delay plot plt.plot(times, delays, 'b+') md = np.nanmedian(delays) plt.yticks([md - 50, md - 20, md, md + 20, md + 50], ['', '', '', '', '']) plt.ylim(np.nanmin(delays), np.nanmax(delays)) plt.xlim(times[0], times[-1]) plt.text(times[0], np.nanmin(delays), str(int(md))) phases = sd[i, 1, 0, :, pol] if len(phases[~np.isnan(phases)]): plt.subplot(nx, ny, i + 1 + 3 * ny, xticks=[], yticks=[]) # phase plot phx = times[~np.isnan(phases)] phy = phases[~np.isnan(phases)] plt.plot(phx, phy, 'b+') plt.ylim(-np.pi, np.pi) plt.yticks([-np.pi, 0, np.pi], ['', '', '']) wdata = WizAIPSUVData(aipsname, 'SPLIT', 1, 1) d, uvw, tjunk = dget(wdata, np.array([intl_antennas[i], refant])) plt.subplot(nx, ny, i + 1 + 4 * ny, xticks=[], yticks=[]) #corr. data if interesting(d): plt.imshow(np.arctan2(d[0][pol].imag, d[0][pol].real)) plt.subplot(nx, ny, i + 1 + 5 * ny, xticks=[], yticks=[]) #FT corr.data plt.imshow(np.sqrt(abs(fft.fftshift(fft.fft2(d[0][pol])))), cmap=matplotlib.cm.gray_r) plt.xlabel(intl_name[i]) # plt.show() plt.savefig(pngdir + aipsname + ('R' if pol else 'L') + '.png', bbox_inches='tight') plt.clf()
def run_load_sort(pwd, data_prefix, delete, disk): ## Load the data into AIPS fitld = AIPSTask('FITLD') fitld.datain = pwd + data_prefix + '_1_1.IDI' fitld.outdisk = disk fitld.digicor = -1 fitld.doconcat = 1 fitld.outname = data_prefix fitld.ncount = 3 fitld.go() #Load the TASAV file which contains the pipelined tables fitld = AIPSTask('FITLD') fitld.datain = pwd + data_prefix + '_1.tasav.FITS' fitld.outdisk = disk fitld.digicor = -1 fitld.outname = 'pipe_TSAV' fitld.ncount = 1 fitld.go() #sort the data into time-baseline order uvdata = WizAIPSUVData(data_prefix, 'UVDATA', disk, 1) tasav = WizAIPSUVData('pipe_TSAV', 'TASAV', disk, 1) uvsrt = AIPSTask('UVSRT') uvsrt.indata = uvdata uvsrt.outdata = uvdata uvsrt.sort = 'TB' uvsrt.go() dqual = AIPSTask('DQUAL') dqual.indata = uvdata dqual.fqcenter = -1 dqual.go() if delete == True: uvdata.zap() uvdata = WizAIPSUVData(data_prefix, 'DQUAL', disk, 1) indxr = AIPSTask('INDXR') uvdata.zap_table('CL', 1) indxr.indata = uvdata indxr.cparm[3] = 0.25 indxr.go() if delete == True: uvdata.rename(data_prefix, 'UVDATA', 1) else: uvdata.rename(data_prefix, 'UVDATA', 2)
def antsortsn(inname='UVSIM', inclass='FITS', indi=1, inseq=1, invers=1): w = WizAIPSUVData(inname, inclass, indisk, inseq) sn = w.table('SN', invers) anno = 8 ### starting no of international station print 'i[refant]', i['refant_1'] for i in sn: #print 'i[refant]', i['refant_1']; #print 'i[antenna_no]', i['antenna_no']; #print 'anno: ', anno i['refant_1'] = 16 i['refant_2'] = 16 i['antenna_no'] = anno if anno == 16: anno = 8 else: anno = anno + 1 i.update()
def find_difmap_chan(inna, incl, indisk=1, inseq=1): INCR = 1 if incl == '': output = inna.split('/')[-1] if '/' in inna else inna try: AIPSUVData('DIFMAP', 'UVDATA', indisk, inseq).zap() print 'Removed DIFMAP.UVDATA.%d disk %d' % (inseq, indisk) except: pass fitld = AIPSTask('fitld') fitld.datain = inna if '/' in inna else './' + inna fitld.outname = 'DIFMAP' fitld.outclass = 'UVDATA' fitld.outdisk = indisk fitld.outseq = inseq fitld.go() inna, incl = 'DIFMAP', 'UVDATA' else: output = '%s_%s' % (inna, incl) data = WizAIPSUVData(inna, incl, indisk, inseq) for i in data: v = i.visibility na = np.asarray(np.ravel(v[:, :, 0, 0]), dtype='bool') try: a = na | a except: a = np.copy(na) bstart, bend = [], [] for i in range(len(a)): if (i == 0 and a[i]) or (i != 0 and a[i] and not a[i - 1]): bstart.append(i + 1) if (i != 0 and not a[i] and a[i - 1]): bend.append(i) if (a[i] and i == len(a) - 1): bend.append(len(a)) fo = open('dchan_%s' % (output), 'w') fo.write('select I,') for i in range(len(bstart)): fo.write('%d,%d' % (bstart[i], bend[i])) if i != len(bstart) - 1: fo.write(',') fo.write('\n') fo.close()
def find_chan_fits(infile, indisk=1, inseq=1): try: AIPSUVData('DIFMAP', 'UVDATA', indisk, inseq).zap() print('Removed DIFMAP.UVDATA.%d disk %d' % (inseq, indisk)) except: pass fitld = AIPSTask('fitld') fitld.datain = infile if '/' in infile else './' + infile fitld.outname = 'DIFMAP' fitld.outclass = 'UVDATA' fitld.outdisk = indisk fitld.outseq = inseq fitld.go() data = WizAIPSUVData('DIFMAP', 'UVDATA', indisk, inseq) for i in data: v = i.visibility na = np.asarray(np.ravel(v[:, :, 0, 0]), dtype='bool') try: a = na | a except: a = np.copy(na) return a
def closure_aips(aipsno, triangle, inna, incl, indisk=1, inseq=1, minmatch=5, ipol=0, dt=0.5, spw=0): AIPS.userno = aipsno data = WizAIPSUVData(inna, incl, indisk, inseq) antnum = np.array([], dtype='int') for i in range(3): foundit = False for j in range(len(data.antennas)): tellen = min(len(data.antennas[j]), len(triangle[i])) if tellen < minmatch: if triangle[i][:tellen] == data.antennas[j][:tellen]: foundit = True antnum = np.append(antnum, j + 1) break else: if triangle[i][:minmatch] == data.antennas[j][:minmatch]: foundit = True antnum = np.append(antnum, j + 1) break antnum = np.sort(antnum) print '***', antnum isbase = [[antnum[0], antnum[1]], [antnum[1], antnum[2]], [antnum[0], antnum[2]]] icou, nvis = 0, len(data) d = [np.array([]), np.array([]), np.array([])] t = [np.array([]), np.array([]), np.array([])] for v in data: if v.baseline in isbase: vwhich = isbase.index(v.baseline) else: continue print '***uuu', v.visibility vvis = v.visibility vv = vvis.reshape(vvis.shape[0] * vvis.shape[1], vvis.shape[2], vvis.shape[3]) vphas = np.arctan2(vv[:, ipol, 1], vv[:, ipol, 0]) np.putmask(vphas, vv[:, ipol, 2] == 0.0, np.nan) try: d[vwhich] = np.vstack((d[vwhich], vphas)) t[vwhich] = np.append(t[vwhich], 86400. * v.time) except: d[vwhich] = np.copy(vphas) t[vwhich] = np.append(t[vwhich], 86400. * v.time) icou += 1 if icou % 100000 == 0: print 'Visibility %d/%d' % (icou, nvis) tu = np.sort(np.unique(np.append(t[0], np.append(t[1], t[2])))) print tu for i in range(2): tu_diff = np.append(np.array([1.0E9]), np.diff(tu)) tu = tu[tu_diff > dt] # print len(t[0]),len(t[1]),len(t[2]),'********' for i in range(3): if len(t[i]) == len(tu): continue j = 0 k = 0 kmiss = [] dummy = np.ones_like(d[i][0]) * np.nan while j < len(tu) and k < len(t[i]): if abs(tu[j] - t[i][k]) < dt: j += 1 k += 1 else: kmiss.append(k) d[i] = np.insert(d[i], j + 1, dummy, axis=0) j += 1 while len(d[i]) < len(tu): # missing data at the end d[i] = np.insert(d[i], len(d[i]), dummy, axis=0) np.save('d0_aips', d[0]) np.save('d1_aips', d[1]) np.save('d2_aips', d[2]) from scipy.fftpack import * p = np.asarray(d[0] + d[1] - d[2], dtype='float') np.putmask(p, p > np.pi, p - 2. * np.pi) # no need to worry about nans np.putmask(p, p < -np.pi, p + 2. * np.pi) prand = np.random.random(p.shape[0] * p.shape[1]).reshape( p.shape) * 2 * np.pi - np.pi np.putmask(p, np.isnan(p), prand) pp = np.cos(p) + 1j * np.sin(p) pprand = np.cos(prand) + 1j * np.sin(prand) qbig = fftshift(fft2(pp)) qbigrand = fftshift(fft2(pprand)) yr = (qbig.shape[0] / 2 - 30, qbig.shape[0] / 2 + 30) xr = (qbig.shape[1] / 2 - 30, qbig.shape[1] / 2 + 30) q = qbig[yr[0]:yr[1], xr[0]:xr[1]] qrand = qbigrand[yr[0]:yr[1], xr[0]:xr[1]] qq = np.sort(np.ravel(abs(q))) qqrand = np.sort(np.ravel(abs(qrand))) x, y = np.arange(-30, 30), np.arange(-30, 30) xx, yy = np.meshgrid(x, y) z = np.hypot(xx, yy) maxsig = 0.0 for i in range(3, 30): zz = np.zeros_like(z) np.putmask(zz, z < i, 1.0) sig = ((zz*abs(q)).sum()-(zz*abs(qrand)).sum()) \ /(np.std(abs(qrand))*np.sqrt(zz.sum())) maxsig = max(maxsig, sig) # plt.subplot(121);plt.imshow(abs(qrand));plt.subplot(122);plt.imshow(abs(q));plt.show() return maxsig, q, p
def panelplot(sd, aipsname, intl_antennas, intl_name, times, refant, ra, dec): ny, nx = len(intl_antennas), 6 fftsn = np.zeros((ny, 2)) pltsquash = 0.5 * float(sd.shape[3]) / float(sd.shape[2]) for pol in [0, 1]: for i in range(ny): wdata = WizAIPSUVData(aipsname, 'FITS', 1, 1) d, uvw, tjunk = dget(wdata, np.array([intl_antennas[i], refant])) plt.subplot(nx, ny, i + 1, xticks=[], yticks=[]) if d != []: dq, val = dqual(d[0], clip=True) if dq == 'A': np.putmask(d[0][pol], abs(d[0][pol]) > CLIP * val, val + 0.0j) plt.imshow(np.arctan2(d[0][pol].imag, d[0][pol].real)) # plt.imshow(abs(d[0][pol])) if i == 2: plt.title(aipsname + ' ' + ra + ' ' + dec) plt.subplot(nx, ny, i + 1 + ny, xticks=[], yticks=[]) if d != []: dfft = abs(fft.fftshift(fft.fft2(d[0][pol]))) fftsn[i, pol] = get_fftsn(dfft) plt.imshow(np.sqrt(dfft), cmap=matplotlib.cm.gray_r) plt.subplot(nx, ny, i + 1 + 2 * ny, xticks=[], yticks=[]) plt.plot(times, sd[i, 0, 0, :, pol], 'b+') meddelay = np.nanmedian(sd[i, 0, 0, :, pol]) meddelay = meddelay if meddelay < 3.e6 else 0 if meddelay: plt.text(times[0], meddelay - 50, str(int(meddelay))) plt.ylim(meddelay - 50., meddelay + 50) plt.subplot(nx, ny, i + 1 + 3 * ny, xticks=[], yticks=[]) phx = times[~np.isnan(sd[i, 1, 0, :, pol])] phy = sd[i, 1, 0, :, pol][~np.isnan(sd[i, 1, 0, :, pol])] medphase = np.median(np.unwrap(phy)) plt.plot(phx, phy, 'b+') # plt.ylim(medphase-2.0,medphase+2.0) wdata = WizAIPSUVData(aipsname, 'SPLIT', 1, 1) d, uvw, tjunk = dget(wdata, np.array([intl_antennas[i], refant])) if d != []: dq, val = dqual(d[0], clip=True) if dq == 'A': np.putmask(d[0][pol], abs(d[0][pol]) > CLIP * val, val + 0.0j) plt.subplot(nx, ny, i + 1 + 4 * ny, xticks=[], yticks=[]) try: plt.imshow(np.arctan2(d[0][pol].imag, d[0][pol].real)) except: print 'No calibrated data on ', intl_antennas[i] flog = open(FLOG, 'a') flog.write('No calibrated data on %s\n' % str(intl_antennas[i])) flog.close() plt.subplot(nx, ny, i + 1 + 5 * ny, xticks=[], yticks=[]) try: plt.imshow(np.sqrt(abs(fft.fftshift(fft.fft2(d[0][pol])))), cmap=matplotlib.cm.gray_r) except: pass plt.xlabel(intl_name[i]) plt.savefig(pngdir + aipsname + ('R' if pol else 'L') + '.png', bbox_inches='tight') plt.clf() return 0.5 * (fftsn[:, 0] + fftsn[:, 1])
try: nif = len(fq[0]['if_freq']) except: nif = 1 source = su[0]['source'].rstrip() pfring_antennas,pfring_name,pfring_qual,intl_antennas,intl_name,\ refant = [],[],[],[],[],-1 for i in an: # Find the reference antenna annew = i['anname'].strip('HBA').strip('LBA')[:5] if annew in SUPERTERP: refant = i['nosta'] refant_name = annew if refant == -1: # No reference antenna print 'Aborting; no reference antenna found' sys.exit() wdata = WizAIPSUVData(aipsname, 'FITS', 1, 1) for i in an: annew = i['anname'].strip('HBA').strip('LBA')[:5] if annew in fring_antennas: if i['nosta'] != refant: d, uvw, tjunk = dget(wdata, np.array([i['nosta'], refant])) if not d[0].sum(): # No data on this antenna print 'No data on antenna', i['nosta'] flog = open(FLOG, 'a') flog.write('No data on antenna %s\n' % str(i['nosta'])) flog.close() continue intl_antennas.append(i['nosta']) intl_name.append(annew) pfring_antennas.append(i['nosta']) pfring_name.append(annew)
uvsub.in2data = imagedatacl uvsub.inver = 1 uvsub.outdisk = indisk uvsub.ncomp[1] = -1000000 uvsub.opcode = 'DIV' uvsub.go() uvdata = AIPSUVData(uvname[i], 'UVSUB', indisk, 1) #wtmod = AIPSTask('WTMOD') #change weight relative to amplitude adjustments #wtmod.indata = uvdata #wtmod.aparm[1] = (maxamplitude(uvname[i])**2)*(10**10) #wtmod.outdisk = indisk #wtmod.go() #uvdata = AIPSUVData(uvname[i],'WTMOD',2,1) uvdata2 = WizAIPSUVData(uvname[i], 'UVSUB', indisk, 1) uvdata2.header['crval'][4] = pointcenRA uvdata2.header.update() uvdata2.header['crval'][5] = pointcenDEC uvdata2.header.update() uvdata.rename(name='COMBO', klass='UV', seq=0) if len(uvname) > 1: dbapp = AIPSTask('DBAPP') uvdata = AIPSUVData('COMBO', 'UV', indisk, 1) dbapp.inname = 'COMBO' dbapp.inclass = 'UV' dbapp.indisk = indisk dbapp.inseq = 2 dbapp.in2seq = len(uvname) dbapp.outdata = uvdata dbapp.outdisk = indisk
imean.indisk = indisk imean.doprint = 1 imean.outtext = 'PWD:IMEAN_%s.txt' % UV_files[i] imean() uvsub = AIPSTask('UVSUB') #Divide visibilites by clean model! uvsub.indata = uvdata uvsub.nmaps = 1 uvsub.in2data = imagedatacl uvsub.inver = 1 uvsub.outdisk = indisk uvsub.ncomp[1] = -1000000 uvsub.opcode = 'DIV' uvsub.go() uvdata = WizAIPSUVData('A%s' % i, 'UVSUB',indisk,1) uvdata.header['crval'][4] = pointcenRA uvdata.header.update() uvdata.header['crval'][5] = pointcenDEC uvdata.header.update() uvdata.rename(name='COMBO',klass='UV', seq=0) os.system('rm %s' % UV_files[i]) update_progress(total/total_progress) if use_DBAPP == 'True': dbapp = AIPSTask('DBAPP') uvdata = WizAIPSUVData('COMBO','UV',indisk,1) dbapp.inname = 'COMBO' dbapp.inclass = 'UV' dbapp.indisk = indisk dbapp.inseq = 2
mystep = 1 ## e.g. this step will load data in directory /Users/jackradcliffe/Documents/EG078E_calibration/calibration/ called eg078e_1_1.IDI' if (mystep in thesteps): print 'Step ', mystep, step_title[mystep] ## FITLD loads data fitld = AIPSTask('FITLD') ## initilise task first (same name as in AIPS) fitld.datain = pwd + data_prefix + '_1_1.IDI' ## set inputs, same as in AIPS! fitld.outdisk = disk fitld.digicor = -1 fitld.doconcat = 1 fitld.outname = data_prefix fitld.ncount = 3 fitld.go() ## <taskname>.go() will run task with inputs above #sort the data into time-baseline order uvdata = WizAIPSUVData(data_prefix, 'UVDATA', disk, 1) ## Parseltongue has these special variables ### which hold the names of data. It is of the form WizAIPSUVData(name,class,disk,seq) look at AIPS catalogue using command pcat ## Uvsrt sorts it in time-baseline order uvsrt = AIPSTask('UVSRT') uvsrt.indata = uvdata ##special input of <taskname>.indata is equivalent to the AIPS getn <num> command but you use the WizAIPSUVData type i.e. uvdata in this case uvsrt.outdata = uvdata ## same as above but AIPS command geton <num> uvsrt.sort = 'TB' uvsrt.go() ## dont worry about this dqual = AIPSTask('DQUAL') dqual.indata = uvdata dqual.fqcenter = -1 dqual.go() if delete == True:
break if s == 'no' or s=='n': sys.exit('Please restate the mysteps parameter') if (thesteps==[]): thesteps = range(0,len(step_title)) print 'Executing all steps: ', thesteps mystep = 1 if(mystep in thesteps): print 'Step ', mystep, step_title[mystep] eg.run_load_sort(pwd=pwd,data_prefix=data_prefix,delete=True,disk=disk) mystep = 2 uvdata = WizAIPSUVData(data_prefix,'UVDATA',disk,1) tasav = WizAIPSUVData('pipe_TSAV','TASAV',disk,1) if(mystep in thesteps): print 'Step ', mystep, step_title[mystep] eg.amplitude_calibration_EVN(uvdata,tasav,disk,refant,sources,snedt_amp) mystep = 3 if(mystep in thesteps): print 'Step ', mystep, step_title[mystep] #eg.initial_flag(uvdata,tasav,disk,refant) eg.eg078e_specific_flagging(uvdata,tasav,disk,refant) mystep = 4 if(mystep in thesteps): print 'Step ', mystep, step_title[mystep]
uvsub.inver = 1 uvsub.outdisk = 2 uvsub.ncomp[1] = -1000000 uvsub.opcode = 'DIV' uvsub.go() uvdata = AIPSUVData(uvname[i], 'UVSUB', 2, 1) wtmod = AIPSTask( 'WTMOD') #change weight relative to amplitude adjustments wtmod.indata = uvdata wtmod.aparm[1] = (maxamplitude(uvname[i])**2) * (10**10) wtmod.outdisk = 2 wtmod.go() uvdata = AIPSUVData(uvname[i], 'WTMOD', 2, 1) uvdata2 = WizAIPSUVData(uvname[i], 'WTMOD', 2, 1) uvdata2.header['crval'][4] = pointcenRA uvdata2.header.update() uvdata2.header['crval'][5] = pointcenDEC uvdata2.header.update() uvdata.rename(name='COMBO', klass='UV', seq=0) if len(uvname) > 1: dbapp = AIPSTask('DBAPP') uvdata = AIPSUVData('COMBO', 'UV', 2, 1) dbapp.inname = 'COMBO' dbapp.inclass = 'UV' dbapp.indisk = 2 dbapp.inseq = 2 dbapp.in2seq = len(uvname) dbapp.outdata = uvdata dbapp.outdisk = 2
tumin -= 60 if tlsec < 0: tlmin -= 1 tlsec += 60 if tlmin < 0: tlhr -= 1 tlmin += 60 return np.array([tday, tlhr, tlmin, tlsec, tday, tuhr, tumin, tusec]) # syntax: checkregular userno inna incl indisk inseq inna = sys.argv[2] incl = sys.argv[3] indisk = 1 if len(sys.argv) < 5 else int(sys.argv[4]) inseq = 1 if len(sys.argv) < 6 else int(sys.argv[5]) w = WizAIPSUVData(inna, incl, indisk, inseq) times = [] nant = float(len(w.antennas)) nbas = int((nant - 1.) * 0.5 * nant) for wi in w: times.append(wi.time) # Get array of times from the data utime = np.unique(np.asarray(times, dtype='f')) for u in utime: if times.count(u) != nbas: print u, times.count(u) new = time2timera(u) try: flg = np.vstack((flg, new))
urlretrieve(url, file) assert (os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) if uvdata.exists(): uvdata.zap() fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = uvdata fitld.msgkill = 2 fitld.go() try: uvdata = WizAIPSUVData(name, 'UVDATA', 1, 1) antable = uvdata.table('AN', 0) arrnam = antable.keywords['ARRNAM'] assert (arrnam.strip() == 'EVN') assert (antable.keywords['FREQID'] == -1) assert (antable.keywords['FREQ'] == 1642490000.0) assert (antable.keywords['IATUTC'] != 33.0) antable.keywords['ARRNAM'] = 'VLBA' antable.keywords['FREQID'] = 1 antable.keywords['FREQ'] = 4974990000.0 antable.keywords['IATUTC'] = 33.0 antable.keywords['E'] = math.e antable.keywords['OPERATOR'] = 'NRAO' antable.close()
def fringemap(aipsno, aipsname, intl_name, refant, imaxoff=0.0, \ aipsclass= 'FITS', utstart=0, utstop=0, utinc=0, fsiz=256, \ dofilt = False, indisk=1, fridir='./', w_max=1000., zap=True, logdir='./'): AIPS.userno = aipsno #if zap: # print 'Removing all files beginning FR_ from directory '+fridir # os.system('rm '+fridir+'FR_*') wdata = WizAIPSUVData(aipsname, aipsclass, indisk, 1) intl_antennas, status = procants(intl_name, AIPSUVData(wdata)) refant, status = procants([refant], AIPSUVData(wdata)) if status: return h = wdata.header ra = h['crval'][h['ctype'].index('RA')] dec = h['crval'][h['ctype'].index('DEC')] npol = min(h['naxis'][h['ctype'].index('STOKES')], 2) # only ll,rr #nc = h['naxis'][h['ctype'].index('FREQ')]*h['naxis'][h['ctype'].index('IF') nc = h['naxis'][h['ctype'].index('FREQ')] f0 = h['crval'][h['ctype'].index('FREQ')] chw = h['cdelt'][h['ctype'].index('FREQ')] uvfac = 1.0 + 0.5 * chw * (nc - 1) / f0 # converts uvw to centre of band baseline = np.dstack((intl_antennas, list(refant) * len(intl_antennas)))[0] baseline = np.array([baseline]) if baseline.ndim == 1 else baseline for i in range(len(baseline)): baseline[i] = np.sort(baseline[i]) utstart = wdata[0].time - 0.0001 if utstart == 0.0 else utstart if utstop == 0.0: try: # quicker if NX table exists nx = AIPSUVData(wdata).table('NX', 0) utstop = nx[len(nx) - 1].time + 0.5 * nx[len(nx) - 1].time_interval + 0.0001 except: # find time of last visibility, can be slow print 'No NX table, so checking for end time manually....' utstop = wdata[len(wdata) - 1].time if utinc == 0.0: # doing the whole file Utstart, Utstop = [utstart], [utstop] else: # setup array of start and stop times for each chunk Utstart = np.arange(utstart, utstop, utinc) Utstop = Utstart + utinc if Utstop[-1] > utstop: # avoid truncated one at the end Utstart, Utstop = Utstart[:-1], Utstop[:-1] print 'Time range: %.4f %.4f, intervals %d' % (utstart, utstop, len(Utstart)) # v0,v1 = visstart (wdata, u0, -1), visstart (wdata, u1, +1) # ------------------ ui = -1 amap = np.array([]) for visibility in wdata: vtime = visibility.time if vtime < Utstart[0]: continue elif vtime >= Utstart[0] and vtime < Utstop[-1]: for j in range(len(Utstart)): if Utstart[j] <= vtime < Utstop[j]: this_ui = j if this_ui != ui: ui = this_ui if ui: amap,maxoff = proc_chunk (d,u,times,baseline,Utstart[ui],\ Utstop[ui],uvfac,npol,intl_antennas,h,imaxoff,\ fsiz,dofilt,fridir,aipsname,intl_name,\ logdir,ra,dec,amap) d = [np.array([])] * len(baseline) u = [np.array([])] * len(baseline) times = [np.array([])] * len(baseline) else: continue_chunk(visibility, baseline, nc, npol, d, u, times) # elif vtime > Utstop[-1]: # amap,maxoff = proc_chunk (d,u,times,baseline,Utstart[-1],Utstop[-1],uvfac,\ # npol,intl_antennas,h,imaxoff,fsiz,dofilt,\ # fridir,aipsname,intl_name,logdir,ra,dec,amap) # break else: print 'WTF?' amap,maxoff = proc_chunk (d,u,times,baseline,Utstart[-1],Utstop[-1],uvfac,\ npol,intl_antennas,h,imaxoff,fsiz,dofilt,\ fridir,aipsname,intl_name,logdir,ra,dec,amap) np.save('amap', amap) if imaxoff != 0.0: amap = np.rollaxis(amap, 2, 0) acomb = imcomb(amap) writeit(acomb, ra, dec, fsiz, maxoff, 'fring.fits') pload('./fring.fits', aipsname, indisk, 'IMAP', logdir=logdir, doindxr=False) b = np.ravel(acomb) b = np.sort(b[~np.isnan(b)]) bmin, bmax = b[len(b) / 10], b[99 * len(b) / 100] addwenss (aipsname,indisk,ra,dec,maxoff,bmin,bmax,w_max=w_max,\ fridir=fridir,logdir=logdir) for name in intl_name: nlist, ncube = np.sort(glob.glob(fridir + 'FR_*' + name + '_*.fits')), np.array([]) for nfile in nlist: try: ncube = np.dstack((ncube, getdata(nfile))) except: ncube = np.copy(getdata(nfile)) h = getheader(nfile) ncube = np.rollaxis(ncube, 2, 0) ncomb = imcomb(ncube) thisname = fridir + 'FR_' + aipsname + '_' + name + '.fits' writeit (ncomb,h['CRVAL1'],h['CRVAL2'],h['NAXIS1'],\ h['NAXIS1']*h['CDELT2'],thisname) pload (thisname,aipsname[:7]+name[:5],indisk,'IMAP',\ logdir=logdir,doindxr=False) b = np.ravel(ncomb) b = np.sort(b[~np.isnan(b)]) bmin, bmax = b[len(b) / 10], b[99 * len(b) / 100]
fitld.msgkill = 2 fitld.go() assert (uvdata.exists()) try: count = 0 for record in uvdata.history: print(record) if record[0:5] == 'FITLD': count += 1 pass continue assert (count > 5) uvdata = WizAIPSUVData(uvdata) history = uvdata.history history.append('Something new!') history.close() uvdata = AIPSUVData(uvdata) seen = 0 for record in uvdata.history: print(record) if record[0:5] == 'Somet': seen = 1 pass continue assert (seen) finally:
import os import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N03L1_030225/fits/n03l1_1_1.IDI1' file = '/tmp/' + os.path.basename(url) if not os.path.isfile(file): urllib.urlretrieve(url, file) assert (os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) if uvdata.exists(): uvdata.zap() fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = uvdata fitld.douvcomp = 0 fitld.msgkill = 2 fitld.go() uvdata = WizAIPSUVData(name, 'UVDATA', 1, 1, AIPS.userno) for vis in uvdata: vis.visibility[0][0][0][2] = 1.234 vis.update() continue
def dfluxpy(freq, uvdata): "Function to calculate 3C286 values, modified from Danielle's dfluxpy.py." "Updated 20140506 to include new coefficients and a calculation for projected" "baseline length from inspecting the u's and v's." data = WizAIPSUVData(uvdata.name, uvdata.klass, uvdata.disk, uvdata.seq) antab = data.table('AN', 1) numLO = 10 numM2 = 10 for row in antab: # Ignore the Lovell baselines if 'Lo' in row.anname: numLO = row.nosta if 'Mk2' in row.anname: numM2 = row.nosta u = [] v = [] proj = [] basel = [] baseline = 10000000 for visibility in data: if (visibility.baseline != [numLO, numM2]) and (visibility.baseline != [numM2, numLO]): u.append(visibility.uvw[0]) v.append(visibility.uvw[1]) newbasel = (299792458.0 / data.header.crval[2]) * math.sqrt( (visibility.uvw[0]**2) + (visibility.uvw[1]**2)) proj.append(newbasel) if newbasel < baseline: baseline = newbasel basel = visibility.baseline antab = data.table('AN', 1) for row in antab: if row.nosta == basel[0]: ant1 = row.anname for row in antab: if row.nosta == basel[1]: ant2 = row.anname print "For projected baseline", baseline / 1000, "km, between", ant1, "and", ant2 # Perley & Butler 2012 values A = 1.2515 B = -0.4605 C = -0.1715 D = 0.0336 log10f = (math.log(freq) / 2.3025851) - 3.0 # Why the -3? Because freq has to be GHz for the formula to work. log_flux = A + B * log10f + C * log10f * log10f + D * log10f * log10f * log10f vlaflux = math.pow(10.0, log_flux) ref_bl_length = 11236.79 # MK-TA separation in metres. ref_freq = 5000.0 ref_rho = 0.04 bl_length = baseline frac = (freq / ref_freq) * (bl_length / ref_bl_length) rho = frac * frac * ref_rho merlinflux = vlaflux / (1.0 + rho) print "\tfor IF with freq =", freq, ", e-MERLIN flux =", merlinflux return merlinflux