Jump to: navigation, search

The Cookbook is a set of user-submitted entries on how to do handy operations in Autoplot.


  1. Address bar
    1. vap file modifiers
  2. Complex Configurations
    1. L-shell as Y axis
    2. Events Bar under all plots
  3. User Interface
    1. collection of scripts
    2. editing entries from address bar recent history
    3. where's my data?
  4. Labels
    1. Hide Axis
    2. IDL strings
    3. Greek and Math Symbols
    4. Modify Many Labels
    5. Add Axis Annotations
    6. Background/Foreground images
  5. Interaction
    1. tweaking plot position
    2. time axis scan buttons
    3. zoom with mousewheel
    4. no mousewheel
  6. Loading Data
    1. watch an ASCII file
    2. handling time ranges with implicit fields
  7. Launching (OS-Specific)
    1. Associate .vap files in Gnome
    2. Using MIME types to launch
  8. Scripting
    1. Animation
    2. Browse a timeseries
    3. getParam
    4. Take the average of many images
    5. Open a web browser
    6. Tweak DOM parameters not saved to VAP
    7. Plot to specific subpanels
    8. list remote website files
    9. make a plot for each file
    10. Python/Jython is great with strings
    11. mash data
    12. compare calibrated and uncalibrated data
    13. generating time ranges in Jython
    14. remove the fill data from a list
    15. interpolating dataset onto another dataset's timetags
    16. run test script to see that everything in history is still plottable
    17. add a Jython/Python script to the Tools menu
    18. Share a script with others
    19. Reduce a long time series
    20. Import set of common functions
    21. Linear Fit Routine
    22. Arbitrary Layout
    23. Add to Jython Search Path
  9. Use Screenshots Tool and Pngwalk Verify
    1. Bind Two PNGWalks Together
    2. Make a tutorial web page
  10. Writing to PDF files for embedding in a science poster presentation

1. Address bar

1.1. vap file modifiers

A vap file may be modified in the address bar by adding ? and the node name:

since this vap shows the time range editor instead of the dataset selector, we change multiple nodes:

2. Complex Configurations

The folks at LANL asked for a page with images associated with complex plot panel configurations or styles and the procedure to create them: Cooking at LANL. See also

2.1. L-shell as Y axis

Often we want to create a spectrogram of Flux against Time and L-shell.

# demonstrate old routine for making Flux(T,L) spectrograms
tr= getParam( 'timerange', '1992-03', 'parameter timerange (default=1992-03)' )
feio= getDataSet('vap+cdf:$Y$m$d_V...cdf?FEIO&slice1=0&timerange=%s' % tr, monitor )
l= getDataSet('vap+cdf:$Y$m$d_V...cdf?L&timerange=%s' % tr )
lgrid= linspace( 6.5, 7.5, 20 )
from org.virbo.dsutil import LSpec
lspec= LSpec.rebin( l, feio, lgrid )

2.2. Events Bar under all plots

Now that leaves the hidden plot above others. We want this to be below the others.

3. User Interface

3.1. collection of scripts

See Scripts that make the application do things (.jy): Scripts that load data (.jyds):

3.2. editing entries from address bar recent history

  • click on down arrow to show droplist of recent entries.
  • use keyboard arrows to select entry to edit.
  • hit escape
  • edit line
  • hit return or the green play button.

3.3. where's my data?

If you were looking at data recently, but can't remember where it was, you can look at Autoplot's history. Every URI plotted is recorded in $HOME/autoplot_data/bookmarks/history.txt. From the menu, you can enter a GUI to browse this file, use File->Open Recent. (Note there's no mechanism to remove old entries now. Just remove the file and restart Autoplot.) Also, adding "nohistory=true" to any URI will make it so it is not logged, and logging is not done in headless mode.

4. Labels

For a complete description of labels, see help#Axes.

4.1. Hide Axis

Right-click on axis->Axis Properties->Visible or axis->Axis Properties->"Tick Labels Visible"

4.2. IDL strings

IDL's formatting strings are supported, based on the specification of Grandle and Nystrom. With "granny" strings you can set the title to "E=mc!U2!n" or m!A2!Ns!A-2!N formats m2s-2

  •  !A superscript
  •  !B subscript
  •  !E superscript with smaller font size
  •  !D subscript with smaller font size
  •  !N normal position

4.3. Greek and Math Symbols

You can use greek symbols such as ρ and π in axis labels as well as unicode characters. Here are a few:

  • Greek letters: Α Β Δ α β δ π ρ ω
  • Math symbols: ∑ (∑) ± (±)

4.4. Modify Many Labels

Layout -> Plot Elements, highlight multiple elements, Right-click->Edit Plot Element Properties and a window will appear. The Value column is used to apply a setting to all other columns to its right.

4.5. Add Axis Annotations

You can add annotations to the X-axis, for labelling ephemeris. Right-click on the X-axis, select "Add additional ticks from..." and put in the name of another dataset with a common X-Axis. Autoplot will use this dataset, picking nearest neighbors to label the axis.

Note only one URI can be specified.

4.6. Background/Foreground images

This Jython script shows how images can be added to the canvas.

# Das2's canvas object has two hooks for decorating the plot, to plot below and
# above the normal graphics.  These provide direct access to the Graphics object
# that paints the canvas.  This demos how they are used.
import javax,java
import org.das2.graph
ur= ''
image= getFile( ur, monitor ) )
class BottomPaint(org.das2.graph.Painter):
  def paint( self, g ):
     g.drawImage( image, java.awt.geom.AffineTransform(), None )
class TopPaint(org.das2.graph.Painter):
  def paint( self, g ):
     g.rotate( -15*PI/180,300,300 )
     g.setFont( java.awt.Font.decode( 'sans-42' ) )
     g.setColor( Color( 255,255,255,80 ) )
     g.drawString( "Provisional", 252,302 )
     g.setColor( Color( 0,0,0,80 ) )
     g.drawString( "Provisional", 250,300 )
bottom= BottomPaint()
top= TopPaint()
dom.canvases[0].controller.dasCanvas.addBottomDecorator( bottom )
dom.canvases[0].controller.dasCanvas.addTopDecorator( top )

5. Interaction

5.1. tweaking plot position

Holding shift while mousing over a plot brings up control points that allow the plot position to be tweaked. By default Autoplot automatically adjusts the outside bounds to make room for colorbars, but this can be used to adjust heights.

5.2. time axis scan buttons

The X axis has hidden scan buttons at the beginning and end of the axis (lower right and left corners of the plot box). Mousing over these locations reveals the buttons. Note these are enabled after zooming in.

5.3. zoom with mousewheel

You can use the mouse wheel to zoom in and out. But did you know that: mouse wheel on the ends of the axis will adjust that axis in one direction. For example, put the mouse on the end of the time axis. Mouse wheeling will adjust the beginning of the axis range... Also, pressing control while spinning the wheel will adjust the range to pan along a dimension without changing the scale.

5.4. no mousewheel

The das2 graphics was developed on Suns that didn't have mousewheels, and its controls are still around and handy when you are on a laptop without a mouse. Left click and drag along an axis to zoom in. Click and drag down slightly to zoom out. An arrow will be drawn to indicate the pending action. If you do have a middle mouse button, it will pan the axis when dragged.

6. Loading Data

6.1. watch an ASCII file

Autoplot can watch a file and get updates by polling it regularly. The following script computes the time for a wget command to execute.

 rm -f $LOG
 while [ $COUNTER -lt 100000 ]; do
     START=`date +'%Y %m %d %H %M %S.%N'`
     start=$(date '+%s.%N')
     wget -q -O /dev/null $SERVER
     end=$(date '+%s.%N')
     delta=$(echo $end-$start | bc)
     echo "$START $delta" >> $LOG
     echo "$START $delta"
     sleep 1

It writes to the file "/tmp/webtest.log". To continuously view this file, use the undocumented (and not fully tested) feature by appending


to the URI, which will plot the last 100 lines of a file every second:


The "&filePollUpdates=1" will work with almost any file-based data reader.

6.2. handling time ranges with implicit fields

You can have implicit fields, so that the time parser can work in more cases. Suppose you have a file 2000-03-04.dat which contains for the first field $H-$M-$S. Here's a few lines of the file

09:45:23  3.4
09:46:26  4.5
09:47:22  5.6

You could use implicit fields to parse this:$(H;Y=2000;m=3;d=4):$M:$S&time=field0

7. Launching (OS-Specific)

7.1. Associate .vap files in Gnome

  • right-click on a file (.vap or .cdf, for example.)
  • Open with... Other application...
  • Use custom command...
  • Enter "/usr/local/java/bin/javaws -open ". (Look on your system for Sun Java.)
  • Autoplot should now be the default mechanism to open this file. The association is described in ~/.local/share/applications.

7.2. Using MIME types to launch

At the Radio and Plasma Wave Group, we defined vap to be MIME type application/x-autoplot-vap+xml so this could be associated with the Autoplot application. We have a single-jar version of autoplot, but Webstart should work as well, with something like: /usr/local/jdk8/bin/javaws -open %S (I think we might have to make a unix script to wrap this...)

8. Scripting

See also scripting, developer.scripting,, and

8.1. Animation

This loops over the day 2012-11-01, shifting to 2012-11-02, making pngs at one minute intervals:

# plot vap or uri to configure the display
plot( 'vap+das2server:' )
tr= DatumRangeUtil.parseTimeRange('2012-11-01')
onemin= Units.seconds.createDatum(60)
count= 24*60
while ( i<count ):
  dom.plots[0].xaxis.range= tr
  writeToPng( '/tmp/anim20121110/%5.5d.png' % i )
  tr= DatumRange( tr.min().add(onemin), tr.max().add(onemin) )

For creating a movie, see #Add_to_Jython_Search_Path.

8.2. Browse a timeseries

Any jyds script with getParam('timerange') has the "Time Series Browse" capability, and it will be added when the jython data source is loaded. See examples in

8.3. getParam

The function getParam(param,default,label) is a special function that allows arguments to be passed into a script. When a script is edited and getParam is found, and GUI is automatically created. getParam is used in all contexts: for data sources, it gets named arguments like &p=1&s=a. For command-line scripts (--script=), command line parameters are passed in. For application scripts, the default value is used unless ALT is held down with the Execute button.

8.4. Take the average of many images

David at Google made this script which takes the average of many flags:

8.5. Open a web browser

import org.virbo.autoplot.AutoplotUtil
org.virbo.autoplot.AutoplotUtil.openBrowser(String url)

8.6. Tweak DOM parameters not saved to VAP

Not all properties in the DOM are saved to the VAP file (anything under "controller" is not saved). As a work-around, load a VAP file and then modify the non-saved DOM elements with a script.

ds= 'file:/tmp/webtest.vap'
plot( ds )
dom= getDocumentModel()
dom.plotElements[0].controller.renderer.cadenceCheck = False

Save the above as /tmp/webtest.jy and enter


in the address bar. (Autoplot 2011 now has cadenceCheck in the DOM, so editing Plot Element Properties can accomplish this as well.)

8.7. Plot to specific subpanels

Subplots may be selected:


This will add plots until the there's a spot "2" for the data. The command setPlotLayout(2,3) will make two rows of three plots each.

8.8. list remote website files

In the script panel (enabled via options):

for i in listDirectory('*.cdf'):
   print i

8.9. make a plot for each file

In the script panel (enabled via options), enter

for i in listDirectory('*.qds'):
   plot( ''+i )
   writeToPng( '/tmp/' + i+'.png' )

8.10. Python/Jython is great with strings

product= 'c1'
date= '20010101'
plot( '' % ( product, date ) )

8.11. mash data

Jython (Python in Java) scripts can be used to mash data. The getParam(parmName,default) function allows data to be passed into a script via the URI:


Here's the script:

Note the script can be read directly from the http web site, this one has local file references.

8.12. compare calibrated and uncalibrated data

I had data in two files that I needed to compare, but a simple calibration had been applied to one but not the other. I could easily apply the calibration with a jython script in autoplot. Instead of plotting the data, I (enable and) flip over to script tab in Autoplot and enter the script:

# code to apply calibration to compare my cdf to Dan's
 ds= getDataSet('vap:file:///home/jbf/temp/rbsp/fm1/L1/2041/01/14/rbsp-a_ws_emfisis-L1_20410114_v1.1.3.cdf?BuBu')
 ds= sqrt(ds) 
 ds= 20 * log10( 2 * ds / 32768. )
 data= ds

These scripts work by plotting the variable "data" by default. Note I can right click in the script tab and select "getDataSet" and the getDataSet command is entered with the current URI. Select "data source context" and hit the execute button, and I need to save this to a file with a .jyds extension before Autoplot can use it. I'd be able to plot this against the other data, except it has units and this new dataset doesn't. I can remove units from Dan's the same way:

# code to remove units from Dan's CDFs
 ds= getDataSet('vap:file:///home/jbf/temp/compareFeb3/rbsp-a_wf_emfisis-L1_20110114134618_v1.1.99.cdf?BuBu')
 ds= putProperty(ds,QDataSet.UNITS,None)
 data= ds

Now I can plot one against the other, and plot slices on the same plot. Note Autoplot will plot data of different units on the same axis, but with a warning message.

8.13. generating time ranges in Jython

In the application script dialog (Options->Enable Feature->Script Panel), you can create a list of timeranges:

trs= generateTimeRanges( '$Y-$m-$d', '2012' )
for i in trs:
  print i

You'll see the output in the java stdout or on the console (Options->Enable Feature->Log Console) if it's enabled.

Here's a more useful script:

# plot all datasets for the year 2012
trs= generateTimeRanges( '$Y-$m-$d', '2012' )
for i in trs:
  ds= '$Y/ac_k0_swe_$Y$m$d_v01.cdf?He_ratio&timerange=%s' % i
  plot( ds )
  writeToPng( '/tmp/ap/%s.png' % i )

8.14. remove the fill data from a list

Remove fill data from a list with the where and valid functions:

list= dataset( [ -1e31, 37.6, 43.2, 55.1, 97.0] )
list= putProperty( list, QDataSet.FILL_VALUE, -1e31 ) 
r= where( valid( list ) )
list= list[r]

8.15. interpolating dataset onto another dataset's timetags

Ivar asked about a function I've always meant to implement explicitly, but I found the current implementation is fine. He has data at timetags with one cadence, and wishes to interpolate them to another dataset's timetags. Here's the script:

# syncTimeTags.jy
# Show how one dataset is synched to another.  Density at 5 min resolution is loaded in,
# and interpolated onto a grid of flux at roughly 4min resolution.
flux4min= getDataSet( '' )
density5min= getDataSet( '')
findx= findex( t5min, t4min )  # 5min tags interpolated to 4 minute tags
density4min= interpolate( density5min, findx )
plotx( 0, density5min, title= 'This is the original data' )
plotx( 1, t4min, density4min, title='These line up with the flux data' )
plotx( 2, flux4min, title='This is the flux' )

Here's a generic routine that syncs up data:

# return a set of datasets which are synchronized to the same timetags.
def synchronize( ds1, *dss ):
    "the first dataset's timetags are used to interpolate the list of datasets"
    tt= QDataSet.DEPEND_0 )
    result= []
    for ds in dss:
        tt1= QDataSet.DEPEND_0 )
        ff= findex( tt1, tt )
        ds= interpolate( ds, ff )
        result.append( ds )
    return result
flux4min= getDataSet( '' )
magn5min= getDataSet( '')
BGSE5min= getDataSet( '')
( density, BGSE ) = synchronize( flux4min, magn5min, BGSE5min )

Keywords: synchronize synchronizing

8.16. run test script to see that everything in history is still plottable

In Jython editor:

from test.endtoend import TryHistory
TryHistory.main( [] )

This attempts to load every URI in $HOME/autoplot_data/bookmarks/history.txt as a QDataSet, printing the result and load times, and then finally reporting the statistics for the run. A future version may also plot each one to a png file.

8.17. add a Jython/Python script to the Tools menu

Jython scripts can be added to the tools menu by putting them in $HOME/autoplot_data/tools/. Set the label for the script by adding a comment to the script: "# label: My Script Label". Right now Autoplot only checks for scripts at startup, so you will need to restart.

8.18. Share a script with others

An application-context script can be shared with others, so that editors can pass scripts to new users. For example, type in the address bar:


and a GUI is presented asking if you'd like to run the script. A checkbox allows the script to be added to your tools menu. Here are some other useful scripts to try (omit the #comment part):

script:     # flash the current plot Element that's selected
script:  # reload all loaded data (remote files in cache will not be loaded from server if the timestamp hasn't changed)
script:   # test to see if we're on line.  (This should be renamed testHttpConnection.jy.)
script:      # toggle the day-of-year setting

Note scripts can contain the special comment "# label:" that gives them nice labels.

Note "*.jy" is now always a script, and the "script:" prefix is no longer needed.

8.19. Reduce a long time series

Often we need to reduce a long high-resolution time series, leaving a process running overnight. This loads the URI with the time series browse capability and saves out a reduced version. This only loads for 26 days, but it can be modified to run over years (with your data).

# title: hourly averages demo shows how to take hourly averages over a long interval
# label: hourly averages
from org.virbo.dsutil.Reduction import reducex
import java.util.LinkedHashMap
import java.lang.Exception
uri= '$Y/$m/$d/610008002FE00410.$Y$m$d.d2s?timerange=%s'
dr= DatumRangeUtil.parseTimeRange('2012-09-01')     
endt= DatumRangeUtil.parseTimeRange('2012-09-26' )  
targetRes= dataset('1 hr')    # '1 min' '2 hr' '3 days'.  Use Length mouse action for examples
exceptions= java.util.LinkedHashMap()
dsall= None
while ( dr.min().lt( endt.max() ) ):
   monitor.progressMessage= "%s until %s" % ( dr, endt )
   uri1= uri % dr.toString()
      ds= getDataSet( uri1 )
      ds= reducex( ds, targetRes )
      dsall= concatenate( dsall, ds )  # TODO: this probably won't scale, replace with dataset builder.
   except java.lang.Exception,ex:
      exceptions.put( uri1, ex )
formatDataSet( dsall, '/tmp/reduced1Hr.qds' )
print 'Exceptions encountered:'
for ex in exceptions.entrySet():
  print '== %s ==' % ex.getKey()
  print ex.getValue()

8.20. Import set of common functions

You can import a set of common functions using getFile and "execfile":

ff= getFile( '',monitor.getSubtaskMonitor('import'))
execfile( ff.toString() )
flux4min= getDataSet( '' )
density5min= getDataSet( '')
dst60min= getDataSet( '')
( density, flux, dst ) = synchronize( t5min, density5min, flux4min, dst60min, nn=1 )
plotx( 0, density )
plotx( 1, flux )
plotx( 2, dst )

This introduces some possible security concerns, and this may be restricted in the future.

8.21. Linear Fit Routine

There's a code to do linear fits:

from org.virbo.dsutil import LinFit
x= linspace(0,5,40)
y= x * 6 + 6 * randn(40)
plot( 0, x, y )
lf= LinFit( x,y, 6*ones(40) )
plot( 1, x, x*lf.b + lf.a )
print lf.chi2 / (x.length()-1)

8.22. Arbitrary Layout

Autoplot v2015a and more recent versions allow scripts to plot to arbitrary locations on the page, bypassing the automatic layout. For example:


Em offsets can be used as well, and pixel locations:


8.23. Add to Jython Search Path

I want to add the ability to create a video. I can add this to the search path in Jython like so:

UNIX% cd /tmp/jcodec/
UNIX% wget -N
UNIX% jar xvf jcodec-0.1.9.jar

and then run the script:

import sys

from org.jcodec.api.awt import SequenceEncoder
from javax.imageio import ImageIO
from import File

enc = SequenceEncoder( File("/tmp/filename.mp4") )
ff= listDirectory('/tmp/ap2/*.png')
for f in ff:
   img= File("/tmp/ap2/"+f) )

9. Use Screenshots Tool and Pngwalk Verify

I used the pngwalk verify tool to select frames from the screenshots tool. First, I recorded my movie with the screenshots tool. In Autoplot, run This starts dumping screenshots into /home/jbf/temp/ap. I quit Autoplot when I was finished with the sequence, and then started up pngwalk and turn on the quality control. I could go through the screenshots and mark the frames I wanted to keep, which would then put .ok files next to my images. Then the unix command to extract my files was for i in *.png.ok; do echo $i; cp ${i%.ok} movie20130208; done

9.1. Bind Two PNGWalks Together

I needed to compare two pngwalks, created in two different directories but with files of the same name. A while ago I added properties to the pngwalk tool so that they could be bound together:

1. start the two pngwalk tools
2. on the console, get references to the two pngwalk tools via the app manager:
   * from org.virbo.autoplot import AppManager   (note org.virbo.autoplot will be changed to org.autoplot after Fall 2015 AGU.)
   * pw1= AppManager.getInstance().getApplication(1)
   * pw2= AppManager.getInstance().getApplication(2)
   * print pw1,pw2   # to verify we got the correct references
3. and bind their "SELECTED_NAME" property:
   * bind( pw1, pw1.PROP_SELECTED_NAME, pw2, pw1.PROP_SELECTED_NAME )

The two pngwalks can be used to compare images now, advancing in one will advance on the other. Note the timerange property can be bound as well, for comparing pngwalks with different filenames or comparing a pngwalk to Autoplot's dom.timerange.

9.2. Make a tutorial web page

You can make effective tutorial html pages (like using the script: This will create an html page showing slides marked as "Okay" with the QC tool. This demo shows how this is done:

10. Writing to PDF files for embedding in a science poster presentation

The pixels on the desktop correspond to points when printing to PDF. So if you want a 5in by 5in figure, you should have a 360 by 360 pixel canvas (72 dpi). To get this, see the style tab, then under Canvas, Canvas Size:

  • uncheck "Adjust to Fit into Application"
  • Set the width to 360 (points)
  • Set the height to 360 (points)

Note there's something flaky about this, so double-check that the canvas is the right size. (This is fixed in the 2015a production branch.)

  • [menubar]->Auto->"AutoLayout" can be turned off to get more control of the layout. This will disable the code that makes room for color bars and new plots.
  • Plot edges can be tweaked to by holding the shift button while mousing over plot boundaries. Control blocks will appear to resize the plot.
  • axes tab, Y Axis, Isotropic will lock the data:pixel ratio for the x and y axes, when the units are compatible.
Personal tools