docstr: Test the feature: centerdistance_xdminus1.
docstr_tok: ["Test","the","feature",":","centerdistance_xdminus1","."]
code: def test_centerdistance_xdminus1(self):
      """Test the feature: centerdistance_xdminus1."""
  
      # 2D with dim (invalid)
      i = numpy.asarray([[0, 0], [0, 0]])
      self.assertRaises(ArgumentError, centerdistance_xdminus1, i, 0)
  
      # 3D with invalid dims (invalid)
      i = numpy.asarray([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
      i = numpy.asarray([i, i, i])
      self.assertRaises(
          ArgumentError, centerdistance_xdminus1, i, (0, 1)
      )
  
      # 3D with invalid dim
      self.assertRaises(ArgumentError, centerdistance_xdminus1, i, 3)
  
      # 3D with valid dim 0
      e = [
          math.sqrt(2),
          1,
          math.sqrt(2),
          1,
          0,
          1,
          math.sqrt(2),
          1,
          math.sqrt(2),
      ]
      e = numpy.asarray([e, e, e]).ravel()
      r = centerdistance_xdminus1(i, 0)
      numpy.testing.assert_allclose(
          r, e, err_msg="centerdistance_xdminus1: 3D, dim = 0 failed"
      )
  
      # 3D multi-spectral
      r = centerdistance_xdminus1([i, i], 0)
      numpy.testing.assert_allclose(
          r,
          e,
          err_msg="centerdistance_xdminus1: 3D, multi-spectral failed",
      )
  
      # 3D masked
      m = [
          [True, False, False],
          [False, True, False],
          [False, False, True],
      ]
      e = [math.sqrt(2), 0, math.sqrt(2)]
      e = numpy.asarray([e, e, e]).ravel()
      r = centerdistance_xdminus1(i, 0, mask=[m, m, m])
      numpy.testing.assert_allclose(
          r, e, err_msg="centerdistance_xdminus1: 3D, masked failed"
      )
  
      # 3D with valid dim 0, uneven image
      i = numpy.asarray(
          [
              [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
              [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
          ]
      )
      e = [
          math.sqrt(3.25),
          math.sqrt(1.25),
          math.sqrt(1.25),
          math.sqrt(3.25),
          math.sqrt(2.25),
          math.sqrt(0.25),
          math.sqrt(0.25),
          math.sqrt(2.25),
          math.sqrt(3.25),
          math.sqrt(1.25),
          math.sqrt(1.25),
          math.sqrt(3.25),
      ]
      e = numpy.asarray([e, e]).ravel()
      r = centerdistance_xdminus1(i, 0)
      numpy.testing.assert_allclose(
          r,
          e,
          err_msg="centerdistance_xdminus1: uneven 3D, dim = 0 failed",
      )
  
      # 3D with valid dim 1, uneven image
      e = [
          [
              math.sqrt(2.5),
              math.sqrt(0.5),
              math.sqrt(0.5),
              math.sqrt(2.5),
          ],
          [
              math.sqrt(2.5),
              math.sqrt(0.5),
              math.sqrt(0.5),
              math.sqrt(2.5),
          ],
      ]
      e = numpy.asarray([e, e, e])
      e = numpy.rollaxis(e, 0, 2).ravel()
      r = centerdistance_xdminus1(i, 1)
      numpy.testing.assert_allclose(
          r,
          e,
          err_msg="centerdistance_xdminus1: uneven 3D, dim = 1 failed",
      )
  
      # 3D with valid dim 2, uneven image
      e = [
          [math.sqrt(1.25), math.sqrt(0.25), math.sqrt(1.25)],
          [math.sqrt(1.25), math.sqrt(0.25), math.sqrt(1.25)],
      ]
      e = numpy.asarray([e, e, e, e])
      e = numpy.rollaxis(e, 0, 3).ravel()
      r = centerdistance_xdminus1(i, 2)
      numpy.testing.assert_allclose(
          r,
          e,
          err_msg="centerdistance_xdminus1: uneven 3D, dim = 2 failed",
      )
  
      # 4D with valid dims 1, 3
      i = numpy.asarray([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
      i = numpy.asarray([i, i, i])
      i = numpy.asarray([i, i, i])
      e = [
          [math.sqrt(2), 1, math.sqrt(2)],
          [1, 0, 1],
          [math.sqrt(2), 1, math.sqrt(2)],
      ]
      e = numpy.asarray([e] * 3)
      e = numpy.rollaxis(e, 0, 2)
      e = numpy.asarray([e] * 3)
      e = numpy.rollaxis(e, 0, 4).ravel()
      r = centerdistance_xdminus1(i, (1, 3))
      numpy.testing.assert_allclose(
          r,
          e,
          err_msg="centerdistance_xdminus1: 4D, dim = (1, 3) failed",
      )
  
file_path: medpy/tests/features_/intensity.py
imports: import unittest
  import math
  import numpy
  from medpy.features.intensity import intensities, centerdistance, centerdistance_xdminus1, indices, local_mean_gauss, local_histogram
  from medpy.features.utilities import join, append
  from medpy.core.exceptions import ArgumentError
label_desc: Use image node_id 4 for calling the TestIntensityFeatures obj's underlying member method code with example usage: obj.test_centerdistance_xdminus1() without return types