def PTestCNO(disk, user, Aname, Aclass, Atype, seq, err): """ Test if AIPS file exists returns AIPS cno, -1 => not found disk = AIPS disk number user = AIPS user number Aname = AIPS file name Aclass = AIPS class name Atype = 'MA' or 'UV' for image or uv data seq = AIPS sequence number err = Python Obit Error/message stack, """ ################################################################ # Checks if err.isErr: return -1 if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # # Print message stack to clear OErr.printErr(err) ret = Obit.AIPSDirFindCNO(disk, user, Aname, Aclass, Atype, seq, err.me) if err.isErr: return ret # Clear any couldn't find message OErr.PClear(err) return ret
def getname(cno, disk=Adisk): """ Return Obit object for AIPS file in cno on disk cno = AIPS catalog slot number disk = AIPS disk number """ ################################################################ Adisk = disk user = AIPS.AIPS.userno s = AIPSDir.PInfo(disk, user, cno, err) OErr.printErrMsg(err, "Error with AIPS catalog") # parse returned string Aname = s[0:12] Aclass = s[13:19] Aseq = int(s[20:25]) Atype = s[26:28] if Atype == 'MA': out = Image.newPAImage("AIPS image", Aname, Aclass, disk, Aseq, True, err) print "AIPS Image",Aname, Aclass, disk, Aseq elif Atype == 'UV': out = UV.newPAUV("AIPS UV data", Aname, Aclass, disk, Aseq, True, err) print "AIPS UV",Aname, Aclass, disk, Aseq out.Aname = Aname out.Aclass = Aclass out.Aseq = Aseq out.Atype = Atype out.Disk = disk out.Acno = cno return out
def PParse(infile, list, err): """ Parse text file Parse parameter format text file and copy to list The input file is basically free format with a keyword=value syntax. Comments follow a "#" symbol. String keywords should have no leading or trailing blanks before the end of the line or a comment delimiter. If a numeric value is followed by a comment there should be at least one blank before the comment delimiter. Allowed types are: Str (String), Flt (float), Dbl (double), Int (int), Boo (boolean) Examples: # Comment $Key = SomeStr Str (9) # Some string Something $Key = FArr Flt (2) # Array of 2 floats 0.0 0.0 $Key = CLEANBox Int(4,1) # Clean box with 4 ints 0 0 0 0 returns 0 on success, else 1 infile = Name of the input text file to parse list = ObitInfoList to accept values. err = ObitErr for reporting errors. """ ################################################################ # Checks if not InfoList.PIsA(list): raise TypeError,"list MUST be a Python Obit InfoList" ret = Obit.Parse(infile, list.me, err.me) if ret or err.isErr: OErr.printErrMsg(err, "Error Parsing "+infile) return ret
def PSetDir(disk, newName, err, URL=None): """ Set the directory name for a given AIPS directory returns disk number actually used disk = AIPS disk number, <=0 => assign newName = new directory path err = Python Obit Error/message stack URL = URL if on a remote host (Only if using OTObit/ParselTongue) """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # retDisk = Obit.AIPSSetDirname(disk, newName, err.me) if err.isErr: OErr.printErrMsg(err, "Error setting AIPS directory name") AIPSdisks.append(newName) nAIPS = len(AIPSdisks) if (disk<=0): try: AIPS.AIPS.disks.append(AIPS.AIPSDisk(URL, retDisk, newName)) except: pass else: pass return retDisk;
def PPBImage (pntImage, outImage, err, minGain=0.1, outPlane=[1,1,1,1,1], antSize=25.0): """ Calculate an image with a primary beam pattern Make an image of the antenna primary beam pattern based on the pointing position in an image. * pntImage = Python Image giving pointing position (ObsRA, ObsDec) * outImage = Python Image to be written. Must be previously instantiated. * err = Python Obit Error/message stack * minGain = minimum allowed gain (lower values blanked). * outPlane = 5 element int array with 1, rel. plane number [1,1,1,1,1] giving location of plane to be written * antSize = Antenna diameter assumed, default 25m """ ################################################################ # Checks if not Image.PIsA(pntImage): print "Actually ",pntImage.__class__ raise TypeError,"pntImage MUST be a Python Obit Image" if not Image.PIsA(outImage): print "Actually ",outImage.__class__ raise TypeError,"outImage MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" if len(outPlane) != 5: raise TypeError,"outPlane must have 5 elements" # Obit.ImageUtilPBImage(pntImage.me, outImage.me, outPlane, antSize, minGain, err.me) if err.isErr: OErr.printErrMsg(err, "Error with primary beam image")
def MakeMask(im, vlver, maskFile, err, minSNR=5.0): """ Create a CLEAN mask file for Obit Imaging tasks CLEANFile Radius of entries = major axis size. im = Image with VL table vlver = VL Table version, generate with FndSou maskFile = name for output mask file err = Obit error/message stack minSNR = Min. SNR to use """ scale = 1.0 # Open output file fd = open(maskFile, 'w') vltab = im.NewTable(Table.READONLY, 'AIPS VL', vlver, err) maxscale = scale / abs(im.Desc.Dict['cdelt'][0]) nrow = vltab.Desc.Dict['nrow'] vltab.Open(Table.READONLY, err) OErr.printErr(err) for irow in range(1, nrow + 1): row = vltab.ReadRow(irow, err) if row['PEAK INT'][0] / row['I RMS'][0] > minSNR: ra = ImageDesc.PRA2HMS(row['RA(2000)'][0]) dec = ImageDesc.PDec2DMS(row['DEC(2000)'][0]) size = min(50, int(row['MAJOR AX'][0] * maxscale + 0.5)) line = "%s %s %d\n" % (ra, dec, size) fd.write(line) vltab.Close(err) OErr.printErr(err) fd.close()
def PPutString(inList, name, dim, data, err): """ Add an string entry, error if conflict * inList = input Python InfoList * name = name of desired entry * dim = dimensionality of array as list, e.g. [1,1,1,1,1] for scalar MUST have 5 entries * data = data as a 1-D array of strings (rectangular char array) * err = Python Obit Error/message stack """ ################################################################ # Checks if data[0].__class__ != str: print("class is", data[0].__class__) raise TypeError("data MUST be a string") if len(dim) < 5: raise RuntimeError("dim has fewer then 5 entries") # make sure dim is long ldim = [] for d in dim: ldim.append(long(d)) prod = 1 for x in dim: if (x > 0): prod = prod * x if prod < len(data): raise RuntimeError("more data than defined in dim") # Call depends on whether single string, 1 or 2 D arrays if (dim[1] > 1): # array of strings Obit.InfoListPutString(inList.me, name, ldim, data, err.me) else: # single Obit.InfoListPutSString(inList.me, name, ldim, data, err.me) if err.isErr: OErr.printErrMsg(err, "Error adding entry")
def PSetDir(newDir, disk, err, URL=None): """ replace FITS directory returns FITS disk number * newDir = new directory path * err = Python Obit Error/message stack * URL = URL if on a remote host (Only if using OTObit/ParselTongue) """ ################################################################ global FITSdisks, nFITS # Checks if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # retDisk = Obit.FITSSetDir(newDir, disk, err.me) FITSdisks[disk] = newDir nFITS = len(FITSdisks) #print "DEBUG nFITS",nFITS if err.isErr: OErr.printErrMsg(err, "Error replacinging FITS directory") # Update ObitTalk stuff try: FITS.FITS.disks[disk] = FITS.FITSDisk(URL, disk, newDir) except: pass else: pass
def getname(cno, disk=Adisk): """ Return Obit object for AIPS file in cno on disk * cno = AIPS catalog slot number * disk = AIPS disk number """ ################################################################ Adisk = disk user = AIPS.AIPS.userno s = AIPSDir.PInfo(disk, user, cno, err) OErr.printErrMsg(err, "Error with AIPS catalog") # parse returned string Aname = s[0:12] Aclass = s[13:19] Aseq = int(s[20:25]) Atype = s[26:28] if Atype == 'MA': out = Image.newPAImage("AIPS image", Aname, Aclass, disk, Aseq, True, err) print("AIPS Image", Aname, Aclass, disk, Aseq) elif Atype == 'UV': out = UV.newPAUV("AIPS UV data", Aname, Aclass, disk, Aseq, True, err) print("AIPS UV", Aname, Aclass, disk, Aseq) out.Aname = Aname out.Aclass = Aclass out.Aseq = Aseq out.Atype = Atype out.Disk = disk out.Acno = cno return out
def PPutDouble(inList, name, dim, data, err): """ Add an double entry, error if conflict * inList = input Python InfoList * name = name of desired entry * dim = dimensionality of array as list, e.g. [1,1,1,1,1] for scalar MUST have 5 entries * data = data as a 1-D array of double * err = Python Obit Error/message stack """ ################################################################ # Checks if data[0].__class__ != float: print("class is", data[0].__class__) raise TypeError("data MUST be float") if len(dim) < 5: raise RuntimeError("dim has fewer then 5 entries") # make sure dim is long ldim = [] for d in dim: ldim.append(long(d)) prod = 1 for x in dim: if (x > 0): prod = prod * x if prod < len(data): raise RuntimeError("more data than defined in dim") if prod > len(data): raise RuntimeError("less data than defined in dim") Obit.InfoListPutDouble(inList.me, name, ldim, data, err.me) if err.isErr: OErr.printErrMsg(err, "Error adding entry")
def PPutBoolean(inList, name, dim, data, err): """ Add an boolean entry (1,0), error if conflict * inList = input Python InfoList * name = name of desired entry * dim = dimensionality of array as list, e.g. [1,1,1,1,1] for scalar MUST have 5 entries * data = data as a 1-D array of boolean (1,0) * err = Python Obit Error/message stack """ ################################################################ # Checks if data[0].__class__ != bool: print "class is", data[0].__class__ raise TypeError, "data MUST be bool" if len(dim) < 5: raise RuntimeError, "dim has fewer then 5 entries" prod = 1 for x in dim: if (x > 0): prod = prod * x if prod < len(data): raise RuntimeError, "more data than defined in dim" if prod > len(data): raise RuntimeError, "less data than defined in dim" Obit.InfoListPutBoolean(inList.me, name, dim, data, err.me) if err.isErr: OErr.printErrMsg(err, "Error adding entry")
def PPutString (inList, name, dim, data, err): """ Add an string entry, error if conflict inList = input Python InfoList name = name of desired entry dim = dimensionality of array as list, e.g. [1,1,1,1,1] for scalar MUST have 5 entries data = data as a 1-D array of strings (rectangular char array) err = Python Obit Error/message stack """ ################################################################ # Checks if data[0].__class__ != str: print "class is" , data[0].__class__ raise TypeError,"data MUST be a string" if len(dim) < 5: raise RuntimeError,"dim has fewer then 5 entries" prod = 1 for x in dim: if (x>0): prod = prod*x if prod < len(data): raise RuntimeError,"more data than defined in dim" # Call depends on whether single string, 1 or 2 D arrays if (dim[1]>1): # array of strings Obit.InfoListPutString(inList.me, name, dim, data, err.me) else: # single Obit.InfoListPutSString(inList.me, name, dim, data, err.me) if err.isErr: OErr.printErrMsg(err, "Error adding entry")
def PPutBoolean (inList, name, dim, data, err): """ Add an boolean entry (1,0), error if conflict inList = input Python InfoList name = name of desired entry dim = dimensionality of array as list, e.g. [1,1,1,1,1] for scalar MUST have 5 entries data = data as a 1-D array of boolean (1,0) err = Python Obit Error/message stack """ ################################################################ # Checks if data[0].__class__ != bool: print "class is" , data[0].__class__ raise TypeError,"data MUST be bool" if len(dim) < 5: raise RuntimeError,"dim has fewer then 5 entries" prod = 1 for x in dim: if (x>0): prod = prod*x if prod < len(data): raise RuntimeError,"more data than defined in dim" if prod > len(data): raise RuntimeError,"less data than defined in dim" Obit.InfoListPutBoolean(inList.me, name, dim, data, err.me) if err.isErr: OErr.printErrMsg(err, "Error adding entry")
def ClearErr(err=err): """ Print any errors and clear stack err = Python Obit Error/message stack, default of PTObit version """ ################################################################ OErr.printErrMsg(err, "Error")
def PTableCCT2Spec (inImage, outImage, nTerm, inCCVer, outCCVer, err, startCC=0, endCC=0): """ Convert an (tabulated) TSpec CC Table to spectral parameter table Output CC Table will have fitted spectra rather than tabulated spectra. Tabulated spectrum fitted with spectrum weighting by primary beam inImage input Obit Python Image 1 Must have freq axis type = "SPECLNMF" Optional parameters on List member: "dropNeg" boolean if True drop negative components [True] "doPBCor" boolean if True Primary beam correct [False] outImage output Obit Python image must be type ObitImageWB This can be created by ImageUtil.PImageT2Spec nTerm Number of output Spectral terms, 2=SI, 3=also curve. inCCVer Input CCTable to convert, 0=> highest outCCVer Output CCTable, 0=>1 err Python Obit Error/message stack startCC First 1-rel component to convert endCC Last 1-rel component to convert, 0=> all """ ################################################################ # Checks if not Image.PIsA(inImage): raise TypeError,"inImage MUST be a Python Obit Image" if not Image.PIsA(outImage): raise TypeError,"outImage MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # Obit.TableCCUtilT2Spec(inImage.me, outImage.me, nTerm, inCCVer, \ outCCVer, startCC, endCC, err.me) if err.isErr: OErr.printErrMsg(err, "Error Converting CC Table")
def PEdit (inHis, startr, endr, err): """ Edit History Deletes a range of history records. return 0 on success, else failure * inHis = input Python History * startr = first (1-rel) history record to delete * endr = highest (1-rel) history record to delete, 0=>to end * err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inHis): raise TypeError("inHis MUST be a History") if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # ret = POpen (inHis, READWRITE, err) ret = Obit.HistoryEdit(inHis.me, startr, endr, err.me) OErr.printErr(err) if err.isErr: OErr.printErrMsg(err, "Error Editing History") ret = PClose (inHis, err) return ret
def PUVFilter(inImage, outImage, radius, err): """ Filter an image outside of a radius from the origin in FT space. Intended to filter out out of band noise in single dish images. Filters by a function with 1.0/(nx*ny) inside radius and outside tapers by an exponential with scale distance 10 pixels. * inImage = Input Image * outImage = Output image, may be inImage * radius = distance from origin in uv space (m) * err = Python Obit Error/message stack """ ################################################################ # Checks if not Image.PIsA(inImage): raise TypeError("inImage MUST be a Python Obit Image") if not Image.PIsA(outImage): raise TypeError("outImage MUST be a Python Obit Image") if not err.IsA(): raise TypeError("err MUST be an OErr") # Obit.ImageUtilUVFilter(inImage.me, outImage.me, radius, err.me) if err.isErr: OErr.printErrMsg(err, "Error UV Filtering image")
def PIoN2SolNTableConvert(inUV, outSNVer, NITable, pos, err): """ Evaluate Ionospheric model table at pos and convert to SN table Returns resultant SN table * inUV = UV data for output SN table. Control parameters on inUV info member: ========== ================ ================================ "doAntOff" OBIT_bool scalar True if correctionss for antenna offset from array center wanted [def False] ========== ================ ================================ * outSNVer = Desired output SN table version, 0=> new * NITable = Ionospheric model table to evaluate * pos = [RA, Dec] shift (deg) in which NITable to be evaluated. * err = Obit Error stack, returns if not empty. """ ################################################################ # Checks if not UV.PIsA(inUV): raise TypeError('PIoN2SolNTableConvert: Bad input UV data') if not Table.PIsA(NITable): raise TypeError('PIoN2SolNTableConvert: Bad NI input table') # Create output SN table object outSNTable = Table.Table("None") # Evaluate outSNTable.me = Obit.IoN2SolNTableConvert (inUV.me, outSNVer, \ NITable.me, pos, err.me) if err.isErr: OErr.printErrMsg(err, "Error Converting NI to SN table") return outSNTable
def AllDest (err, disk=None, Atype=" ", Aname=" ", Aclass=" ", Aseq=0): """ Delete AIPS files matching a pattern Strings use AIPS wild cards: blank => any '?' => one of any character "*" => arbitrary string disk = AIPS disk number, 0=>all Atype = AIPS entry type, 'MA' or 'UV'; ' => all Aname = desired AIPS name, using AIPS wildcards, None -> don't check Aclass = desired AIPS class, using AIPS wildcards, None -> don't check Aseq = desired AIPS sequence, 0=> any """ ################################################################ global Adisk if disk==None: disk = Adisk else: if disk>0: Adisk = disk # NO Confirm #prompt = "Do you really want to delete all AIPS "+Atype+" files on disk(s) "\ # +str(disk)+"\nwith names matching "+Aname+"."+Aclass+"."+str(Aseq)+ \ # " y/n " #ans = raw_input(prompt) #if ans.startswith('y'): AIPSDir.PAllDest (disk, err, Atype=Atype, Aname=Aname, Aclass=Aclass, Aseq=Aseq) #else: # print "Not confirmed" OErr.printErrMsg(err, "Error with destroying AIPS enreies")
def CreateSU(inUV, outUV, err): """ Write data in meta to SU table * inUV = list of input Obit UV objects (freq order) * outUV = output Obit UV object, defined but not instantiated * err = Obit error/message stack """ ############################################################### # Create SU table idd = inUV.Desc.Dict # Info from input header nIF = idd["inaxes"][idd["jlocif"]] # how many IFs sutab = outUV.NewTable(Table.READWRITE, "AIPS SU", 1, err, numIF=nIF) if err.isErr: OErr.printErrMsg(err, "Error with SU table") sutab.Open(Table.READWRITE, err) if err.isErr: OErr.printErrMsg(err, "Error opening SU table") # Update header sutab.keys['RefDate'] = idd["obsdat"] sutab.keys['Freq'] = idd["crval"][idd["jlocf"]] Table.PDirty(sutab) # Force update row = sutab.ReadRow(1, err) if err.isErr: OErr.printErrMsg(err, "Error reading SU table") irow = 1 IFZero = [] # Array of NIF zeroes for i in range(0, nIF): IFZero.append(0.0) row['ID. NO.'] = [1] row['SOURCE'] = [idd["object"]] row['RAEPO'] = [idd["crval"][idd["jlocr"]]] row['DECEPO'] = [idd["crval"][idd["jlocd"]]] row['RAOBS'] = [idd["obsra"]] row['DECOBS'] = [idd["obsdec"]] row['EPOCH'] = [idd["equinox"]] row['RAAPP'] = [0.0] row['DECAPP'] = [0.0] row['BANDWIDTH'] = [idd["cdelt"][idd["jlocf"]]] row['Table name'] = 'AIPS SU' row['IFLUX'] = IFZero row['QFLUX'] = IFZero row['UFLUX'] = IFZero row['VFLUX'] = IFZero row['FREQOFF'] = IFZero row['RESTFREQ'] = IFZero row['LSRVEL'] = IFZero row['CALCODE'] = [' '] row['NumFields'] = 22 row['QUAL'] = [0] row['PMRA'] = [0.0] row['PMDEC'] = [0.0] row['_status'] = [1] sutab.WriteRow(irow, row, err) if err.isErr: OErr.printErrMsg(err, "Error writing SU table") sutab.Close(err) if err.isErr: OErr.printErrMsg(err, "Error closing SU table")
def PMakeImage (inUV, outImage, channel, doBeam, doWeight, err): """ Grids UV, FFTs and makes corrections for the gridding convolution. inUV = Input Python uv data. Should be in form of Stokes to be imaged will all calibration and selection applied. outImage = Python Image to be written. Must be previously instantiated. Beam normalization factor is written to output Beam infoList as SUMWTS channel = Which frequency channel to image, 0->all. doBeam = if TRUE also make beam. Will make the myBeam member of outImage. If FALSE, and myGrid->BeamNorm 0.0 then reads SUMWTS value from beam infolist doWeigh = if TRUE Apply uniform weighting corrections to uvdata before imaging err = Python Obit Error/message stack """ ################################################################ # Checks if not UV.PIsA(inUV): raise TypeError,"inUV MUST be a Python Obit UV" if not Image.PIsA(outImage): print "Actually ",outImage.__class__ raise TypeError,"outImage MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # Obit.ImageUtilMakeImage(inUV.me, outImage.me, channel, doBeam, doWeight, err.me) if err.isErr: OErr.printErrMsg(err, "Error creating Image from UV data")
def Histo(self, blc, trc, nbin, range, err): """ Computes histograms self = object blc = BLC (1-rel) in image trc = TRC (1-rel) in image nbin = number of bins (should be odd) range = range in units of Image RMS about 0 err = Obit error/message stack """ ################################################################ # Checks if not PIsA(self): raise TypeError("self MUST be a Python Obit PixHistFDR") # make sure blc, trc are long lblc = [] ltrc = [] for t in trc: ltrc.append(int(t)) for t in blc: lblc.append(int(t)) Obit.PixHistFDRHisto(self.me, lblc, ltrc, nbin, range, err.me) if err.isErr: OErr.printErrMsg(err, "Error creating PixHistFDR histogram") return
def PInfo(disk, user, cno, err): """ Get information for a AIPS catalog slot number Returned string s: ====== ============= Aname s[0:12] Aclass s[13:19] Aseq int(s[20:25]) Atype s[26:28] ====== ============= returns string describing entry, None=>empty * disk = AIPS disk number * user = AIPS user number * cno = AIPS catalog slot to deassign * err = Python Obit Error/message stack """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # ret = Obit.AIPSDirInfo(disk, user, cno, err.me) if err.isErr: OErr.printErrMsg(err, "Error reading AIPS catalog header") return ret
def PInterpolateImage (inImage, outImage, err, inPlane=[1,1,1,1,1], outPlane=[1,1,1,1,1], hwidth=2): """ Interpolates one image onto another's grid. Pixels in outImage are interpolated from inImage inImage = Input Python Image. outImage = Python Image to be written. Must be previously instantiated. err = Python Obit Error/message stack inPlane = 5 element int array with 1, rel. plane number [1,1,1,1,1] giving location of plane to be interpolated outPlane = 5 element int array with 1, rel. plane number [1,1,1,1,1] giving location of plane to be written hwidth = half width of interpolation kernal [1-4] default 2 """ ################################################################ # Checks if not Image.PIsA(inImage): raise TypeError,"inImage MUST be a Python Obit Image" if not Image.PIsA(outImage): print "Actually ",outImage.__class__ raise TypeError,"outImage MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # if len(inPlane) != 5: raise TypeError,"inPlane must have 5 elements" if len(outPlane) != 5: raise TypeError,"outPlane must have 5 elements" # Obit.ImageUtilInterpolateImage(inImage.me, outImage.me, inPlane, outPlane, hwidth, err.me) if err.isErr: OErr.printErrMsg(err, "Error interpolating Image")
def VLAClearCal(uv, err, doGain=True, doBP=False, doFlag=False): """ Clear previous calibration Delete all SN tables, all CL but CL 1 uv = UV data object to clear err = Obit error/message stack doGain = If True, delete SN and CL tables doBP = If True, delete BP tables doFlag = If True, delete FG tables """ ################################################################ # Gain tables if doGain: uv.ZapTable("AIPS SN", -1, err) ver = uv.GetHighVer("AIPS CL") while (ver > 1): uv.ZapTable('AIPS CL', ver, err) ver = ver - 1 # Bandpass if doBP: uv.ZapTable("AIPS BP", -1, err) # Flag tables if doFlag: uv.ZapTable("AIPS FG", -1, err) OErr.printErrMsg(err, "VLAClearCal: Error reseting calibration")
def PTestCNO(disk, user, Aname, Aclass, Atype, seq, err): """ Test if AIPS file exists returns AIPS cno, -1 => not found * disk = AIPS disk number * user = AIPS user number * Aname = AIPS file name * Aclass = AIPS class name * Atype = 'MA' or 'UV' for image or uv data * seq = AIPS sequence number * err = Python Obit Error/message stack, """ ################################################################ # Checks if err.isErr: return -1 if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # # Print message stack to clear OErr.printErr(err) ret = Obit.AIPSDirFindCNO(disk, user, Aname, Aclass, Atype, seq, err.me) if err.isErr: return ret # Clear any couldn't find message OErr.PClear(err) return ret
def PTableCCFixTSpec (inImage, inCCVer, refFreq, nTerm, terms, \ err, startCC=1, endCC=0, ): """ Convert an (tabulated) TSpec CC Table to spectral parameter table Output CC Table will have fitted spectra rather than tabulated spectra. Tabulated spectrum fitted with spectrum weighting by primary beam inImage input Obit Python Image 1 Must have freq axis type = "SPECLNMF" inCCVer CCTable to modify, 0=> highest refFreq Reference frequency for spectrum (Hz) nTerm Number of terms in spectrum err Python Obit Error/message stack startCC First 1-rel component to consider endCC Last 1-rel component to consider, 0=> all """ ################################################################ # Checks if not Image.PIsA(inImage): raise TypeError,"inImage MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # Obit.TableCCUtilFixTSpec(inImage.me, inCCVer, refFreq, nTerm, terms, \ startCC, endCC, err.me) if err.isErr: OErr.printErrMsg(err, "Error Modifying CC Table")
def DescMakeIF(outUV, nIF, err): """ Convert outUV descriptor divided into nIF IFs * outUV = output Obit UV object * nIF = number of desired output IFs MUST be the same number of channels per IF * err = Obit error/message stack """ ################################################################ d = outUV.Desc.Dict # Have IF axis? if d["jlocif"] >= 0: jlocif = d["jlocif"] else: # create one jlocif = d['naxis'] d['naxis'] += 1 d['ctype'][jlocif] = "IF" d['crval'][jlocif] = 1.0 d['crpix'][jlocif] = 1.0 d['cdelt'][jlocif] = 1.0 d['crota'][jlocif] = 0.0 jlocf = d["jlocf"] nchan = d["inaxes"][jlocf] // nIF d["inaxes"][jlocif] = nIF d["inaxes"][jlocf] = nchan outUV.Desc.Dict = d UV.PGetIODesc(outUV).Dict = d # And your little dog too # Update outUV.UpdateDesc(err) outUV.Open(UV.WRITEONLY, err) outUV.Close(err) #outUV.Header(err) OErr.printErrMsg(err, "Error converting Descriptor")
def PMakeImage(inUV, outImage, channel, doBeam, doWeight, err): """ Grids UV, FFTs and makes corrections for the gridding convolution. * inUV = Input Python uv data. Should be in form of Stokes to be imaged will all calibration and selection applied. * outImage = Python Image to be written. Must be previously instantiated. Beam normalization factor is written to output Beam infoList as SUMWTS * channel = Which frequency channel to image, 0->all. * doBeam = if TRUE also make beam. Will make the myBeam member of outImage. If FALSE, and myGrid->BeamNorm 0.0 then reads SUMWTS value from beam infolist * doWeigh = if TRUE Apply uniform weighting corrections to uvdata before imaging * err = Python Obit Error/message stack """ ################################################################ # Checks if not UV.PIsA(inUV): raise TypeError("inUV MUST be a Python Obit UV") if not Image.PIsA(outImage): print("Actually ", outImage.__class__) raise TypeError("outImage MUST be a Python Obit Image") if not err.IsA(): raise TypeError("err MUST be an OErr") # Obit.ImageUtilMakeImage(inUV.me, outImage.me, channel, doBeam, doWeight, err.me) if err.isErr: OErr.printErrMsg(err, "Error creating Image from UV data")
def POverlap(inID1, inID2, err): """ Determine if there is any overlap between images Compares ImageDesc objects to see if the associated images overlap on the sky. Returns True if so sles False * inID1 = First Python Obit ImageDesc for test * inID2 = Second Python Obit ImageDesc for test * err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inID1): raise TypeError("inID1 MUST be a Python Obit ImageDesc") if not PIsA(inID2): raise TypeError("inID2 MUST be a Python Obit ImageDesc") if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # res = Obit.ImageDescOverlap(inID1.me, inID2.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error determining overlap") return res != 0
def PSetDir(disk, newName, err, URL=None): """ Set the directory name for a given AIPS directory returns disk number actually used * disk = AIPS disk number, <=0 => assign * newName = new directory path * err = Python Obit Error/message stack * URL = URL if on a remote host (Only if using OTObit/ParselTongue) """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # retDisk = Obit.AIPSSetDirname(disk, newName, err.me) if err.isErr: OErr.printErrMsg(err, "Error setting AIPS directory name") AIPSdisks.append(newName) nAIPS = len(AIPSdisks) if (disk <= 0): try: AIPS.AIPS.disks.append(AIPS.AIPSDisk(URL, retDisk, newName)) except: pass else: pass return retDisk
def UpdateDescriptor(outUV, meta, err): """ Update information in data descriptor NB: Cannot change geometry of visibilities * outUV = Obit UV object * meta = dict with data meta data * err = Python Obit Error/message stack to init """ ################################################################ chinc = meta["spw"][0][2] # Frequency increment reffreq = meta["spw"][0][1] # reference frequency nchan = meta["spw"][0][0] # number of channels nif = len(meta["spw"]) # Number of IFs nstok = meta["nstokes"] # Number of Stokes products desc = outUV.Desc.Dict outUV.Desc.Dict = desc desc['obsdat'] = meta["obsdate"] desc['observer'] = meta["observer"] desc['JDObs'] = UVDesc.PDate2JD(meta["obsdate"]) desc['naxis'] = 6 desc['inaxes'] = [3, nstok, nchan, nif, 1, 1, 0] desc['cdelt'] = [1.0, -1.0, chinc, 1.0, 0.0, 0.0, 0.0] desc['crval'] = [1.0, -5.0, reffreq, 1.0, 0.0, 0.0, 0.0] desc['crota'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] outUV.Desc.Dict = desc outUV.UpdateDesc(err) if err.isErr: OErr.printErrMsg(err, "Error updating UV descriptor")
def PAllDest(disk, err, Atype=" ", Aname=None, Aclass=None, Aseq=0): """ Delete selected AIPS catalog entries Entries can be selected using Atype, Aname, Aclass, Aseq, using AIPS wildcards A "?" matches one of any character, "*" matches any string all blanks matches anything * disk = AIPS disk number, 0=>all * err = Python Obit Error/message stack * type = optional file type * Aname = desired name, using AIPS wildcards, None -> don't check * Aclass = desired class, using AIPS wildcards, None -> don't check * Aseq = desired sequence, 0=> any * first = optional first slot number (1-rel) * last = optional last slot number * giveList = If true, return list of CNOs matching """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # if (disk < 0) or (disk > (len(AIPS.AIPS.disks) + 1)): raise RuntimeError("Disk " + str(disk) + " out of range") # disks if disk > 0: disks = [disk] else: disks = list(range(1, len(AIPS.AIPS.disks))) user = OSystem.PGetAIPSuser() # loop over disks for dsk in disks: ncno = PNumber(dsk, user, err) OErr.printErrMsg(err, "Error getting number of cnos") for cno in range(1, ncno): line = PInfo(dsk, user, cno, err) OErr.printErrMsg(err, "Error reading entry") if WantDir(line, type=Atype, Aname=Aname, Aclass=Aclass, Aseq=Aseq): # parse directory string Tname = line[0:12] Tclass = line[13:19] Tseq = int(line[20:25]) Ttype = line[26:28] z = None if Ttype == 'MA': z = Image.newPAImage("Zap image", Tname, Tclass, dsk, Tseq, True, err, \ verbose=False) print("Zap AIPS Image", Tname, Tclass, dsk, Tseq) elif Ttype == 'UV': z = UV.newPAUV("Zap UV data", Tname, Tclass, dsk, Tseq, True, err, \ verbose=False) print("Zap AIPS UV", Tname, Tclass, dsk, Tseq) # Delete entry if z: z.Zap(err) del z
def PPBImage (pntImage, outImage, err, minGain=0.1, outPlane=[1,1,1,1,1], antSize=25.0): """ Calculate an image with a primary beam pattern Make an image of the antenna primary beam pattern based on the pointing position in an image. pntImage = Python Image giving pointing position (ObsRA, ObsDec) outImage = Python Image to be written. Must be previously instantiated. err = Python Obit Error/message stack minGain = minimum allowed gain (lower values blanked). outPlane = 5 element int array with 1, rel. plane number [1,1,1,1,1] giving location of plane to be written antSize = Antenna diameter assumed, default 25m """ ################################################################ # Checks if not Image.PIsA(pntImage): print "Actually ",pntImage.__class__ raise TypeError,"pntImage MUST be a Python Obit Image" if not Image.PIsA(outImage): print "Actually ",outImage.__class__ raise TypeError,"outImage MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" if len(outPlane) != 5: raise TypeError,"outPlane must have 5 elements" # Obit.ImageUtilPBImage(outImage.me, outImage.me, outPlane, antSize, minGain, err.me) if err.isErr: OErr.printErrMsg(err, "Error with primary beam image")
def __init__(self): """ Constructor Largely derived from https://github.com/bill-cotton/Obit/blob/master/ObitSystem/Obit/share/scripts/AIPSSetup.py """ # Get the current configuration cfg = kc.get_config() self.err = err = OErr.OErr() self.obitsys = OSystem.OSystem("Pipeline", 1, cfg['userno'], 0, [" "], 0, [" "], True, False, err) OErr.printErrMsg(err, "Error starting Obit System") # Setup AIPS userno AIPS.userno = cfg['userno'] # Setup Obit Environment ObitTalkUtil.SetEnviron(AIPS_ROOT=cfg['aipsroot'], AIPS_VERSION=cfg['aipsversion'], OBIT_EXEC=cfg['obitexec'], DA00=cfg['da00'], ARCH="LINUX", aipsdirs=cfg['aipsdirs'], fitsdirs=cfg['fitsdirs'])
def PReimage (inCleanVis, uvdata, err): """ See if an image needs to be remade See if an image needs to be remade because a source which exceeds the flux threshold is not centered (as determined by moments) on the reference pixel (within toler pixel). A new (96x96) field is added centered on the offending source and a negative clean window added to the position of the source in its original window. Avoid duplicates of the same source and ensure that all occurances of this source in any exant field has a negative clean window added. Multiple centering sources per facet are allowed A boolean entry "autoCenField" with value True is added to the info member of any image members added to the mosaic member. * inCleanVis = Python CleanVis object * uvdata = Python uv data from which image is made * err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inCleanVis): raise TypeError,"inCleanVis MUST be a Python ObitCleanVis" if not UV.PIsA(uvdata): raise TypeError,"uvData MUST be a Python Obit UV" # out = Obit.CleanVisReimage(inCleanVis.me, uvdata.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error in Reimage") return out
def PAddDir(newDir, err, URL=None): """ Add a new FITS directory returns FITS disk number newDir = new directory path err = Python Obit Error/message stack URL = URL if on a remote host (Only if using OTObit/ParselTongue) """ ################################################################ global FITSdisks, nFITS # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # retDisk = Obit.FITSAddDir(newDir, err.me) FITSdisks.append(newDir) nFITS = len(FITSdisks) #print "DEBUG nFITS",nFITS if err.isErr: OErr.printErrMsg(err, "Error adding FITS directory") # Update ObitTalk stuff try: FITS.FITS.disks.append(FITS.FITSDisk(URL, retDisk, newDir)) except: pass else: pass return retDisk;
def PUVImage(InImager, err, field=0, doWeight=False, doBeam=True, doFlatten=False): """ Form image optionally doing the calibration/weighting and flatten stages UV Data is imaged to form dirty beam. Control parameters are those on UV data passed at UVImager creation. InImager = UVImager object field = field number (1-rel) to image, 0=> all err = Python Obit Error/message stack doWeight = Do weighting (Uniform, tapering,...) before imaging If True then input data is modified. doBeam = Make Beam before image, must be done once. doFlatten = Flatten image mosaic onto single image """ ################################################################ # # Checks if not PIsA(InImager): print("input class actually ", InImager.__class__) raise TypeError('PUVImage: Bad input UVImager') # Obit.UVImagerImage(InImager.me, field, doWeight, doBeam, doFlatten, err.me) if err.isErr: OErr.printErrMsg(err, "Error Imaging data")
def GetFreqArr(inUV, err, inc = 1): """ Get Array of channel frequencies in data Return list of channel Frequencies (Hz) * inUV = Obit UV data with tables * err = Python Obit Error/message stack * inc = increment in channel """ ################################################################ # Checks if not UV.PIsA(inUV): print "Actually ",inUV.__class__ raise TypeError,"inUV MUST be a Python Obit UV" d = inUV.Desc.Dict # UV data descriptor dictionary refFreq = d["crval"][ d["jlocf"]] # reference frequency nchan = d["inaxes"][ d["jlocf"]] # Number of channels per IF nif = d["inaxes"][ d["jlocif"]] # Number of IFs chwid = abs(d["cdelt"][ d["jlocf"]]) # channel width from header fqtab = inUV.NewTable(Table.READONLY,"AIPS FQ",1,err) fqtab.Open(Table.READONLY,err) fqrow = fqtab.ReadRow(1, err) # Only bother with first OErr.printErrMsg(err) # catch table errors IFfreq = fqrow['IF FREQ'] # IF offset ChWidth = fqrow['CH WIDTH'] # IF channel width sideband = fqrow['SIDEBAND'] # IF sizeband, 1=USB, -1=LSB freqs = [] for iif in range(0,nif): for ifq in range(0,nchan,inc): frq = refFreq + IFfreq[iif] + sideband[iif] * ifq * min (chwid, ChWidth[iif]) freqs.append(frq) # End loops return freqs
def VLAClearCal(uv, err, doGain=True, doBP=False, doFlag=False): """ Clear previous calibration Delete all SN tables, all CL but CL 1 uv = UV data object to clear err = Obit error/message stack doGain = If True, delete SN and CL tables doBP = If True, delete BP tables doFlag = If True, delete FG tables """ ################################################################ # Gain tables if doGain: uv.ZapTable("AIPS SN",-1,err) ver = uv.GetHighVer("AIPS CL") while (ver>1): uv.ZapTable ('AIPS CL', ver, err) ver = ver-1 # Bandpass if doBP: uv.ZapTable("AIPS BP",-1,err) # Flag tables if doFlag: uv.ZapTable("AIPS FG",-1,err) OErr.printErrMsg(err, "VLAClearCal: Error reseting calibration")
def PAddDir(newDir, err, URL=None): """ Add a new FITS directory returns FITS disk number * newDir = new directory path * err = Python Obit Error/message stack * URL = URL if on a remote host (Only if using OTObit/ParselTongue) """ ################################################################ global FITSdisks, nFITS # Checks if not OErr.OErrIsA(err): raise TypeError, "err MUST be an OErr" # retDisk = Obit.FITSAddDir(newDir, err.me) FITSdisks.append(newDir) nFITS = len(FITSdisks) #print "DEBUG nFITS",nFITS if err.isErr: OErr.printErrMsg(err, "Error adding FITS directory") # Update ObitTalk stuff try: FITS.FITS.disks.append(FITS.FITSDisk(URL, retDisk, newDir)) except: pass else: pass return retDisk
def PCreate(name, mosaic, err): """ Create the parameters and underlying structures of a CleanImage. Note: The dirty image will be replaced by the CLEAN image by the Clean. * name = Name to be given to object Most control parameters are in InfoList member * mosaic = Python ImageMosaic to attach * err = Python Obit Error/message stack """ ################################################################ # Checks if not ImageMosaic.PIsA(mosaic): raise TypeError("mosaic MUST be a Python Obit ImageMosaic") if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # out = CleanImage(name) out.me = Obit.CleanImageCreate(name, mosaic.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error creating CleanImage") return out
def PNVSSFetch (RA, Dec, outfile, err, \ Type = 'image/xfits', Equinox = '2000', \ ObjName='unnamed', Size = '0.50 0.50', \ Poltype = 'I', MAPROJ = 'SIN', rotate = 0.0, Cells=[15.,15.]): """ Postage Stamp server for the NRAO/VLA Sky Survey (1.4 GHz) Fetch a postage stamp (AKA cutout) FITS image, jpeg or contour from the NVSS If a FITS file, returns an ObitImage object pointing to the result, otherwise the output file name If something goes wrong with the request or download, the output file will likely contain an HTML file explaining the results. Throws exception on error * RA = Right Ascension as 'hh mm ss.sss' * Dec = Declination as 'sdd mm ss.ss' * outfile = Name of the output file, absolute path or relative to CWD None => use name from server * err = Python Obit Error/message stack * Type = Type = "type" of result; 'image/jpeg' = jpeg image, 'application/octet-stream' = fits file 'image/x-fits' = fits image (default = /image/jpeg) * Equinox = coordinate equinox ('2000' or '1950') * ObjName = object name - used for labeling only (optional) * Size = field size (RA,dec) in deg. (default 0.50 0.50) * Poltype = total intensity 'I' or 'IQU' (default 'I') * MAPROJ = Map projection type: 'SIN', 'TAN', 'ARC', 'NCP', 'GLS', 'MER', 'AIT','STG' * rotate = Rotation on sky in deg in sense of from North to East * Cells = pixel spacing in aseconds (default 15. 15.) """ ################################################################ # Package parameters query_args = { 'Type': Type, 'Equinox': Equinox, 'ObjName': ObjName, 'RA': RA, 'Dec': Dec, 'Size': Size, 'Poltype': Poltype, 'MAPROJ': MAPROJ, 'rotate': str(rotate), 'Cells': str(Cells[0]) + ' ' + str(Cells[1]) } NVSSURL = "https://www.cv.nrao.edu/cgi-bin/postage.pl" # fetch PWebFetch(NVSSURL, query_args, outfile, err) # Get fits image if requested if (Type == 'image/x-fits') or (Type == 'application/octet-stream'): #print "Get FITS" outfits = Image.newPFImage(ObjName, outfile, 0, True, err) OErr.printErrMsg(err, "Problem with FITS image, see contents of outfile") else: return outfile return outfits
def PAllDest(disk, err, Atype = " ", Aname=None, Aclass=None, Aseq=0): """ Delete selected AIPS catalog entries Entries can be selected using Atype, Aname, Aclass, Aseq, using AIPS wildcards A "?" matches one of any character, "*" matches any string all blanks matches anything disk = AIPS disk number, 0=>all err = Python Obit Error/message stack type = optional file type Aname = desired name, using AIPS wildcards, None -> don't check Aclass = desired class, using AIPS wildcards, None -> don't check Aseq = desired sequence, 0=> any first = optional first slot number (1-rel) last = optional last slot number giveList = If true, return list of CNOs matching """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # if (disk<0) or (disk>(len(AIPS.AIPS.disks)+1)): raise RuntimeError,"Disk "+str(disk)+" out of range" # disks if disk>0: disks=[disk] else: disks= range(1,len(AIPS.AIPS.disks)) user = OSystem.PGetAIPSuser() # loop over disks for dsk in disks: ncno = PNumber (dsk, user, err) OErr.printErrMsg(err, "Error getting number of cnos") for cno in range(1, ncno): line=PInfo(dsk, user, cno, err); OErr.printErrMsg(err, "Error reading entry") if WantDir(line, type=Atype, Aname=Aname, Aclass=Aclass, Aseq=Aseq): # parse directory string Tname = line[0:12] Tclass = line[13:19] Tseq = int(line[20:25]) Ttype = line[26:28] z = None if Ttype == 'MA': z = Image.newPAImage("Zap image", Tname, Tclass, dsk, Tseq, True, err, \ verbose=False) print "Zap AIPS Image",Tname, Tclass, dsk, Tseq elif Ttype == 'UV': z = UV.newPAUV("Zap UV data", Tname, Tclass, dsk, Tseq, True, err, \ verbose=False) print "Zap AIPS UV",Tname, Tclass, dsk, Tseq # Delete entry if z: z.Zap(err) del z
def PFit (inImageFit, err, input=FitInput): """ Fit a model to an image Resultant model left in FitRegion reg inImageFit = Python ImageFit object image = ObitImage to be fitted reg = Fit region defining what is to be fitted and initial guess err = Python Obit Error/message stack input = input parameter dictionary Input dictionary entries: fitImage = Image to be fitted fitRegion = FitRegion to be fitted MaxIter int Maximum number of iterations [def. 10 per fitted parameter] prtLv int Message level, 0=>none [def 0] PosGuard float Distance (cells) from edge to allow center [def no bound] FluxLow float Lower bounds on Flux density [def no bound] GMajUp float Major axis upper bound (cells) [def no bound] GMajLow float Major axis lower bound (cells) [def no bound] GMinUp float Minor axis upper bound (cells) [def no bound] GMinLow float Minor axis lower bound (cells) [def no bound] """ ################################################################ # Get input parameters fitImage = input["fitImage"] fitRegion = input["fitRegion"] # Checks if not PIsA(inImageFit): raise TypeError,"inImageFit MUST be a Python Obit ImageFit" if not Image.PIsA(fitImage): raise TypeError,"fitImage MUST be a Python Obit Image" if not FitRegion.PIsA(fitRegion): raise TypeError,"fitRegion MUST be a Python Obit FitRegion" # dim = [1,1,1,1,1] # # Set control values on ImageFit inInfo = PGetList(inImageFit) # InfoList.PAlwaysPutInt (inInfo, "MaxIter", dim, [input["MaxIter"]]) InfoList.PAlwaysPutInt (inInfo, "prtLv", dim, [input["prtLv"]]) InfoList.PAlwaysPutDouble (inInfo, "PosGuard", dim, [input["PosGuard"]]) InfoList.PAlwaysPutDouble (inInfo, "FluxLow", dim, [input["FluxLow"]]) InfoList.PAlwaysPutDouble (inInfo, "GMajUp", dim, [input["GMajUp"]]) InfoList.PAlwaysPutDouble (inInfo, "GMajLow", dim, [input["GMajLow"]]) InfoList.PAlwaysPutDouble (inInfo, "GMinUp", dim, [input["GMinUp"]]) InfoList.PAlwaysPutDouble (inInfo, "GMinLow", dim, [input["GMinLow"]]) # # Do operation sm = inImageFit.cast(myClass) # cast pointer ret = Obit.ImageFitFit(sm, fitImage.me, fitRegion.me, err.me) if ret==0: print "Fit converged" else: print "Fit hit iteration limit" if err.isErr: OErr.printErrMsg(err, "Error Fitting model")
def AUcat(disk=Adisk, first=1, last=1000): """ Catalog listing of AIPS UV data files on disk disk disk = AIPS disk number to list first = lowest slot number to list last = highest slot number to list """ ################################################################ Adisk = disk AIPSDir.PListDir(disk, err, type=AIPSDir.UVType, first=first, last=last) OErr.printErrMsg(err, "Error with AIPS catalog")
def Acat(disk=Adisk, first=1, last=1000): """ Catalog listing of AIPS files on disk disk The class remembers the last disk accessed disk = AIPS disk number to list first = lowest slot number to list last =highest slot number to list """ ################################################################ Adisk = disk AIPSDir.PListDir(disk, err, first=first, last=last) OErr.printErrMsg(err, "Error with AIPS catalog")
def PUVWeight (InImager, err, input=UVWeightInput): """ Apply any calibration/editing/selection and do UV weighting UV Data is calibrated and weighted, values in input override those given when the UVImage was created. This operation is optionally done in PUVImage. err = Python Obit Error/message stack input = input parameter dictionary Input dictionary entries: InImager = Input Python UVImager to image Robust = Briggs robust parameter. (AIPS definition) UVTaper = UV plane taper, sigma in klambda,deg as [maj, min, pa] WtSize = Size of weighting grid in cells [same as image nx] WtBox = Size of weighting box in cells [def 1] WtFunc = Weighting convolution function [def. 1] 1=Pill box, 2=linear, 3=exponential, 4=Gaussian if positive, function is of radius, negative in u and v. WtPower = Power to raise weights to. [def = 1.0] Note: a power of 0.0 sets all the output weights to 1 as modified by uniform/Tapering weighting. Applied in determinng weights as well as after. Channel = Channel (1-rel) number to image, 0-> all. """ ################################################################ # Get input parameters Channel = input["Channel"] WtSize = input["WtSize"] # # Checks if not PIsA(InImager): raise TypeError, 'PUVWeight: Bad input UVImager' # Set control values on UV dim[0] = 1; dim[1] = 1; dim[2] = 1; dim[3] = 1; dim[4] = 1 inInfo = UV.PGetList(PGetUV(InImager)) InfoList.PAlwaysPutFloat (inInfo, "Robust", dim, [input["Robust"]]) InfoList.PAlwaysPutInt (inInfo, "WtBox", dim, [input["WtBox"]]) InfoList.PAlwaysPutInt (inInfo, "WtFunc", dim, [input["WtFunc"]]) InfoList.PAlwaysPutFloat (inInfo, "WtPower",dim, [input["WtPower"]]) dim[1] = len(input["UVTaper"]) InfoList.PAlwaysPutFloat (inInfo, "Taper", dim, input["UVTaper"]) if (WtSize>0): print "WtSize", WtSize # Change name for C routine. dim[0] = 1; InfoList.PAlwaysPutInt (inInfo, "nuGrid", dim, [WtSize]) InfoList.PAlwaysPutInt (inInfo, "nvGrid", dim, [WtSize]) # Obit.UVImagerWeight (InImager.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error weighting UV data")
def PNumber(disk, user, err): """ Return highest current allowed AIPS catalog Slot number disk = AIPS disk number user = AIPS user number err = Python Obit Error/message stack """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # ret = Obit.AIPSDirNumber(disk, user, err.me) if err.isErr: OErr.printErrMsg(err, "Error obtaining highest AIPS catalog number") return ret
def PRestore (clean, err): """ Restore subtracted CLEAN components to residual image clean = Clean object containing mosaic err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(clean): raise TypeError,"mosaic MUST be a Python Obit CleanImage" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # Obit.CleanImageRestore(clean.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error defining window")
def PZap (inHis, err): """ Destroy the persistent form of a History inHis = input Python Obit History err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inHis): raise TypeError,"inHis MUST be a History" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # Obit.HistoryZap (inHis.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error deleting History")
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 PGetMosaic (InImager, err): """ Return the member ImageMosaic returns ImageMosaic InImager = Python ImageMosaic object err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(InImager): raise TypeError,"InImager MUST be a Python Obit UVImager" # out = ImageMosaic.ImageMosaic("None", 1) out.me = Obit.UVImagerGetMosaic(InImager.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error obtaining Mosaic member") return out
def PDump(infile, list, err): """ Dump list to text file Dump parameter format text file and copy to list returns 0 on success, else 1 outfile = Name of the output text file to write list = ObitInfoList to dump err = ObitErr for reporting errors. """ ################################################################ # Checks if not InfoList.PIsA(list): raise TypeError,"list MUST be a Python Obit InfoList" ret = Obit.Dump(infile, list.me, err.me) if ret or err.isErr: OErr.printErrMsg(err, "Error Dumping to "+infile) return ret
def PRemove(disk, user, cno, err): """ Deallocate AIPS catalog slot number disk = AIPS disk number user = AIPS user number cno = AIPS catalog slot to deassign err = Python Obit Error/message stack """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # ret = Obit.AIPSDirRemoveEntry(disk, user, cno, err.me) if err.isErr: OErr.printErrMsg(err, "Error removing AIPS catalog entry") return ret
def PClone (inFA, err): """ Make copy the structure of an FArray Zero fill and return FArray with same structure as in inFA = input Python FArray err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inFA): print "Actually ",inFA.__class__ raise TypeError,"inFA MUST be a Python Obit FArray" outFA = FArray("Clone") Obit.FArrayClone (inFA.me, outFA.me, err.me); if err.isErr: OErr.printErrMsg(err, "Error zero cloning FArray") return outFA
def PCopy (inFA, err): """ Make copy an FArray returns copy inFA = input Python FArray err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inFA): print "Actually ",inFA.__class__ raise TypeError,"inFA MUST be a Python Obit FArray" outFA = FArray("None") outFA.me = Obit.FArrayCopy (inFA.me, outFA.me, err.me); if err.isErr: OErr.printErrMsg(err, "Error copying FArray") return outFA
def PTimeStamp (inHis, label, err): """ Write timestamp and label to History return 0 on success, else failure inHis = input Python History label = character string for label err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inHis): raise TypeError,"inHis MUST be a History" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # ret = Obit.HistoryTimeStamp(inHis.me, label, err.me) if err.isErr: OErr.printErrMsg(err, "Error writing History time stamp")
def PClose (inHis, err): """ Close History return 0 on success, else failure inHis = input Python History err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inHis): raise TypeError,"inHis MUST be a History" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # ret = Obit.HistoryClose(inHis.me, err.me) if err.isErr: OErr.printErrMsg(err, "Error closing History") return ret
def PCompressCC (inSkyModel, err): """ Compress CC tables Compresses CC tables on all Images in mosaic inSkyModel = Python SkyModel object to compress err = Python Obit Error/message stack """ ################################################################ # Checks if not PIsA(inSkyModel): raise TypeError,"inSkyModel MUST be a Python Obit SkyModel" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # smi = inSkyModel.cast(myClass) # cast pointer Obit.SkyModelCompressCC (smi, err.me) if err.isErr: OErr.printErrMsg(err, "Error copying SkyModel")