[Neuroimaging] Using Python libs from MATLAB
Ariel Rokem
arokem at gmail.com
Mon Jun 13 14:12:27 EDT 2016
Hi,
On Mon, Jun 13, 2016 at 10:43 AM, Samuel St-Jean <stjeansam at gmail.com>
wrote:
> Regarding loading mat files, I was exactly doing that today, and it turns
> out anything that is matlab >= 2006b is using a file format without any
> converter currently existing.
>
> There are bug reports about that, but it still is a work in progress since
> a long time ago, so maybe not waiting on that for now is better to get
> stuff rolling.
>
> See https://savannah.gnu.org/bugs/?45706 and while looking for it I alos
> found this
> http://octave.1599824.n4.nabble.com/Support-for-Matlab-s-7-3-file-format-td4676198.html
Have you tried using h5py? I have had success with that, even for very
recent versions of Matlab (2016a), and intricately nested structs.
>
> Le 2016-06-13 à 18:47, Matthew Brett a écrit :
>
>> Hi,
>>
>> On Mon, Jun 13, 2016 at 7:56 AM, Marmaduke Woodman
>> <marmaduke.woodman at univ-amu.fr> wrote:
>>
>>> hi all,
>>>
>>> I'm a dev behind the Virtual Brain (TVB) a neuroimaging simulation
>>> library,
>>> written in Python. As part of an effort to reach out to some users stuck
>>> in
>>> MATLAB, I've been testing MATLAB's recent *official* support for Python
>>> (2014b+). It is notably better than the many other attempts because it
>>> appears to use Py's C API to expose objects and methods as MATLAB objects
>>> and methods instead of just providing eval/exec.
>>>
>>
Yes - as a co-author of an eval/exec solution (
http://arokem.github.io/python-matlab-bridge/), I am happy to see that they
are doing the work to provide a more thorough solution. I wish that they
told us what they are doing (rather than providing an opaque executable).
These kinds of solutions can be reconfigured into many other useful things
(think 0MQ). But hey - it's a start! To be fair, there was an attempt at an
open-source project in this direction (I believe this one:
http://mlabwrap.sourceforge.net/), but of course it's better if Mathworks
provide the authoritative solution.
>
>>> Generally it's working, but there are some workarounds to avoid
>>> segfaults,
>>> errors and lack of stdout/err. I've started to collect a series of tips
>>> and
>>> workarounds and figured there might be common interest in the community
>>> for
>>> a "helper" library so all our projects can benefit from a larger user
>>> base,
>>> and maybe ease the transition for potential Python users.
>>>
>>> The most important in order,
>>>
>>> - Anything touching HDF5 must use exactly the same version as MATLAB or
>>> segfault
>>>
>> Ouch - I guess this means it's not possible to use h5py or pytables?
>>
>
So - yes - the answer here seems to be "yes" (see above).
Marmaduke - what exactly do you mean "anything touching HDF5"? What series
of steps causes this segfault?
> - Scipy.io.{save,load}mat segfault
>>>
>> That's interesting - it's probably possible to fix that, because that
>> stuff doesn't call any external libraries. Do you have any more
>> details?
>>
>> - C++ extension modules whose exception model doesn't match MATLAB's,
>>> segfault on exception
>>> - Linalg segfault unless using MKL (which is what MATLAB uses)
>>> - stdout/err and logging must be redirecting to mexPrintf via a ctypes
>>> monkey patch
>>> - Numpy/MATLAB array conversion is O(1) op, but can probably be made zero
>>> copy with a ctypes + lib mx workaround
>>>
>>> Aside from these (for which I sent a service request to MathWorks), it's
>>> working well and we (TVB) expect our next release to include demo
>>> scripts in
>>> MATLAB.
>>>
>>> So, again, if there is common interest in collecting notes and a helper
>>> library to monkey patch around the segfaults, it'd be great to not do
>>> this
>>> alone ;)
>>>
>> Thanks too for the feedback. You might also get some interest over
>> at the numpy / scipy lists. Although the blas / lapack thing is a bit
>> of a downer...
>>
>> Cheers,
>>
>> Matthew
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160613/bfb89433/attachment-0001.html>
More information about the Neuroimaging
mailing list