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. Declaring weights in simulation combiner from array changes wrong channels

Declaring weights in simulation combiner from array changes wrong channels

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

    I want to use the Python API to generate different predefined configurations of eight channels in a multiport simulation. As a simplified example, I would like to make eight different simulation combiners, with for every nth simulation, the power of the nth channel being 1W (and all other channels 0W). I would do this using the following code:

    def multiport_SAR_export(powers, phases, config_nr):
        # Adding a new EmMultiPortSimulationCombiner
        inputs = [em_multi_port_simulation_extractor.Outputs["EM - Source 1  (pTx coil/Channel 1)"], em_multi_port_simulation_extractor.Outputs["EM - Source 2  (pTx coil/Channel 2)"], em_multi_port_simulation_extractor.Outputs["EM - Source 3  (pTx coil/Channel 3)"], em_multi_port_simulation_extractor.Outputs["EM - Source 4  (pTx coil/Channel 4)"], em_multi_port_simulation_extractor.Outputs["EM - Source 5  (pTx coil/Channel 5)"], em_multi_port_simulation_extractor.Outputs["EM - Source 6  (pTx coil/Channel 6)"], em_multi_port_simulation_extractor.Outputs["EM - Source 7  (pTx coil/Channel 7)"], em_multi_port_simulation_extractor.Outputs["EM - Source 8  (pTx coil/Channel 8)"]]
        em_multi_port_simulation_combiner = analysis.extractors.EmMultiPortSimulationCombiner(inputs=inputs)
        em_multi_port_simulation_combiner.UpdateAttributes()
        weights = em_multi_port_simulation_combiner.GetChannelWeights()
    	
        for n, channel in enumerate(weights):
        	weights[channel] = powers[n], phases[n]
        
        for channel in weights: 
    		em_multi_port_simulation_combiner.SetChannelWeight(channel, *weights[channel])
        
        document.AllAlgorithms.Add(em_multi_port_simulation_combiner)
        
        # Adding a new EmMultiPortSensorCombiner
        inputs = [em_multi_port_simulation_combiner.Outputs["Overall Field"]]
        em_multi_port_sensor_combiner = analysis.extractors.EmMultiPortSensorCombiner(inputs=inputs)
        
        em_multi_port_sensor_combiner.Name = "Overall Field (combined)"
        em_multi_port_sensor_combiner.UpdateAttributes()
        document.AllAlgorithms.Add(em_multi_port_sensor_combiner)
    
    configs_powers = np.identity(8)
    for config_nr in range(8):
        multiport_SAR_export(configs_powers[config_nr,:], np.zeros(8), config_nr)
    

    As expected, I get eight simulation combiners, in which each one has a single channel with power 1. However, it is not always the case that the nth channel has a power of 1W for the nth simulation combiner. For example, I've had a case with the following combination of simulation numbers and powered channels:
    simulation 1 = channel 1
    simulation 2 = channel 7
    simulation 3 = channel 3
    simulation 4 = channel 8
    simulation 5 = channel 2
    simulation 6 = channel 6
    simulation 7 = channel 4
    simulation 8 = channel 5

    This "remapping" is consistent throughout simulations: if I would in the next simulation try to power channels 4 and 5, in the simulation combiner channels 8 and 2 would be powered. However, after a restart of the computer (and changing a few things to the code) a new remapping has appeared:
    simulation 1 = channel 4
    simulation 2 = channel 5
    simulation 3 = channel 3
    simulation 4 = channel 6
    simulation 5 = channel 1
    simulation 6 = channel 2
    simulation 7 = channel 8
    simulation 8 = channel 7

    Does anyone know what could cause those seemingly random changes in channel declarations? I've something is not clear, please ask me and I am happy to try explaining it better.

    1 Reply Last reply
    1
    • N Offline
      N Offline
      Nogniks
      wrote on last edited by
      #2

      The problem has to do with (to me) unlogical ordering of the 'weights'-dict. I have made a workaround which extracts the values from the dict in alphabetical order of the keys, which seems to work.

      1 Reply Last reply
      1
      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