Acquisition Scripting Nion Swift Workshop Chris Meyer 2018 October - - PowerPoint PPT Presentation

acquisition scripting
SMART_READER_LITE
LIVE PREVIEW

Acquisition Scripting Nion Swift Workshop Chris Meyer 2018 October - - PowerPoint PPT Presentation

Nion Swift Acquisition Scripting Nion Swift Workshop Chris Meyer 2018 October 4 Introduce STEM control, scan devices, cameras, and also programming techniques, instrument simulator, and threading concerns. Nion Swift Acquisition Scripting


slide-1
SLIDE 1

Nion Swift Acquisition Scripting

Introduce STEM control, scan devices, cameras, and also programming techniques, instrument simulator, and threading concerns.

Nion Swift Workshop Chris Meyer 2018 October 4

slide-2
SLIDE 2

In this session, we will cover preliminary material regarding STEM control, scan devices, cameras, and also review the programming techniques that we'll be using in the following sessions to access those devices. We will introduce the instrument simulator and show how it can be used to experiment offline with instruments and acquisition devices. We will also discuss issues related to threading.

Nion Swift Acquisition Scripting

slide-3
SLIDE 3

In this talk you'll learn about: The STEM controller, scan controller, and cameras. The instrument simulator. Acquisition and Python threading.

Nion Swift Acquisition Scripting

slide-4
SLIDE 4

What is an API? An API is an "application programming interface". It describes the functions that are provided to interface with Nion Swift. The functions are intended to be supported in the long term so that code you write today which uses the API will work the same way in the coming years. But… sometimes things will break. It is up to the maintainers of the code to ensure that the code works with Nion Swift as it evolves.

Nion Swift Acquisition Scripting

slide-5
SLIDE 5

What is an API? There are more functions than defined in the documentation. Sometimes you may need to use an undocumented function or parameter to work around a bug or access a capability not yet available in the API. Trade-off: undocumented functions may disappear or change behavior. Use the defined API as much as possible. Projects maintained by Nion use different standards since we can coordinate releases.

Nion Swift Acquisition Scripting

slide-6
SLIDE 6

STEM Controller

  • Base object for accessing other objects
  • Access to AS2, scan controller,

Ronchigram and EELS cameras, video

  • Probe position
  • Future: Access to additional detectors

(EDS, CL, etc.)

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") scan = stem_controller.scan_controller ronchigram = stem_controller.ronchigram_camera eels = stem_controller.eels_camera

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-7
SLIDE 7

AS2 Controls

  • Get and set controls in AS2
  • GetVal, SetValAndConfirm
  • Gwyn will cover more in later talk

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") defocus = stem_controller.GetVal("C10") stem_controller.SetValAndConfirm("C10", -2000E-9, 1.0, 3000)

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-8
SLIDE 8

Acquisition devices

  • Scan, camera, and video
  • General concept is that devices have

different modes of operation

  • View mode, recording mode
  • Also known as "playback"

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") ronchigram_camera = stem_controller.ronchigram_camera ronchigram_camera.start_playing() time.sleep(5.0) ronchigram_camera.stop_playing()

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-9
SLIDE 9

Acquisition settings

  • Saved sets of frame parameters, called "settings".
  • Future API will include ability to access, modify, and use settings.
  • If you need this before API available, talk to us.

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-10
SLIDE 10

Frame parameters

  • Acquisition devices use frame parameters

to describe desired acquisition.

  • Frame parameters can be read, modified,

and set when playing

  • Sets of frame parameters configurable by

users are called settings; limited support.

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") camera = stem_controller.ronchigram_camera frame_params = camera.get_current_frame_parameters() frame_params["exposure_ms"] = 50 ronchigram_camera.start_playing(frame_params)

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-11
SLIDE 11

Frame timing

  • Some acquisition devices such as

cameras expose detector.

  • Tricky to ensure that the detector is

exposed after a state change.

  • Sometimes throwing out frames to

compensate.

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") camera = stem_controller.ronchigram_camera stem_controller.SetValAndConfirm("C10", 1E-9, 1.0, 3000) camera.grab_next_to_start() # throw away data_list = camera.grab_next_to_start() # real data

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-12
SLIDE 12

Data Channels

  • Most data coming from acquisition devices will be sent to a data channel
  • This is the way that Nion Swift receives the data from an arbitrary thread
  • Easy to view data channels, to see what's going on most of the time
  • Some exceptions, SI (work in progress)

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-13
SLIDE 13

Sequence Acquisition

  • Some devices (cameras) support sequence

acquisition

  • Sequence acquisition grabs consecutive

frames, must prepare memory

  • Difficult to synchronize cameras precisely
  • Returns an xdata sequence for each

channel

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") camera = stem_controller.eels_camera camera.start_playing() if camera.grab_sequence_prepare(10): data_list = camera.grab_sequence(10)

slide-14
SLIDE 14

Buffer Acquisition

  • Some devices support buffered acquisition,

grabbing previously acquired data.

  • Returns a Python list of xdata tuples (one

for each channel)

  • Again: difficult to synchronize

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") camera = stem_controller.eels_camera camera.start_playing() data_list = camera.grab_buffer(10)

slide-15
SLIDE 15

Scan Controller

  • Primary interface to control scanning
  • Scan device can acquire multiple channels
  • f data.
  • Scan device: easy to predict frame timing.

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") scan = stem_controller.scan_controller

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-16
SLIDE 16

Scan Frame Parameters

  • Describe the physical scan area (field of view,

rotation)

  • Describe the scan resolution (size)
  • Describe the timing (pixel time)
  • Applications should save/restore frame

parameters when finished

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") scan = stem_controller.scan_controller params = scan.get_current_frame_parameters() params["fov_nm"] = 20 params["pixel_time_us"] = 4

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-17
SLIDE 17

Scan Channels

  • SuperScan can acquire multiple channels
  • Channels are shared between frame

parameters (currently)

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") scan = stem_controller.scan_controller scan.set_enabled_channels([0, 1]) print(scan.get_enabled_channels())

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-18
SLIDE 18

Sub-scan and line scan

  • A context scan establishes a reference frame
  • Possible to specify further scans relative to

that reference frame

  • Sub-scan or line scan are special scans

configured within the reference frame

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") scan = stem_controller.scan_controller params = scan.get_current_frame_parameters() params["subscan_fractional_size"] = (0.40, 0.25) params["subscan_fractional_center"] = (0.60, 0.70)

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-19
SLIDE 19

Synchronized scan

  • A synchronized scan synchronizes a camera

to the scan so that one camera frame is acquired for each scan position.

  • Requires hardware trigger to be configured

properly.

  • Produces scan data and camera data (lots of

it, too!)

Nion Swift Acquisition Scripting

combined_data = scan.grab_synchronized( scan_frame_parameters=scan_frame_param eters, camera=eels, camera_frame_parameters= eels_frame_parameters) scan_datas, camera_datas = combined_data haadf_data = scan_datas[0] eels_data = camera_datas[0]

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-20
SLIDE 20

Probe position

  • Once a scan has established a context /

reference frame, possible to position probe within that reference frame.

  • Accessed as a property on the STEM

controller

  • Fractional coordinates

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") probe_position = stem_controller.probe_position Stem_controller.probe_position = (0.6, 0.7)

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-21
SLIDE 21

Camera Controllers

  • Each camera may have specific features
  • Cameras generally free running, making

them difficult to synchronize

  • Use synchronized acquisitions when

required

  • Don't roll your own! Difficult.

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") scan = stem_controller.scan_controller ronchigram = stem_controller.ronchigram_camera eels = stem_controller.eels_camera

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-22
SLIDE 22

Video Controllers

  • System will typically have multiple video

controllers

  • Access by identifier
  • Uses standard Python libraries, easy to

add new cameras

  • Not available in API yet

Nion Swift Acquisition Scripting

from nion.utils import Registry stem_controller = Registry.get_component("stem_controller") video = stem_controller.get_video_controller("slit")

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-23
SLIDE 23

Custom Camera

  • Relatively easy to add custom cameras to Nion Swift
  • Nion supplies camera support for their integrated cameras
  • 3rd parties may provide support for other specific cameras
  • Also possible to provide a piggy-back scan device

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-24
SLIDE 24

Instrument Simulator

  • Simulates a STEM microscope, scan controller, Ronchigram and EELS cameras
  • Simplistic simulation, but useful for debugging applications
  • Simple aberrations, but only a start.
  • Provides EELS data too.
  • Always looking for improvements. It's open source!
  • https://github.com/nion-software/nionswift-usim

Nion Swift Acquisition Scripting

slide-25
SLIDE 25

Python threading

  • Python is an interpreted language, which means it runs code at a higher level than machine code
  • Python is slower than lower level languages such as C++
  • Python has threads, which helps improve performance

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-26
SLIDE 26

Python threading

  • Python is an interpreted language, which means it runs code at a higher level than machine code
  • Python is slower than lower level languages such as C++
  • Python has threads, which helps improve performance
  • But… Python threads are cooperative, meaning only one can be running at once. Limiting.

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-27
SLIDE 27

Python threading

  • Python is an interpreted language, which means it runs code at a higher level than machine code
  • Python is slower than lower level languages such as C++
  • Python has threads, which helps improve performance
  • But… Python threads are cooperative, meaning only one can be running at once. Limiting.
  • But… Python can let other threads run while making lower level non-Python calls.

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-28
SLIDE 28

Python threading - what does this all mean?

  • In order to be responsive, Nion Swift limits what it does in the user interface (UI) thread
  • That puts limits on when we can do acquisition
  • Acquisition will generally release Python to do other things
  • We just need to be careful to follow the rules

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-29
SLIDE 29

Python threading - rules

  • Acquisition should generally be performed on threads

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-30
SLIDE 30

Python threading - rules

  • Acquisition should generally be performed on threads
  • Console is not on a thread, will block UI while running acquisition

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-31
SLIDE 31

Python threading - rules

  • Acquisition should generally be performed on threads
  • Console is not on a thread, will block UI while running acquisition
  • Run Script is on a thread, but this imposes other limits

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-32
SLIDE 32

Python threading - rules

  • Acquisition should generally be performed on threads
  • Console is not on a thread, will block UI while running acquisition
  • Run Script is on a thread, but this imposes other limits
  • Plug-ins must handle threads themselves

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

slide-33
SLIDE 33

Python threading - data channels

  • To avoid blocking the UI, acquired data is sent into data channels
  • In Nion Swift, data channels can be connected to a data item
  • Use make_reference_key to get a data channel reference key
  • Access associated data item using reference key

Nion Swift Acquisition Scripting

Full documentation: https://nionswift-instrumentation.readthedocs.io/en/latest/

reference_key = scan.make_reference_key(channel_index=0, subscan=True) data_item = api.library.get_data_item_for_reference_key(reference_key)

slide-34
SLIDE 34

In this talk you've learned: The STEM controller, scan controller, and cameras. The instrument simulator. Acquisition and Python threading.

Nion Swift Acquisition Scripting