Esempio n. 1
0
	def test_angles2matrix_rot_y(self):
		rotz = 0
		roty = 23*np.pi/180
		rotx = 0
		mat_exact = np.array([0.92050485, 0., 0.39073113, 0., 1., 0., -0.39073113, 0., 0.92050485]).reshape((3,3))
		
		mat_test = at.angles2matrix(rotz, roty, rotx)
		np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 2
0
	def test_angles2matrix_rot_z(self):
		rotz = -57*np.pi/180
		roty = 0
		rotx = 0
		mat_exact = np.array([0.54463904, 0.83867057, 0., -0.83867057, 0.54463904, 0., 0., 0., 1.]).reshape((3,3))
		
		mat_test = at.angles2matrix(rotz, roty, rotx)
		np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 3
0
	def test_angles2matrix_rot_x(self):
		rotz = 0
		roty = 0
		rotx = 50*np.pi/180
		mat_exact = np.array([1., 0., 0., 0., 0.64278761, -0.76604444, 0., 0.76604444, 0.64278761]).reshape((3,3))
	
		mat_test = at.angles2matrix(rotz, roty, rotx)
		np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 4
0
	def test_angles2matrix_rot_xyz(self):
		rotz = 10*np.pi/180
		roty = 20*np.pi/180
		rotx = 30*np.pi/180
		mat_exact = np.array([0.92541658, -0.16317591, 0.34202014, 0.31879578, \
			0.82317294, -0.46984631, -0.20487413, 0.54383814, 0.81379768]).reshape((3,3))
		
		mat_test = at.angles2matrix(rotz, roty, rotx)
		np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 5
0
    def test_angles2matrix_rot_xyz(self):
        rotz = 10 * np.pi / 180
        roty = 20 * np.pi / 180
        rotx = 30 * np.pi / 180
        mat_exact = np.array([0.92541658, -0.16317591, 0.34202014, 0.31879578, \
         0.82317294, -0.46984631, -0.20487413, 0.54383814, 0.81379768]).reshape((3,3))

        mat_test = at.angles2matrix(rotz, roty, rotx)
        np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 6
0
    def rotation_matrix(self):
        """
        The rotation matrix (according to rot_angle_x, rot_angle_y,
        rot_angle_z).

        :rtype: numpy.ndarray
        """
        return at.angles2matrix(np.radians(self.rot_angle[2]),
                                np.radians(self.rot_angle[1]),
                                np.radians(self.rot_angle[0]))
Esempio n. 7
0
    def test_angles2matrix_rot_z(self):
        rotz = -57 * np.pi / 180
        roty = 0
        rotx = 0
        mat_exact = np.array([
            0.54463904, 0.83867057, 0., -0.83867057, 0.54463904, 0., 0., 0., 1.
        ]).reshape((3, 3))

        mat_test = at.angles2matrix(rotz, roty, rotx)
        np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 8
0
    def test_angles2matrix_rot_y(self):
        rotz = 0
        roty = 23 * np.pi / 180
        rotx = 0
        mat_exact = np.array([
            0.92050485, 0., 0.39073113, 0., 1., 0., -0.39073113, 0., 0.92050485
        ]).reshape((3, 3))

        mat_test = at.angles2matrix(rotz, roty, rotx)
        np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 9
0
    def test_angles2matrix_rot_x(self):
        rotz = 0
        roty = 0
        rotx = 50 * np.pi / 180
        mat_exact = np.array([
            1., 0., 0., 0., 0.64278761, -0.76604444, 0., 0.76604444, 0.64278761
        ]).reshape((3, 3))

        mat_test = at.angles2matrix(rotz, roty, rotx)
        np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 10
0
    def rotation_matrix(self):
        """
        The rotation matrix (according to rot_angle_x, rot_angle_y,
        rot_angle_z).

        :rtype: numpy.ndarray
        """
        return at.angles2matrix(
            np.radians(self.rot_angle[2]), np.radians(self.rot_angle[1]),
            np.radians(self.rot_angle[0]))
Esempio n. 11
0
	def test_angles2matrix_rot_default(self):
		mat_exact = np.eye(3)
		mat_test = at.angles2matrix()
		np.testing.assert_array_almost_equal(mat_exact, mat_test)
Esempio n. 12
0
    def read_parameters(self, filename='parameters.prm'):
        """
		Reads in the parameters file and fill the self structure.

		:param string filename: parameters file to be read in.
		"""
        if not isinstance(filename, str):
            raise TypeError("filename must be a string")

        # Checks if the parameters file exists. If not it writes the default
        # class into filename.
        if not os.path.isfile(filename):
            self.write_parameters(filename)
            return

        config = configparser.RawConfigParser()
        config.read(filename)

        self.n_control_points[0] = config.getint('Box info',
                                                 'n control points x')
        self.n_control_points[1] = config.getint('Box info',
                                                 'n control points y')
        self.n_control_points[2] = config.getint('Box info',
                                                 'n control points z')

        self.lenght_box[0] = config.getfloat('Box info', 'box lenght x')
        self.lenght_box[1] = config.getfloat('Box info', 'box lenght y')
        self.lenght_box[2] = config.getfloat('Box info', 'box lenght z')

        self.origin_box[0] = config.getfloat('Box info', 'box origin x')
        self.origin_box[1] = config.getfloat('Box info', 'box origin y')
        self.origin_box[2] = config.getfloat('Box info', 'box origin z')

        self.rot_angle[0] = config.getfloat('Box info', 'rotation angle x')
        self.rot_angle[1] = config.getfloat('Box info', 'rotation angle y')
        self.rot_angle[2] = config.getfloat('Box info', 'rotation angle z')

        self.array_mu_x = np.zeros(self.n_control_points)
        self.array_mu_y = np.zeros(self.n_control_points)
        self.array_mu_z = np.zeros(self.n_control_points)

        mux = config.get('Parameters weights', 'parameter x')
        muy = config.get('Parameters weights', 'parameter y')
        muz = config.get('Parameters weights', 'parameter z')

        for line in mux.split('\n'):
            values = np.array(line.split())
            self.array_mu_x[tuple(map(int, values[0:3]))] = float(values[3])

        for line in muy.split('\n'):
            values = line.split()
            self.array_mu_y[tuple(map(int, values[0:3]))] = float(values[3])

        for line in muz.split('\n'):
            values = line.split()
            self.array_mu_z[tuple(map(int, values[0:3]))] = float(values[3])

        self.rotation_matrix = at.angles2matrix(
            self.rot_angle[2] * np.pi / 180, self.rot_angle[1] * np.pi / 180,
            self.rot_angle[0] * np.pi / 180)

        self.position_vertex_0 = self.origin_box
        self.position_vertex_1 = self.position_vertex_0 + \
         np.dot(self.rotation_matrix, [self.lenght_box[0], 0, 0])
        self.position_vertex_2 = self.position_vertex_0 + \
         np.dot(self.rotation_matrix, [0, self.lenght_box[1], 0])
        self.position_vertex_3 = self.position_vertex_0 + \
         np.dot(self.rotation_matrix, [0, 0, self.lenght_box[2]])

        self.psi_mapping = np.diag(1. / self.lenght_box)
        self.inv_psi_mapping = np.diag(self.lenght_box)
Esempio n. 13
0
	def read_parameters(self, filename='parameters.prm'):
		"""
		Reads in the parameters file and fill the self structure.

		:param string filename: parameters file to be read in.
		"""
		if not isinstance(filename, basestring):
			raise TypeError("filename must be a string")

		# Checks if the parameters file exists. If not it writes the default class into filename.
		if not os.path.isfile(filename):
			self.write_parameters(filename)
			return
		
		config = ConfigParser.RawConfigParser()
		config.read(filename)

		self.n_control_points[0] = config.getint('Box info', 'n control points x')
		self.n_control_points[1] = config.getint('Box info', 'n control points y')
		self.n_control_points[2] = config.getint('Box info', 'n control points z')

		self.lenght_box_x = config.getfloat('Box info', 'box lenght x')
		self.lenght_box_y = config.getfloat('Box info', 'box lenght y')
		self.lenght_box_z = config.getfloat('Box info', 'box lenght z')

		origin_box_x = config.getfloat('Box info', 'box origin x')
		origin_box_y = config.getfloat('Box info', 'box origin y')
		origin_box_z = config.getfloat('Box info', 'box origin z')
		self.origin_box = np.array([origin_box_x, origin_box_y, origin_box_z])

		self.rot_angle_x = config.getfloat('Box info', 'rotation angle x')
		self.rot_angle_y = config.getfloat('Box info', 'rotation angle y')
		self.rot_angle_z = config.getfloat('Box info', 'rotation angle z')

		self.array_mu_x = np.zeros((self.n_control_points[0], self.n_control_points[1], \
			self.n_control_points[2]))
		mux = config.get('Parameters weights', 'parameter x')
		lines = mux.split('\n')
		for line in lines:
			values = line.split()
			self.array_mu_x[int(values[0])][int(values[1])][int(values[2])] = float(values[3])

		self.array_mu_y = np.zeros((self.n_control_points[0], self.n_control_points[1], \
			self.n_control_points[2]))
		muy = config.get('Parameters weights', 'parameter y')
		lines = muy.split('\n')
		for line in lines:
			values = line.split()
			self.array_mu_y[int(values[0])][int(values[1])][int(values[2])] = float(values[3])

		self.array_mu_z = np.zeros((self.n_control_points[0], self.n_control_points[1], \
			self.n_control_points[2]))
		muz = config.get('Parameters weights', 'parameter z')
		lines = muz.split('\n')
		for line in lines:
			values = line.split()
			self.array_mu_z[int(values[0])][int(values[1])][int(values[2])] = float(values[3])

		self.rotation_matrix = at.angles2matrix(self.rot_angle_z * np.pi/180, \
				self.rot_angle_y * np.pi/180, self.rot_angle_x * np.pi/180)

		self.position_vertex_0 = self.origin_box
		self.position_vertex_1 = self.position_vertex_0 + \
			np.dot(self.rotation_matrix, [self.lenght_box_x, 0, 0])
		self.position_vertex_2 = self.position_vertex_0 + \
			np.dot(self.rotation_matrix, [0, self.lenght_box_y, 0])
		self.position_vertex_3 = self.position_vertex_0 + \
			np.dot(self.rotation_matrix, [0, 0, self.lenght_box_z])

		self.psi_mapping = np.diag([1./self.lenght_box_x, 1./self.lenght_box_y, 1./self.lenght_box_z])
		self.inv_psi_mapping = np.diag([self.lenght_box_x, self.lenght_box_y, self.lenght_box_z])
Esempio n. 14
0
 def test_angles2matrix_rot_default(self):
     mat_exact = np.eye(3)
     mat_test = at.angles2matrix()
     np.testing.assert_array_almost_equal(mat_exact, mat_test)