SWIG & python

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

SWIG & python

StevenF
Hello Micromanager community,

I have so far been satisfied and have been using the python wrapper for
Micromanager. Unfortunately, I am having problems with a few of the
functions and i can't pinpoint why these functions aren't working!

for example,

I can use the function setXYposition() without any problem, but
getXYposition() doesn't seem to work.

So according with the doc :

setXYPosition(self, char xyStageLabel, double x, double y)

        """
        setXYPosition(self, char xyStageLabel, double x, double y)
        Parameters:
           xyStageLabel: char const * value
           x: double value
           y: double value

        setXYPosition(self, double x, double y)
        Parameters:
           self: CMMCore * value
           x: double value
           y: double value
        """

setXYposition('XY Stage', 100, 100) will successfully move my stage.



        """
        getXYPosition(self, char xyStageLabel, double x_stage, double
y_stage)
        Parameters:
           xyStageLabel: char const * value
           x_stage: double & value
           y_stage: double & value

        getXYPosition(self, double x_stage, double y_stage)
        Parameters:
           self: CMMCore * value
           x_stage: double & value
           y_stage: double & value

        """

x=0
y=0
getXYPosition('XY Stage', x, y) is if i understand correctly supposed to
work, but it does not. Instead i get :

NotImplementedError: Wrong number of arguments for overloaded function
'CMMCore_getXYPosition'.
  Possible C/C++ prototypes are:
    getXYPosition(self, char xyStageLabel, double x_stage, double y_stage)
    getXYPosition(self, double x_stage, double y_stage)

I am having problems with many functions involving refrences (double & value
vs double value)
What am doing wrong?



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

Egor Zindy

Hi Steven,

Any referenced input variables will be returned by the wrapped function as part of a tuple. If that makes sense.

See if

x,y = getXYPosition(stageName)

works any better.

Cheers,
Egor

On Dec 1, 2017 3:48 PM, "StevenF" <[hidden email]> wrote:
Hello Micromanager community,

I have so far been satisfied and have been using the python wrapper for
Micromanager. Unfortunately, I am having problems with a few of the
functions and i can't pinpoint why these functions aren't working!

for example,

I can use the function setXYposition() without any problem, but
getXYposition() doesn't seem to work.

So according with the doc :

setXYPosition(self, char xyStageLabel, double x, double y)

        """
        setXYPosition(self, char xyStageLabel, double x, double y)
        Parameters:
           xyStageLabel: char const * value
           x: double value
           y: double value

        setXYPosition(self, double x, double y)
        Parameters:
           self: CMMCore * value
           x: double value
           y: double value
        """

setXYposition('XY Stage', 100, 100) will successfully move my stage.



        """
        getXYPosition(self, char xyStageLabel, double x_stage, double
y_stage)
        Parameters:
           xyStageLabel: char const * value
           x_stage: double & value
           y_stage: double & value

        getXYPosition(self, double x_stage, double y_stage)
        Parameters:
           self: CMMCore * value
           x_stage: double & value
           y_stage: double & value

        """

x=0
y=0
getXYPosition('XY Stage', x, y) is if i understand correctly supposed to
work, but it does not. Instead i get :

NotImplementedError: Wrong number of arguments for overloaded function
'CMMCore_getXYPosition'.
  Possible C/C++ prototypes are:
    getXYPosition(self, char xyStageLabel, double x_stage, double y_stage)
    getXYPosition(self, double x_stage, double y_stage)

I am having problems with many functions involving refrences (double & value
vs double value)
What am doing wrong?



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

StevenF
Hello Egor,

Unfortunately no it is not working and i am getting the same error.
I am beginning to suspect there is a problem somewhere concerning SWIG and some of the functions.

Thanks,

Steven


De: "Egor Zindy" <[hidden email]>
À: "Micro-Manager General" <[hidden email]>
Envoyé: Vendredi 1 Décembre 2017 17:32:10
Objet: Re: [micro-manager-general] SWIG & python

Hi Steven,

Any referenced input variables will be returned by the wrapped function as part of a tuple. If that makes sense.

See if

x,y = getXYPosition(stageName)

works any better.

Cheers,
Egor

On Dec 1, 2017 3:48 PM, "StevenF" <[hidden email]> wrote:
Hello Micromanager community,

I have so far been satisfied and have been using the python wrapper for
Micromanager. Unfortunately, I am having problems with a few of the
functions and i can't pinpoint why these functions aren't working!

for example,

I can use the function setXYposition() without any problem, but
getXYposition() doesn't seem to work.

So according with the doc :

setXYPosition(self, char xyStageLabel, double x, double y)

        """
        setXYPosition(self, char xyStageLabel, double x, double y)
        Parameters:
           xyStageLabel: char const * value
           x: double value
           y: double value

        setXYPosition(self, double x, double y)
        Parameters:
           self: CMMCore * value
           x: double value
           y: double value
        """

setXYposition('XY Stage', 100, 100) will successfully move my stage.



        """
        getXYPosition(self, char xyStageLabel, double x_stage, double
y_stage)
        Parameters:
           xyStageLabel: char const * value
           x_stage: double & value
           y_stage: double & value

        getXYPosition(self, double x_stage, double y_stage)
        Parameters:
           self: CMMCore * value
           x_stage: double & value
           y_stage: double & value

        """

x=0
y=0
getXYPosition('XY Stage', x, y) is if i understand correctly supposed to
work, but it does not. Instead i get :

NotImplementedError: Wrong number of arguments for overloaded function
'CMMCore_getXYPosition'.
  Possible C/C++ prototypes are:
    getXYPosition(self, char xyStageLabel, double x_stage, double y_stage)
    getXYPosition(self, double x_stage, double y_stage)

I am having problems with many functions involving refrences (double & value
vs double value)
What am doing wrong?



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

Nico Stuurman-2
In reply to this post by StevenF

On 12/1/17 7:28 AM, StevenF wrote:

> I have so far been satisfied and have been using the python wrapper for
> Micromanager. Unfortunately, I am having problems with a few of the
> functions and i can't pinpoint why these functions aren't working!
>
> for example,
>
> x=0
> y=0
> getXYPosition('XY Stage', x, y) is if i understand correctly supposed to
> work, but it does not. Instead i get :
>
> NotImplementedError: Wrong number of arguments for overloaded function
> 'CMMCore_getXYPosition'.
>    Possible C/C++ prototypes are:
>      getXYPosition(self, char xyStageLabel, double x_stage, double y_stage)
>      getXYPosition(self, double x_stage, double y_stage)
>
> I am having problems with many functions involving refrences (double & value
> vs double value)

I have no experience with Python, but this is painful in the Java
wrappers as well.  In Java, one has to declare arrays to receive values
of the C++ references, so:

double[] x = new double[1];
double[] y = new double[1];
getXYPosition("XY Stage", x, y);
System.out.println("X positioin: " + x[0] + ", Y  position: " + y[0]);

(did not test this, so there may be errors, but you get the idea).

One other idea:  I read that Python has integers, floating point
numbers, and complex numbers.  Does it help to define x and y as "0.0",
rather than "0" (forcing them to be floating point numbers)?

Hope this helps!  Please report back to the list when you get this working!

Best,

Nico



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

Egor Zindy
In reply to this post by StevenF
Hi Steven,

> Unfortunately no it is not working and i am getting the same error.
> I am beginning to suspect there is a problem somewhere concerning SWIG and some of the functions. I'm looking at
>

That's definitely possible. I thought this is how it should it work
but it doesn't. MMCorePy_wrap/MMCorePy.i is where we should start
digging.

In the meantime, retrieving x and y separately using getXPosition and
getYPosition seems to work:

import MMCorePy
mmc = MMCorePy.CMMCore()
mmc.loadDevice('Stage', 'DemoCamera', 'DXYStage')
mmc.initializeAllDevices()
mmc.setXYStageDevice('Stage')
mmc.getXYStageDevice()

'Stage'

mmc.setXYPosition('Stage',10,10)
x = mmc.getXPosition('Stage')
y = mmc.getYPosition('Stage')
print x,y

10.005 10.005

Hope this helps!

Cheers,
Egor

On 1 December 2017 at 16:46, Steven Fletcher <[hidden email]> wrote:
>
> Hello Egor,
>

>
> Thanks,
>
> Steven
>
> ________________________________
>
> De: "Egor Zindy" <[hidden email]>
> À: "Micro-Manager General" <[hidden email]>
> Envoyé: Vendredi 1 Décembre 2017 17:32:10
> Objet: Re: [micro-manager-general] SWIG & python
>
>
> Hi Steven,
>
> Any referenced input variables will be returned by the wrapped function as part of a tuple. If that makes sense.
>
> See if
>
> x,y = getXYPosition(stageName)
>
> works any better.
>
> Cheers,
> Egor
>
> On Dec 1, 2017 3:48 PM, "StevenF" <[hidden email]> wrote:
>>
>> Hello Micromanager community,
>>
>> I have so far been satisfied and have been using the python wrapper for
>> Micromanager. Unfortunately, I am having problems with a few of the
>> functions and i can't pinpoint why these functions aren't working!
>>
>> for example,
>>
>> I can use the function setXYposition() without any problem, but
>> getXYposition() doesn't seem to work.
>>
>> So according with the doc :
>>
>> setXYPosition(self, char xyStageLabel, double x, double y)
>>
>>         """
>>         setXYPosition(self, char xyStageLabel, double x, double y)
>>         Parameters:
>>            xyStageLabel: char const * value
>>            x: double value
>>            y: double value
>>
>>         setXYPosition(self, double x, double y)
>>         Parameters:
>>            self: CMMCore * value
>>            x: double value
>>            y: double value
>>         """
>>
>> setXYposition('XY Stage', 100, 100) will successfully move my stage.
>>
>>
>>
>>         """
>>         getXYPosition(self, char xyStageLabel, double x_stage, double
>> y_stage)
>>         Parameters:
>>            xyStageLabel: char const * value
>>            x_stage: double & value
>>            y_stage: double & value
>>
>>         getXYPosition(self, double x_stage, double y_stage)
>>         Parameters:
>>            self: CMMCore * value
>>            x_stage: double & value
>>            y_stage: double & value
>>
>>         """
>>
>> x=0
>> y=0
>> getXYPosition('XY Stage', x, y) is if i understand correctly supposed to
>> work, but it does not. Instead i get :
>>
>> NotImplementedError: Wrong number of arguments for overloaded function
>> 'CMMCore_getXYPosition'.
>>   Possible C/C++ prototypes are:
>>     getXYPosition(self, char xyStageLabel, double x_stage, double y_stage)
>>     getXYPosition(self, double x_stage, double y_stage)
>>
>> I am having problems with many functions involving refrences (double & value
>> vs double value)
>> What am doing wrong?
>>
>>
>>
>> --
>> Sent from: http://micro-manager.3463995.n2.nabble.com/
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> micro-manager-general mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/micro-manager-general
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> micro-manager-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/micro-manager-general
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> micro-manager-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/micro-manager-general
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

StevenF
Hello Nico & Egor and thank you for your responses!

I have tried many things to make this function work but alas to no avail,
and i was only using this function as an example, because i am have the same
error concerning a function that is even more important to my project :

setSLMImage()

As i had stated in a previous thread
http://micro-manager.3463995.n2.nabble.com/python-CMMCore-amp-SLM-Device-td7588762.html#a7588788
<http://micro-manager.3463995.n2.nabble.com/python-CMMCore-amp-SLM-Device-td7588762.html#a7588788>
,
I could not get this function working whatever i tried.
After some investigation i found that i was having the same error concerning
a few of these functions (getXYPosition) and for reasons i could not figure
out why.

An Engineer help me did around a little and has come up with the hypothesis
that it's because these functions make the use of references (&), but being
unfamiliar with SWIG & C++ as a whole it's hard for me to confirm.

So if Someone could try and make getXYPostion() or more importantly
setSLMImage() to work in python it would be greaty appreciated!

Thanks in advance!

Steven



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

Egor Zindy
Hi Steven,

I sent a patch to Nico that will hopefully make its way to the 1.4 nightlies soon. The fix probably works for 2.0 as well, but I haven't checked that yet.

I have tried many things to make this function work but alas to no avail,
and i was only using this function as an example, because i am have the same
error concerning a function that is even more important to my project :

setSLMImage()

That's interesting. Please let us know which Python methods cause you difficulties. My fix only concerns getXYPosition() and getGalvoPosition() for now, but I can check any other methods which aren't SWIG-wrapped properly.


As i had stated in a previous thread
http://micro-manager.3463995.n2.nabble.com/python-CMMCore-amp-SLM-Device-td7588762.html#a7588788
<http://micro-manager.3463995.n2.nabble.com/python-CMMCore-amp-SLM-Device-td7588762.html#a7588788>
,
I could not get this function working whatever i tried.
After some investigation i found that i was having the same error concerning
a few of these functions (getXYPosition) and for reasons i could not figure
out why.

An Engineer help me did around a little and has come up with the hypothesis
that it's because these functions make the use of references (&), but being
unfamiliar with SWIG & C++ as a whole it's hard for me to confirm.


No worries, thanks for trying! You were on the right track though! Variables passed by reference need to be explicitly defined as outputs in the SWIG interface file (.i). For x_stage and y_stage, they weren't.

If you can't wait for the fix and can compile MM yourself, replace x/y lines 205-206 in MMCorePy_wrap/MMCorePy.i with x_stage/y_stage because these are the variable names used for the method prototype in MMCore/MMCore.h


The idea is to check whether every single variable in MMCore/MMCore.h is properly accounted for as an input or output in the .i file. It may also be worth checking MMCoreJ_wrap/MMCoreJ.i  for inspiration.
 
So if Someone could try and make getXYPostion() or more importantly
setSLMImage() to work in python it would be greaty appreciated!

OK, this will need a bit of scaffolding around

void setSLMImage(const char* slmLabel, unsigned char * pixels) throw (CMMError);
void setSLMImage(const char* slmLabel, imgRGB32 pixels) throw (CMMError);

I'll see what I can do.

Cheers,
Egor


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

StevenF
Thank you Egor,

I will update you if i find any more functions that do not seem to be
working as intended! And i am eager to hear if you manage de get the
setSLMImage working!

Thanks again,

Steven



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

Egor Zindy
Hi Steven,

> I will update you if i find any more functions that do not seem to be
> working as intended! And i am eager to hear if you manage de get the
> setSLMImage working!

some progress at last! From today (2017-12-15), the following SLM
functions are now wrapped in Python with support for type and string
size checks:

setSLMImage (for both greyscale and RGB)
loadSLMSequence (lists of greyscale image strings, for those devices
that support loading sequences).

Please let me know if any other Python wrapped MMCore methods (SLM or
otherwise) require attention.

There's a bit of discussion on the github issue tracker if anyone
wants to participate:
https://github.com/micro-manager/micro-manager/issues/599

In particular, if anyone is familiar with Python / SWIG and C++, I
would love to hear why my first approach using "%typemap(in) unsigned
char *" failed.

Anyway, a test Python program is attached to show how it all fits
together for now.

Cheers,
Egor

>
> Thanks again,
>
> Steven
>
>
>
> --
> Sent from: http://micro-manager.3463995.n2.nabble.com/
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> micro-manager-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/micro-manager-general

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

test_slm.py (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SWIG & python

StevenF
Hello Egor,

Thanks for all the help, if i find any more unusual problems concerning the python wrapper.
It's the main tool i am using at the moment for scripting with micromanager so if there are more problems i am bound to find them!

Best regards,

Steven
----- Mail original -----

> De: "Egor Zindy" <[hidden email]>
> À: "Micro-Manager General" <[hidden email]>
> Envoyé: Vendredi 15 Décembre 2017 09:24:14
> Objet: Re: [micro-manager-general] SWIG & python
>
> Hi Steven,
>
> > I will update you if i find any more functions that do not seem to be
> > working as intended! And i am eager to hear if you manage de get the
> > setSLMImage working!
>
> some progress at last! From today (2017-12-15), the following SLM
> functions are now wrapped in Python with support for type and string
> size checks:
>
> setSLMImage (for both greyscale and RGB)
> loadSLMSequence (lists of greyscale image strings, for those devices
> that support loading sequences).
>
> Please let me know if any other Python wrapped MMCore methods (SLM or
> otherwise) require attention.
>
> There's a bit of discussion on the github issue tracker if anyone
> wants to participate:
> https://github.com/micro-manager/micro-manager/issues/599
>
> In particular, if anyone is familiar with Python / SWIG and C++, I
> would love to hear why my first approach using "%typemap(in) unsigned
> char *" failed.
>
> Anyway, a test Python program is attached to show how it all fits
> together for now.
>
> Cheers,
> Egor
>
> >
> > Thanks again,
> >
> > Steven
> >
> >
> >
> > --
> > Sent from: http://micro-manager.3463995.n2.nabble.com/
> >
> > ------------------------------------------------------------------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > micro-manager-general mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/micro-manager-general
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> micro-manager-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/micro-manager-general
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general