Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. How to export voxel data using python API?

How to export voxel data using python API?

Scheduled Pinned Locked Moved Python API
3 Posts 2 Posters 709 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mingjuan
    wrote on last edited by
    #1

    Hi,
    I wonder how to export voxel data using Python API. Is there anyone who can help me? Thank you!

    6f5de903-8bc0-4328-a7ac-04ae75f6b3b0-image.png

    1 Reply Last reply
    0
    • M Offline
      M Offline
      montanaro
      wrote on last edited by montanaro
      #2

      I normally just get it from the h5 input file if you know where it is (in Acoustics it's under Meshes, then eventually in a dataset called voxels - you can use HDF5View to examine your input file).

      Some (untested) code to get you started:

      import h5py
      import s4l_v1 as s4l
      
      def geth5Dataset(h5f, group_name, dataset_name):
      	def find_dataset(name):
      		if dataset_name in name:
      			return name
      	
      	with h5py.File(h5f, 'r') as f:
      		k = f[group_name].visit(find_dataset)
      		return f[group_name + '/' + k][()]
      
      def getVoxels(h5f):
      	return geth5Dataset(h5f, 'Meshes', 'voxels')
      
      sim_idx = 0 # Simulation number
      sim = s4l.document.AllSimulations[sim_idx]
      file_name = sim.GetInputFileName()
      
      file_path = "c:/file_path/"
      
      vox = getVoxels(file_path + file_name)
      
      M 1 Reply Last reply
      1
      • M montanaro

        I normally just get it from the h5 input file if you know where it is (in Acoustics it's under Meshes, then eventually in a dataset called voxels - you can use HDF5View to examine your input file).

        Some (untested) code to get you started:

        import h5py
        import s4l_v1 as s4l
        
        def geth5Dataset(h5f, group_name, dataset_name):
        	def find_dataset(name):
        		if dataset_name in name:
        			return name
        	
        	with h5py.File(h5f, 'r') as f:
        		k = f[group_name].visit(find_dataset)
        		return f[group_name + '/' + k][()]
        
        def getVoxels(h5f):
        	return geth5Dataset(h5f, 'Meshes', 'voxels')
        
        sim_idx = 0 # Simulation number
        sim = s4l.document.AllSimulations[sim_idx]
        file_name = sim.GetInputFileName()
        
        file_path = "c:/file_path/"
        
        vox = getVoxels(file_path + file_name)
        
        M Offline
        M Offline
        mingjuan
        wrote on last edited by
        #3

        @montanaro I've tried it and it worked. Thank you very much!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Search