# -*- coding: iso-8859-1 -*- ''' #Brian Kent, NRAO 2012 Simple CASA task script to call the linelists web service, parse the XML file, and plot the results. Right now results are trimmed to about 4000 channels during testing. Note this will only work on the NRAO network right now. Start CASA and then run: os.system('buildmytasks') execfile('mytasks.py') inp linelists go ''' import math import sys import os from xml.dom.minidom import parse, parseString, Document import urllib from pylab import * from taskinit import * def linelists(sourceid='15', minFreq=130000, maxFreq=132000, plotDisplay=True): ''' Example method for grabbing the XML file from the line lists, parse out needed information, and plot the result ''' #sourceid = '15' xmlurl = 'http://www.cv.nrao.edu/php-internal/bkent/linelists/linelists.php' xmlpath = xmlurl + '?sourceid=' + str(sourceid) try: xml = urllib.urlopen(xmlpath) xmldom = parse(xml) except e as Exception: print(e) tablelist = xmldom.getElementsByTagName('TD') #print len(tablelist) freq=[] inten=[] for i in range(0,len(tablelist),2): freq.append(float(tablelist[i].firstChild.data)) inten.append(float(tablelist[i+1].firstChild.data)) #print freq #print inten fig=figure(facecolor='w', edgecolor='w', frameon=True, figsize=(10,6)) ax = fig.add_subplot(111) istat=ax.plot(freq[50:4000],inten[50:4000]) ax.set_xlabel('Frequency [MHz]') #Parse Intensity units tmplist=xmldom.getElementsByTagName('FIELD') tmp = tmplist[1] units = str(tmp.attributes['unit'].value) #Parse source name and velocity resolution tmplist=xmldom.getElementsByTagName('INFO') tmp = tmplist[4] sourcename = str(tmp.attributes['value'].value) ax.set_ylabel('Intensity ['+ units + ']') ax.set_xlim(minFreq,maxFreq) ax.set_title(sourcename+ ' (source id = '+sourceid+')') show() return True