Transcript Option

Custom Web Plotting with IDL
Carl Drews
Technical demonstration for the Web Advisory Group
September 4, 2008
The Problem:
A scientist (let's call her Louisa, since that's her name) says,
“I have an IDL program that creates plots from model output.
Can you put this on our project's web site?”
You reply, “Sure!”
(You think, “I hope I can figure out how to do this.”)
Solution is implemented at:
http://gctm.acd.ucar.edu/arctas/plot.shtml
Solution uses html, Python, and IDL.
Option 1
Re-write Louisa's plotting code in some more webfriendly language: Perl, Python, JavaScript, PHP,
etc.
In this case, plot_moz_with_args.pro is 157 lines long.
Not huge, but it has some sophisticated processing
that I don't want to replicate.
Reject Option 1.
Option 2
Pre-generate every possible plot by name,
and display them when requested.
20 * 4 * 3 = 240 plots at 10k each.
That's manageable.
Numeric input is not manageable;
too many possible plots!
Reject Option 2
Option 3
Wrap the IDL code in a Python script that will retrieve html
input, call the IDL program, and deliver the produced image to
the browser.
Louisa may need to add a few command-line arguments to
the IDL program.
She's okay with that.
The data must be accessible to the web server somehow.
plot.shtml to Python
<div class="rightcol" id="plot-area">
<h1>Mozart Plotting</h1>
<form action="/cgi-bin/acd/arctas/plot.py"
method="post">
call Python script.
<h3>Please specify the plot parameters below: </h3>
Date:
<select name="date">
<option value="20080331">20080331</option>
<option value="20080406">20080406</option>
<option value="20080407" Selected>20080407</option>
<option value="20080408">20080408</option>
.
.
.
</select>
<br>
Time:
<select name="time">
<option value="00" Selected>00 Z</option>
<option value="06">06 Z</option>
<option value="12">12 Z</option>
<option value="18">18 Z</option>
</select>
<br>
The usual html form input.
plot.py to IDL
(Retrieve form input from sys.stdin as name-value pairs.)
# generate the plot
#fp = os.popen('echo "plot_moz_with_args, 20080416, 18,
\'CO\', 4, 30, 90, 190, 300" | /usr/local/rsi/idl70/bin/idl')
fp = os.popen('echo \"' + idlCommand + '\" |
/usr/local/rsi/idl70/bin/idl')
#print "IDL output:<br>"
#for line in fp:
# print line + "<br>"
fp.close()
#print "End of IDL output.<br>"
Within the Depths of IDL
Louisa creates the plot and places it in the agreed-upon directory,
using the agreed-upon naming convention:
; save image to PNG file
outpath = "/var/www/html/gctm/arctas/plots/"
pngfile =
'mz4_'+species+'_'+salt_plot+'_'+String(date_plot,time_plot,for
mat='(i8,"-",i2.2,"Z")')+'.png'
print,'Creating: ',pngfile
tvlct, r,g,b, /get
img = tvrd()
write_png, outpath + pngfile, img, r,g,b
Back in Python
plot.py sends to the browser a few lines of html, just
enough to display the image:
# image URL
imageName = "mz4_" + species + "_" + altitude + "km_"
imageName += date + "-" + time + "Z.png"
print "<img src=\"/arctas/plots/" + imageName + "\">"
# html footer
print "</body>"
Back in the browser, the html code looks like:
<head>
<title>ARCTAS Plot</title>
</head>
<body>
<h3><center>ARCTAS Plot</center></h3>
<img src="/arctas/plots/mz4_CO_7km_20080407-00Z.png">
</body>
Ta-dah!
Drawbacks
1. Can create a lot of image files on your server.
Each unique plot creates a file.
Fill up the disk?
Wipe them out every night?
2. The system is not thread-safe for multiple users.
Images get served by filename, no matter which user created
them.
Should use all input parameters in the filename to avoid this.
Generate unique file names?
Improvement
It would be nice if IDL could return
the created image as a memory
block, which Python could then return
to the browser.
Avoid creating image files on disk.
Avoid thread conflicts.
Questions?
Comments?
Reactions?