Coverage for navipy/processing/mcode.py : 63%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Motion code """ import compose_matrix import spherical_to_cartesian, cartesian_to_spherical_vectors
velocity): raise TypeError('velocity should be a pandas Series') raise ValueError("velocity must not be None") raise Exception('velocity must not be empty') raise Exception('velocity must have a multiindex containing \ the convention used')
msg = "the chosen convention {} is not supported" msg = msg.format(convention) raise ValueError(msg) raise ValueError('missing index x') raise ValueError('missing index y') raise ValueError('missing index z') raise ValueError('missing index alpha_0') raise ValueError('missing index alpha_1') raise ValueError('missing index alpha_2') raise ValueError('velocity must not contain nan') raise ValueError("viewing direction must not be None") (not isinstance(viewing_directions, np.ndarray)): raise TypeError("angels must be list or np.ndarray") raise TypeError("viewing_direction must be of numerical type")
""" rotational optic flow :param viewing_directions: viewing direction of each pixel (azimuth,elevation) :param velocity: pandas series (x,y,z,alpha,beta,gamma,dx,dy,dz,dalpha,dbeta,dgamma) """ velocity)
# Check if rotation are not too large # because we assume small rotation # according to Koenderink van Dorn (np.abs(dpitch) > np.pi/2 and 2*np.pi - np.abs(dpitch) > np.pi/2) or (np.abs(droll) > np.pi/2 and 2*np.pi - np.abs(droll) > np.pi/2)): raise ValueError('rotation exceeds 90°, computation aborted') # we init a matrix for rot # Calculate the angular velocities dyaw, dpitch, droll, convention) perspective=None, axes=convention)[:3, :3] # project it on the eye # in the bee coordinate system # Decompose into el, az cartesian_to_spherical_vectors(opticFlowR, [a, e])
velocity): """ translational optic flow : param distance: distance to objects : param viewing_directions: viewing direction of each pixel (azimuth, elevation) : param velocity: pandas series (x, y, z, alpha, beta, gamma, dx, dy, dz, dalpha, dbeta, dgamma) """ msg = 'distance and viewing_directions should have the same size' msg += '{} != {}'.format(distance.shape, viewing_directions.shape[:-1].shape) raise ValueError(msg) velocity) # optic flow depnd of distance # and translational velocity # Express in the global coordinate system velocity['location']['dy'], velocity['location']['dz']] else: # we init a matrix for rot # transformation perspective=None, axes=convention)[:3, :3] # The spline express in the bee coordinate system # the Translation-part of the Optic Flow: # Decompose into el, az cartesian_to_spherical_vectors(opticFlowT, [a, e])
""" optic flow : param distance: distance to surrounding objects : param viewing_directions: viewing direction of each pixel (azimuth, elevation) : param velocity: pandas series (x, y, z, alpha, beta, gamma, dx, dy, dz, dalpha, dbeta, dgamma) """ velocity)
""" This class represents a Module that functions as a storage """
""" initializes the storage as an np.ndarray containing zeros of size size : param size: the tupel containing the size of the storage(Input) """ raise ValueError("size must not be None") raise TypeError("size must be a tuple") raise Exception("length of size must at least be two")
def size(self): """ getter for the the size field : returns size: size of the Input field : rtype tuple """
def size(self, size): """ setter for the size of the storage : param size: tuple that contains the size of the storage """ raise ValueError("size must not be None") raise TypeError("size must be a tuple") raise Exception("length of size must at least be two")
def Input(self): """ getter for the Input field : returns Input : rtype np.ndarray """
def Input(self, Input): """ setter for the Input field, automaticaly sets the the size field to the shape of the Input : param Input """ raise ValueError("Input must not be None") raise TypeError("Input must be np array") raise Exception("Input must have at least 2 dimensions") raise Exception("Each dimension of the Input\ must have at least be of size one")
"""" update function can be implemented for inheriting classes """
""" Implementation of a low pass filter """
""" Initializes the lowpass filter, the size of the output is set to the size of the input signal(inM) : param tau: time constant of the filter : param freq: cut off frequence of the filter : param inM: Module that stores and represents the input signal """ raise ValueError("tau must be of type float or integer") raise ValueError("input Module must not be None") raise ValueError("input Module must be of type Module")
def itau(self): """ getter of the time constant which is calculated by 1000/(tau*freq) """
def itau(self, itau): """ setter of the time constant : param itau: time constant """ raise ValueError("itau must be of type float or integer")
def inM(self): """ setter of the input Module : returns inM : rtype Module """
def inM(self, inM): """ setter of the input Module : param inM """ raise ValueError("input Module must not be None") raise ValueError("input Module must be of type Module")
""" update functions, updates the filtered signal for the the current input signal. out_t+1 += tau*(input-out_t) """
""" Implements a high pass filter """
""" Initializes the high pass filter : param tau: time constant : param freq: cut off frequency : param inM: Module that stores the input signal """ raise ValueError("tau must be of type float or integer") raise ValueError("input Module must not be None") raise ValueError("input Module must be of type Module")
def inM(self): """ getter for the input Module : returns inM : rtype Module """
def inM(self, inM): """ setter for the input Module : param inM: input Module for the input signal """ raise ValueError("input Module must not be None") raise ValueError("input Module must be of type Module")
""" updates the output signal with the current input signal out_t+1 = Input-lowpass(Input) """
""" Implements the multiplication of two Modules """
""" Initializes the multiplication module : param inM1: first input Module : param inM2: second input Module """ if inM1 is None: raise ValueError("input Module must not be None") if not isinstance(inM1, Module): raise ValueError("input Module must be of type Module") if inM2 is None: raise ValueError("input Module must not be None") if not isinstance(inM2, Module): raise ValueError("input Module must be of type Module") Module.__init__(self, inM1.size) self.inM1 = inM1 self.inM2 = inM2
def inM1(self): """ getter for the first input Module : returns inM1 : rtype Module """ return self.__inM1
def inM(self, inM1): """ setter for the first input Module : param inM1 """ if inM1 is None: raise ValueError("input Module must not be None") if not isinstance(inM1, Module): raise ValueError("input Module must be of type Module") self.__inM1 = inM1
def inM2(self): """ getter for the second input Module : returns inM2 : rtype Module """ return self.__inM2
def inM2(self, inM2): """ setter for the first input Module : param inM1 """ if inM2 is None: raise ValueError("input Module must not be None") if not isinstance(inM2, Module): raise ValueError("input Module must be of type Module") self.__inM2 = inM2
""" updates the output(multiplication of the two input Modules) for the current input(see numpy roll) : param shift: shifts the Input provided by the first module by the given amount : param axis: shifts the Input of the first module along the provided axis """ if not isinstance(shift, int): raise TypeError("shift must be an integer") if axis is not None: if not isinstance(axis, int): raise TypeError("axis must be of type integer") shiftedInput = np.roll(self.inM1.Input, shift, axis) for i in range(self.size[0]): for j in range(self.size[1]): sig_left1 = self.inM1.Input[i, j] sig_left2 = shiftedInput[i, j] self.Input[i, j] = sig_left1*sig_left2
""" Implements the division of two Modules """
""" Initializes the multiplication module : param inM1: first input Module : param inM2: second input Module """ if inM1 is None: raise ValueError("input Module must not be None") if not isinstance(inM1, Module): raise ValueError("input Module must be of type Module") if inM2 is None: raise ValueError("input Module must not be None") if not isinstance(inM2, Module): raise ValueError("input Module must be of type Module") Module.__init__(self, inM1.size) self.inM1 = inM1 self.inM2 = inM2
def inM1(self): """ getter for the first input Module : returns inM1 : rtype Module """ return self.__inM1
def inM(self, inM1): """ setter for the first input Module : param inM1 """ if inM1 is None: raise ValueError("input Module must not be None") if not isinstance(inM1, Module): raise ValueError("input Module must be of type Module") self.__inM1 = inM1
def inM2(self): """ getter for the second input Module : returns inM2 : rtype Module """ return self.__inM2
def inM2(self, inM2): """ setter for the first input Module : param inM1 """ if inM2 is None: raise ValueError("input Module must not be None") if not isinstance(inM2, Module): raise ValueError("input Module must be of type Module") self.__inM2 = inM2
""" updates the output(division of the two input Modules) for the current input(see numpy roll) : param shift: shifts the Input provided by the first module by the given amount : param axis: shifts the Input of the first module along the provided axis """ if not isinstance(shift, int): raise TypeError("shift must be an integer") if axis is not None: if not isinstance(axis, int): raise TypeError("axis must be of type integer") shiftedInput = np.roll(self.inM1.Input, shift, axis) for i in range(self.size[0]): for j in range(self.size[1]): sig_left1 = self.inM1.Input[i, j] sig_left2 = shiftedInput[i, j] if sig_left2 != 0: self.Input[i, j] = sig_left1/sig_left2 else: self.Input[i, j] = 0 |