This post summarizes forum-relevant highlights of the PanoplyCL scripting manual, as applied to the 49 Geo2D files in the 3 daily ESRL download folders (REB_plots, REB, and RASM-ESRL_4NIC).
PanoplyCL, while written in Java, uses unrelated Javascript as its scripting language. (Java 8 can internally parse and run Javascript.) Not everyone wants to learn full-on Javascript so the goal of this post is to collect the minimal number of code snippets sufficient for the typical forum use cases or alternatively develop tricks for staying within the more intuitive menu-driven GUI environment.
The scripts are actually saved out of the GUI as say vvel_h_in_REB.2017-09-20.pancl.pcl (ie variable_in_netCDFsourceFile.pcl rather than myscript.pjs as in the draft manual. While this may suggest PanoplyCL (Command Language) is a variant of Javascript, later on conventional Javascript snippets are added, suggesting they run as they would anywhere.
As explained up-forum, someone wanting to make a simple map or multi-frame animation just experiments with Panoply settings until they generate a satisfactory map. Exporting the CL script allows that map to be regenerated later by anyone running a copy of the script, typically on the same Geo2D line within the same netCDF but equally from the next day (or older archived dates) if the file name is bumped in the first line, eg the script vvel_h_in_REB.2017-09-20.pancl.pcl would draw the same map but from the appropriately dated data with a simple script revision:
var ncdata = panoply.openDataset ( "/Users/Fred/REB.2017-09-20.nc" );
-->
var ncdata = panoply.openDataset ( "/Users/Fred/REB.2017-09-21.nc" );
Had "Save Plot Settings as Preferences" been invoked, this could have been done without delving into script particulars, provides some other map prescription hadn't overwritten it. This suggests that simply allowing Preferences to be saved under a name, along with Preference navigation to saved names (like Plot Size menu) would let the user stay within the GUI. For now, representative maps can be held open and used to overwrite Preferences as needed. However this rapidly becomes unwieldy with 49 Geo2D maps from ESRL alone.
A simple script edit would output the map .png in a different preferred palette by simply stubbing in the new palette name:
myplot.set ( "scale-colorbar", "CB_RdBu.cpt" );
-->
myplot.set ( "scale-colorbar", "bluescale.act" );
To help with palette choice, it might be advantageous to enable scrolling through the available palettes by category. Right now, palettes are sorted alphabetically which can group related palettes but doesn't always. Other sort options are by number of distinct colors, from 'continuous' (256) to binned (typically 8, 9, 10)., or by sequential vs divergent. Once the palette is sorted to user preferences, a keyboard up or down arrow could quickly cycle the map through related palettes, with the option key reversing color order. Right now, there is endless mousing of the awkward popup palette.
The script that the current PanoplyCL beta saves from a time series merely generates the first frame, whereas ESRL provides forecasts as ten days at 24 hr steps, five days at 6 hr steps, or ten days at 6 hr steps. Those 'strides' can be adjusted to larger intervals at the time of saving an animation to make fewer frames (eg first and last) but saving the script won't capture that or the time stamps that the frames need.
However it could if Export Animation... dialog had an additional checkbox for Save Script As. That would save users from delving into the details of how JavaScript loops through variables. This does not generate an error message if the script is mis-applied to a file that has no additional times.
However a common situation in climate science might be air temperatures both by date and elevation (or ocean temperatures by date and depth). It would be unusual for an animation to first circulate through the dates at a set elevation and then through the dates at the other elevations. So the dialog needs simply build out the slice options as radio buttons from the file variables.
However for thumbnail maps, it might be feasible to stack the elevation slices (though this is easily done later in Gimp). Alternately, separate time animations could be output for all the elevation choices by a dialog setting. However there isn't any mechanism in the gif89 specification to synch them on a web page so that they all display the same date as the animations go forward.
In summary the current beta of PanoplyCL is 'animation-unaware' and all the saved scripts look the same except for palette choice, image size, and minor appearance settings. However the PanoplyCL manual provides a fix for that with Javascript examples.
The Javascript add-on deduces the frame count for a given netCDF and loops through it using fixed settings from the rest of the script, saving them out as a folder of pngs. Even better, these pngs have their time stamp as a sub-title. The user can then load them into an ImageJ stack or Gimp layers and export out a forum-ready gif animation.
Note that the directory path to the file has to be provided so the script can find it. On a Mac, right-click on the file, then hold down the Option key: the menu will offer copying of the pathway.
var ncdata = panoply.openDataset ( "/Users/Fred/Downloads/REBS_nc/REB.2017-09-20.nc" );
var ncvar1 = ncdata1.getVariable ( "aice_h" );
var myplot = panoply.createPlot ( "lonlat", ncvar1 );
// Set to the first frame of 40, the 1 in third coordinate position
myplot.setVarDimension ( 1, 1, 1 );
var tdim = ncvar.getDimension (1);
var tlength = tdim.getLength ( );
for (var i = 3; i <= tlength; ++i)
{
myplot.setVarDimension ( 1, 1, i );
myplot.set ( "subtitle-text", "Time step: " + tdim.getStrValue ( i ) );
var istr = "" + i;
while (istr.length < 3) { istr = "0" + istr; }
myplot.saveImage ("PNG", "T_" + istr + ".png");
}
No further examples of more complex scripts are provided but the manual states these could include "if-then constructs, iterative loops, string concatenation, create multiple plots, changing plot dimensions and appearance settings as you create each plot."
In other words, it is quite feasible to run a single script that processes all 49 Geo2D files into their daily png sets. These could use different palettes and be of different sizes and formats.
As a practical matter, someone has to go through each of the Geo2D files, decide which are useful at what scale, whether linear or log scaling is appropriate, whether a sequential or divergent palette makes sense and so on, saving each out as a script. These are then concatenated as the master script. To make changes on a particular Geo2D, it is simply re-run with the new parameters and the old version replaced.
It might be easier to make and edit the master script from a 'mail merge' setup. The database is simply the matrix of Geo2D x parameters. It merges into a text document that is the script; the concatenation of all the text documents is the master script.
To avoid typos and unacceptable parameter values, that could be done via a web front end that forces menu choices to admissible, like plot size, file name, and most importantly palette.
The manual also provides examples for all the other map situations such as zonal average, generic 2D, combined array plots and so forth. Again, it seems there is little gained over simply getting the display set and then saving to a Preferences to be called up for future use.
"5.5. Running PanoplyCL in a Server Environment. Because PanoplyCL runs headless, it has potential to be used on a web server to create graphics based on input received from a remote user. Although this is indeed a possibility, note that there are limitations."
"PanoplyCL does not run continuously but must be invoked each time that you want it to process a script and create a graphic or graphics. The most time-consuming part is initializing Java graphics handling. Repeatedly calling PanoplyCL to create and save a single plot image each invocation is very inefficient compared to calling it once with a script that saves multiple plot images."
For security reasons, it is far better to use a pre-written script that can be altered to use different predetermined options rather than insert any content that may have been provided by the user."
https://www.giss.nasa.gov/tools/panoply/betax75/PanoplyCL_Guide_20161109.pdf