1 / 17

Custom Web Plotting with IDL

Custom Web Plotting with IDL. Carl Drews Technical demonstration for the Web Advisory Group September 4, 2008. The Problem:

amyrogers
Télécharger la présentation

Custom Web Plotting with IDL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Custom Web Plotting with IDL Carl Drews Technical demonstration for the Web Advisory Group September 4, 2008

  2. 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.”)‏

  3. Solution is implemented at: http://gctm.acd.ucar.edu/arctas/plot.shtml Solution uses html, Python, and IDL.

  4. Option 1 Re-write Louisa's plotting code in some more web-friendly 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.

  5. 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

  6. 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.

  7. plot.shtml to Python <div class="rightcol" id="plot-area"> <h1>Mozart Plotting</h1> <form action="/cgi-bin/acd/arctas/plot.py" method="post"> <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> call Python script. The usual html form input.

  8. 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>"

  9. 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,format='(i8,"-",i2.2,"Z")')+'.png' print,'Creating: ',pngfile tvlct, r,g,b, /get img = tvrd()‏ write_png, outpath + pngfile, img, r,g,b

  10. 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>"

  11. 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>

  12. Ta-dah!

  13. 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?

  14. 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.

  15. Questions? Comments? Reactions?

More Related