code: def test_param_to_matrix_3d(rng):
      # Test translation matrix 3D
      transform = regtransforms[("TRANSLATION", 3)]
      dx, dy, dz = rng.uniform(size=(3,))
      theta = np.array([dx, dy, dz])
      expected = np.array(
          [[1, 0, 0, dx], [0, 1, 0, dy], [0, 0, 1, dz], [0, 0, 0, 1]]
      )
      actual = transform.param_to_matrix(theta)
      assert_array_equal(actual, expected)
  
      # Create helpful rotation matrix function
      def get_rotation_matrix(alpha, beta, gamma):
          ca = np.cos(alpha)
          sa = np.sin(alpha)
          cb = np.cos(beta)
          sb = np.sin(beta)
          cc = np.cos(gamma)
          sc = np.sin(gamma)
  
          X = np.array([[1, 0, 0], [0, ca, -sa], [0, sa, ca]])
          Y = np.array([[cb, 0, sb], [0, 1, 0], [-sb, 0, cb]])
          Z = np.array([[cc, -sc, 0], [sc, cc, 0], [0, 0, 1]])
  
          return Z.dot(
              X.dot(Y)
          )  # Apply in order: Y, X, Z (Y goes to the right)
  
      # Test rotation matrix 3D
      transform = regtransforms[("ROTATION", 3)]
      theta = rng.uniform(size=(3,))
      R = get_rotation_matrix(theta[0], theta[1], theta[2])
      expected = np.eye(4)
      expected[:3, :3] = R[:3, :3]
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test rigid matrix 3D
      transform = regtransforms[("RIGID", 3)]
      theta = rng.uniform(size=(6,))
      R = get_rotation_matrix(theta[0], theta[1], theta[2])
      expected = np.eye(4)
      expected[:3, :3] = R[:3, :3]
      expected[:3, 3] = theta[3:6]
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test rigid isoscaling matrix 3D
      transform = regtransforms[("RIGIDISOSCALING", 3)]
      theta = rng.uniform(size=(7,))
      R = get_rotation_matrix(theta[0], theta[1], theta[2])
      expected = np.eye(4)
      expected[:3, :3] = R[:3, :3] * theta[6]
      expected[:3, 3] = theta[3:6]
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test rigid scaling matrix 3D
      transform = regtransforms[("RIGIDSCALING", 3)]
      theta = rng.uniform(size=(9,))
      R = get_rotation_matrix(theta[0], theta[1], theta[2])
      expected = np.eye(4)
      R[0, :3] *= theta[6]
      R[1, :3] *= theta[7]
      R[2, :3] *= theta[8]
      expected[:3, :3] = R[:3, :3]
      expected[:3, 3] = theta[3:6]
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test scaling matrix 3D
      transform = regtransforms[("SCALING", 3)]
      factor = rng.uniform()
      theta = np.array([factor])
      expected = np.array(
          [
              [factor, 0, 0, 0],
              [0, factor, 0, 0],
              [0, 0, factor, 0],
              [0, 0, 0, 1],
          ]
      )
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test affine 3D
      transform = regtransforms[("AFFINE", 3)]
      theta = rng.uniform(size=(12,))
      expected = np.eye(4)
      expected[0, :] = theta[:4]
      expected[1, :] = theta[4:8]
      expected[2, :] = theta[8:12]
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Verify that ValueError is raised if incorrect number of parameters
      for transform in regtransforms.values():
          n = transform.get_number_of_parameters()
          # Set incorrect number of parameters
          theta = np.zeros(n + 1, dtype=np.float64)
          assert_raises(ValueError, transform.param_to_matrix, theta)
  
file_path: dipy/dipy/align/tests/test_transforms.py
imports: import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_equal, assert_raises
  from dipy.align.transforms import regtransforms, Transform
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 3 for calling a global function with example usage: test_param_to_matrix_3d(rng) and returns: Z