Calling Python Code from Igor Pro
JMurray
It would be very useful to be able to call python code from within Igor Pro, storing the results into variables, waves, or pre-defined structures. Matlab has such functionality, but I’ve only seen this mentioned with regard to Igor Pro in a brief discussion back in 2010.
Is this something others would benefit from? Any chance we might be able to get something like this in Igor Pro 9?
We've considered this, but there hasn't been a lot of demand for it and it would require a lot of work to implement.
"Matlab has such functionality" is true, but I believe that Mathworks also has thousands of employees. You can count the number of WM employees on two hands, even if you are missing some fingers :)
April 4, 2019 at 09:13 am - Permalink
I could use that functionality as well.
May 12, 2019 at 06:43 am - Permalink
This may seem a bit like using a grenade to kill a fly, but couldn't one compile a python interpreter into an Igor Pro XOP using open source code from the latest python distribution?
June 3, 2019 at 01:36 pm - Permalink
Embedding python is what this 2010 topic was about: https://www.wavemetrics.com/forum/general/embedded-python
It would seem that it might be possible to just call a standard python distro via ExecuteScriptText using files for passing data back a forth. You would need to write some code on both the Igor and python side to deal with the data.
I would be helpful to know what kind of processing and data you need via python.
June 4, 2019 at 06:45 am - Permalink
Be aware that, according to https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_release_notes?language=objc:
Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. In future versions of macOS, scripting language runtimes won’t be available by default, and may require you to install an additional package. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app. (49764202)
Use of Python 2.7 isn’t recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS won’t include Python 2.7. Instead, it’s recommended that you run
python3
in Terminal. (51097165)June 4, 2019 at 02:05 pm - Permalink
I imagine that those folks on macOS who want Python are not wanting the macOS standard 2.7 Python libraries anyway. So, it is a good call from Apple to just dump this in favor of letting folks pip or homebrew their "third party" installations.
June 5, 2019 at 06:14 pm - Permalink
10.15 ships with python3 also.
June 6, 2019 at 07:47 am - Permalink
I would say anyone who is like really using python is using a custom installation. The one shipping with the OS/distro is usually outdated and incomplete.
June 6, 2019 at 10:15 am - Permalink
In reply to I would say anyone who is… by thomas_braun
Isn't that an argument for NOT linking in a standard install of python?
Also, speaking as a python novice, it seem that python seems to make a special effort to break programs developed under previous versions.
[My only experience with python was in translating a Neural Net tutorial into Igor. A useful project where I made some changes to Igor syntax and programming in order to match speed of learning the NIST handwriting examples.]
June 6, 2019 at 03:01 pm - Permalink
In reply to thomas_braun wrote: I… by Larry Hutchinson
I would say that folks who currently use python *in a serious way* do not link to a standard installation, at least under macOS. And, perhaps being tongue-in-cheek or factious or cynical ... Python is totally free. You only need to invest your time to fix what was broken during the recent update.
Full Disclosure: I started about a year ago at python3 and I only dabble at the edges of it using JupyterLabs to make interactive demos. I have no dog in the fight as to whether python should or should be linked with Igor Pro.
June 6, 2019 at 05:51 pm - Permalink
I asked this before with no response so again: What kind of processing and data transfer do you want to do with Python?
I ask this because I am looking into using the pickle format to exchange data between Igor and Python and I'd like to know if the effort would be worthwhile.
The pickle format is not designed to be used by programs other than Python but a subset could be read and written using Igor code.
I've been able to read an array of images from a sample file (mnist.pkl from http://neuralnetworksanddeeplearning.com/chap1.html) but only after manually inspecting the output of pickletools.dis(). Making this automatic and general is the hard part.
August 17, 2019 at 06:48 am - Permalink
@Larry: I'm not very fond of pickled data. What would you do with that in igor? I would say usually it is about array data and that is much easier exported from python via numpy.save, https://www.numpy.org/devdocs/reference/generated/numpy.lib.format.html. So support for reading/writing that is in my eyes more worthwhile than partial pickle support. Of course you could save in hdf5 from python and just load it into igor as well.
What I would like to see in IP is the ability to call python code from within Igor and exchange data with it. https://github.com/pybind/pybind11 is used by a project I know for writing python code on top of C++. Of course that is easier suggested than done.
August 20, 2019 at 12:40 pm - Permalink
I was just thinking the pickle format was easy for python users. The one file I have contains multiple numpy arrays.
Any reason you cant just call python using ExecuteScriptText with disk files to pass data?
August 20, 2019 at 04:10 pm - Permalink
If all you want to read numpy arrays from file then I wouldn't use pickles, the format spec is available: https://www.numpy.org/devdocs/reference/generated/numpy.lib.format.html.
Reading Pickle files would be a fragile way to go.
To call Python from C/C++: https://docs.python.org/3.7/extending/embedding.html
Otherwise it could be possible via ExecuteScriptText, but you have to know the correct path to the Python command.
Otherwise it could be done via sockets, by making a Python webapp.
August 21, 2019 at 02:50 am - Permalink
I agree with Larry about pkl in terms of usability and familiarity to python users, although something like feather or HDF5 (which I think I have seen in Igor) could work too -- I believe Andy is correct from a 'python that lasts' perspective though. pkl can behave strangely depending on how the user is working with python. Yes, this contradicts my earlier statement about usability, but my experience with pkl is that it is easy until it is not, at which point you actually need to understand how python works at a level many people do not.
I would love to be able to [call Igor]/[pass data to an awaiting Igor] just for the sake of plotting moderately sized datasets with snappy interactivity (ie. 1000s of FTIR spectra with ~4000 variables each). This is still something that is difficult to achieve without . . . writing the plotting code in C or C++. To me, just the snappy plots are well worth the cost of Igor Pro, and I am just outputting my data to a .csv and loading it into Igor with the GUI. If I could call Igor for plotting from Python, with the ability to specify some characteristics of my desired plot, that would incredible.
February 4, 2022 at 08:47 am - Permalink
In reply to I agree with Larry about pkl… by kelleyjbrady
If you simply want to use Igor as a plotting engine from python, some combination of subprocess on the python side, igor scripting (displayhelptopic "Calling Igor from Scripts"), and perhaps an itx file as a container for data and commands might get you there. Not sure that it would work well for the volume of data you're dealing with, though.
February 7, 2022 at 01:30 pm - Permalink