Commit 703d77f6 authored by Stephan Seitz's avatar Stephan Seitz

Update to use JPype 0.7 (had breaking API changes)

parent 2b708146
Pipeline #2463 failed with stage
in 4 seconds
......@@ -12,20 +12,14 @@ except:
__version__ = 'unknown'
from jpype import JDouble, JArray, JInt, JString, JShort, JProxy, JByte, JBoolean, JChar, JLong, JFloat, JClass, JIterator, java, JPackage, attachThreadToJVM, detachThreadFromJVM
try:
from jpype import JavaException as JException
except Exception as e:
from jpype import JException
from jpype import JDouble, JArray, JInt, JString, JShort, JProxy, JByte, JBoolean, JChar, JLong, JFloat, JClass, JIterator, java, JPackage, attachThreadToJVM, JException, detachThreadFromJVM
import jpype
import jpype.imports
# TODO: deprecate PyGrid
from ._pygrid import PyGrid
from pyconrad._pyconrad import setup_pyconrad, start_gui, start_reconstruction_pipeline_gui, is_initialized, is_gui_started, terminate_pyconrad
from ._autocomplete_files.autocomplete_conrad import AutoCompleteConrad
from pyconrad._autocomplete_files.autocomplete_conrad import AutoCompleteConrad
from pyconrad._classgetter import ClassGetter
from .constants import java_float_dtype
from ._autocomplete import generate_autocomplete_file
from pyconrad.constants import java_float_dtype
from pyconrad._autocomplete import generate_autocomplete_file
from pyconrad._imageutils import imshow, to_conrad_grid
import pyconrad.config
import jpype.imports
......
import pyconrad
import os
import warnings
from mock import MagicMock
import pyconrad
def generate_autocomplete_file(file, conrad_dir:str, classname:str, alsoMembers = True):
def generate_autocomplete_file(file, conrad_dir: str, classname: str, alsoMembers=True):
if not pyconrad.is_initialized():
pyconrad.setup_pyconrad(min_ram='50M')
dir_list = [ conrad_dir ]
dir_list = [conrad_dir]
with open(file, 'w') as writer:
zero_indentation = conrad_dir.count('/') + 1
writer.writelines('import pyconrad\r\n')
......@@ -29,7 +34,7 @@ def generate_autocomplete_file(file, conrad_dir:str, classname:str, alsoMembers
if os.path.basename(f) != 'coneBeam':
writer.writelines(' ' * indentation + 'class ' + os.path.basename(f) + ':\r\n')
for item in os.listdir(f):
dir_list.append(os.path.join(f,item))
dir_list.append(os.path.join(f, item))
if os.path.isfile(f):
filename, extension = os.path.splitext(os.path.basename(f))
if extension == '.java' and filename != 'package-info':
......@@ -37,28 +42,23 @@ def generate_autocomplete_file(file, conrad_dir:str, classname:str, alsoMembers
if alsoMembers:
try:
jclass = pyconrad.JClass(classname.replace('/','.'))
jclass = pyconrad.JClass(classname.replace('/', '.'))
writer.writelines(' ' * indentation + 'class ' + filename + ':\r\n')
for member in jclass.__dict__:
if member != 'class' and member[0] != '_' and member != "and" and member != "lambda":
writer.writelines(' ' * (indentation +1) + member + ' = None\r\n')
writer.writelines(' ' * (indentation + 1) + member + ' = None\r\n')
except:
print("fail " + classname.replace('/','.'))
print("fail " + classname.replace('/', '.'))
writer.writelines(' ' * indentation + filename + ' = None\r\n')
else:
writer.writelines(' ' * indentation + filename + ' = None\r\n')
if __name__ == '__main__':
generate_autocomplete_file('/home/stephan/foo.py', '/home/stephan/projects/CONRAD/src', 'AutoCompleteConrad', True)
print(open('/home/stephan/foo.py','r').read())
print(open('/home/stephan/foo.py', 'r').read())
import warnings
class AutoCompleteConrad(pyconrad.ClassGetter):
def __init__(self):
warnings.warn('This class should never be initialized! Use it as type hint: #type: pyconrad.AutoCompleteConrad')
AutoCompleteConrad = MagicMock()
import pyconrad
from jpype import JPackage
import pyconrad
from pyconrad._autocomplete import AutoCompleteConrad
from pyconrad._pyconrad import assert_pyconrad_initialization
......@@ -23,57 +25,57 @@ class ClassGetter:
self._imported_namespaces.append(namespaces)
@property
def SimpleVector(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.numerics.SimpleVector:
def SimpleVector(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.numerics.SimpleVector:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.numerics.SimpleVector')
@property
def PointND(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.geometry.shapes.simple.PointND:
def PointND(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.geometry.shapes.simple.PointND:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.geometry.shapes.simple.PointND')
@property
def SimpleMatrix(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.numerics.SimpleMatrix:
def SimpleMatrix(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.numerics.SimpleMatrix:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.numerics.SimpleMatrix')
@property
def NumericGrid(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.NumericGrid:
def NumericGrid(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.NumericGrid:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.NumericGrid')
@property
def Grid1D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid1D:
def Grid1D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid1D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.Grid1D')
@property
def Grid2D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid2D:
def Grid2D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid2D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.Grid2D')
@property
def Grid3D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid3D:
def Grid3D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid3D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.Grid3D')
@property
def Grid4D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid4D:
def Grid4D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.Grid4D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.Grid4D')
@property
def OpenCLGrid1D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid1D:
def OpenCLGrid1D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid1D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid1D')
@property
def OpenCLGrid2D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid2D:
def OpenCLGrid2D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid2D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid2D')
@property
def OpenCLGrid3D(self) -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid3D:
def OpenCLGrid3D(self) -> AutoCompleteConrad.edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid3D:
assert_pyconrad_initialization()
return pyconrad.JClass('edu.stanford.rsl.conrad.data.numeric.opencl.OpenCLGrid3D')
......
......@@ -9,20 +9,24 @@ import numpy as np
from jpype import JArray, JClass, JDouble, JInt, JPackage, JProxy
import pyconrad
from pyconrad._java_pyconrad import JavaPyConrad
from ._imageutils import ImageUtil
from ._pygrid import PyGrid
from .constants import java_float_dtype
try:
import pyconrad._vtk
except Exception:
import warnings
warnings.warn("Could not import pyconrad._vtk")
from pyconrad._java_pyconrad import JavaPyConrad
from ._imageutils import ImageUtil
from ._pygrid import PyGrid
from .constants import java_float_dtype
del JClass.__setattr__
try:
import pyopencl as cl
except:
except Exception:
cl = None
......@@ -180,6 +184,10 @@ def _extend_numeric_grid():
def _numeric_grid_shape(self):
return tuple(reversed(self.getSize()[:]))
@property
def _numeric_grid_size(self):
return tuple(self.getSize()[:])
@property
def _numeric_grid_ndim(self):
return len(self.getSize()[:])
......@@ -232,6 +240,7 @@ def _extend_numeric_grid():
grid_class.__getitem__ = _numeric_grid_getitem
grid_class.__setitem__ = _numeric_grid_setitem
grid_class.shape = _numeric_grid_shape
grid_class.size = _numeric_grid_size
grid_class.ndim = _numeric_grid_ndim
grid_class.pygrid = _pygrid
grid_class.__array__ = _numpy_grid
......
......@@ -10,18 +10,20 @@ import warnings
from os.path import join
from pathlib import Path
import jpype
from jpype import (JArray, JClass, JDouble, JPackage, JProxy,
attachThreadToJVM, detachThreadFromJVM, getDefaultJVMPath,
isJVMStarted, java, shutdownJVM, startJVM)
from . import _download_conrad, _extend_conrad_classes
from . import _windowlistener as wl
try:
from jpype import JavaException as JException
except Exception as e:
from jpype import JException
import jpype
from . import _download_conrad, _extend_conrad_classes
from . import _windowlistener as wl
module_path = os.path.dirname(__file__)
......@@ -114,7 +116,7 @@ class PyConrad:
_download_conrad.download_conrad()
os.chdir(self.__conrad_path)
startJVM(getDefaultJVMPath(), conrad_source_and_libs,
"-Xmx%s" % max_ram, "-Xmn%s" % min_ram)
"-Xmx%s" % max_ram, "-Xmn%s" % min_ram, convertStrings=True)
os.chdir(curr_directory)
self._check_jre_version()
......
......@@ -2,11 +2,11 @@
# Copyright (C) 2010-2017 - Andreas Maier
# CONRAD is developed as an Open Source project under the GNU General Public License (GPL-3.0)
import jpype.awt.event.WindowAdapter as wa
import pyconrad
class WindowListener(wa):
class WindowListener:
def __init__(self, *mth, **kw):
object.__init__(self)
......
import numpy as np
from pyconrad._classgetter import ClassGetter
import pyconrad
from ._autocomplete_files.autocomplete_conrad import AutoCompleteConrad
_ = pyconrad.ClassGetter(
'edu.stanford.rsl.conrad.utils',
'java.beans',
......@@ -10,14 +13,14 @@ _ = pyconrad.ClassGetter(
)
def get_conf() -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.utils.Configuration:
def get_conf() -> AutoCompleteConrad.edu.stanford.rsl.conrad.utils.Configuration:
from edu.stanford.rsl.conrad.utils import Configuration
conf = Configuration.getGlobalConfiguration()
return conf
def get_geometry() -> pyconrad.AutoCompleteConrad.edu.stanford.rsl.conrad.geometry.trajectories.Trajectory:
def get_geometry() -> AutoCompleteConrad.edu.stanford.rsl.conrad.geometry.trajectories.Trajectory:
from edu.stanford.rsl.conrad.utils import Configuration
geo = Configuration.getGlobalConfiguration().getGeometry()
return geo
......
# Copyright (C) 2010-2017 - Andreas Maier
# CONRAD is developed as an Open Source project under the GNU General Public License (GPL-3.0)
from pyconrad import setup_pyconrad, PyGrid, java_float_dtype, JArray, JDouble, ClassGetter
from pyconrad import setup_pyconrad, java_float_dtype, JArray, JDouble, ClassGetter
import pyconrad
import numpy as np
......@@ -11,7 +11,6 @@ pyconrad.setup_pyconrad(min_ram='500M', max_ram='8G', dev_dirs=[])
_ = ClassGetter()
# Create PyGrid from numpy array (more efficient if using Java float type pyconrad.java_float_dtype)
array = np.random.rand(4, 2, 3).astype(pyconrad.java_float_dtype)
grid = _.NumericGrid.from_numpy(array)
......@@ -75,31 +74,3 @@ np_grid3D = java_grid3D.as_numpy()
np_grid3D2 = java_grid3D2.as_numpy()
np_grid3D3 = java_grid3D3.as_numpy()
# Create PyGrid from Grid2D
pygrid1 = PyGrid.from_grid(phantom)
# use Java method
pygrid1.grid.show()
# use Python method
# from scipy.misc import imshow
# imshow(pygrid1)
# Create PyGrid from numpy array (must be of type pyconrad.java_float_dtype)
array = np.random.rand(4, 2, 3).astype(java_float_dtype)
pygrid2 = PyGrid.from_numpy(array)
# Manipulate data in using CONRAD at Position (x,y,z) = (1,2,4)
pygrid2.grid.setValue(5.0, [0, 1, 3])
# Print this pixel using Python indexes [z,y,x]
print("Before update: %f" % pygrid2[3, 1, 0])
# Python data must be synchronized with CONRAD
pygrid2.update_numpy()
print("After update: %f" % pygrid2[3, 1, 0])
# Manipulate pixel using python
pygrid2[1, 1, 1] = 3.0
# Update CONRAD data
pygrid2.update_grid()
# Print
print(pygrid2)
......@@ -67,12 +67,12 @@ def setup_package():
author_email='andreas.maier@fau.de',
license='GPL 3.0',
install_requires=[
'jpype1', 'numpy', 'pathlib', 'urllib3', 'pyevtk', 'setuptools', 'vtk', 'procbridge', 'cppimport'
'jpype1>=0.7', 'numpy', 'pathlib', 'urllib3', 'pyevtk', 'setuptools', 'vtk', 'procbridge', 'cppimport'
],
extras_require={'opencl': ['pyopencl']},
cmdclass={'install': install},
url='https://git5.cs.fau.de/PyConrad/pyCONRAD/',
description='Python wrapper for CONRAD (https://www5.cs.fau.de/conrad/), a framework for cone beam radiography',
description='Python wrapper for CONRAD (https://www5.cs.fau.de/conrad/), a framework for cone beam radiography', # noqa
long_description=read('README.rst'),
entry_points={
'gui_scripts': [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment