Skip to content
  • Search
Skins
  • Light
  • Brite
  • 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. SetUp Field Crop Filter

SetUp Field Crop Filter

Scheduled Pinned Locked Moved Analysis & Postprocessing
python
2 Posts 2 Posters 1.3k 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.
  • S Offline
    S Offline
    snowy
    wrote on last edited by Sylvain
    #1

    Hi Guys,

    I am currently adapting a code I've written in Sim4Life 2.3 some years ago to Sim4Life 6.0 and found out that a lot has changed in the meantime.

    How do I properly set up a Field Crop Filter (for the EMLF-Solver)?
    This is what my original code looks like and the SetInputConnection and Value commands seem to be deprecated.

    import sys, os
    import s4l_v1.analysis as analysis
    import s4l_v1.analysis.core as core
    
    # Create extractor for a given simulation output file
    results = sim.Results()
    overall_field_sensor = results[ 'Overall Field' ]
    e_field = overall_field_sensor['EM E(x,y,z,f0)']
    
    # pipe the E_field through a crop filter
    crop_filter = core.FieldCropFilter()
    crop_filter.SetInputConnection(0, e_field)
    crop_filter.Update(0)
    crop_filter[0].SetValue = (63, 123, 513)  # set lower extent of crop region (in grid indexes)
    crop_filter[1].SetValue = (198, 271, 662) # set upper extent of crop region (in grid indexes)
    analysis.RegisterAlgorithm(crop_filter) 
    

    Thanks for your help!

    1 Reply Last reply
    1
    • SylvainS Offline
      SylvainS Offline
      Sylvain
      ZMT
      wrote on last edited by
      #2

      In general, an easy way to create a postprocessing script is to first do it in the GUI and then use the "To-Python" function (available via right-click on the algorithm in the Explorer window).

      Here is what the auto-generated script looks like for a simple pipeline with a Crop Filter:

      	# Creating the analysis pipeline
      	# Adding a new SimulationExtractor
      	simulation = document.AllSimulations["EM"]
      	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.Normalization.Normalize = True
      	em_sensor_extractor.SurfaceCurrent.SurfaceResolution = 0.001, units.Meters
      	document.AllAlgorithms.Add(em_sensor_extractor)
      
      	# Adding a new FieldCropFilter
      	inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
      	field_crop_filter = analysis.core.FieldCropFilter(inputs=inputs)
      	field_crop_filter.LowerExtent = numpy.array([1, 3, 2])
      	field_crop_filter.UpperExtent = numpy.array([21, 21, 21])
      	field_crop_filter.UpdateAttributes()
      	document.AllAlgorithms.Add(field_crop_filter)
      

      Note fyi that you don't actually need to pass a Numpy array to UpperExtent or LowerExtent, it also works if you pass any iterable, like a list or a tuple.

      1 Reply Last reply
      1

      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
      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