Skip to content

python_reset

Jeremy Faden edited this page Jul 1, 2023 · 6 revisions

The old JPYPE interface isn't working properly now, and its interface was designed originally for IDL and Matlab. It's time to redesign this interface to be more comfortable and conventional in the Python environment. This should be designed from the perspective of the scientist working in Python, and how they would expect and benefit from this interface. Further, Python makes this trivial to install, and it might be a nice mode where Autoplot can be launched from within the Python environment where the scientist is working already.

Example code in this document is hypothetical, and is not implemented!

The interface will provide the primary functions:

  • load data into Python for handling
    • this should be with an abstract model which handles times and inter-dependencies.
    • this model should be array-like, so that it can be used in a familiar way
    • this model should work well with existing analysis packages like SpacePy and SunPy.
  • export data to Autoplot supported formats
  • launch Autoplot, thwarting Mac security
  • plot Python data in Autoplot thick client, providing fast, interactive graphics.
  • Use Autoplot to create static plots for Jupyter environment.

Loading data into Python

Autoplot's Jython has provided a rich and convenient environment for handling data. It's getDataSet call provides a one-line call to load data, while the IDL, Matlab, and old Python interfaces would require interaction with a stateful "apds" object. This was because typically the getDataSet call loads multiple arrays of data, for example the time and the density. These are handled within the Autoplot Jython environment with the QDataSet object, but the SpacePy data object can also hold multiple arrays. This would allow the Python scripts to look more like Autoplot's Jython scripts.

ds = ap.getDataSet('vap+cdaweb:ds=OMNI2_H0_MRG1HR&id=N1800&timerange=Oct+2016')
from matplotlib import pyplot as plt
plt.plot( ap.xtags(ds),ds )
plt.show()

Exporting data using Autoplot

Autoplot contains the knowledge for loading data from many sources, but also format data to many data formats from CDF to WAV files. This should also look like the formatDataSet command in Autoplot's Jython:

ap.formatDataSet(ds,'/tmp/ap/data.cdf')

This command would take the data in ds and format it as a cdf file.

Plotting in Python

The Autoplot application should provide rich plotting capabilities to Python. Autoplot handles data in many different formats creating line plots and spectrograms, and many other graphic types. These graphics are interactive, typically painting data in milliseconds so that graphics are interactive. This supports "live" axes which can be rapidly set to optimal ranges, crosshair digitizers and interactive slicing, and property editors with access to many controls for fine tuning.

Launching Autoplot

A new use case for this interface will be to launch Autoplot, starting up the thick Java client for interactive analysis. Python is able to call into JPype and start up the Java/Swing event thread and Autoplot GUI, this has been verified. To launch Autoplot, something like the following command could be used:

ap.start()

It would be nice if multiple Autoplot instances could be managed, so maybe a string identifying each instance could be used as well:

slices_ap = ap.start('slices')
slices_ap.plot(ds)

Creating static plots for Jupyter notebooks

Jupyter notebooks provide a popular way for an analysis to be scripted, and Autoplot should be made to contribute to this enviroment as well.