# Set data inData = OTF.newPOTF("Input data", inFile, disk, 1, err) OErr.printErrMsg(err, "Error initializing") # Set scans scan = [126, 128] # Part 2 #scan = [40,42] # Part 1, first #scan = [77,75] # Part 1, second dim = OTF.dim dim[0] = 1 dim[1] = 1 inInfo = OTF.PGetList(inData) dim[0] = 2 InfoList.PAlwaysPutInt(inInfo, "Scan", dim, scan) #Bomb() # Do fitting OTFUtil.PFitOnOff(inData, -1, err) OErr.printErrMsg(err, "Error fitting cal scan") # Give results print "Fitting scans", scan, "in", inFile stuff = InfoList.PGet(inInfo, "TRX") print "Average TRx = ", stuff[4] stuff = InfoList.PGet(inInfo, "CALJY") print "Average CalJy = ", stuff[4] # Shutdown Obit OErr.printErr(err)
OErr.printErrMsg(err, "Error with Obit startup") # Files disk = 1 inFile = "GBTDaisyX2OTF.fits" # input OTF data imageFile = "PythonDaisyXClean.fits" # Input image to subtract (clean) #imageFile= "PythonTDaisyX.fits" # Input image to subtract (dirty) outFile = "!GBTDaisyXSubOTF.fits" # output OTF data # Set data inData = OTF.newPOTF("Input data", inFile, disk, 1, err) outData = OTF.newPOTF("Output data", outFile, disk, 0, err) OTF.POTFClone(inData, outData, err) # Same structure etc modImage = Image.newPImage("Model Image", imageFile, disk, 1, err) OErr.printErrMsg(err, "Error initializing") # Read image imageData = Image.PImageReadPlane(modImage, err) imageDesc = Image.PImageGetDesc(modImage) OErr.printErrMsg(err, "Error reading image") # Subtract image from scratch OTFUtil.POTFUtilSubImage(inData, outData, imageData, imageDesc, err) OErr.printErrMsg(err, "Error subtracting image") # Say something print "Subtracted", imageFile, "from", inFile, " and wrote to", outFile # Shutdown Obit OErr.printErr(err)
scan = [15] tsky = [300.0] minEl = [10.0] tcal = [9.6, 9.8, 5.65, 5.55, 9.6, 9.8, 5.65, 5.55] # Qband dim = OTF.dim dim[0] = 1 dim[1] = 1 inInfo = OTF.PGetList(inData) InfoList.PAlwaysPutInt(inInfo, "Scan", dim, scan) InfoList.PAlwaysPutFloat(inInfo, "TSKY", dim, tsky) InfoList.PAlwaysPutFloat(inInfo, "MINEL", dim, minEl) dim[0] = len(tcal) InfoList.PAlwaysPutFloat(inInfo, "TCAL", dim, tcal) # Do fitting OTFUtil.PFitTip(inData, err) OErr.printErrMsg(err, "Error fitting tipping scan") # Give results print "Fitting scan", scan[0], "in", inFile, "above elev", minEl[0] stuff = InfoList.PGet(inInfo, "TAU0") print "tau0 = ", stuff[4] stuff = InfoList.PGet(inInfo, "TRX") print "TRx = ", stuff[4], "cal units" print "TRx = ", stuff[4][0] * tcal[0], stuff[4][1] * tcal[1], "K" stuff = InfoList.PGet(inInfo, "ATEMP") print "ATemp = ", stuff[4], "cal units per airmass" print "ATemp = ", stuff[4][0] * tcal[0], stuff[4][1] * tcal[1], "K" stuff = InfoList.PGet(inInfo, "TIPRMS") print "RMS residuals (K) = ", stuff[4]
# Files disk = 1 inFile = "QbandOTF.fits" # input OTF data # Editing timerange = [0.0, 1.0e20] # all times chans = [1, 0] # all channels flagVer = 1 # Flagging table 1 target = "Any" # all targets feed = 2 # Flag microphonic data stokes = "100" # Stokes flag reason = "Microphonic" # reason string # Set data inData = OTF.newPOTF("Input data", inFile, disk, 1, err) OErr.printErrMsg(err, "Error creating input data object") # Make edit OTFUtil.PFlag(inData, err, timerange, target, flagVer, chans, stokes, feed, reason) feed = 4 OTFUtil.PFlag(inData, err, timerange, target, flagVer, chans, stokes, feed, reason) OErr.printErrMsg(err, "Error writing flag table") # tell results print "Flag", inFile, "timerange", timerange, "stokes", stokes, 'feed', feed # Shutdown Obit OErr.printErr(err)
OTF.PClone(inData, outData, err) # Same structure etc #tttData = OTF.newPOTF("tmp data", "!"+tmpFile, disk, 0, err) #OTF.PClone(inData, tttData, err) # Same structure etc modImage = Image.newPImage("Model Image", imageFile, disk, 1, err) OErr.printErrMsg(err, "Error initializing") # Read image imageData = Image.PReadPlane(modImage, err) imageDesc = Image.PGetDesc(modImage) OErr.printErrMsg(err, "Error reading image") # Make scratch version tmpData = OTF.PScratch(inData, err) OErr.printErrMsg(err, "Error making scratch file") # zero scratch data scale = 0.0 offset = 0.0 OTFUtil.PScale(inData, tmpData, scale, offset, err) OErr.printErrMsg(err, "Error scaling OTF") # Subtract image from scratch OTFUtil.PSubImage(tmpData, outData, imageData, imageDesc, err) OErr.printErrMsg(err, "Error subtracting image") # Say something print "Subtracted", imageFile, "from", inFile, " and wrote to", outFile # Shutdown Obit OErr.printErr(err)
# Set scans scan = [80, 81, 82, 83] # 16Apr04 Q band test tau0 = 0.03 #Qband - wild guess ATemp = [0.735, 0.722, 0.722, 0.722, 0.722, 0.722, 0.722, 0.722] # wild guess dim = OTF.dim dim[0] = 1 dim[1] = 1 inInfo = OTF.PGetList(inData) InfoList.PAlwaysPutFloat(inInfo, "TAU0", dim, [tau0]) dim[0] = len(ATemp) InfoList.PAlwaysPutFloat(inInfo, "ATEMP", dim, ATemp) dim[0] = 4 InfoList.PAlwaysPutInt(inInfo, "Scan", dim, scan) # Do fitting OTFUtil.PFitCal(inData, -1, err) OErr.printErrMsg(err, "Error fitting cal scan") # Give results print "Fitting scans", scan, "in", inFile stuff = InfoList.PGet(inInfo, "TRX") print "Average TRx = ", stuff[4] stuff = InfoList.PGet(inInfo, "CALJY") print "Average CalJy = ", stuff[4] stuff = InfoList.PGet(inInfo, "Timeoff") print "Average Timeoff = ", stuff[4] print "Use opposite sign of Timeoff in DCR2OTR input" # Shutdown Obit OErr.printErr(err)
tsky = [300.0] minEl = [10.0] #XBand tcal = [3.24,3.35] tcal = [3.93, 2.88] # Cband dim = OTF.dim dim[0] = 1 dim[1] = 1 inInfo = OTF.PGetList(inData) InfoList.PAlwaysPutInt(inInfo, "Scan", dim, scan) InfoList.PAlwaysPutFloat(inInfo, "TSKY", dim, tsky) InfoList.PAlwaysPutFloat(inInfo, "MINEL", dim, minEl) dim[0] = 2 InfoList.PAlwaysPutFloat(inInfo, "TCAL", dim, tcal) # Do fitting OTFUtil.POTFUtilFitTip(inData, err) OErr.printErrMsg(err, "Error fitting tipping scan") # Give results print "Fitting scan", scan[0], "in", inFile, "above elev", minEl[0] stuff = InfoList.PGet(inInfo, "TAU0") print "tau0 = ", stuff[4] stuff = InfoList.PGet(inInfo, "TRX") print "TRx = ", stuff[4], "cal units" print "TRx = ", stuff[4][0] * tcal[0], stuff[4][1] * tcal[1], "K" stuff = InfoList.PGet(inInfo, "ATEMP") print "ATemp = ", stuff[4], "cal units per airmass" print "ATemp = ", stuff[4][0] * tcal[0], stuff[4][1] * tcal[1], "K" stuff = InfoList.Pet(inInfo, "TIPRMS") print "RMS residuals (K) = ", stuff[4]
inInfo.set("Targets", target) inInfo.set("Scans", scans) inInfo.set("timeRange", timerange) inInfo.set("doCalSelect", True) inInfo.set("flagVer", flagver) gainuse = 0 inInfo.set("gainUse", gainuse) inInfo.set("doCalib", 1) # Copy/calibrate Scan list or range? if ScanList: inOTF.CopyList(outOTF, ScanList, err) else: inOTF.Copy(outOTF, err) # Index OTFUtil.PIndex(outOTF, err) OErr.printErrMsg(err, "Error selecting data") # Create an initial dummy table with a interval 1/4 of the shortest # Filter type solution interval. inter = solInt / 4 OTFGetSoln.POTFGetDummyCal(outOTF, outOTF, inter, 1, 1, err) inInfo = outOTF.List ############################ Initial Common Mode filter ######################## baseCal = 1 if (CommonInt): print "Common mode only calibration, si=", CommonInt ResidCalInput = OTF.ResidCalInput ResidCalInput["InData"] = outOTF ResidCalInput["solInt"] = CommonInt ResidCalInput["solType"] = "MultiBeam" # Common mode
def InitCal (inData, targets, err, \ flagver=1, CalJy=[38.5], BLInt=30., AtmInt=20.,tau0=0.1, PointTab=None, prior=None, priorModel = True, PSF=None, clip=0.0): """ Initial calibration of Mustang (PAR) data Any prior calibration tables are removed and then does the following: 1) Generate an initial Cal table with a time increment of 1/4 of the lesser of BLInt and AtmInt 2) Gain and Weight calibration, conversion to Jy uses CalJy CalJy can contain either a single value for all detectors or one value per detector. This is the value of the cal in Jy. 3) a "Baseline" per detector offsets on timescales longer than BLInt are determined and applied 4) "Atmosphere" calibration determining one offset per detector per scan and a common mode offset on time scales longer than AtmInt. Opacity corrections are based on tau0 (zenith opacity in nepers) 5) If PointTab is specified, pointing corrections are applied. When the procedure is finished, data cal be calibrated using the highest Cal table. If prior is given it is a Clean image if the target to be subtracted prior to the Baseline and Atmosphere calibration. Note: this only makes sense when all targets are covered by prior. If this option is used the instrumental PSF must also be provided in PSF. inData = OTF data set to be calibrated targets = list of target names, empty list = all err = Python Obit Error/message stack flagver = CalJy = Array of the cal in Jy. CalJy can contain either a single value for all detectors or one value per detector. BLInt = Baseline filter shortest timescale in sec AtmInt = Atmospheric filter shortest timescale in sec tau0 = zenith opacity in nepers this can be either a scalar constant opacity, or a table in the form of a list of lists of time (days) and opacity, e.g.: # From Ron's weather server from CLEO tau0 = [[0.000, 0.102], \ [0.042, 0.100], \ [0.083, 0.100], \ [0.250, 0.154]] PointTab= a table of pointing offsets in time order [time(day) d Xel (asec), d el (asec)] an example: PointTab=[[0.06189,-0.38, 0.38], \ [0.09888,-2.77,-1.80], \ [0.13052,-2.10,-0.92], \ [0.16667,-1.86, 1.07], \ [0.19509,-2.32, 1.29]] Such a table can be generated from a dataset by CalImage prior = If given, a CLEAN image covering all targets given, This model will be subtracted from the data prior to "Baseline" and "Atmosphere" calibration If this option is used the instrumental PSF must also be provided in PSF. priorModel = If prior defined then priorModel is true if the model (CC table) is to be used, if False then the image itself is used. PSF = If prior is given, this is the instrumental PSF to use in the subtraction. clip = clip model below this value """ # Initial calibration # delete any prior calibration tables print "Remove previous calibration" OTF.ClearCal(inData, err) OErr.printErrMsg(err, "Error deleting prior cal tables") solInt = min(BLInt, AtmInt) # Create an initial dummy table with a interval 1/4 of the shortest # Filter type solution interval. inter = solInt / 4 print "Create initial calibration table, interval", inter OTFGetSoln.POTFGetDummyCal(inData, inData, inter, 1, 1, err) OErr.printErrMsg(err, "Error creating initial cal table") # Gain/Weight calibration print "Gain/Weight calibration" inInfo = inData.List inInfo.set("calJy", CalJy) inInfo.set("doWate", True) # Do weight calibration OTFGetSoln.POTFGetSolnPARGain(inData, inData, err) OErr.printErrMsg(err, "Error with Gain/Weight calibration") # Update OTF Cal table OTF.Soln2CalInput["InData"] = inData # Input data object OTF.Soln2CalInput["oldCal"] = 1 # Use initial cal OTF.Soln2CalInput["newCal"] = 2 # New cal table OTF.Soln2Cal(err, OTF.Soln2CalInput) # Apply OErr.printErrMsg(err, "Error updating Cal table with Soln") ################################## Target specification ################################# inInfo.set("Targets", targets) # select only target data inInfo.set("Stokes", " ") # Set Stokes inInfo.set("doCalSelect", True) inInfo.set("flagVer", flagver) inInfo.set("gainUse", 0) ########################### Residual data from prior model ############################# # Get prior model, if any and compute residual OTF if prior != None: print "Using prior model, priorModel=", priorModel gainuse = 0 inInfo.set("gainUse", gainuse) inInfo.set("doCalib", 1) inInfo.set("flagVer", flagver) if priorModel: # Use CC table prior.List.set("clip", clip) resid = OTFUtil.PSubModel(inData, None, prior, PSF, err) else: # Use Image prior.Open(Image.READONLY, err) prior.Read(err) prior.Close(err) resid = OTF.PScratch(inData, err) OTFUtil.PSubImage(inData, resid, prior.FArray, prior.Desc, err) OErr.printErrMsg(err, "Error with residial data") else: print "No prior model used" resid = inData ############################## "Baseline" filter ############################# print "Baseline Filter" solint = BLInt / 86400.0 inInfo.set("solInt", solint) inInfo.set("doCalSelect", True) inInfo.set("flagVer", flagver) gainuse = 2 inInfo.set("gainUse", gainuse) inInfo.set("doCalib", 1) OTFGetSoln.PFilter(resid, inData, err) OErr.printErrMsg(err, "Error with Baseline calibration") # Soln2Cal parameters for filter cal (most defaulted) OTF.Soln2CalInput["InData"] = inData # Input data object OTF.Soln2CalInput["oldCal"] = 2 # Use gain cal output OTF.Soln2CalInput["newCal"] = 3 # New cal table OTF.Soln2Cal(err, OTF.Soln2CalInput) # Apply OErr.printErrMsg(err, "Error updating Cal table with Soln") ########################### Residual data from prior model ############################# # Get prior model, if any and compute residual OTF if prior != None: print "Using prior model, priorModel=", priorModel gainuse = 0 inInfo.set("gainUse", gainuse) inInfo.set("doCalib", 1) inInfo.set("flagVer", flagver) if priorModel: # Use CC table resid = OTFUtil.PSubModel(inData, None, prior, PSF, err) else: # Use Image prior.Open(Image.READONLY, err) prior.Read(err) prior.Close(err) resid = OTF.PScratch(inData, err) OTFUtil.PSubImage(inData, resid, prior.FArray, prior.Desc, err) OErr.printErrMsg(err, "Error with residial data") else: print "No prior model used" resid = inData ############################## Common atmosphere + offset ############################# print "Common atmosphere removal" inInfo.set("Tau0", tau0) # Opacity table inInfo.set("doCalSelect", True) inInfo.set("flagVer", flagver) gainuse = 0 inInfo.set("gainUse", gainuse) inInfo.set("doCalib", 1) solint = AtmInt / 86400.0 inInfo.set("solInt", solint) clipsig = 5.0 inInfo.set("ClipSig", clipsig) plotDet = -10 inInfo.set("plotDet", plotDet) OTFGetSoln.PMBBase(resid, inData, err) OErr.printErrMsg(err, "Error with atmosphere calibration") # Soln2Cal for Atm cal OTF.Soln2CalInput["InData"] = inData # Input data object OTF.Soln2CalInput["oldCal"] = 3 # Use baseline cal output OTF.Soln2CalInput["newCal"] = 4 # New cal table OTF.Soln2Cal(err, OTF.Soln2CalInput) # Apply OErr.printErrMsg(err, "Error updating Cal table with Soln") ############################### Pointing correction ################################## if PointTab != None: print "Apply pointing corrections" inInfo.set("POffset", PointTab) OTFGetSoln.POTFGetSolnPointTab(inData, inData, err) OErr.printErrMsg(err, "Error with pointing corrections") # Soln2Cal for Point cal OTF.Soln2CalInput["InData"] = inData # Input data object OTF.Soln2CalInput["oldCal"] = 4 # Use baseline cal output OTF.Soln2CalInput["newCal"] = 5 # New cal table OTF.Soln2Cal(err, OTF.Soln2CalInput) # Apply OErr.printErrMsg(err, "Error updating Cal table with Soln")
def CleanSkyModel(err, input=CleanSkyModelInput): """ Create a CLEAN image sky model of an OTF data set Does imaging and cleaning of specified data. Returns an image model of the CLEAN components convolved with PSF err = Python Obit Error/message stack input = input parameter dictionary, for interactive use, the function input will display the contents in human readable format. Input dictionary entries: InData = Python input OTF to calibrate DirtyName = Dirty image name, None = scratch CleanName = Clean image name, None = scratch outDisk = Disk number for output files PSF = Image with telescope psf scans = scan range to image target = list of targets to include, center will be position of first nx = number of pixels in 'X' = RA ny = number of pixels in 'Y' = dec xCells = Cell spacing in x (asec) yCells = Cell spacing in y (asec) ConvType= Convolving function Type 0=pillbox,3=Gaussian,4=exp*sinc,5=Sph wave ConvParm= Convolving function parameters depends on ConvType Type 2 = Sinc, (poor function - don't use) Parm[0] = halfwidth in cells, Parm[1] = Expansion factor Type 3 = Gaussian, Parm[0] = halfwidth in cells,[def 3.0] Parm[1] = Gaussian with as fraction or raw beam [def 1.0] Type 4 = Exp*Sinc Parm[0] = halfwidth in cells, [def 2.0] Parm[1] = 1/sinc factor (cells) [def 1.55] Parm[2] = 1/exp factor (cells) [def 2.52] Parm[3] = exp power [def 2.0] Type 5 = Spherodial wave Parm[0] = halfwidth in cells [def 3.0] Parm[1] = Alpha [def 5.0] Parm[2] = Expansion factor [not used] gainUse = version number of prior table (Soln or Cal) to apply, -1 is none flagVer = version number of flagging table to apply, -1 is none Niter = Maximum number of CLEAN iterations Patch = Beam patch in pixels [def 100] noResid = If True do not include residuals in restored image BeamSize = Restoring beam (deg) Gain = CLEAN loop gain Window = list of Clean windows autoWindow = True if autoWindow feature wanted. """ ################################################################ # Get input parameters dim = [1, 1, 1, 1, 1] inData = input["InData"] inInfo = inData.List # Checks if not OTF.PIsA(inData): raise TypeError, 'Image: Bad input OTF' if err.isErr: # existing error? return None # Set calibration gainUse = input["gainUse"] flagVer = input["flagVer"] # Default table versions (the Obit routines will do this as well) if gainUse == 0: # Get highest numbered OTFCal table gainUse = Obit.OTFGetHighVer(inData.me, "OTFCal") if gainUse == 0: # Doesn't seem to be one, try OTFSoln gainUse = Obit.OTFGetHighVer(inData.me, "OTFSoln") if gainUse == 0: # Must not be one gainUse = -1 inInfo.set("doCalSelect", True) inInfo.set("flagVer", flagVer) if gainUse > 0: inInfo.set("doCalib", 1) inInfo.set("gainUse", gainUse) # Get position from OTF target = input["target"] pos = GBTUtil.GetTargetPos(inData, target[0], err) ra = pos[0] # ra of center dec = pos[1] # dec of center # Set imaging/calibration parameters outDisk = input["outDisk"] # Imaging parameters DirtyName = input["DirtyName"] if DirtyName == None: DirtyName = "tmp" + target[0] + "Dirty.fits" OTF.ImageInput["InData"] = inData OTF.ImageInput["OutName"] = DirtyName OTF.ImageInput["disk"] = outDisk OTF.ImageInput["Beam"] = input["PSF"] OTF.ImageInput["ra"] = ra OTF.ImageInput["dec"] = dec OTF.ImageInput["xCells"] = input["xCells"] OTF.ImageInput["yCells"] = input["yCells"] OTF.ImageInput["nx"] = input["nx"] OTF.ImageInput["ny"] = input["ny"] OTF.ImageInput["gainUse"] = 0 OTF.ImageInput["flagVer"] = flagVer OTF.ImageInput["minWt"] = input["minWt"] OTF.ImageInput["ConvType"] = input["ConvType"] OTF.ImageInput["ConvParm"] = input["ConvParm"] # Make image DirtyImg = OTF.makeImage(err, OTF.ImageInput) OErr.printErrMsg(err, "Error making initial image") # Clean to get sky model cleanFile = input["CleanName"] if cleanFile: CleanImg = Image.newPFImage("Clean Image", cleanFile, outDisk, False, err) else: # scratch CleanImg = DirtyImg.Scratch(err) CleanObj = CleanOTF.PCreate("Clean", DirtyImg, input["PSF"], CleanImg, err) for win in input["Window"]: CleanOTF.PAddWindow(CleanObj, win, err) # CLEAN parameters CleanOTF.CleanInput["CleanOTF"] = CleanObj # Clean object CleanOTF.CleanInput["autoWindow"] = input["autoWindow"] CleanOTF.CleanInput["Patch"] = input["Patch"] CleanOTF.CleanInput["Niter"] = input["Niter"] CleanOTF.CleanInput["Gain"] = input["Gain"] CleanOTF.CleanInput["BeamSize"] = input["BeamSize"] CleanOTF.CleanInput["noResid"] = input["noResid"] #DEBUG CleanOTF.CleanInput["disp"] = input["disp"] CleanOTF.CleanInput["minFlux"] = 0.0 resid = CleanObj.Clean # Copy image just produced Image.PCopy(DirtyImg, resid, err) # to clean(resid) #input(CleanInp) CleanOTF.PClean(err, CleanOTF.CleanInput) # Do Clean OErr.printErrMsg(err, "Error Cleaning") # Replace with Clean model CCTab = CleanImg.NewTable(1, "AIPS CC", 0, err) OErr.printErrMsg(err, "Error getting CCTable") # Use all components dim = [1, 1, 1, 1, 1] CCTab.List.set("BComp", 1) CCTab.List.set("EComp", 0) # Make model image, CC convolved with beam CleanImg.Open(Image.READONLY, err) model = CleanImg.ReadPlane(err) CleanImg.Close(err) model = OTFUtil.PConvBeam(CCTab, CleanObj.Beam, model, err) OErr.printErrMsg(err, "Error making model") # Write model to clean image CleanImg.Open(Image.READWRITE, err) CleanImg.WriteFA(model, err) CleanImg.Close(err) # Delete Dirty Image? if input["DirtyName"] == None: DirtyImg.Zap(err) return CleanImg