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. Analysis & Postprocessing
  4. Python code for outputting analysis results

Python code for outputting analysis results

Scheduled Pinned Locked Moved Analysis & Postprocessing
2 Posts 2 Posters 46 Views 2 Watching
  • 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.
  • K Offline
    K Offline
    Kazu
    wrote last edited by
    #1

    Excuse me for butting in.
    Nice to meet you. I’m currently a graduate student conducting research on temperature distribution in liver tumors with respiratory motion using Sim4Life.
    Could you please share some code that uses Python scripts to output the analysis results of temperature distributions after running the simulation?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brown
      ZMT
      wrote last edited by
      #2

      Hello,

      If you would just like to export the temperature distributions computed by the solver, you can use one of the built in Exporter tools (e.g. VTK, MATLAB, Text files), which produce formats that can be read externally.

      I would recommend that you do this manually first by using the GUI. Once you are satisfied with the configuration, you can right-click on your analysis tree and select 'To Python' to automatically generate the code required to reproduce the analysis.

      For example:

      import s4l_v1.analysis as analysis
      import s4l_v1.document as document
      
      # Incident EM parent simulation
      simulation = document.AllSimulations["EM Simulation Name"]
      simulation_extractor = simulation.Results()
      
      # Thermal simulation 
      simulation = document.AllSimulations["Thermal Simulation Name"]
      simulation_extractor_2 = simulation.Results()
      
      # Choose a sensor to extract
      thermo_sensor_extractor = simulation_extractor_2["Overall Field"]
      document.AllAlgorithms.Add(thermo_sensor_extractor)
      
      # Adding a new MatlabExporter
      inputs = [thermo_sensor_extractor.Outputs["T(x,y,z,t)"]]
      matlab_exporter = analysis.exporters.MatlabExporter(inputs=inputs)
      matlab_exporter.FileName = u"C:\\Users\\Test\\Downloads\\myfile.mat"
      matlab_exporter.UpdateAttributes()
      document.AllAlgorithms.Add(matlab_exporter)
      
      # Call Update() to trigger writing the file
      matlab_exporter.Update()
      

      This will produce a .mat file that contains separate arrays for every 'Snapshot' in your thermal simulation. For transient thermal simulations, a snapshot represents the field distribution at some point in time. It is dependent on the 'Maximum No. Samples' option in the Sensor settings of the simulation configuration.

      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