hiss(w)
The SolarSoftware (SSW) stack contains nearly every piece of software a solar physicist needs. While libraries like Astropy, SunPy, and ChiantiPy provide Python equivalents to many of these IDL packages, there's still a lot of functionality only available in SSW.
hissw (hiss (like a snake) + SSW) is a (VERY) lightweight (~1 file) Python package that allows you to write IDL scripts (either inline or in a separate file) which use your installed SSW packages and return the results to your local Python namespace. hissw uses Jinja2 templates to generate SSW startup scripts and then runs your IDL code using subprocess
, i.e. the shell. You can also use Jinja syntax to inject arguments from Python into IDL. The results are then saved to a file and then loaded back in using the amazing readsav()
function in scipy.io
.
Install and Configuration
hissw has two dependencies,
jinja2
a powerful templating enginescipy
standard scientific tools for Python
To install hissw and its dependencies,
$ pip install hissw
You can also install the above dependencies with conda
. Alternatively, you can download and install the source yourself,
$ git clone https://github.com/wtbarnes/hissw.git
$ cd hissw
$ python setup.py install
Lastly, you can set the locations of your IDL and SSW installs in a configuration file located in $HOME/.hissw/hisswrc
,
[hissw]
ssw_home=/path/to/ssw/tree
idl_home=/path/to/local/idl/install
Note that if you do not create this file, you will be required to specify it each time you setup a SSW script environment, using the keywords ssw_home
and idl_home
.
If you've downloaded the source, you can run the tests (requires pytest
to be installed) to make sure everything is working properly,
$ pytest
Bridging the IDL-Python Gap the Bad Way...
hissw
is a hack, albeit a clever one. In general, the methodology employed here (round-tripping everything in memory to disk) is a terrible idea. There's no shared memory between Python and IDL or anything fancy like that. If you're interested in something more complicated (and harder to install), you may want to check out the more official Python-to-IDL bridge.
Word(s) of Caution
- Python-3 only
- A local install of of IDL and SSW is required
- Relies on executing shell commands with the
subprocess
module. I've only tested this on Linux and macOS. Windows users may encounter difficulties. - Be careful when injecting large pieces of data into your IDL script as this must be written to a file. It may be better to load it at (IDL) runtime.
- Widgets and plotting will (likely) not work
- This has not been tested extensively against all SSW/IDL functionality. There are likely many cases where hissw will not work. Bug reports and pull requests welcome!
A Note on Preserving Precision between Python and IDL
hissw
relies on string representations of Python objects when inserting values into the resulting IDL script.
However, the default string representation of Python floats is truncated well below the actual floating point precision.
This can result in a loss of precision when injecting floating point values into IDL from Python as documented in this issue.
Thus, to ensure that floating point values are accurately represented, hissw provides the force_double_precision
filter.
This filter can be used as follows, where var
is a (scalar or array) variable containing a floating point value,
var = {{ var | force_double_precision }}
This filter uses the builtin float.as_integer_ratio
method to represent floating point values as division operations between integer values
to ensure that precision is not lost in the string representation Python values in the resulting IDL script.
If used in combination with other filters, this filter should be used last.