""" # Start this in the Script directory import os import shutil import glob cwd = os.path.split(os.getcwd())[1] if cwd != 'script': raise ValueError("Start this script in the script/ directory") # AnalysisUtils required (probably because I didn't disable the QA2 stuff...) import sys sys.path.append(os.path.join(os.getcwd(), 'analysis_scripts')) sys.path.append("/users/thunter/AIV/science/analysis_scripts/") import analysisUtils as au import analysisUtils as aU es = au.stuffForScienceDataReduction() # yep, start it in script, then immediately chdir os.chdir('../calibrated') sourcefiles = [ '../raw/uid___A002_X95e355_X1f13.asdm.sdm', '../raw/uid___A002_X9cffbd_Xefe.asdm.sdm', '../raw/uid___A002_X95e355_X220a.asdm.sdm', '../raw/uid___A002_X9d13e3_Xd4f.asdm.sdm', ] uidnames = [os.path.basename(sf[:-9]) for sf in sourcefiles] for source in sourcefiles: for target in (',', os.path.basename(source[:-9])):
def extractSpw(self,msName,intent = 'CALIBRATE_BANDPASS', listCal = []): "Extract the spectra from a spw of a given intent" es = aU.stuffForScienceDataReduction() # vm = aU.ValueMapping(msName) try: tb.open(msName) dataColNames = tb.colnames() tb.close() except: print("##") print("## Error to open : %s"%(msName)) print('## \n\n') return(False,[], [],[]) if 'CORRECTED_DATA' in dataColNames: dataCol = 'corrected' else: dataCol = 'data' tb.open(msName+'/FIELD') sourceIds = tb.getcol('SOURCE_ID') tb.close() intentSources = es.getIntentsAndSourceNames(msName) if intentSources[intent]['name'][0] == '': return(False, [], [], []) calIds = intentSources[intent]['sourceid'] calName = intentSources[intent]['name'] calIds = sorted(dict.fromkeys(calIds).keys()) calName = sorted(dict.fromkeys(calName).keys()) ### spw info spwInfo = es.getSpwInfo(msName) spwIds = sorted(spwInfo.keys()) print spwIds listFile = [] listCalFile = [] listSuccess = [] listSpw = [] for calNameJ in calName: found = False if calNameJ in listCal: found = True if not found: listCal.append(calNameJ) for spwj in spwIds: # spwChanFreqs = vm.spwInfo[j]['chanFreqs'] # print spwChanFreqs spwId = "%s"%(spwj) msNameWithoutSlash = msName.split('/')[-1] msNameDat = self.workingDirectory+msNameWithoutSlash calNameJwithoutmultiplename = calNameJ.split(";")[0] fileName = "%s-%s-%s-spw%s.dat"%(msNameDat,intent,calNameJwithoutmultiplename,spwj) print fileName successSpw = plotms(vis = msName ,xaxis="frequency",xdatacolumn = "",yaxis="amp",ydatacolumn = dataCol ,selectdata=True,field = calNameJ, spw = spwId ,timerange="",uvrange="",antenna="",scan="",correlation="",array="",observation="",msselect="",averagedata=True, avgchannel="1",avgtime="1e9",avgscan=True,avgfield=True, avgbaseline=True,avgantenna= False,avgspw=False,scalar=False, transform=False,freqframe="",restfreq="",veldef="RADIO",shift=[0.0, 0.0],extendflag=False,extcorr=False,extchannel=False, iteraxis="",plotfile = fileName ,expformat="txt", highres=False, overwrite=False,showgui=False) listFile.append(fileName) listCalFile.append(calNameJwithoutmultiplename) listSpw.append(spwj) listSuccess.append(successSpw) if not successSpw : print("## Problem with the extraction of %s ..."%(fileName)) print("vvvvvvvvvvvvvvvvvvvvvvvv") print listFile print("vvvvvvvvvvvvvvvvvvvvvvv") return(listSuccess, listFile, listCalFile, listSpw)
def splitCalibrator(self, msName): "Split the MS calibrators" listCalibratorMS = [] es = aU.stuffForScienceDataReduction() try : tb.open(msName) dataColNames = tb.colnames() tb.close() except: print("###") print("### Error to open MS : %s \n"%(msName)) return(-1) ## Band msmd.open(msName) chan_freq = msmd.chanfreqs(1) band = aU.freqToBand(chan_freq[0]) print("## band %s"%(band)) if 'CORRECTED_DATA' in dataColNames: dataCol = 'corrected' else: dataCol = 'data' calNameList = [] intentSources = es.getIntentsAndSourceNames(msName) for intentkey in self.listIntent: calIds = intentSources[intentkey]['sourceid'] calName = intentSources[intentkey]['name'] # calIds = sorted(dict.fromkeys(calIds).keys()) # calName = sorted(dict.fromkeys(calName).keys()) # print calName # print calIds iterCalid = iter(calIds) for name in calName: sourceid = iterCalid.next() if name != '': found = False else : found = True ## avoid empty name for checkname in calNameList: if checkname['name'] == name : found = True if not found : calNameList.append({'name' : name, 'intent': intentkey, 'sourceId': sourceid}) print calNameList for cal in calNameList: ## split the calibrators nameMSCal = "%s-%s-%s.ms"%(msName, cal['intent'], cal['name']) print("## splitting %s \n"%(nameMSCal)) if os.path.exists(nameMSCal): shutil.rmtree(nameMSCal) success = split(vis=msName, outputvis= nameMSCal,datacolumn= dataCol,field= cal['name'],spw="",width=1,antenna="", timebin="0s",timerange="",scan="",intent="",array="",uvrange="",correlation="",observation="",combine="", keepflags=True,keepmms=False) print success if success : refdir = msmd.refdir(cal['sourceId']) listCalibratorMS.append([nameMSCal,cal['name'], band, refdir]) print("## direction:") print(refdir) print("#") else: print("### Splitting : Error with %s"%(nameMSCal)) msmd.close() return(listCalibratorMS)
#raise ValueError("Does not work: need to specify a reference antenna.") # Start this in the Script directory import shutil import glob import os cwd = os.path.split(os.getcwd())[1] if cwd != 'script': raise ValueError("Start this script in the script/ directory") # AnalysisUtils required (probably because I didn't disable the QA2 stuff...) import sys sys.path.append(os.path.join(os.getcwd(), 'analysis_scripts')) sys.path.append("/users/thunter/AIV/science/analysis_scripts/") import analysisUtils as au import analysisUtils as aU es = au.stuffForScienceDataReduction() # yep, start it in script, then immediately chdir os.chdir('../calibrated') sourcefiles = [ '../raw/uid___A002_X85b7b2_Xb3.asdm.sdm', '../raw/uid___A002_X85c183_X1434.asdm.sdm', '../raw/uid___A002_X85dcf7_Xc7c.asdm.sdm', '../raw/uid___A002_X85dcf7_Xefe.asdm.sdm', ] refant = 'CM03' uidnames = [os.path.basename(sf[:-9]) for sf in sourcefiles]