def CompareUV(uvFile1, uvFile2, err, verbose=True): """ Compare UV FITS files *uvFile1* and *uvFile2*. * uvFile1, uvFile2 = UV FITS files to be compared * err = OErr object """ uv1 = UV.newPFUV('uv1', uvFile1, 0, True, err) uv2 = UV.newPFUV('uv2', uvFile2, 0, True, err) rms = UV.PUtilVisCompare(uv1, uv2, err) if verbose: print("UV data set 1: " + uvFile1) print("UV data set 2: " + uvFile2) print("RMS of real, imag differences / amplitude of data set 2 =\n%6i" % (rms))
def VLAUVLoad(filename, inDisk, Aname, Aclass, Adisk, Aseq, err, logfile=''): """ Read FITS uvtab file into AIPS Read a UVTAB FITS UV data file and write an AIPS data set filename = name of FITS file inDisk = FITS directory number Aname = AIPS name of file Aclass = AIPS class of file Aseq = AIPS sequence number of file, 0=> create new Adisk = FITS directory number err = Python Obit Error/message stack logfile = logfile for messages returns AIPS UV data object """ ################################################################ # # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # # Get input inUV = UV.newPFUV("FITS UV DATA", filename, inDisk, True, err) if err.isErr: OErr.printErrMsg(err, "Error with FITS data") # Get output, create new if seq=0 if Aseq<1: OErr.printErr(err) # Print any outstanding messages user = OSystem.PGetAIPSuser() Aseq=AIPSDir.PHiSeq(Adisk,user,Aname,Aclass,"MA",err) # If it already exists, increment seq if AIPSDir.PTestCNO(Adisk,user,Aname,Aclass,"MA",Aseq,err)>0: Aseq = Aseq+1 OErr.PClear(err) # Clear any message/error mess = "Creating AIPS UV file "+Aname+"."+Aclass+"."+str(Aseq)+" on disk "+str(Adisk) printMess(mess, logfile) outUV = UV.newPAUV("AIPS UV DATA", Aname, Aclass, Adisk, Aseq, False, err) if err.isErr: OErr.printErrMsg(err, "Error creating AIPS data") # Copy UV.PCopy (inUV, outUV, err) if err.isErr: OErr.printErrMsg(err, "Error copying UV data to AIPS") # Copy History inHistory = History.History("inhistory", inUV.List, err) outHistory = History.History("outhistory", outUV.List, err) History.PCopyHeader(inHistory, outHistory, err) # Add history outHistory.Open(History.READWRITE, err) outHistory.TimeStamp(" Start Obit uvlod",err) outHistory.WriteRec(-1,"uvlod / FITS file "+filename+" disk "+str(inDisk),err) outHistory.Close(err) # # Copy Tables exclude=["AIPS HI", "AIPS AN", "AIPS FQ", "AIPS SL", "AIPS PL", "History"] include=[] UV.PCopyTables (inUV, outUV, exclude, include, err) return outUV # return new object
def VLAUVFITS(inUV, filename, outDisk, err, compress=False, \ exclude=["AIPS HI", "AIPS AN", "AIPS FQ", "AIPS SL", "AIPS PL"], \ include=[], headHi=False): """ Write UV data as FITS file Write a UV data set as a FITAB format file History written to header inUV = UV data to copy filename = name of FITS file inDisk = FITS directory number err = Python Obit Error/message stack exclude = List of table types NOT to copy NB: "AIPS HI" isn't really a table and gets copied anyway include = List of table types to copy (FQ, AN always done ) Exclude has presidence over include headHi = if True move history to header, else leave in History table returns FITS UV data object """ ################################################################ # Checks if not UV.PIsA(inUV): raise TypeError, "inUV MUST be a Python Obit UV" if not OErr.OErrIsA(err): raise TypeError, "err MUST be an OErr" # # Set output outUV = UV.newPFUV("FITS UV DATA", filename, outDisk, False, err) if err.isErr: OErr.printErrMsg(err, "Error creating FITS data") #Compressed? if compress: inInfo = UV.PGetList(outUV) # dim = [1, 1, 1, 1, 1] InfoList.PAlwaysPutBoolean(inInfo, "Compress", dim, [True]) # Copy UV.PCopy(inUV, outUV, err) if err.isErr: OErr.printErrMsg(err, "Error copying UV data to FITS") # History inHistory = History.History("inhistory", outUV.List, err) outHistory = History.History("outhistory", outUV.List, err) # Add history outHistory.Open(History.READWRITE, err) outHistory.TimeStamp(" Start Obit uvtab", err) outHistory.WriteRec( -1, "uvtab / FITS file " + filename + " disk " + str(outDisk), err) outHistory.Close(err) # History in header? if headHi: History.PCopy2Header(inHistory, outHistory, err) OErr.printErrMsg(err, "Error with history") # zap table outHistory.Zap(err) # Copy Tables UV.PCopyTables(inUV, outUV, exclude, include, err) return outUV # return new object
def VLAUVFITS(inUV, filename, outDisk, err, compress=False, \ exclude=["AIPS HI", "AIPS AN", "AIPS FQ", "AIPS SL", "AIPS PL"], \ include=[], headHi=False): """ Write UV data as FITS file Write a UV data set as a FITAB format file History written to header inUV = UV data to copy filename = name of FITS file inDisk = FITS directory number err = Python Obit Error/message stack exclude = List of table types NOT to copy NB: "AIPS HI" isn't really a table and gets copied anyway include = List of table types to copy (FQ, AN always done ) Exclude has presidence over include headHi = if True move history to header, else leave in History table returns FITS UV data object """ ################################################################ # Checks if not UV.PIsA(inUV): raise TypeError,"inUV MUST be a Python Obit UV" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # # Set output outUV = UV.newPFUV("FITS UV DATA", filename, outDisk, False, err) if err.isErr: OErr.printErrMsg(err, "Error creating FITS data") #Compressed? if compress: inInfo = UV.PGetList(outUV) # dim = [1,1,1,1,1] InfoList.PAlwaysPutBoolean (inInfo, "Compress", dim, [True]) # Copy UV.PCopy (inUV, outUV, err) if err.isErr: OErr.printErrMsg(err, "Error copying UV data to FITS") # History inHistory = History.History("inhistory", outUV.List, err) outHistory = History.History("outhistory", outUV.List, err) # Add history outHistory.Open(History.READWRITE, err) outHistory.TimeStamp(" Start Obit uvtab",err) outHistory.WriteRec(-1,"uvtab / FITS file "+filename+" disk "+str(outDisk),err) outHistory.Close(err) # History in header? if headHi: History.PCopy2Header (inHistory, outHistory, err) OErr.printErrMsg(err, "Error with history") # zap table outHistory.Zap(err) # Copy Tables UV.PCopyTables (inUV, outUV, exclude, include, err) return outUV # return new object
def _init(self, desc, verbose=True): # Open with full path in disk 0 disk = 0 path = desc['dirname']+"/"+desc['filename'] uvdata = UV.newPFUV(desc['filename'], path, disk, True, self.err, verbose = verbose) if not uvdata.isOK: # Exception if something went wrong raise OErr.OErr OErr.printErrMsg(self.err, "Error with FITSUVdata") return uvdata
def getFITS(file, disk=Adisk, Ftype='Image'): """ Return Obit object for FITS file in file on disk file = FITS file name disk = FITS disk number Ftype = FITS data type: 'Image', 'UV' """ ################################################################ if Ftype == 'Image': out = Image.newPFImage("FITS image", file, disk, True, err) elif Ftype == 'UV': out = UV.newPFUV("FITS UV data", file, disk, True, err) out.Fname = file out.Disk = disk out.Otype = Ftype return out
def getFITS(file, disk=Adisk, Ftype='Image'): """ Return Obit object for FITS file in file on disk * file = FITS file name * disk = FITS disk number * Ftype = FITS data type: 'Image', 'UV' """ ################################################################ if Ftype == 'Image': out = Image.newPFImage("FITS image", file, disk, True, err) elif Ftype == 'UV': out = UV.newPFUV("FITS UV data", file, disk, True, err) out.Fname = file out.Disk = disk out.Otype = Ftype return out
def VLAPolCal(uv, InsCals, RLCal, RLPhase, err, RM=0.0, \ doCalib=2, gainUse=0, flagVer=-1, \ soltype="APPR", fixPoln=False, avgIF=False, \ solInt=0.0, refAnt=0, \ pmodel=[0.0,0.0,0.0,0.0,0.0,0.0,0.0], \ FOV=0.05, niter = 100, \ nThreads=1, noScrat=[], logfile = ""): """ Polarization calibration, both instrumental and orientation Do Instrumental and R-L calibration Instrumental cal uses PCAL, R-L cal is done by imaging each IF in Q and U and summing the CLEAN components. uv = UV data object to calibrate InsCals = Instrumental poln calibrators, name or list of names If None no instrumental cal RLCal = R-L (polarization angle) calibrator, If None no R-L cal RLPhase = R-L phase of RLCal (deg) at 1 GHz err = Obit error/message stack RM = Rotation measure of RLCal doCalib = Apply prior calibration table, positive=>calibrate gainUse = CL/SN table to apply flagVer = Input Flagging table version soltype = solution type fixPoln = if True, don't solve for source polarization in ins. cal avgIF = if True, average IFs in ins. cal. solInt = instrumental solution interval (min), 0=> scan average refAnt = Reference antenna pmodel = Instrumental poln cal source poln model. pmodel[0] = I flux density (Jy) pmodel[1] = Q flux density (Jy) pmodel[2] = U flux density (Jy) pmodel[3] = V flux density (Jy) pmodel[4] = X offset in sky (arcsec) pmodel[5] = Y offset in sky (arcsec) FOV = field of view radius (deg) needed to image RLCal niter = Number of iterations of CLEAN in R-L cal nThreads = Number of threads to use in imaging noScrat = list of disks to avoid for scratch files logfile = Log file for task """ ################################################################ # Instrumental calibrtation if InsCals != None: pcal = AIPSTask.AIPSTask("pcal") pcal.logFile = logfile setname(uv, pcal) if type(InsCals) == list: pcal.calsour[1:] = InsCals else: pcal.calsour[1:] = [InsCals] pcal.docalib = doCalib pcal.gainuse = gainUse pcal.flagver = flagVer pcal.soltype = soltype pcal.solint = solInt pcal.refant = refAnt if fixPoln: pcal.bparm[10] = 1.0 if avgIF: pcal.cparm[1] = 1.0 pcal.pmodel[1:] = pmodel pcal.i pcal.g # end instrumental poln cal # R-L phase cal if RLCal != None: img = ObitTask.ObitTask("Imager") img.logFile = logfile setname(uv, img) img.doCalib = doCalib img.gainUse = gainUse img.flagVer = flagVer img.doPol = True img.Sources[0] = RLCal img.Stokes = "IQU" img.FOV = FOV img.Niter = niter img.autoWindow = True img.dispURL = "None" img.Catalog = "None" img.nThreads = nThreads img.noScrat = noScrat # Temporary output files if img.DataType == "AIPS": img.outName = "TEMP" img.outClass = "IPOLCL" img.outDisk = img.inDisk img.outSeq = 6666 img.out2Name = "TEMP" img.out2Class = "IPOLCL" img.out2Disk = img.inDisk img.out2Seq = 7777 elif img.DataType == "FITS": img.outFile = "TEMPPOLCAL.fits" img.outDisk = img.inDisk img.out2File = "TEMPPOLCAL2.uvtab" img.out2Disk = img.inDisk # How many IFs? h = uv.Desc.Dict if h["jlocif"] >= 0: nif = h["inaxes"][h["jlocif"]] else: nif = 1 # Lists of flux densities and RMSes IFlux = [] IRMS = [] QFlux = [] QRMS = [] UFlux = [] URMS = [] # Loop over IF imaging I,Q, U for iif in range(1, nif + 1): img.BIF = iif img.EIF = iif #img.dispURL = "ObitView" # DEBUG #img.debug=True # DEBUG img.g # Get fluxes from inner quarter of images if img.DataType == "AIPS": outName = (img.Sources[0].strip() + "TEMP")[0:12] outDisk = img.outDisk outSeq = 6666 # Stokes I outClass = "IPOLCL" x = Image.newPAImage("I", outName, outClass, outDisk, outSeq, True, err) h = x.Desc.Dict blc = [h["inaxes"][0] / 4, h["inaxes"][1] / 4] trc = [3 * h["inaxes"][0] / 4, 3 * h["inaxes"][1] / 4] stat = imstat(x, err, blc=blc, trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes Q outClass = "QPOLCL" x = Image.newPAImage("Q", outName, outClass, outDisk, outSeq, True, err) stat = imstat(x, err, blc=blc, trc=trc) QFlux.append(stat["Flux"]) QRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes U outClass = "UPOLCL" x = Image.newPAImage("U", outName, outClass, outDisk, outSeq, True, err) stat = imstat(x, err, blc=blc, trc=trc) UFlux.append(stat["Flux"]) URMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Delete UV output out2Name = (img.Sources[0].strip() + "TEMP")[0:12] out2Class = "IPOLCL" out2Disk = img.inDisk out2Seq = 7777 u = UV.newPAUV("UV", out2Name, out2Class, out2Disk, out2Seq, True, err) u.Zap(err) del u elif img.DataType == "FITS": # Stokes I outFile = img.Sources[0].strip() + "ITEMPPOLCAL.fits" x = Image.newPFImage("I", outFile, img.outDisk, True, err) h = x.Desc.Dict blc = [h["inaxes"][0] / 4, h["inaxes"][1] / 4] trc = [3 * h["inaxes"][0] / 4, 3 * h["inaxes"][1] / 4] stat = imstat(x, err, blc=blc, trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes Q outFile = img.Sources[0].strip() + "ITEMPPOLCAL.fits" x = Image.newPFImage("Q", outFile, img.outDisk, True, err) stat = imstat(x, err, blc=blc, trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes U outFile = img.Sources[0].strip() + "ITEMPPOLCAL.fits" x = Image.newPFImage("Q", outFile, img.outDisk, True, err) stat = imstat(x, err, blc=blc, trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x out2File = img.Sources[0].strip() + "TEMPPOLCAL2.uvtab" u = UV.newPFUV("UV", outFile, img.outDisk, True, err) u.Zap(err) del u # End accumulate statistics by file type # End loop over IF # Give results, compute R-L correction RLCor = [] import math mess = " IF IFlux IRMS QFlux QRMS UFlux URMS R-L Corr" printMess(mess, logfile) for i in range(0, len(IFlux)): # REALLY NEED RM Correction!!!!! cor = RLPhase - 57.296 * math.atan2(UFlux[i], QFlux[i]) RLCor.append(cor) mess = "%3d %8.3f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f "%\ (i+1, IFlux[i], IRMS[i], QFlux[i], QRMS[i], UFlux[i], URMS[i], cor) printMess(mess, logfile) # Copy highest CL table hiCL = uv.GetHighVer("AIPS CL") # Apply R-L phase corrections clcor = AIPSTask.AIPSTask("clcor") clcor.logFile = logfile setname(uv, clcor) clcor.opcode = "POLR" clcor.gainver = hiCL clcor.gainuse = hiCL + 1 clcor.clcorprm[1:] = RLCor clcor.g
def VLAUVLoad(filename, inDisk, Aname, Aclass, Adisk, Aseq, err, logfile=''): """ Read FITS uvtab file into AIPS Read a UVTAB FITS UV data file and write an AIPS data set filename = name of FITS file inDisk = FITS directory number Aname = AIPS name of file Aclass = AIPS class of file Aseq = AIPS sequence number of file, 0=> create new Adisk = FITS directory number err = Python Obit Error/message stack logfile = logfile for messages returns AIPS UV data object """ ################################################################ # # Checks if not OErr.OErrIsA(err): raise TypeError, "err MUST be an OErr" # # Get input inUV = UV.newPFUV("FITS UV DATA", filename, inDisk, True, err) if err.isErr: OErr.printErrMsg(err, "Error with FITS data") # Get output, create new if seq=0 if Aseq < 1: OErr.printErr(err) # Print any outstanding messages user = OSystem.PGetAIPSuser() Aseq = AIPSDir.PHiSeq(Adisk, user, Aname, Aclass, "MA", err) # If it already exists, increment seq if AIPSDir.PTestCNO(Adisk, user, Aname, Aclass, "MA", Aseq, err) > 0: Aseq = Aseq + 1 OErr.PClear(err) # Clear any message/error mess = "Creating AIPS UV file " + Aname + "." + Aclass + "." + str( Aseq) + " on disk " + str(Adisk) printMess(mess, logfile) outUV = UV.newPAUV("AIPS UV DATA", Aname, Aclass, Adisk, Aseq, False, err) if err.isErr: OErr.printErrMsg(err, "Error creating AIPS data") # Copy UV.PCopy(inUV, outUV, err) if err.isErr: OErr.printErrMsg(err, "Error copying UV data to AIPS") # Copy History inHistory = History.History("inhistory", inUV.List, err) outHistory = History.History("outhistory", outUV.List, err) History.PCopyHeader(inHistory, outHistory, err) # Add history outHistory.Open(History.READWRITE, err) outHistory.TimeStamp(" Start Obit uvlod", err) outHistory.WriteRec( -1, "uvlod / FITS file " + filename + " disk " + str(inDisk), err) outHistory.Close(err) # # Copy Tables exclude = [ "AIPS HI", "AIPS AN", "AIPS FQ", "AIPS SL", "AIPS PL", "History" ] include = [] UV.PCopyTables(inUV, outUV, exclude, include, err) return outUV # return new object
def VLAPolCal(uv, InsCals, RLCal, RLPhase, err, RM=0.0, \ doCalib=2, gainUse=0, flagVer=-1, \ soltype="APPR", fixPoln=False, avgIF=False, \ solInt=0.0, refAnt=0, \ pmodel=[0.0,0.0,0.0,0.0,0.0,0.0,0.0], \ FOV=0.05, niter = 100, \ nThreads=1, noScrat=[], logfile = ""): """ Polarization calibration, both instrumental and orientation Do Instrumental and R-L calibration Instrumental cal uses PCAL, R-L cal is done by imaging each IF in Q and U and summing the CLEAN components. uv = UV data object to calibrate InsCals = Instrumental poln calibrators, name or list of names If None no instrumental cal RLCal = R-L (polarization angle) calibrator, If None no R-L cal RLPhase = R-L phase of RLCal (deg) at 1 GHz err = Obit error/message stack RM = Rotation measure of RLCal doCalib = Apply prior calibration table, positive=>calibrate gainUse = CL/SN table to apply flagVer = Input Flagging table version soltype = solution type fixPoln = if True, don't solve for source polarization in ins. cal avgIF = if True, average IFs in ins. cal. solInt = instrumental solution interval (min), 0=> scan average refAnt = Reference antenna pmodel = Instrumental poln cal source poln model. pmodel[0] = I flux density (Jy) pmodel[1] = Q flux density (Jy) pmodel[2] = U flux density (Jy) pmodel[3] = V flux density (Jy) pmodel[4] = X offset in sky (arcsec) pmodel[5] = Y offset in sky (arcsec) FOV = field of view radius (deg) needed to image RLCal niter = Number of iterations of CLEAN in R-L cal nThreads = Number of threads to use in imaging noScrat = list of disks to avoid for scratch files logfile = Log file for task """ ################################################################ # Instrumental calibrtation if InsCals!=None: pcal = AIPSTask.AIPSTask("pcal") pcal.logFile = logfile setname(uv,pcal) if type(InsCals)==list: pcal.calsour[1:] = InsCals else: pcal.calsour[1:] = [InsCals] pcal.docalib = doCalib pcal.gainuse = gainUse pcal.flagver = flagVer pcal.soltype = soltype pcal.solint = solInt pcal.refant = refAnt if fixPoln: pcal.bparm[10]=1.0 if avgIF: pcal.cparm[1]=1.0 pcal.pmodel[1:] = pmodel pcal.i pcal.g # end instrumental poln cal # R-L phase cal if RLCal!=None: img = ObitTask.ObitTask("Imager") img.logFile = logfile setname(uv,img) img.doCalib = doCalib img.gainUse = gainUse img.flagVer = flagVer img.doPol = True img.Sources[0] = RLCal img.Stokes = "IQU" img.FOV = FOV img.Niter = niter img.autoWindow = True img.dispURL = "None" img.Catalog = "None" img.nThreads = nThreads img.noScrat = noScrat # Temporary output files if img.DataType=="AIPS": img.outName = "TEMP" img.outClass= "IPOLCL" img.outDisk = img.inDisk img.outSeq = 6666 img.out2Name = "TEMP" img.out2Class= "IPOLCL" img.out2Disk = img.inDisk img.out2Seq = 7777 elif img.DataType=="FITS": img.outFile = "TEMPPOLCAL.fits" img.outDisk = img.inDisk img.out2File = "TEMPPOLCAL2.uvtab" img.out2Disk = img.inDisk # How many IFs? h = uv.Desc.Dict if h["jlocif"]>=0: nif = h["inaxes"][h["jlocif"]] else: nif = 1 # Lists of flux densities and RMSes IFlux = [] IRMS = [] QFlux = [] QRMS = [] UFlux = [] URMS = [] # Loop over IF imaging I,Q, U for iif in range (1, nif+1): img.BIF = iif img.EIF = iif #img.dispURL = "ObitView" # DEBUG #img.debug=True # DEBUG img.g # Get fluxes from inner quarter of images if img.DataType=="AIPS": outName = (img.Sources[0].strip()+"TEMP")[0:12] outDisk = img.outDisk outSeq = 6666 # Stokes I outClass="IPOLCL" x = Image.newPAImage("I",outName, outClass, outDisk,outSeq,True,err) h = x.Desc.Dict blc = [h["inaxes"][0]/4,h["inaxes"][1]/4] trc = [3*h["inaxes"][0]/4,3*h["inaxes"][1]/4] stat = imstat(x, err, blc=blc,trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes Q outClass="QPOLCL" x = Image.newPAImage("Q",outName, outClass, outDisk,outSeq,True,err) stat = imstat(x, err, blc=blc,trc=trc) QFlux.append(stat["Flux"]) QRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes U outClass="UPOLCL" x = Image.newPAImage("U",outName, outClass, outDisk,outSeq,True,err) stat = imstat(x, err, blc=blc,trc=trc) UFlux.append(stat["Flux"]) URMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Delete UV output out2Name = (img.Sources[0].strip()+"TEMP")[0:12] out2Class="IPOLCL" out2Disk = img.inDisk out2Seq = 7777 u = UV.newPAUV("UV",out2Name,out2Class,out2Disk,out2Seq,True,err) u.Zap(err) del u elif img.DataType=="FITS": # Stokes I outFile = img.Sources[0].strip()+"ITEMPPOLCAL.fits" x = Image.newPFImage("I",outFile,img.outDisk,True,err) h = x.Desc.Dict blc = [h["inaxes"][0]/4,h["inaxes"][1]/4] trc = [3*h["inaxes"][0]/4,3*h["inaxes"][1]/4] stat = imstat(x, err, blc=blc,trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes Q outFile = img.Sources[0].strip()+"ITEMPPOLCAL.fits" x = Image.newPFImage("Q",outFile,img.outDisk,True,err) stat = imstat(x, err, blc=blc,trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x # Stokes U outFile = img.Sources[0].strip()+"ITEMPPOLCAL.fits" x = Image.newPFImage("Q",outFile,img.outDisk,True,err) stat = imstat(x, err, blc=blc,trc=trc) IFlux.append(stat["Flux"]) IRMS.append(stat["RMSHist"]) x.Zap(err) # Cleanup del x out2File = img.Sources[0].strip()+"TEMPPOLCAL2.uvtab" u = UV.newPFUV("UV",outFile,img.outDisk,True,err) u.Zap(err) del u # End accumulate statistics by file type # End loop over IF # Give results, compute R-L correction RLCor = [] import math mess = " IF IFlux IRMS QFlux QRMS UFlux URMS R-L Corr" printMess(mess, logfile) for i in range (0,len(IFlux)): # REALLY NEED RM Correction!!!!! cor = RLPhase - 57.296 * math.atan2(UFlux[i],QFlux[i]) RLCor.append(cor) mess = "%3d %8.3f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f "%\ (i+1, IFlux[i], IRMS[i], QFlux[i], QRMS[i], UFlux[i], URMS[i], cor) printMess(mess, logfile) # Copy highest CL table hiCL = uv.GetHighVer("AIPS CL") # Apply R-L phase corrections clcor = AIPSTask.AIPSTask("clcor") clcor.logFile = logfile setname(uv,clcor) clcor.opcode = "POLR" clcor.gainver = hiCL clcor.gainuse = hiCL+1 clcor.clcorprm[1:] = RLCor clcor.g
Stokes = 'I' TimeRange = [0.0,10.0] UVRange = [0.0,0.0] Robust = 0.0 UVTaper = [0.0,0.0] # NVSS catalog Catalog = 'NVSSVZ.FIT' OutlierDist = 1.0 # Maximum distance to add outlyers (deg) OutlierFlux = 0.001 # Minimum estimated outlier flux density (Jy) OutlierSI = -0.7 # Spectral index to estimate flux density OutlierSize = 50 # Size of outlyer field # Convert files into uvdata inUV = UV.newPFUV("input data", inFile, inDisk, 1, err) OErr.printErrMsg(err, "Error initializing uvdata") # Set inputs Input = CleanVis.CleanInput #Input['Sources'] = ["C346R422"] Input['Sources'] = ["C346R424"] Input['doCalSelect'] = True; Input['Niter'] = 1000 Input['minFlux'] = 0.0001 Input['minPatch'] = 200 Input['Gain'] = 0.1 Input['CCVer'] = 1 #Input['BMAJ'] = 4.0/3600.0 #Input['BMIN'] = 4.0/3600.0 #Input['BPA'] = 0.0
import UV, UVImager, Image, ImageMosaic, SkyModel from Obit import Bomb # Files (FITS) inDisk = 1 outDisk = 1 inFile = 'PModel.uvtab' inModel = 'PModelQ.fits' outFile = 'UVSubTestOut.uvtab' # Bombs away #Bomb() # Set data print "Set data" inData = UV.newPFUV("Input uv data", inFile, inDisk, True, err) inImage = Image.newPFImage("Input image", inModel, inDisk, True, err) outData = UV.newPFUV("Output uv data", outFile, outDisk, True, err) OErr.printErrMsg(err, "Error initializing") # Make Mosaic mosaic = ImageMosaic.newObit("Mosaic", 1, err) OErr.printErrMsg(err, "Error making mosaic") # Add image ImageMosaic.PSetImage(mosaic, 0, inImage) # Make SkyModel model = SkyModel.newObit("SkyModel", err) OErr.printErrMsg(err, "Error making SkyModel") SkyModel.PSetMosaic(model, mosaic)
UVTaper = [0.0,0.0] # NVSS catalog Catalog = 'NVSSVZ.FIT' OutlierDist = 1.0 # Maximum distance to add outlyers (deg) OutlierFlux = 0.01 # Minimum estimated outlier flux density (Jy) OutlierSI = -1.0 # Spectral index to estimate flux density OutlierSize = 50 # Size of outlyer field # If debugging #Bomb() # Set data print "Set data" inData = UV.newPFUV("Input data", inFile, inDisk, True, err) OErr.printErrMsg(err, "Error initializing") # Calibration/selection parameters Input = UVImager.UVCreateImagerInput # Data selection, cal etc. Input['InData'] = inData Input['doCalSelect'] = True Input['Stokes'] = Stokes Input['BChan'] = 0 Input['EChan'] = 0 Input['BIF'] = 0 Input['EIF'] = 0 Input['doCalib'] = -1 Input['gainUse'] = 1 Input['flagVer'] = 1
FOV = 25.0 / 60.0 # BADASS Stokes = 'I' TimeRange = [0.0, 10.0] UVRange = [0.0, 0.0] Robust = 0.0 UVTaper = [0.0, 0.0] # NVSS catalog Catalog = 'NVSSVZ.FIT' OutlierDist = 1.0 # Maximum distance to add outlyers (deg) OutlierFlux = 0.001 # Minimum estimated outlier flux density (Jy) OutlierSI = -0.7 # Spectral index to estimate flux density OutlierSize = 50 # Size of outlyer field # Convert files into uvdata inUV = UV.newPFUV("input data", inFile, inDisk, 1, err) OErr.printErrMsg(err, "Error initializing uvdata") # Set inputs Input = CleanVis.CleanInput #Input['Sources'] = ["C346R422"] Input['Sources'] = ["C346R424"] Input['doCalSelect'] = True Input['Niter'] = 1000 Input['minFlux'] = 0.0001 Input['minPatch'] = 200 Input['Gain'] = 0.1 Input['CCVer'] = 1 #Input['BMAJ'] = 4.0/3600.0 #Input['BMIN'] = 4.0/3600.0 #Input['BPA'] = 0.0
# Files (FITS) inDisk = 1 outDisk = 1 inFile = 'UVSubTestIn.uvtab' inModel = 'UVSubTestModIn.fits' outFile = 'UVSubTestOut.uvtab' masterDisk = 1 masterFile = 'UVSubTestMaster.uvtab' # Bombs away #Bomb() # Set data print "Set data" inData = UV.newPFUV("Input uv data", inFile, inDisk, True, err) inImage = Image.newPFImage("Input image", inModel, inDisk, True, err) outData = UV.newPFUV("Output uv data", outFile, outDisk, False, err) OErr.printErrMsg(err, "Error initializing") # Make Mosaic mosaic = ImageMosaic.newObit("Mosaic", 2, err) #mosaic = ImageMosaic.newObit("Mosaic", 1, err) OErr.printErrMsg(err, "Error making mosaic") # Add image ImageMosaic.PSetImage(mosaic, 0, inImage) ImageMosaic.PSetImage(mosaic, 1, inImage) # Make SkyModel model model = SkyModel.PCreate("SkyModel", mosaic) OErr.printErrMsg(err, "Error making SkyModel")
# Files (FITS) inDisk = 1 outDisk = 1 inFile = 'UVSubTestIn.uvtab' inModel = 'UVSubTestModIn.fits' outFile = 'UVSubTestOut.uvtab' masterDisk = 1 masterFile = 'UVSubTestMaster.uvtab' # Bombs away #Bomb() # Set data print "Set data" inData = UV.newPFUV("Input uv data", inFile, inDisk, True, err) inImage = Image.newPFImage("Input image",inModel, inDisk, True, err) outData = UV.newPFUV("Output uv data", outFile, outDisk, False, err) OErr.printErrMsg(err, "Error initializing") # Make Mosaic mosaic = ImageMosaic.newObit("Mosaic", 2, err) #mosaic = ImageMosaic.newObit("Mosaic", 1, err) OErr.printErrMsg(err, "Error making mosaic") # Add image ImageMosaic.PSetImage(mosaic, 0, inImage) ImageMosaic.PSetImage(mosaic, 1, inImage) # Make SkyModel model model = SkyModel.PCreate("SkyModel", mosaic) OErr.printErrMsg(err, "Error making SkyModel")
import UV, UVImager, Image, ImageMosaic, SkyModel from Obit import Bomb # Files (FITS) inDisk = 1 outDisk = 1 inFile = 'PModel.uvtab' inModel = 'PModelQ.fits' outFile = 'UVSubTestOut.uvtab' # Bombs away #Bomb() # Set data print "Set data" inData = UV.newPFUV("Input uv data", inFile, inDisk, True, err) inImage = Image.newPFImage("Input image",inModel, inDisk, True, err) outData = UV.newPFUV("Output uv data", outFile, outDisk, True, err) OErr.printErrMsg(err, "Error initializing") # Make Mosaic mosaic = ImageMosaic.newObit("Mosaic", 1, err) OErr.printErrMsg(err, "Error making mosaic") # Add image ImageMosaic.PSetImage(mosaic, 0, inImage) # Make SkyModel model = SkyModel.newObit("SkyModel", err) OErr.printErrMsg(err, "Error making SkyModel") SkyModel.PSetMosaic(model, mosaic)
def open_uv(aips_path, nvispio=1024, mode=None): """ Opens an AIPS/FITS UV file and returns a wrapped :class:`UVFacade` object. Parameters ---------- aips_path: :class:`AIPSPath` Obit file object. nvispio: integer Number of visibilities to read/write per I/O operation mode(optional): str "r" to read, "w" to write, "rw" to read and write. Defaults to "r" Returns ------- :class:`UV` An Obit UV object """ err = obit_err() if mode is None: mode = "r" uv_mode = uv_file_mode(mode) exists = False # Test if the file exists if aips_path.dtype == "AIPS": try: uv = UV.newPAUV(aips_path.label, aips_path.name, aips_path.aclass, aips_path.disk, aips_path.seq, exists, err, nvis=nvispio) except Exception: raise ValueError("Error calling newPAUV on '%s'" % aips_path) elif aips_path.dtype == "FITS": raise NotImplementedError("newPFUV calls do not currently work") try: uv = UV.newPFUV(aips_path.label, aips_path.name, aips_path.disk, exists, err, nvis=nvispio) except Exception: raise ValueError("Error calling newPFUV on '%s'" % aips_path) else: raise ValueError("Invalid dtype '{}'".format(aips_path.dtype)) handle_obit_err("Error opening '%s'" % aips_path, err) try: uv.Open(uv_mode, err) except Exception: raise ValueError("Error opening '%s'" % aips_path) handle_obit_err("Error opening '%s'" % aips_path, err) return uv