diff --git a/navipy/database/__init__.py b/navipy/database/__init__.py index bf3bd608fd9e2964e9938fde7036950a93491be6..973fa1d1a0c90e8803cc507a12967322de8348e9 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 fafd2eabd997cb6ff84613648e983ba00cc73fcd..a4cf7d13eb44d6c6ee3d41b3fe6528e26b1fc367 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 8837f87e650a9c1ce37df96d440b1ea3812519c9..ab2cf95b42ed890f704234dfa6f91b7a37430bbf 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))