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

Move processing tools and constants to scene for more intuitive use with other modules

parent fa405968
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ Tutorials ...@@ -42,7 +42,7 @@ Tutorials
.. container:: descr .. container:: descr
.. figure:: /tutorials/database.jpeg .. figure:: /tutorials/examples/database.svg
:target: database.html :target: database.html
:doc:`/tutorials/database` :doc:`/tutorials/database`
...@@ -50,7 +50,7 @@ Tutorials ...@@ -50,7 +50,7 @@ Tutorials
.. container:: descr .. container:: descr
.. figure:: /tutorials/renderimage.svg .. figure:: /tutorials/examples/renderimage.svg
:target: renderimage.html :target: renderimage.html
:doc:`/tutorials/renderimage` :doc:`/tutorials/renderimage`
......
...@@ -38,6 +38,7 @@ An agent using an average skyline homing vector, could be build as follow ...@@ -38,6 +38,7 @@ An agent using an average skyline homing vector, could be build as follow
""" """
from navipy.database import DataBaseLoad from navipy.database import DataBaseLoad
import numpy as np
class Bunch: class Bunch:
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
Comparing Comparing
""" """
import numpy as np import numpy as np
from navipy.processing.tools import is_ibpc, is_obpc from navipy.scene import is_ibpc, is_obpc, check_scene
from navipy.processing.tools import check_scene
def simple_imagediff(current, memory): def simple_imagediff(current, memory):
......
...@@ -2,7 +2,7 @@ import unittest ...@@ -2,7 +2,7 @@ import unittest
import numpy as np import numpy as np
import navipy.database as database import navipy.database as database
import navipy.comparing as comparing import navipy.comparing as comparing
from navipy.processing.tools import is_numeric_array from navipy.scene import is_numeric_array
import pkg_resources import pkg_resources
......
...@@ -8,7 +8,7 @@ import pandas as pd ...@@ -8,7 +8,7 @@ import pandas as pd
import sqlite3 import sqlite3
import io import io
import warnings import warnings
import navipy.processing.tools as tools from navipy.scene import is_numeric_array
def adapt_array(arr): def adapt_array(arr):
...@@ -528,7 +528,7 @@ class DataBaseSave(DataBase): ...@@ -528,7 +528,7 @@ class DataBaseSave(DataBase):
if image.shape[2] != len(self.channels): if image.shape[2] != len(self.channels):
raise Exception('image channels number differs from\ raise Exception('image channels number differs from\
given channel number') given channel number')
if not tools.is_numeric_array(image): if not is_numeric_array(image):
raise TypeError('scene is of non numeric type') raise TypeError('scene is of non numeric type')
normed_im = np.zeros(image.shape, dtype=dtype) normed_im = np.zeros(image.shape, dtype=dtype)
maxval_nim = np.iinfo(normed_im.dtype).max maxval_nim = np.iinfo(normed_im.dtype).max
......
"""
Conversion between coordinates systems
"""
import numpy as np
def cartesian_to_spherical(x, y, z):
radius = np.sqrt(x**2 + y**2 + z**2)
elevation = np.arctan2(z, np.sqrt(x**2 + y**2))
azimuth = np.arctan2(y, x)
spherical = np.zeros_like(x)
spherical = np.tile(spherical[..., np.newaxis], (3,))
return elevation, azimuth, radius
def spherical_to_cartesian(elevation, azimuth, radius=1):
cartesian = np.zeros_like(elevation)
cartesian = np.tile(cartesian[..., np.newaxis], (3,))
x = np.cos(elevation) * np.cos(azimuth)
y = np.cos(elevation) * np.sin(azimuth)
z = np.sin(elevation)
cartesian = radius * cartesian
return x, y, z
"""
Define some constant
"""
__spherical_indeces__ = {'elevation': 0,
'azimuth': 1,
'radius': 2}
__cartesian_indeces__ = {'x': 0,
'y': 1,
'z': 2}
__ibpc_indeces__ = {'elevation': 0,
'azimuth': 1,
'channel': 2,
'component': 3}
__obpc_indeces__ = {'ommatidia': 0,
'channel': 1,
'component': 2}
__eye_indeces__ = {'elevation': 0,
'azimuth': 1,
'component': 2}
__ommadia_indeces__ = {'ommatidia': 0,
'component': 1}
...@@ -3,14 +3,15 @@ place code derived from scene ...@@ -3,14 +3,15 @@ place code derived from scene
""" """
import numpy as np import numpy as np
from scipy.ndimage import maximum_filter, minimum_filter from scipy.ndimage import maximum_filter, minimum_filter
from .constants import __spherical_indeces__ from navipy.scene import __spherical_indeces__
from .constants import __ibpc_indeces__ from navipy.scene import __cartesian_indeces__
from .constants import __obpc_indeces__ from navipy.scene import __ibpc_indeces__
from .tools import is_ibpc from navipy.scene import __obpc_indeces__
from .tools import is_obpc from navipy.scene import is_ibpc
from .tools import spherical_to_cartesian from navipy.scene import is_obpc
from .tools import check_scene from navipy.maths.coordinates import spherical_to_cartesian
from .tools import check_viewing_direction from navipy.scene import check_scene
from navipy.scene import check_viewing_direction
def skyline(scene): def skyline(scene):
...@@ -132,7 +133,13 @@ def pcv(place_code, viewing_directions): ...@@ -132,7 +133,13 @@ def pcv(place_code, viewing_directions):
should be 1'.format(place_code.shape[component_dim])) should be 1'.format(place_code.shape[component_dim]))
elevation = viewing_directions[..., __spherical_indeces__['elevation']] elevation = viewing_directions[..., __spherical_indeces__['elevation']]
azimuth = viewing_directions[..., __spherical_indeces__['azimuth']] azimuth = viewing_directions[..., __spherical_indeces__['azimuth']]
unscaled_lv = spherical_to_cartesian(elevation, azimuth, radius=1) x, y, z = spherical_to_cartesian(elevation, azimuth, radius=1)
unscaled_lv = np.zeros((viewing_directions.shape[0],
viewing_directions.shape[1],
3))
unscaled_lv[..., __cartesian_indeces__['x']] = x
unscaled_lv[..., __cartesian_indeces__['y']] = y
unscaled_lv[..., __cartesian_indeces__['z']] = z
scaled_lv = np.zeros_like(place_code) scaled_lv = np.zeros_like(place_code)
# (3,) -> (1,1,3) or (1,1,1,3) see numpy.tile # (3,) -> (1,1,3) or (1,1,1,3) see numpy.tile
scaled_lv = np.tile(scaled_lv, (unscaled_lv.shape[-1],)) scaled_lv = np.tile(scaled_lv, (unscaled_lv.shape[-1],))
......
...@@ -4,7 +4,7 @@ import numpy as np ...@@ -4,7 +4,7 @@ import numpy as np
import pandas as pd import pandas as pd
import navipy.database as database import navipy.database as database
import navipy.processing.pcode as pcode import navipy.processing.pcode as pcode
from navipy.processing.tools import is_numeric_array from navipy.scene import is_numeric_array
import pkg_resources import pkg_resources
......
from .constants import __ibpc_indeces__ """
from .constants import __spherical_indeces__ Define what a scene is
from .constants import __cartesian_indeces__ """
from .constants import __obpc_indeces__
from .constants import __eye_indeces__
import numpy as np import numpy as np
#
# Define constants
#
__spherical_indeces__ = {'elevation': 0,
'azimuth': 1,
'radius': 2}
__cartesian_indeces__ = {'x': 0,
'y': 1,
'z': 2}
__ibpc_indeces__ = {'elevation': 0,
'azimuth': 1,
'channel': 2,
'component': 3}
__obpc_indeces__ = {'ommatidia': 0,
'channel': 1,
'component': 2}
__eye_indeces__ = {'elevation': 0,
'azimuth': 1,
'component': 2}
__ommadia_indeces__ = {'ommatidia': 0,
'component': 1}
def check_scene(scene): def check_scene(scene):
if is_ibpc(scene): if is_ibpc(scene):
# print("normal") # print("normal")
...@@ -139,27 +160,3 @@ def ibs_to_obs(scene, eye_map): ...@@ -139,27 +160,3 @@ def ibs_to_obs(scene, eye_map):
eye_map.shape[__ibpc_indeces__['component']]) eye_map.shape[__ibpc_indeces__['component']])
ommatidia_map = eye_map.reshape(omm_size) ommatidia_map = eye_map.reshape(omm_size)
return (obs_scene, ommatidia_map) return (obs_scene, ommatidia_map)
def cartesian_to_spherical(x, y, z):
radius = np.sqrt(x**2 + y**2 + z**2)
elevation = np.arctan2(z, np.sqrt(x**2 + y**2))
azimuth = np.arctan2(y, x)
spherical = np.zeros_like(x)
spherical = np.tile(spherical[..., np.newaxis], (3,))
spherical[..., __spherical_indeces__['elevation']] = elevation
spherical[..., __spherical_indeces__['azimuth']] = azimuth
spherical[..., __spherical_indeces__['radius']] = radius
return spherical
def spherical_to_cartesian(elevation, azimuth, radius=1):
cartesian = np.zeros_like(elevation)
cartesian = np.tile(cartesian[..., np.newaxis], (3,))
cartesian[..., __cartesian_indeces__['x']] = np.cos(
elevation) * np.cos(azimuth)
cartesian[..., __cartesian_indeces__['y']] = np.cos(
elevation) * np.sin(azimuth)
cartesian[..., __cartesian_indeces__['z']] = np.sin(elevation)
cartesian = radius * cartesian
return cartesian
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