cookbook

From autoplot.org

Jump to: navigation, search

User-submitted entries on how to do handy operations in Autoplot

Contents

  1. Address bar
    1. vap file modifiers
  2. Products
    1. Cooking at LANL
  3. User Interface
    1. editing entries from address bar recent history
    2. 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
  5. OS-Specific
    1. Associate .vap files in Gnome
  6. Interaction
    1. tweaking plot position
    2. time axis scan buttons
    3. zoom with mousewheel
    4. no mousewheel
  7. Loading Data
    1. watch an ASCII file
    2. handling time ranges with implicit fields
  8. Scripting
    1. Take the average of many images
    2. Tweak DOM parameters not saved to VAP
    3. Plot to specific subpanels
    4. list remote website files
    5. make a plot for each file
    6. Python/Jython is great with strings
    7. mash data
    8. getParam
    9. compare calibrated and uncalibrated data
    10. generating time ranges in Jython
    11. interpolating dataset onto another dataset's timetags
    12. run test script to see that everything in history is still plottable
    13. add a Jython/Python script to the Tools menu
    14. Share a script with others

1 Address bar

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_HYD.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_HYD.vap?options.useTimeRangeEditor=false&timerange=1999-05-30

2 Products

2.1 Cooking at LANL

The folks at LANL asked for a page of images and the procedure to get to those images. Here it is: Cooking at LANL

3 User Interface

3.1 editing entries from address bar recent history

  • click on history 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.2 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. Please let me know if this gets too big.) Also, adding "nohistory=true" to any URI will make it so it is not logged. This should be used in scripts to avoid problems with the file growing too large.

4 Labels

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

4.1 Hide Axis

Right-click on axis->Axis Properties->Visible.

4.2 IDL strings

IDL's "Granny" strings [1] are supported, so for example 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

In Autoplot2011, 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, which is a bit limiting, and this will be addressed soon.

5 OS-Specific

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

6 Interaction

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

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

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

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

7 Loading Data

7.1 watch an ASCII file

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 (i.e., 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

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

8 Scripting

8.1 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.2 Tweak DOM parameters not saved to VAP

Not all properties in the DOM are saved to the VAP file. 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.3 Plot to specific subpanels

Subplots may be selected:

plot(0,ds0)
plot(1,ds1)
plot(2,ds2)

at present, the layout must be first set in the GUI. Additional plots are added automatically to make a stack of plots.

8.4 list remote website files

In the script panel (enabled via options):

for i in listDirectory('http://www.autoplot.org/data/*.cdf'):
  print i

8.5 make a plot for each file

In the script panel (enabled via options), enter

for i in listDirectory('http://www.autoplot.org/data/*.qds'):
  plot( 'http://www.autoplot.org/data/'+i )
  writeToPng( '/tmp/' + i+'.png' )

8.6 Python/Jython is great with strings

product= 'c1'
date= '20010101'
plot( 'http://www.autoplot.org/data/%s_%s.dat' % ( product, date ) )

8.7 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:file:///home/jbf/inbox/larry.20100212.icee/icee.jyds?type='e_star'

Here's the script:

 http://autoplot.org/data/icee.jyds

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

8.8 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 always used (for now at least).

8.9 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(QDataSet.UNITS,None)
data= ds

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

8.10 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', '2008' )
 for i in trs:
   print i

You'll see the output in the java stdout or on the console (Options->Enable Feature->Log Console,restart) if it's enabled. Note this doesn't work in jython data source scripts, but probably could be moved so it's available.

Here's a more useful script:

# plot all datasets for the year 2008
trs= generateTimeRanges( '%Y-%m-%d', '2008' )
for i in trs:
  ds= 'vap:http://cdaweb.gsfc.nasa.gov/istp_public/data/ace/swe/$Y/ac_k0_swe_$Y$m$d_v01.cdf?He_ratio&timerange=%s' % i
  plot( ds )
  writeToPng( '/Users/jeremyfaden/tmp/%s.png' % i )

8.11 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( 'http://cdaweb.gsfc.nasa.gov/istp_public/data/ace/sis_h1/2011/ac_h1_sis_20110117_v03.cdf?flux_He' )
density5min= getDataSet( 'http://cdaweb.gsfc.nasa.gov/istp_public/data/ace/mfi/2011/ac_k0_mfi_20110117_v01.cdf?Magnitude')

t5min= density5min.property(QDataSet.DEPEND_0)
t4min= flux4min.property(QDataSet.DEPEND_0)

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' )


8.12 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.13 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.14 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:

script:http://autoplot.org/data/tools/flashFocus.jy

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:http://autoplot.org/data/tools/flashFocus.jy     # flash the current plot Element that's selected
script:http://autoplot.org/data/tools/ReplaceFile.jy    # replace all references to one file with another, and reset the time axis.
script:http://autoplot.org/data/tools/reloadAllUris.jy  # reload all loaded data (remote files in cache will not be loaded from server if the timestamp hasn't changed)
script:http://autoplot.org/data/tools/testHtmlConnection.jy   # test to see if we're on line.  (This should be renamed testHttpConnection.jy.)
script:http://autoplot.org/data/tools/toggleDayOfYear.jy      # toggle the day-of-year setting

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

Personal tools