I have generated a set of simulations and i would be interested to export some information like:
1 - SAR slice : How to determine the slice number which is closer to a coordinate: lets say at 0cm but due to gridding it corresponds to 0.013 cm.
2- In the extracted SAR slice I am interested in the SAR values in a line along for example Y-axis. Again i know the absolute value of the line but i dont know exactly to which coordinate would correspond due to gridding.
I generated a python script of a manually extracted line, then i run the generated script, but it gives errors.
Could you show an example script of generating and exporting the SAR slice and a line in that slice?
# Creating the analysis pipeline
# Adding a new SimulationExtractor
simulation = document.AllSimulations["SCC34 Benchmark Simulation"]
simulation_extractor = simulation.Results()
# Adding a new EmSensorExtractor
em_sensor_extractor = simulation_extractor["Overall Field"]
em_sensor_extractor.FrequencySettings.ExtractedFrequency = u"All"
em_sensor_extractor.SurfaceCurrent.SurfaceResolution = 0.001, units.Meters
# Get data object
em_sensor_extractor.Outputs["SAR(x,y,z,f0)"].Update() # output needs to be updated before extracting data
sar = em_sensor_extractor.Outputs["SAR(x,y,z,f0)"].Data
# a location in space:
x = 0
y = -0.00910
z = -0.00025
# get grid cell indices closest to that location:
id_x, id_y, id_z = sar.Grid.FindCell(x,y,z)
# Create Slice Viewer at that location
inputs = [em_sensor_extractor.Outputs["SAR(x,y,z,f0)"]]
slice_field_viewer = analysis.viewers.SliceFieldViewer(inputs=inputs)
slice_field_viewer.Data.Mode = slice_field_viewer.Data.Mode.enum.QuantityRealModulus
slice_field_viewer.Slice.Index = id_z
# Get raw data array (in the form of a numpy array)
sar_array = em_sensor_extractor.Outputs["SAR(x,y,z,f0)"].Data.Field(snapshot_index=0)
nx, ny, nz = numpy.array(sar.Grid.Dimensions) - numpy.array((1,1,1)) # grid is defined on nodes, SAR data is in cell centers
sar_array = numpy.reshape(sar_array, (nx, ny, nz), order='F')
# now data can be accessed easily:
print sar_array[:, id_y, id_z]
Thank you Sylvain.
Could you possibly add one example of code writing array (for the line) or matrix ( for the slice ) using the Matlab export ?
Currently the Matlab exporter only allows exporting a whole quantity (i.e. the whole 3D array if it is a 3D quantity, like the SAR(x,y,z,f0)).
Once exported, though, it is relatively straightforward to slice through the array in Matlab. See for example this post: https://forum.zurichmedtech.com/topic/47/exporting-data-to-matlab-how-to-access-the-data-as-a-volume-matrix
Dear Redi, you can export arbitrary data to Matlab (e.g. field array and grid coordinates) using the Scipy.io library. A generic use of it is the following:
import scipy.io as sio
where xgrid,ygrid,zgrid are the vectors containing the cartesian coordinates of the grid.