Skip to content

scripting cookbook

Jeremy Faden edited this page Jun 13, 2022 · 11 revisions

Purpose: Reformat and clean up of the cookbook page at autoplot.org/cookbook.

Introduction

This page hopes to create a useful resource showing example scripts and describing in more detail how they work. Some may find the scripts useful to perform some science task, while others may use these as a reference for writing scripts on their own.

Science Graphics

L-shell as Y-axis

The script NewLSpec shows how data can be reformed so that L-Shell is used for the Y-axis, Time the X-axis, and another parameter, such as the density, is used for the Z-axis (colorbar).

Lines 4 and 5 get the input for the script, namely the timerange to load data and the spacecraft to load. Lines 8-10 load the three parameters which are scalars which are a function of time. These datasets are called "rank 1" datasets because they use one index which is the record number. (An example rank 2 dataset might have three components for each time: B[Time,Component]. This script will produce a rank 2 spectrogram where each record is a the parameters against the L-Shell.)

Line 14 defines the Y tags for the result, which will be rank 2.

Lines 16-19 set up the data to hold the results.

LANL has produced a variable to mark the inward and outward direction of the spacecraft. Line 16 identifies where this changes, and these changes delimit the inward and outward sweeps. In lines 21-34 we accumulate the data in each sweep to produce a uniform sweep in L.

Lines 36-42 display the results. Line 36 resets Autoplot to clear any graphics which are on the display, returning it to its initial state. Line 38 "links" the data together, asserting that the result is a rank 2 dataset which is a function of the times and the lgrid. If result has more records than times, this would raise an error. If lgrid has more channels than result has in each record, this too would raise an error. Line 39 plots the top color plot. The plot command returns a reference to the plot and the plot element used for the data. (A plot is the container with three axes, and the plot element is the spectrogram itself). To verify things, at line 40 we plot a color scatter of time,l,density and if you look carefully at the image you'll see that they are consistent. Lines 41 and 42 show L and density used for the plot.

Data Processing

Multi-core processing

Often we have thousands of small tasks which together accomplish a bigger task. For example, we have files which are ASCII and we want to store them as CDF. Autoplot's scripting environment has the "runInParallel" command, which allows these tasks to be run on multiple "threads," so that multiple cores of the CPU can be utilized at once.

The script demoRunInParallel423.jy demonstrates how this can be used. Here, a simple function "runone" takes a file for a given month and converts it to a CDF file. Calling runone('199501') converts the ASCII file for January 1995 to a CDF file (which is commented out at line 14). At line 16 we generate all the independent jobs, which are identified by six-digit strings ($Y$m or YYYYmm). The runInParallel command is then given the function "runone" and then the list of 12 strings for the year 1998. The runInParallel command uses only six threads, and may soon be made to utilitize more CPU cores available.

Table Of Contents

URIs that Point to Data Files

Download a CDF and Plot it with Autoplot

Load a CDF directly from a website

URIs that Point to Data Servers

Saving to vap files

Loading vap files

Data Sources

CDF Files

HDF/NetCDF Files

Aggregation

CDAWeb

HAPI Servers

Exporting Data

Export Types

Additional controls

Aggregation

Tools

PNGWalk Tool

Data Mash Up

Events List

Run Batch

Advanced Topics

TimeSeriesBrowse and other Capabilities

Events Lists

Caching

Autoranging

Managing Autoplot's Data Cache

Using Autoplot with Python, IDL, and Matlab

Reading data into Python

Reading data into IDL

Reading data into Matlab

QDataSet Data Model

Clone this wiki locally