# cookbook

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

## 1.1. vap file modifiers

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

http://autoplot.org/data/vap/PO_H0_HYD0.vap?timerange=1999-05-30


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

http://autoplot.org/data/vap/PO_H0_HYD0.vap?options.useTimeRangeEditor=false&timerange=1999-05-30


# 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 http://autoplot.org/developer.renderTypes

## 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:ftp://ftp.virbo.org/LANL/LANL1991/SOPA+ESP/H0/LANL_1991_080_H0_SOPA_ESP_$Y$m$d_V...cdf?FEIO&slice1=0&timerange=%s' % tr, monitor ) l= getDataSet('vap+cdf:ftp://ftp.virbo.org/LANL/LANL1991/SOPA+ESP/H0/LANL_1991_080_H0_SOPA_ESP_$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 )
plot(lspec)

## 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 http://autoplot.org/data/script. Scripts that make the application do things (.jy): https://sourceforge.net/p/autoplot/code/HEAD/tree/autoplot/trunk/VirboAutoplot/src/scripts/ Scripts that load data (.jyds): https://sourceforge.net/p/autoplot/code/HEAD/tree/autoplot/trunk/JythonDataSource/src/

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

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: &Alpha; &Beta; &Delta; &alpha; &beta; &delta; &pi; &rho; &omega; • Math symbols: &sum; (∑) &plusmn; (±) ## 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. reset() import javax,java import org.das2.graph ur= 'http://www.cottagesystems.com/honeycomb.1.gif' image= javax.imageio.ImageIO.read( 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.removeBottomDecorators() dom.canvases[0].controller.dasCanvas.removeTopDecorators() dom.canvases[0].controller.dasCanvas.addBottomDecorator( bottom ) dom.canvases[0].controller.dasCanvas.addTopDecorator( top ) dom.plots[0].controller.dasPlot.setOpaque(True) dom.dataSourceFilters[0].uri='http://cdaweb.gsfc.nasa.gov/istp_public/data/polar/hydra/hyd_h0/$Y/po_h0_hyd_$Y$m$d_v01.cdf?ELECTRON_DIFFERENTIAL_ENERGY_FLUX&timerange=20000109' # 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. #!/bin/bash SERVER="http://autoplot.org/" LOG="/tmp/webtest.log" COUNTER=0 rm -f$LOG
while [ $COUNTER -lt 100000 ]; do let COUNTER=$COUNTER+1
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 done It writes to the file "/tmp/webtest.log". To continuously view this file, use the undocumented (and not fully tested) feature by appending &filePollUpdates=1&tail=100  to the URI, which will plot the last 100 lines of a file every second: vap+dat:file:/tmp/webtest.log?time=field0&column=field6&timeFormat=$Y+$m+$d+$H+$M+$S&filePollUpdates=1&tail=100  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 http://autoplot.org/data/noDate.dat:

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


You could use implicit fields to parse this:

http://autoplot.org/data/noDate.dat?column=field1&timeFormat=$(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 http://autoplot.org/autoplot.jnlp -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 http://autoplot.org/autoplot.jnlp -open %S (I think we might have to make a unix script to wrap this...) # 8. Scripting ## 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:http://emfisis.physics.uiowa.edu/das/das2Server?dataset=rbsp/RBSP-A/HFR_spectra.dsdf&start_time=2012-11-01T00:00:00.000Z&end_time=2012-11-02T00:00:00.000Z' ) tr= DatumRangeUtil.parseTimeRange('2012-11-01') onemin= Units.seconds.createDatum(60) count= 24*60 monitor.started() i=0 monitor.setTaskSize(count) while ( i<count ): dom.plots[0].xaxis.range= tr writeToPng( '/tmp/anim20121110/%5.5d.png' % i ) i=i+1 tr= DatumRange( tr.min().add(onemin), tr.max().add(onemin) ) monitor.setTaskProgress(i) monitor.finished() 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 http://autoplot.org/data/jyds. ## 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: https://plus.google.com/117808384777851490555/posts/WEBtTuDRubF ## 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 script:file:/tmp/webtest.jy  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: setPlotLayout(2,3) plot(0,ripples(20)) plot(1,ripples(30)) plot(2,ripples(40)) 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('http://www.autoplot.org/data/*.cdf'): print i ## 8.9. make a plot for each file In the script panel (enabled via options), enter for i in listDirectory('http://autoplot.org/data/*.qds'): plot( 'http://autoplot.org/data/'+i ) writeToPng( '/tmp/' + i+'.png' ) ## 8.10. Python/Jython is great with strings product= 'c1' date= '20010101' plot( 'http://www.autoplot.org/data/%s_%s.dat' % ( 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:  vap+jyds:file:///home/jbf/inbox/larry.20100212.icee/icee.jyds?type='e_star'  Here's the script:  http://autoplot.org/data/jyds/icee.jyds  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

## 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 http://sarahandjeremy.net/~jbf/autoplot/tutorials/findJava8/20160204_1502.html) using the script: http://autoplot.org/data/tools/makeTutorialHtml.jy. This will create an html page showing slides marked as "Okay" with the QC tool. This demo shows how this is done: http://autoplot.org/autoplot/data/tutorials/20160116meta/20160116_1426.html

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