Skip to content

py_falcon is a Python wrapper for the MATLAB version of FALCON, a package to calculate nestedness of matrices, but more importantly it includes a module that allows wrapping of any arbitrary MATLAB code in Python.

License

Notifications You must be signed in to change notification settings

ganileni/py_falcon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py_falcon

py_falcon is a Python wrapper for the MATLAB version of FALCON, a package to calculate nestedness of matrices. It also includes a small tutorial, together with some code that makes it easy to wrap MATLAB packages in Python.


For work, I had to use some code that is only available in MATLAB. Most of my workflow, though, is in Python, and I didn't want to mix two languages. I came up with a reasonable way to write a wrapper for MATLAB code very fast, and I wrote a small tutorial about it. The first MATLAB package wrapped is FALCON, written by Stephen Beckett.

Code Example

The only thing you'll need is falcon.nested_test(), FALCON's main routine, from which all tests can be called and executed. Provided the package is installed correctly, you can get away with a couple of lines of code:

import numpy as np
test_matrix = np.loadtxt('test.csv',delimiter=',')

# literally two lines, MATLAB starts automatically
import falcon
result = falcon.nested_test(test_matrix)

print(result)

# recommended: quit the MATLAB engine when you're done
falcon.quit_matlab()

# if you don't want to have to remember to quit the MATLAB engine,
# a context manager is available that shuts it down on exit:

# `as eng` not required, use if you need direct access to MATLAB engine
with falcon.AutoEngineShutdown() as eng:
     result = falcon.nested_test(test_matrix)

nested_test()'s docstring documents the various options of the package. If you need more understanding, in this order, delve into the MATLAB code; see FALCON's repository (which contains much better documentation); or go hardcore and read directly his PhD dissertaton.

Again, if you want to understand how I implemented the wrapper, read this tutorial. Have fun!

Installation

The code has been tested with python 3.6. It depends on the matlab package, which is the MATLAB API for Python, and at the moment only supports Python <=3.6.

The instructions to install the matlab package are:

$ cd $MATLABROOT/extern/engines/python
$ python setup.py install

where $MATLABROOT is your MATLAB installation directory (e.g. for my sistem it's ~/.MathWorks/MATLAB/R2018a).

After that, just pull the code with

$ git clone git@github.com:ganileni/py_falcon.git

and install the requirements:

$ cd py_falcon
$ pip install -r requirements.txt

(note that matlab is not listed within the requirements, since it cannot be found on pypi.org, you need to install it manually).

You can install the package with

$ python setup.py install

or only symlink the files in your python installation with

$ python setup.py develop

Contributors

All of the MATLAB code in this repository was written by Stephen Beckett, I'm just reposting it and added absolutely nothing. I wrote all the Python code, and the notebooks.

License

vanilla MIT license. Check out LICENSE.

About

py_falcon is a Python wrapper for the MATLAB version of FALCON, a package to calculate nestedness of matrices, but more importantly it includes a module that allows wrapping of any arbitrary MATLAB code in Python.

Resources

License

Stars

Watchers

Forks

Packages

No packages published