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. Access data directly

Access data directly

Scheduled Pinned Locked Moved Python API
2 Posts 2 Posters 115 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.
  • P Offline
    P Offline
    parsley
    wrote on last edited by
    #1

    Hi,

    I'm trying to automatically access some data that you would usually display via the Tableviewers in S4L via my Python script. For example, after a lot of trial and error, I found the way to extract the psSAR via something like

    	average_sar_field_evaluator = analysis.em_evaluators.AverageSarFieldEvaluator(inputs=inputs)
    	average_sar_field_evaluator.TargetMass = 10.0, Unit("g")
    	average_sar_field_evaluator.UpdateAttributes()
    	document.AllAlgorithms.Add(average_sar_field_evaluator)
    	
    	# perform the actual computation, throw an exception if an error occurs
    	assert average_sar_field_evaluator.Update(), 'ERROR, failed to compute SAR'
    
    	dictionary=average_sar_field_evaluator.Outputs[1].Data.DataJson
    
    psSAR=json.loads(dictionary)['simple_data_collection']['data_collection']['PeakValue']['data']
    
    

    Now, I'd also like to extract the reflection coefficient but I only got to

    em_sensor_extractor.Outputs["Reflection Coefficient(f)"].Data
    

    which does not return the numbers. How do I access it? Is there a general method or some place in the documentation that explains how to access the outputs of different algorithms?

    Thanks!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      halder
      ZMT
      wrote on last edited by halder
      #2

      Hi, you can try something like the following to extract the reflection coefficient. You can always try to build extraction manually once and select "To python" by right-clicking on the end of the tree (i.e. the component you extract from your pipeline)

      import numpy
      import s4l_v1.analysis as analysis
      import s4l_v1.document as document
      import s4l_v1.model as model
      import s4l_v1.units as units
      from s4l_v1 import ReleaseVersion
      from s4l_v1 import Unit

      sim_name = "MRI Volume Coil Cleg = 29.5 pF" ###### define the sim name in this case this is a multiport FDTD simulation

      Adding a new EmMultiPortSimulationExtractor

      simulation = document.AllSimulations[sim_name]
      em_multi_port_simulation_extractor = simulation.Results()

      this is extracting a port

      inputs = [em_multi_port_simulation_extractor.Outputs["MRI Volume Coil Cleg = 29.5 pF - Endring source 1 (Birdcage 1)"]]
      em_port_simulation_extractor = analysis.extractors.EmPortSimulationExtractor(inputs=inputs)
      em_port_simulation_extractor.Name = "MRI Volume Coil Cleg = 29.5 pF - Endring source 1 (Birdcage 1)"
      em_port_simulation_extractor.UpdateAttributes()
      document.AllAlgorithms.Add(em_port_simulation_extractor)

      em_sensor_extractor = em_port_simulation_extractor["Endring source 1 (Birdcage 1)"]
      document.AllAlgorithms.Add(em_sensor_extractor)

      ref_coef_data = em_sensor_extractor.Outputs["Reflection Coefficient(f)"]
      ref_coef_data.Update()
      freqlist = ref_coef_data.Data.Axis
      ref_coef = refCoeff.Data.GetComponent(0)
      ref_coef_magnitude = np.sqrt(np.real(ref_coef)**2 + np.imag(ref_coef)**2)
      import matplotlib.pyplot as plt

      plt.plot(freqlist,ref_coef_magnitude)

      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