[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Python from Matlab



Hi,
as you can simply set up calls to the shell from Matlab, like with this example on a Linux machine:
unix(['pwd']);

... you can run the same way your python scripts:
unix(['python mynewfancyscript.py ' mybestoptions '>>& mystuff.log']);

Or add the shebang line '#! /usr/bin/env python' on top of your python script to avoid the explicit call of the python interpeter:
unix(['mynewfancyscript.py ' mybestoptions '>>& mystuff.log']);


Moreover, scipy provides with the interface scipy.io a straightforward manner to translate Matlab files 1-to-1 into Python.
http://docs.scipy.org/doc/scipy/reference/tutorial/io.html

In Matlab you save your options, e.g. a parameter struct:
save('params.mat','params');

The loadmat function in python then returns a dictionary with your variable names as keys and your matrices as its values:
#! /usr/bin/env python

import sys
import scipy.io as sio

if __name__ == "__main__":
    if (len(sys.argv[:]) == 2):
        matparams = sio.loadmat(sys.argv[1], struct_as_record=False, squeeze_me=True)
        params = matparams['params']

Best,
-- 
Stefan Huber
Ph.D. candidate at the Sound Analysis/Synthesis Team, IRCAM, Stefan.Huber@xxxxxxxx
Staff member, Acapela Group, Stefan.Huber@xxxxxxxxxxxxxxxx 




On Fri, Aug 22, 2014 at 10:55 AM, Sebastian Ewert <s.ewert@xxxxxxxxxx> wrote:
Hi,

the upcoming version of matlab has native python support (at least according to the beta changelog). I have no idea how useful it is going to be...

>From the pre-release documentation:

"py package for using Python functions and objects in MATLAB, and engine interface for calling MATLAB from Python"

Sebastian


On 22/08/2014 08:44, Alain de Cheveigne wrote:
Hi Marek,

I am looking for the opposite: an easy, efficient  and reliable way to call Python from Matlab.  My programming environment nowdays is matlab and I can't easily change.  The best course that I see is to implement new code in Python and call it from matlab, and make the switch to Python when Python code reaches critical mass.  I suspect many people are in a similar position.

Alain



On 21 Aug 2014, at 11:20, Marek Rudnicki <marek.rudnicki@xxxxxx> wrote:

Etienne Gaudrain <e.p.c.gaudrain@xxxxxxx> writes:

Dear Marek,

This looks very promising, I'm glad to finally see the first signs of a
shift from Matlab to Python. Thanks a lot for sharing this!!
Dear Etienne

I'm glad you like it.

BTW, if you still have some MATLAB legacy code that you would like to
use in Python, then matlab_wrapper [1] could be helpful.  It allows you
to call MATLAB functions directly from Python environment (the MATLAB
process is started in the background), e.g.:

matlab.workspace.sin([0.1, 0.2, 0.3])


Cheers
Marek


[1] https://github.com/mrkrd/matlab_wrapper



On 19/08/2014 14:50, Marek Rudnicki wrote:
Hi all,

we would like to announce *cochlea* -- a collection of inner ear
models in Python.  It was developed in the group of Werner Hemmert [1]
at the Technische Universität München.  After a few years of
development, we decided that it is stable and would like to contribute
it to the auditory community.



The main features of the package are:

   - simple to use (each model is implemented as a single Python
     function: sound in, spikes out)
   - fast (you can generate responses of hundreds or even thousands of
     nerve fibers)
   - all models have the same interface (easy to make comparisons and
     pick the one that best suits your needs)
   - up-to-date (recent models included)



Currently implemented models are:

   - Zilany, M. S., Bruce, I. C., & Carney, L. H. (2014). Updated
     parameters and expanded simulation options for a model of the
     auditory periphery. The Journal of the Acoustical Society of
     America, 135(1), 283-286.
   - Zilany, M. S., Bruce, I. C., Nelson, P. C., & Carney,
     L. H. (2009). A phenomenological model of the synapse between the
     inner hair cell and auditory nerve: long-term adaptation with
     power-law dynamics. The Journal of the Acoustical Society of
     America, 126(5), 2390-2412.
   - Holmberg, M. (2007). Speech Encoding in the Human Auditory
     Periphery: Modeling and Quantitative Assessment by Means of
     Automatic Speech Recognition. PhD thesis, Technical University
     Darmstadt.
   - MATLAB Auditory Periphery by Meddis et al. (external model, not
     implemented in the package, but easily accessible through
     matlab_wrapper).



We are really grateful to the authors of those models for allowing us
to use their code it in *cochlea*.  We release the package under the
GNU General Public License, so that you are free to copy, use and
modify the code.  We also encourage you to contribute back your
changes.


The code is distributed on GitHub [2] and the package/documentation
are hosted on the Python Package Index [3].  Check also our demo [4]!


If you would like to give a feedback, have questions or found some
problem, do not hesitate to email me or open an issue on GitHub [2].


Thank you and best regards
Marek Rudnicki


[1] http://www.imetum.tum.de/research/bai/home/?L=1
[2] https://github.com/mrkrd/cochlea
[3] https://pythonhosted.org/cochlea/
[4] http://nbviewer.ipython.org/github/mrkrd/cochlea/blob/master/examples/cochlea_demo.ipynb

--
Dr. Sebastian Ewert
Centre for Digital Music, Queen Mary University of London
s.ewert@xxxxxxxxxx
Phone: +44 207 882 8287