code: def test_tractogram_to_world(self):
      tractogram = DATA["tractogram"].copy()
      affine = np.random.RandomState(1234).randn(4, 4)
      affine[-1] = [0, 0, 0, 1]  # Remove perspective projection.
  
      # Apply the affine to the streamlines, then bring them back
      # to world space in a lazy manner.
      transformed_tractogram = tractogram.apply_affine(affine)
      assert_array_equal(
          transformed_tractogram.affine_to_rasmm, np.linalg.inv(affine)
      )
  
      tractogram_world = transformed_tractogram.to_world(lazy=True)
      assert type(tractogram_world) is LazyTractogram
      assert_array_almost_equal(
          tractogram_world.affine_to_rasmm, np.eye(4)
      )
      for s1, s2 in zip(
          tractogram_world.streamlines, DATA["streamlines"]
      ):
          assert_array_almost_equal(s1, s2)
  
      # Bring them back streamlines to world space in a in-place manner.
      tractogram_world = transformed_tractogram.to_world()
      assert tractogram_world is tractogram
      assert_array_almost_equal(tractogram.affine_to_rasmm, np.eye(4))
      for s1, s2 in zip(tractogram.streamlines, DATA["streamlines"]):
          assert_array_almost_equal(s1, s2)
  
      # Calling to_world twice should do nothing.
      tractogram_world2 = transformed_tractogram.to_world()
      assert tractogram_world2 is tractogram
      assert_array_almost_equal(tractogram.affine_to_rasmm, np.eye(4))
      for s1, s2 in zip(tractogram.streamlines, DATA["streamlines"]):
          assert_array_almost_equal(s1, s2)
  
      # Calling to_world when affine_to_rasmm is None should fail.
      tractogram = DATA["tractogram"].copy()
      tractogram.affine_to_rasmm = None
      with pytest.raises(ValueError):
          tractogram.to_world()
  
imports: import copy
  import operator
  import sys
  import unittest
  import warnings
  from collections import defaultdict
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ...testing import assert_arrays_equal, clear_and_catch_warnings
  from ..None import tractogram
  from ..tractogram import LazyDict, LazyTractogram, PerArrayDict, PerArraySequenceDict, Tractogram, TractogramItem, is_data_dict, is_lazy_dict
label_desc: Use image node_id 8 for calling the TestTractogram obj's underlying member method code with example usage: obj.test_tractogram_to_world() without return types