#!/usr/bin/env python #usage: vectorradar.py KIWA.vol140.dat # v0.24, 8 July 2011 import simpleSVG # http://mensch.org/simpleSVG, put simpleSVG.py into same directory as this script import sys ### MAKE COLOR CODES UNDERSTANDABLE BY SVG # The following are the positive colors in the legend for the RAP radar images # at http://www.rap.ucar.edu/weather/radar/ : hexc="fff 93c f0f 900 c30 f00 f60 fc0 ff0 090 0c0 0f0 00f 39f 6ff 000".split() hexc.reverse() # flip order to be from low to high levels=range(0,76,5) # the lower bounds to the the dBZ color (but we don't use this) sixlet=[] # for new color format understood by simpleSVG for xyz in hexc: #convert colors such as 'fa3' to '#ffaa33' x,y,z=list(xyz) # e.g., 'fa3' => ['f','a','3'] sixlet.append('#'+x+x+y+y+z+z) ### OPEN THE FILE, AND SAMPLE IT try: # try to get file name from command line value filename=sys.argv[1] except: # if not successful, prompt user to enter it filename=raw_input("enter file name of radar data=>") inf=open(filename,'r') header=inf.readline().split() # read first line, and split at white space scale=header[20] #this prints 100, but I think we should ignore it missing=header[21] #missing value, but we simply replace all negatives as 0 print "from header in "+filename+" : scale=",scale," missing=",missing datalines=inf.readlines() # read all the rest of the lines into a list, one line per item numangl=len(datalines[0].split()) # number of angular measurements per line numrang=len(datalines) # number of lines of data, of increasing radius (number of "range gates") print "sampled "+filename+" : scale=",scale," missing=",missing," num of angl=",numangl," num ranges=",numrang ### CREATE A PLAYFUL SVG FILE FOR DEMO w=simpleSVG.svg_class(fname="sectors.svg",bbx=610,bby=610) # open file sectors.svg w.scale(xmin=-1.,ymin=-1.,ymax=1.,xmax=1.) w.group(stroke="none") # so will not stroke around colorized areas ### iterate thru the colors and plot them in sectors ### (you will need to plot colorized data in sectors for the task) for i in range(len(sixlet)): a=i*20 # starting angle ap=a+20 # ending angle w.sector(0.,0.,100,250,a,ap,fill=sixlet[i]) # write sector code to sectors.svg w.text(0.,26,0,"playing with colors",font_size="24pt",fill='maroon',text_anchor="middle") w.close() ### YOUR TASK: plot the first 25 km of radar data here, using simpleSVG module b=simpleSVG.svg_class(fname="first25.svg",bbx=920,bby=610) # open file for your task b.scale(xmin=-1.,ymin=-1.,ymax=1.,xmax=2.) b.group(stroke="none") maxrad=25.1 # maximum radius to plot amp=int(300/maxrad) #for scaling the radial position in km to pts for line in datalines[0:25]: print line[0:10] # approximately 20 lines of code needed here, to plot both the data and color legend: #### end task code b.close()