Access data directly
-
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)"].Datawhich 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!
-
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 Unitsim_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 pltplt.plot(freqlist,ref_coef_magnitude)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login