Skip to content
Snippets Groups Projects
Commit 56ff818e authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Improve loading of the image in database

parent 182b80f0
No related branches found
No related tags found
No related merge requests found
...@@ -704,6 +704,20 @@ class DataBase(): ...@@ -704,6 +704,20 @@ class DataBase():
WHERE (rowid=?) WHERE (rowid=?)
""".format(tablename), (rowid,)) """.format(tablename), (rowid,))
image = self.db_cursor.fetchone()[0] 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 # Read cmaxminrange
tablename = 'normalisation' tablename = 'normalisation'
cmaxminrange = pd.read_sql_query( cmaxminrange = pd.read_sql_query(
......
...@@ -56,7 +56,12 @@ def parser_blend_alongtraj(): ...@@ -56,7 +56,12 @@ def parser_blend_alongtraj():
type=str, type=str,
default=None, default=None,
help=arghelp) 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 return parser
...@@ -100,14 +105,19 @@ def main(): ...@@ -100,14 +105,19 @@ def main():
tfile.write('except Exception:\n'.encode(encoding)) tfile.write('except Exception:\n'.encode(encoding))
tfile.write(' sys.exit(1)\n'.encode(encoding)) tfile.write(' sys.exit(1)\n'.encode(encoding))
tfile.seek(0) 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 += '--blender-world {} --python-script {}'
command = command.format(args.blender_world, tfile.name) command = command.format(args.blender_world, tfile.name)
if args.blender_command is not None: if args.blender_command is not None:
command += ' --blender-command {}'.format(args.blender_command) command += ' --blender-command {}'.format(args.blender_command)
for _ in range(args.verbose): for _ in range(args.verbose):
command += ' -v' command += ' -v'
print(command)
os.system(command) os.system(command)
......
...@@ -82,6 +82,13 @@ def parser_blendnavipy(): ...@@ -82,6 +82,13 @@ def parser_blendnavipy():
action='count', action='count',
default=0, default=0,
help=arghelp) 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 return parser
...@@ -120,14 +127,17 @@ def main(): ...@@ -120,14 +127,17 @@ def main():
with tempfile.NamedTemporaryFile() as tfile: with tempfile.NamedTemporaryFile() as tfile:
# Start of file # Start of file
tfile.write(header.encode(encoding)) tfile.write(header.encode(encoding))
# Check blender version
tfile.write('# check blender version\n'.encode(encoding)) tfile.write('# check blender version\n'.encode(encoding))
tfile.write('import sys \n'.encode(encoding)) tfile.write('import sys \n'.encode(encoding))
tfile.write('import os \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(line.encode(encoding))
tfile.write('\n\n'.encode(encoding)) # Load venv
line = 'blender_version({})\n'.format(pyver)
tfile.write(line.encode(encoding))
if venv_path is not None: if venv_path is not None:
tfile.write( tfile.write(
'# activate virtualenv within blender\n'.encode(encoding)) '# activate virtualenv within blender\n'.encode(encoding))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment