contrast.detectors package

Module contents

Provides the Detector base class, base classes that bring other functionality, as well as derived detector subclasses.

Does not automatically load hardware-specific submodules or classes as these might have special dependencies that aren’t available everywhere.

Submodules

contrast.detectors.Detector module

class contrast.detectors.Detector.Detector(*args, **kwargs)[source]

Bases: contrast.Gadget.Gadget

Base class representing any device which can be read out to produce recordable data.

classmethod get_active()[source]

Returns a DetectorGroup instance containing the currently active Detector instances.

prepare(acqtime, dataid, n_starts=None)[source]

Run before acquisition, once per scan.

Parameters:
  • acqtime (float) – Acquisition time
  • dataid – Data identifier, a scan id, for example.
  • n_starts (int) – The number of start commands we expect to issue.
arm()[source]

Run before every acquisition. Arm any hardware triggered detectors.

start()[source]

Start acquisition for any software triggered detectors.

initialize()[source]

Override this method, which initializes the detector.

stop()[source]

Override this method, stops the dector.

busy()[source]

Override this method, returns the busy state.

read()[source]

Override this method, returns the data.

class contrast.detectors.Detector.TriggerSource(*args, **kwargs)[source]

Bases: contrast.detectors.Detector.Detector

A TriggerSource is a device which follows the Detector API, but which does not produce data. It can be seen as a lightweight Detector subclass, where some of the methods are not mandatory.

classmethod get_active()[source]

Returns a DetectorGroup instance containing the currently active TriggerSource instances.

class contrast.detectors.Detector.LiveDetector[source]

Bases: object

Abstract class to define the interface of live detectors, which can run continuously with no synchronization or data capture.

start_live(acqtime=1.0)[source]

Override this method.

stop_live()[source]

Override this method.

Should be made harmless, so that it can be run even if the detector is not running.

class contrast.detectors.Detector.SoftwareLiveDetector[source]

Bases: contrast.detectors.Detector.LiveDetector

Implements a software live mode, where detectors that do not provide a monitoring mode get started repeatedly from a background thread.

start_live(acqtime=1.0)[source]

Starts background acquisition.

Parameters:acqtime (float) – Acquisition time.
stop_live()[source]

Stops background acquisition.

class contrast.detectors.Detector.TriggeredDetector[source]

Bases: object

Defines the API for detectors that optionally accept hardware triggers.

class contrast.detectors.Detector.BurstDetector[source]

Bases: object

Defines the API for detectors that optionally run in burst mode, so that an autonomous train of measurements is made for one arm/start command.

Defines three attributes:

  • burst_n: the number of autonomous measurements
  • burst_latency: the time between measurements
  • burst_acqtime: an optional parameter which (if not None) overrides the value received via the prepare() method.
class contrast.detectors.Detector.DetectorGroup(*args)[source]

Bases: object

Collection of Detector objects to be acquired together, in a scan for example. Convenience class to call prepare, arm, busy etc in shorthand. Provides some safe measures too.

Parameters:*args – Sequence of Detector instances
prepare(acqtime, dataid, n_starts, trials=1, trial_delay=1.0)[source]

Runs prepare on each of the constituent Detector instances.

arm()[source]

Arms all constituent devices.

start(trials=1, trial_delay=1.0)[source]

Starts all constituent devices.

stop()[source]

Stops all constituent devices.

busy()[source]

Checks if one or more of the constituent devices is busy.

class contrast.detectors.Detector.LsDet[source]

Bases: object

This class generates the macro `lsdet`

List available detectors.

class contrast.detectors.Detector.LsTrig[source]

Bases: object

This class generates the macro `lstrig`

List available trigger sources.

class contrast.detectors.Detector.StartLive(*args)[source]

Bases: object

This class generates the macro `startlive`

Starts software live mode on listed eligible detectors. If none are listed, all active and eligible detectors are started.

startlive [<det1> ... <detN> <exposure time>]
class contrast.detectors.Detector.StopLive(*args)[source]

Bases: object

This class generates the macro `stoplive`

Stops software live mode on listed eligible detectors. If no arguments are given, all active live detectors are stopped.

stoplive [<det1> ... <detN>]
class contrast.detectors.Detector.Deactivate(*args)[source]

Bases: object

This class generates the macro `deactivate`

Deactivates all detectors or those specified.

deactivate [<det1> ... <detN>]
class contrast.detectors.Detector.Activate(*args)[source]

Bases: object

This class generates the macro `activate`

Activates all detectors or those specified.

activate [<det1> ... <detN>]

contrast.detectors.Dummies module

class contrast.detectors.Dummies.DummyDetector(name=None)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector

Dummy detector which returns a single number.

class contrast.detectors.Dummies.Dummy1dDetector(name=None)[source]

Bases: contrast.detectors.Dummies.DummyDetector

Dummy detector which returns a 1d vector.

class contrast.detectors.Dummies.DummyWritingDetector(name=None)[source]

Bases: contrast.detectors.Dummies.DummyDetector

Hdf5 writing detector which puts sequential frames in separate files.

class contrast.detectors.Dummies.DummyWritingDetector2(name=None)[source]

Bases: contrast.detectors.Dummies.DummyDetector

Hdf5 writing detector which puts sequential frames in a big array.

class contrast.detectors.Dummies.DummyDictDetector(name=None)[source]

Bases: contrast.detectors.Dummies.DummyDetector

Illustrates how multi-channel detectors can return dict values.

contrast.detectors.Pseudo module

contrast.detectors.Pseudo.get_dict_recursive(dct, key)[source]

Helper function to get the value corresponding to path/to/key from a nested dict.

class contrast.detectors.Pseudo.PseudoDetector(variables, expression, *args, **kwargs)[source]

Bases: contrast.detectors.Detector.Detector

Derived detector which transforms signals from other Detector objects. Defines a dict of variables corresponding to detector labels, and one or more expressions to apply to these.

Variables can be of the form detector/sub/value, where “detector” is interpreted as the basic gadget, and “sub/value” are components keys into the value dictionary.

If ‘expressions’ is a string, the detector will return a single value, if it’s a dict, the detector will return a corresponding dict of results.

Example:

r = PseudoDetector(variables={'x':'npointbuff/x', 'y':npointbuff/y'},
                   expressions={'r':np.sqrt(x**2+y**2)'},
                   name='r'')
initialize()[source]

find our gadgets so we don’t have to search every time

contrast.detectors.Eiger module

class contrast.detectors.Eiger.Eiger(name=None, host='b-nanomax-eiger-dc-1.maxiv.lu.se', api_version='1.8.0', use_image_appendix=False)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Provides a direct interface to the Dectris Eiger server.

Class to interact directly with the Eiger Simplon API.

max_count_rate

Maximum count rate according to the server

compression

Whether bitshuffle compression is enabled

energy

Operating energy in keV

mask_applied

Whether to apply the mask

pixel_splitting

Whether to use virtual pixel splitting

threshold

Energy threshold for the counters

get_mask()[source]

Get the Eiger mask, taken from the example in the manual.

set_mask(array)[source]

Set the Eiger mask, also adapted from the manual.

contrast.detectors.Merlin module

class contrast.detectors.Merlin.Merlin(name=None, host='b-nanomax-controlroom-cc-2', port=8000)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Provides an interface to the Merlin detector streaming manager,

https://github.com/maxiv-science/merlin-streamer

gapless

Whether to use the continuous alternating-counter mode

energy

Operating photon energy

contrast.detectors.Xspress3 module

class contrast.detectors.Xspress3.Xspress3(device='staff/alebjo/xspress3', name=None)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Provides an interface to the Xspress3 streaming manager,

https://github.com/maxiv-science/xspress3-streamer

contrast.detectors.Pilatus module

class contrast.detectors.Pilatus.Pilatus2(hostname, name=None)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Provides an interface to the Pilatus streaming manager,

https://github.com/maxiv-science/pilatus-streamer https://gitlab.maxiv.lu.se/nanomax-beamline/streaming-receiver

This class talks socket directly to the camserver.

energy

Operating energy

class contrast.detectors.Pilatus.Pilatus3(device_name, **kwargs)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.LiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Provides an interface to the MAX IV Pilatus Tango DS,

https://gitlab.maxiv.lu.se/kits-maxiv/dev-pilatus https://github.com/maxiv-science/pilatus-streamer https://gitlab.maxiv.lu.se/nanomax-beamline/streaming-receiver

There’s no soft trigger on this detector. Also, the DS seems not to have HW triggered burst mode exposed.

start()[source]

Start acquisition for any software triggered detectors.

contrast.detectors.Andor3 module

class contrast.detectors.Andor3.Andor3(device='zyla/test/1', name=None)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector, contrast.detectors.Detector.BurstDetector

Provides an interface to the Andor3 Zyla streaming manager,

https://github.com/maxiv-science/andor-streamer

Note: hw trigger not yet implemented.

contrast.detectors.AlbaEM module

This module contains an interface to the Alba electrometer, as well as a contrast Detector class representing it.

Requires the “STREAMING” mode now available as standard firmware.

For the old school data-polling version, see LegacyAlbaEM.py.

class contrast.detectors.AlbaEM.Stream(host, port, debug=False)[source]

Bases: threading.Thread

Server which receives the electrometer stream.

class contrast.detectors.AlbaEM.Electrometer(host='b-nanomax-em2-2', port=5025, trig_source='DIO_1', streaming=False, stream_host=None, stream_port=22003)[source]

Bases: object

Interface to a 4-channel Alba electrometer.

query(cmd)[source]

Issue a command and read the answer.

burst(period=1.0, n=1, latency=0.00032)[source]

Take a series of measurements with internal timing. No triggering is possible, the series starts immediately.

arm(acqtime=1.0, n=1, hw=False)[source]

Prepare for hw- or sw-triggered acquisition, n x acqtime.

ndata

ACQU:NDAT? increments before the integration time is over, so cannot be used. Look at the stream instead.

test_soft_triggers(N=1000)[source]

The soft triggering wasn’t reliable up until SW version 2.0.0, and seems to have started working from 2.0.04. This procedure typically halted after a few 100 points.

class contrast.detectors.AlbaEM.AlbaEM(name=None, debug=False, **kwargs)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.LiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Contrast interface to the alba EM.

The specifics of the EM enables these four cases, each of which causes a different triggering and readout behaviour below:

  1. HW triggered expecting one trigger per SW step -> arm at the top
  2. HW triggered expecting hw_trig_n triggers per SW step -> arm on every sw step
  3. Burst mode, burst_n > 1, uses a special EM command
  4. Software triggered mode, -> arm at the top

Note that the electrometer itself (as of SW version 2.0.04) does not allow for triggered burst acquisition, as reflected in the code.

contrast.detectors.PandaBox module

class contrast.detectors.PandaBox.PandaBox(name=None, host='172.16.126.101', ctrl_port=8888, data_port=8889, bitblock='BITS1', debug=False)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Basic class for treating a PandaBox as a detector, capable of operating in burst mode (thereby acting as a time-based trigger source).

The PandaBox is infinitely configurable, and this class assumes that:

  1. the PCAP block is used,
  2. the PULSE1 block is used to control the number of acquired points and their timing, and
  3. flickering the “A” bit causes a trigger.

contrast.detectors.DG645 module

class contrast.detectors.DG645.StanfordTriggerSource(name=None, device_name=None)[source]

Bases: contrast.detectors.Detector.TriggerSource, contrast.detectors.Detector.BurstDetector

Class representing the DG645 as a simple source for hardware triggers. All channels are fired with the requested high time.

contrast.detectors.Lima module

class contrast.detectors.Lima.LimaDetector(name=None, lima_device=None, det_device=None)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.SoftwareLiveDetector, contrast.detectors.Detector.TriggeredDetector, contrast.detectors.Detector.BurstDetector

Lima base class.

Lima is sometimes very slow to finish writing data, which is why this gadget has a ‘hybrid mode’, where Lima is started only once, and sequential arm/start calls to this gadget only increment counters. The busy state is set based on Lima’s last_image_acquired compared to these counters, and does not reflect the state of the Lima device.

class contrast.detectors.Lima.LimaPilatus(*args, **kwargs)[source]

Bases: contrast.detectors.Lima.LimaDetector

Pilatus specific LimaDetector.

class contrast.detectors.Lima.LimaMerlin(*args, **kwargs)[source]

Bases: contrast.detectors.Lima.LimaDetector

Merlin specific LimaDetector.

class contrast.detectors.Lima.LimaAndor(*args, **kwargs)[source]

Bases: contrast.detectors.Lima.LimaDetector

Andor specific LimaDetector.

class contrast.detectors.Lima.LimaXspress3(*args, **kwargs)[source]

Bases: contrast.detectors.Lima.LimaDetector

Xspress3 specific LimaDetector.

class contrast.detectors.Lima.Lima_hybrid_on(*args)[source]

Bases: object

This class generates the macro `lima_hybrid_on`

Turn on ‘hybrid triggering’ for the specified Lima device, or for all Lima devices if nothing is specified.

class contrast.detectors.Lima.Lima_hybrid_off(*args)[source]

Bases: contrast.detectors.Lima.Lima_hybrid_on

This class generates the macro `lima_hybrid_off`

Turn on ‘hybrid triggering’ for the specified Lima device, or for all Lima devices if nothing is specified.

contrast.detectors.Ni6602 module

class contrast.detectors.Ni6602.Ni6602CounterCard(name=None, device=None)[source]

Bases: contrast.detectors.Detector.Detector, contrast.detectors.Detector.LiveDetector, contrast.detectors.Detector.TriggeredDetector

Interface to the Ni6602 Tango device exposing counters.

contrast.detectors.TangoAttributeDetector module

Provides a Detector interface to Tango attributes, so that anything can be monitored during scans.

class contrast.detectors.TangoAttributeDetector.TangoAttributeDetector(name, device, attribute)[source]

Bases: contrast.detectors.Detector.Detector

Detector interface to Tango attributes, so that anything can be monitored during scans. These detectors simply take snapshots of Tango attributes and are never busy.