From 2acd50ded689cd5d29c46d8a300a94862ebc8ff9 Mon Sep 17 00:00:00 2001 From: "Olivier J.N. Bertrand" <olivier.bertrand@uni-bielefeld.de> Date: Wed, 7 Mar 2018 16:49:47 +0100 Subject: [PATCH] Handle infinite value in blender and a scene checker --- navipy/database/__init__.py | 14 +++++++++++++- navipy/sensors/bee_sampling.py | 3 ++- navipy/sensors/renderer.py | 11 +++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/navipy/database/__init__.py b/navipy/database/__init__.py index 511d66b..f81bd01 100644 --- a/navipy/database/__init__.py +++ b/navipy/database/__init__.py @@ -8,7 +8,7 @@ import pandas as pd import sqlite3 import io import warnings -from navipy.scene import is_numeric_array +from navipy.scene import is_numeric_array, check_scene def adapt_array(arr): @@ -291,6 +291,16 @@ database posorient.set_index('id', inplace=True) return posorient + @property + def normalisations(self): + """Return the position orientations of all points in the \ +database + """ + posorient = pd.read_sql_query( + "select * from normalisation;", self.db) + posorient.set_index('id', inplace=True) + return posorient + def read_posorient(self, posorient=None, rowid=None): if posorient is not None: if not isinstance(posorient, pd.Series): @@ -406,6 +416,7 @@ database cmaxminrange = cmaxminrange.astype(float) toreturn = self.denormalise_image(image, cmaxminrange) toreturn = toreturn[..., np.newaxis] + check_scene(toreturn) return toreturn def denormalise_image(self, image, cmaxminrange): @@ -557,4 +568,5 @@ class DataBaseSave(DataBase): cmaxminrange.loc[str(chan_n) + '_max'] = cmax cmaxminrange.loc[str(chan_n) + '_min'] = cmin cmaxminrange.loc[str(chan_n) + '_range'] = crange + check_scene(normed_im[...,np.newaxis]) return normed_im, cmaxminrange diff --git a/navipy/sensors/bee_sampling.py b/navipy/sensors/bee_sampling.py index 5d657e0..8284d86 100644 --- a/navipy/sensors/bee_sampling.py +++ b/navipy/sensors/bee_sampling.py @@ -12,7 +12,7 @@ import os import numpy as np import pandas as pd from navipy.database import DataBaseSave - +from navipy.scene import check_scene class BeeSampling(): """ @@ -163,6 +163,7 @@ so that they are not rendered # and the cmaxminrange has not already been assigned # so the image need to be rendered scene = self.renderer.scene(posorient) + check_scene(scene) scene = scene[..., 0] distance = scene[..., -1] distance[distance > self.world_dim] = self.world_dim diff --git a/navipy/sensors/renderer.py b/navipy/sensors/renderer.py index 469865b..3098394 100644 --- a/navipy/sensors/renderer.py +++ b/navipy/sensors/renderer.py @@ -324,4 +324,15 @@ is the distance. self.update(posorient) toreturn = np.concatenate((self.image, self.distance), axis=2) + ninffound=0 + for chan_i in range(4): + cim = toreturn[...,chan_i] + cmax=cim.max() + if np.isinf(cmax): + ninffound += np.sum(np.isinf(cim)) + cmax=cim[np.isinf(cim)==0].max() + toreturn[np.isinf(cim)==1]=cmax + + if ninffound > 0: + warnings.warn('{} Inf found in image'.format(ninffound)) return toreturn[..., np.newaxis] -- GitLab