From 56ff818e9d8dcf81b39d68041aadd1f67bbf8ded Mon Sep 17 00:00:00 2001 From: "Olivier J.N. Bertrand" <olivier.bertrand@uni-bielefeld.de> Date: Tue, 6 Nov 2018 14:59:23 +0100 Subject: [PATCH] Improve loading of the image in database --- navipy/database/__init__.py | 14 ++++++++++++++ navipy/scripts/blend_alongtraj.py | 14 ++++++++++++-- navipy/scripts/blendnavipy.py | 18 ++++++++++++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/navipy/database/__init__.py b/navipy/database/__init__.py index bf3bd60..973fa1d 100644 --- a/navipy/database/__init__.py +++ b/navipy/database/__init__.py @@ -704,6 +704,20 @@ class DataBase(): WHERE (rowid=?) """.format(tablename), (rowid,)) image = self.db_cursor.fetchone()[0] + # Check image size + # and try to correct it whenever possible + if not isinstance(image, np.ndarray): + msg = 'image must be np.array' + self._logger.exception(msg) + raise TypeError(msg) + if len(image.shape) > 3: + if np.all(image.shape[3:] == np.ones_like(image.shape[3:])): + image = image[:, :, :, 0] # Other dim are useless + if len(image.shape) != 3: + msg = 'image should be 3D array' + msg += 'image size is {}'.format(image.shape) + self._logger.exception(msg) + raise Exception(msg) # Read cmaxminrange tablename = 'normalisation' cmaxminrange = pd.read_sql_query( diff --git a/navipy/scripts/blend_alongtraj.py b/navipy/scripts/blend_alongtraj.py index fafd2ea..a4cf7d1 100644 --- a/navipy/scripts/blend_alongtraj.py +++ b/navipy/scripts/blend_alongtraj.py @@ -56,7 +56,12 @@ def parser_blend_alongtraj(): type=str, default=None, help=arghelp) - + arghelp = 'To ignore the autocheck of python version' + arghelp += 'and blender' + parser.add_argument('--ignorepycheck', + default=0, + help=arghelp, + action='count') return parser @@ -100,14 +105,19 @@ def main(): tfile.write('except Exception:\n'.encode(encoding)) tfile.write(' sys.exit(1)\n'.encode(encoding)) tfile.seek(0) + if args.ignorepycheck == 0: + ignorepyversion = '' + else: + ignorepyversion = '--ignorepycheck ' - command = 'blendnavipy --background ' + command = 'blendnavipy --background {}'.format(ignorepyversion) command += '--blender-world {} --python-script {}' command = command.format(args.blender_world, tfile.name) if args.blender_command is not None: command += ' --blender-command {}'.format(args.blender_command) for _ in range(args.verbose): command += ' -v' + print(command) os.system(command) diff --git a/navipy/scripts/blendnavipy.py b/navipy/scripts/blendnavipy.py index 8837f87..ab2cf95 100644 --- a/navipy/scripts/blendnavipy.py +++ b/navipy/scripts/blendnavipy.py @@ -82,6 +82,13 @@ def parser_blendnavipy(): action='count', default=0, help=arghelp) + + arghelp = 'To ignore the autocheck of python version' + arghelp += 'and blender' + parser.add_argument('--ignorepycheck', + default=0, + help=arghelp, + action='count') return parser @@ -120,14 +127,17 @@ def main(): with tempfile.NamedTemporaryFile() as tfile: # Start of file tfile.write(header.encode(encoding)) + # Check blender version tfile.write('# check blender version\n'.encode(encoding)) tfile.write('import sys \n'.encode(encoding)) tfile.write('import os \n'.encode(encoding)) - for line in inspect.getsourcelines(blender_version)[0]: + if args.ignorepycheck == 0: + for line in inspect.getsourcelines(blender_version)[0]: + tfile.write(line.encode(encoding)) + tfile.write('\n\n'.encode(encoding)) + line = 'blender_version({})\n'.format(pyver) tfile.write(line.encode(encoding)) - tfile.write('\n\n'.encode(encoding)) - line = 'blender_version({})\n'.format(pyver) - tfile.write(line.encode(encoding)) + # Load venv if venv_path is not None: tfile.write( '# activate virtualenv within blender\n'.encode(encoding)) -- GitLab