Class PythonUtil
java.lang.Object
com.eco.bio7.pybridge.PythonUtil
The API of the embedded Python of Bio7 for Java, Groovy and BeanShell
scripts (as REval for R; Python scripts use the module bio7). The
variables are created in the namespace of the Python console and of the
scripts (__main__).
PythonUtil.toPython("x", 1.0, 2.0, 3.0); // numpy array
PyValue mean = PythonUtil.fromPython("float(x.mean())");
PythonUtil.imageToPython("img"); // the current ImageJ image
PythonUtil.pythonToR("x", "xr"); // Python -> R
PythonUtil.rToPython("summary(cars)", "s"); // R -> Python
-
Method Summary
Modifier and TypeMethodDescriptionstatic PyValueEvaluates a Python expression and returns its value.static voidExecutes Python statements (an error raises an exception with the traceback).static PyValuefromPython(String expression) Evaluates a Python expression and returns its value.static double[]fromPythonDoubles(String expression) Returns the numbers of an expression (e.g., a numpy array) as double[].static voidAlias ofrToPython(String, String).static ij.ImagePlusimageFromPython(String expression, String title) Creates and shows an ImageJ image from a numpy array (2-d, stack or RGB).static voidimageToPython(String name) Transfers the current ImageJ image as numpy array (seePythonConvert.image(ImagePlus)).static voidimageToPython(String name, ij.ImagePlus imp) Transfers an image as numpy array.static booleanisAlive()Returns true if the embedded Python runs.static voidTransfers the value of a Python expression to R (embedded R): arrays keep their shape (matrices, arrays), DataFrames become data frames, dicts named lists.static voidresultsTableToPython(String name) Transfers the ImageJ results table as pandas DataFrame (a dict without pandas).static voidTransfers the value of an R expression to Python: vectors and matrices become numpy arrays, data frames pandas DataFrames, named lists dicts.static voidExecutes Python code like a script: the output and errors in the console, new plots in the view.static voidstart()Starts the embedded Python with the Python of the preferences (if not running).static voidAssigns booleans (a numpy bool array).static voidAssigns numbers (a numpy array).static voidAssigns a matrix (rows) as 2-d numpy array.static voidAssigns integers (a numpy int32 array).static voidAssigns any value (arrays with shape, lists, dicts, DataFrames).static voidAssigns strings (a str for one string, else a list).static voidAlias ofpythonToR(String, String).
-
Method Details
-
isAlive
public static boolean isAlive()Returns true if the embedded Python runs. -
start
public static void start() throws com.eco.bio7.pyffm.PyExceptionStarts the embedded Python with the Python of the preferences (if not running).- Throws:
com.eco.bio7.pyffm.PyException- with the reason if it can't be started
-
toPython
Assigns numbers (a numpy array).- Throws:
com.eco.bio7.pyffm.PyException
-
toPython
Assigns integers (a numpy int32 array).- Throws:
com.eco.bio7.pyffm.PyException
-
toPython
-
toPython
Assigns booleans (a numpy bool array).- Throws:
com.eco.bio7.pyffm.PyException
-
toPython
Assigns a matrix (rows) as 2-d numpy array.- Throws:
com.eco.bio7.pyffm.PyException
-
toPython
-
fromPython
-
eval
-
exec
Executes Python statements (an error raises an exception with the traceback).- Throws:
com.eco.bio7.pyffm.PyException
-
run
Executes Python code like a script: the output and errors in the console, new plots in the view.- Throws:
com.eco.bio7.pyffm.PyException
-
fromPythonDoubles
Returns the numbers of an expression (e.g., a numpy array) as double[].- Throws:
com.eco.bio7.pyffm.PyException
-
imageToPython
Transfers the current ImageJ image as numpy array (seePythonConvert.image(ImagePlus)).- Throws:
com.eco.bio7.pyffm.PyException
-
imageToPython
public static void imageToPython(String name, ij.ImagePlus imp) throws com.eco.bio7.pyffm.PyException Transfers an image as numpy array.- Throws:
com.eco.bio7.pyffm.PyException
-
imageFromPython
-
resultsTableToPython
Transfers the ImageJ results table as pandas DataFrame (a dict without pandas).- Throws:
com.eco.bio7.pyffm.PyException
-
pythonToR
-
rToPython
-
toR
Alias ofpythonToR(String, String).- Throws:
Exception
-
fromR
Alias ofrToPython(String, String).- Throws:
Exception
-