aflux / neutrino

A light, expandable and full featured image analysis tool for research
10 stars 1 forks source link

Status of Python Scripting? #28

Closed sfeister closed 8 years ago

sfeister commented 10 years ago

Hello!

My colleagues and I have been using Neutrino's wavelet package to analyze interferograms, as an alternative to the IDEA software (http://www.optics.tugraz.at/idea/idea.html). Our interferometric setup is described at http://arxiv.org/abs/1406.3639. We are interested in developing Neutrino for real-time analysis of interferometric camera images.

Working through this problem, I have come up with a question for the Neutrino developers. What is the status of the Python scripting? Is it functional?

I have seen references to a GUI element related to the python shell, but it does not appear to be in the release. I am running v1.0rc release on 64-bit Ubuntu. When I follow the instructions on the wiki (https://github.com/aflux/neutrino/wiki/neutrino-python), I get an error. Here is what I have done:"

  1. Install Neutrino (.deb)
  2. Run Neutrino. It works fine. Close Neutrino.
  3. Run "python"
  4. From the python shell, enter "from PyQt4 import QtCore, QtGui, uic". No errors.
  5. Type the second line: "import PyNeutrino as pn". Receive an error: "ImportError: No module named PyNeutrino"

Any help you could give would be greatly appreciated!

Thank you,

Scott

sfeister commented 10 years ago

Good news -- we were able to get past the error mentioned above. We did this in a version we have compiled from source. Here are the steps that worked (Ubuntu 13.10 64-bit):

  1. Navigate to the Neutrino v1.0rc source code directory
  2. sudo apt-get install python-sip-dev
  3. sudo apt-get install python-qt4-dev
  4. make -f nMakefile py

After this, "PyNeutrino.so" was created, and following the wiki instructions did not give any errors at "import PyNeutrino as pn". I'll keep you posted with how our python scripting goes. Thanks, Scott

aflux commented 10 years ago

On 06/20/2014 11:33 PM, Scott F wrote:

Good news -- we were able to get past the error mentioned above. We did this in a version we have compiled from source. Here are the steps that worked (Ubuntu 13.10 64-bit):

  1. Navigate to the Neutrino v1.0rc source code directory
  2. sudo apt-get install python-sip-dev
  3. sudo apt-get install python-qt4-dev
  4. make -f nMakefile py

After this, following the wiki instructions did not give any errors at "import PyNeutrino as pn". I'll keep you posted with how our python scripting goes. Thanks, Scott


Reply to this email directly or view it on GitHub: https://github.com/aflux/neutrino/issues/28#issuecomment-46729133

Dear Scott,

very glad to hear you are working for the implementation of a camera support!

To be honest this was one of the ideas behind the generation of python bindings for neutrino (the others being automation and giving the user the freedom to implement/integrate plugins seamlessly).

In principle all of neutrino structure is being exported to the python module, so what you are trying to do is possible. However we switched not long ago to sip/libNeutrino from pythonQt, so the present state is not well documented (or at all ;-))

Don't hesitate to contact us if you need particular hooks integrated in the main source or if you need to be pointed to relevant parts of the source code.

A.

sfeister commented 10 years ago

It's great to hear that you are supportive of our effort! We are very appreciative to you for developing this resource. In fact, if you grant me wiki access, I would be happy to add a page or two for describing how we installed Neutrino from source on our system (there were a lot of dependencies!) Also, I could add potential future python scripting examples, to help future scripters.

Following the lead of the "neutrino python" wiki page, I am now at the point where I can call a Neutrino instance from python, open a file, and open the various windows, such as the Wavelet window. I can execute certain functions from python, such as the Wavelet "Unwrap" function. I am using the latest version of Neutrino pulled from GitHub.

I am going to take you up on your offer to let me know about particular hooks! Regarding python scripting, my biggest questions right now are:

  1. Do you have any idea as to how to use python to fill in pan window options? (For example, in the Wavelet window, I want to use python to fill in "Image, Min, Max, and "Number, Rel. to carrier, ..."). Looking at the code, it seems like what I want is to access the "my_w" structure that is created along with every pan window. Does a hook exist?
  2. Do you have any suggestions as to how I might pass image data between python and Neutrino? One way within my reach involves continuous saving and loading images from disk, but it seems very round-about! It seems like a better solution would be to directly access the buffers.

Thanks again,

Scott

iltommi commented 10 years ago

Hi Scott, glad you're using our program :) here is some help.

  1. To fill and query stuff on window you can use the "set" and "get" methods of the nGenericPan class (mother of all the window toolboxes around) to know the string associated to every combobox you just have to hover over it and it will display in square brackets (or you can open the .ui associated file with the qt-designer). To hit a button you have the "button" method of
  2. To get and set the data in neutrino you can use the getData and setData of neutrino. Those will use a list of lists so to use it in numpy ypu need to covert forward and backward with np.array(n.getData()) and n.setData(numpyarray.tolist())

there's a neutrino.py in the sip folder that will open a neutrino win (n) and a small console (c) where you can send python commands to n. I use that for tests.

here is a small example of what you can do.

import numpy as np
n.openFile("/Users/tommaso/Desktop/tir46.sif") 
w=n.Wavelet()
w.button("doWavelet")

print w.set("synthetic",False)

print w.get("thickness")
w.set("thickness",50)
print w.get("thickness")
data = np.array(n.getData())
print data.shape

data2=np.fft.fftshift(np.log(abs(np.fft.fft2(data))))
n.setData(data2.tolist())

Please note that I fixed a small bug that prevented to show the image data2, so you have to download the lastest snapshot and recompile. Otherwise you have to manually move the sliders of the colorbar to see the image

Hope this helps and please let us if you need something more. As @aflux said, scripting changed recently and user feedback is highly appreciated.

sfeister commented 10 years ago

Wow, this is really helpful, and I've made a lot of progress with scripting our interferometry analysis. Thanks!

One more python obstacle that I'm running into is changing the image buffer selections within combo boxes (e.g. "0 : ImageA, 1 : ImageB, 2 : phase, .."). For example, in the Wavelet window, w.get("image") returns nothing (I might expect it to return the buffer index), and w.set("image", 2) does not work! Do you know of another way to select the image buffer in the various dynamic combo boxes?

Also, if you don't mind, I have two general questions about the Wavelet package and algorithms. First, what does the "synthetic" checkbox mean? Second, have you looked at how Neutrino phase reconstructions compare with those from other interferometric reconstruction software (such as IDEA -- http://www.optics.tugraz.at/idea/idea.html)? Are there any known resultant differences between Neutrino and other interferometry software / any known issues?

Thanks again!

Scott

iltommi commented 10 years ago

Ok, I corrected the bug (still coming from the switch from pythonqt to sip/pyqt), you can grab the latest snapshot and recompile

now you can get/set image comboBoxes and you can also use geData to get the array in python

from PyNeutrino import *
import numpy as np
n= neutrino()
n.openFile('/Users/tommaso/Desktop/tir52.sif')
w=n.openPan("Wavelet")
print w.get("image")
d=np.array(w.getData("image"))
print d.shape

The synthetic checkbox produces a sythetic interferogram based on the recovered phase and contrast of the fringes (called quality in neutrino). it's just quality*cos(phase).

It's just cosmetic stuff , but it's sometimes useful to have a look at what the algorithms actually "sees"

We didn't benchmark with Idea, we had some student using it here at the lab, but I don't like the closeness of their program.

Moreover a couple of years ago (11/18/06) I contacted them to have a Mac port of their program but the answer was

Indeed, we had a discussion at the beginning, whether we should add a Mac version or not. We decided not. It seemed more important to us to offer a Linux version in addition to the MS edition, which is the most downloaded version.

We have more than hundred downloads a year from various institutions and companies. Nearly all of them use the MS version. So, at the moment it does not make sense to offer a third line. I am sorry.

They also refused help.

Tommaso

sfeister commented 10 years ago

Thanks for making those fixes! It works now. Just as update, with all your help we've really made some good progress scripting. I'm able feed images from python into Neutrino, perform Wavelet analysis, unwrapping, and reference subtraction, and then get the results back in python. In a loop of 80+ images, that's a good bit of Neutrino automation! Since I deliberately call any "file open" functions without involving Neutrino, it's also potentially a good foundation for real-time analysis. Furthermore, with certain parameters the Wavelet results seem qualitatively similar to what we had seen in IDEA (I have not yet checked quantitatively). Thanks so much for your efforts in making this open source project. I'll continue to send you updates and/or bugs and requests. -Scott

aflux commented 10 years ago

Scott, great to hear that!

As soon as I've figured out how to add you as a wiki mantainer, it'd be great if you could share it.

A.

On 06/28/2014 03:10 AM, Scott F wrote:

Thanks for making those fixes! It works now. Just as update, with all your help we've really made some good progress scripting. I'm able feed images from python into Neutrino, perform Wavelet analysis, unwrapping, and reference subtraction, and then get the results back in python. In a loop of 80+ images, that's a good bit of Neutrino automation! Since I deliberately call any "file open" functions without involving Neutrino, it's also potentially a good foundation for real-time analysis. Furthermore, with certain parameters the Wavelet results seem qualitatively similar to what we had seen in IDEA (I have not yet checked quantitatively). Thanks so much for your efforts in making this open source project. I'll continue to send you updates and/or bugs and requests. -Scott

— Reply to this email directly or view it on GitHub https://github.com/aflux/neutrino/issues/28#issuecomment-47414145.

sfeister commented 10 years ago

@aflux I have started some help-oriented wiki pages of my experiences installing Neutrino / getting started scripting in the meantime!

https://github.com/phyzicist/wiktest/wiki

aflux commented 10 years ago

Great job!

I linked it from the neutrino-python wiki page, https://github.com/aflux/neutrino/wiki/neutrino-python

~A

On 06/30/2014 07:11 PM, Scott F wrote:

@aflux https://github.com/aflux I have started some help-oriented wiki pages of my experiences installing Neutrino / getting started scripting in the meantime!

https://github.com/phyzicist/wiktest/wiki

— Reply to this email directly or view it on GitHub https://github.com/aflux/neutrino/issues/28#issuecomment-47558389.