If you are using iolite 4, you’ve probably noticed references to something called ‘python’ in the user interface. Python is a general purpose interpreted programming language widely for many things, but has become particularly popular among scientists for data processing and analysis. iolite 4 has a built-in python interpreter that you can use for a variety of tasks and one of the main goals of iolite notes is to educate our users on the various ways we can harness its power to do something interesting.
More about python
Like all programming languages, python has a specific syntax. To acquaint yourself with python syntax you can refer to any number of external resources, such as:
- The official python beginner’s guide
- learnpython.org
- And for the more data/math/science oriented stuff: SciPy Lecture Notes.
Libraries, packages and friends
iolite 4 is built with Qt, and a great deal of that functionality is available to you through iolite’s use of PythonQt. More information about the Qt and PythonQt application programming interface (API) and functionality is readily available online.
Python is known for its many packages. iolite is distributed with many useful data science packages such as:
- NumPy
- SciPy
- pandas
- scikit-learn
- matplotlib
- And more!
It is also possible to add your own packages to be used with iolite’s python interpreter. More on that later!
The python “API”
The API is described in the online iolite documentation. A few basics are outlined below to give you an idea how it works.
Getting a selection from a selection group:
|
|
Doing something to each selection:
|
|
Getting the data and time arrays from a channel:
|
|
Note: if you try to get a selection group or channel that does not exist, python will raise an exception, e.g.
Traceback (most recent call last):
File “”, line 1, in
RuntimeError: std::runtime_error: [DataManager::timeSeries] no matches for …
Integration in iolite
We have integrated python in several places, not all of which are obvious, so let’s review the various ways python can be used now.
Console
This is a place to type in a quick command or short series of commands that you are not likely to do often. It can be accessed from the Tools menu as Python Console or from the keyboard short cut CTRL+SHIFT+P (PC) or CMD+SHIFT+P (Mac).
Workspace
This is a place to write small (or large!) reusable scripts that are not suitable to be written as a plugin (see below). It can be accessed from iolite’s toolbar on the left side of the main window.
Plugins
We have also included the ability to write plugins or add ons for iolite by including specific metadata in your python file and putting the file in the location configured in iolite’s preferences.
Note that by default these paths are within the main program folder (i.e. in Program Files for Windows and /Applications/iolite4.app for Mac). This is convenient, but problematic (see below). If you want to keep iolite up to date (recommended) and have your own add ons and/or reference material files, you should change these paths to a separate folder (e.g. in your Documents).
Python plugin types that required extra metadata include importers, data reduction schemes, QA/QC and user interface (UI). The meta data generally looks something like this:
|
|
In addition to the metadata, certain functions are also required and vary depending on the plugin type. This metadata and the required functions allow iolite to parse these files and insert them into the user interface as appropriate. For example, a DRS needs to have functions runDRS and settingsWidget. To learn more about plugins and their format you can visit our examples repository on github.
Other places
There are a few more places that python can be used in iolite, including to write custom export scripts (e.g. if you wanted to output certain columns in a certain format and did not want to fuss with it after exporting), within processing templates (e.g. if you wanted to check for outliers within selection groups and move them to a different group, or to perform some custom QA/QC). The calculator tool also uses python to evaluate each expression and therefore python syntax and benefits apply.
Potential problems
- Since some parts of iolite depend on python, if the path to python packages is not configured properly in iolite’s preferences, iolite may not be able to start. If that happens, you can hold down shift while starting iolite to reset some of the preferences to their default value.
- Since the paths for python-based add ons are within the program folder by default, you may encounter problems when trying to create a new add on from the iolite interface because the operating system may prevent you from creating new files in those locations.
- Additionally, if you have modified files in the default paths be warned that these files will be lost when updating!
Click here to discuss.