项目作者: tiagocoutinho

项目描述 :
A box of tools to support Lima.
高级语言: Python
项目地址: git://github.com/tiagocoutinho/lima-toolbox.git
创建时间: 2020-05-16T17:56:59Z
项目社区:https://github.com/tiagocoutinho/lima-toolbox

开源协议:GNU Lesser General Public License v3.0

下载


Lima tool box

A set of command line tools which hopefully ease the configuration and
development of Lima cameras.

Lima toolbox in action

Installation

TL;DR

From within your favorite python environment, type:

pip install lima-toolbox[all]



The toolbox is composed of a core library and plug-ins for diverse set of
cameras.

The core can be installed with:

pip install lima-toolbox

To install support for specific camera(s) use (example):

pip install lima-toolbox[basler,eiger]

At the end you can find a mini-catalog of the available cameras.

PRs which implement new cameras (or improve, or fix existing ones) are most
welcome.

CLI

Probably the most useful tool is the CLI. You can use it to discover cameras
on the network, display information about a specfic camera and even perform
acquisitions.

The limatb CLI provides global commands like scan which are not camera specific.
In addtition, each camera provides its own set of sub-commands. They are accessible
by typing lima <camera> <sub-command> (ex: lima eiger --host=bl99eiger info).

Typing limatb --help will display help. Help is context sensitive, so
typing limatb basler --help will display help for the basler subset of
commands.

camera discovery

camera toolbox plug-ins which provides scan capability allow you to
discover them by using the scan command:

  1. $ limatb scan --table-style=box_rounded
  2. Basler:
  3. ╭──────────────┬──────────────────────────────┬───────────────────────┬───────────┬────────────┬───────────┬────────╮
  4. Class Friendly name Full name Name Serial Nb. User name Vendor
  5. ├──────────────┼──────────────────────────────┼───────────────────────┼───────────┼────────────┼───────────┼────────┤
  6. BaslerCamEmu Basler Emulation (0815-0000) Emulation (0815-0000) Emulation 0815-0000 Basler
  7. ├──────────────┼──────────────────────────────┼───────────────────────┼───────────┼────────────┼───────────┼────────┤
  8. BaslerCamEmu Basler Emulation (0815-0001) Emulation (0815-0001) Emulation 0815-0001 Basler
  9. ├──────────────┼──────────────────────────────┼───────────────────────┼───────────┼────────────┼───────────┼────────┤
  10. BaslerCamEmu Basler Emulation (0815-0002) Emulation (0815-0002) Emulation 0815-0002 Basler
  11. ╰──────────────┴──────────────────────────────┴───────────────────────┴───────────┴────────────┴───────────┴────────╯
  12. Eiger:
  13. ╭───────────┬───────────┬─────────────┬──────┬───────╮
  14. Host Alias(es) Address(es) Port API
  15. ├───────────┼───────────┼─────────────┼──────┼───────┤
  16. bl04eiger 172.95.4.11 8000 1.6.0
  17. ╰───────────┴───────────┴─────────────┴──────┴───────╯
  18. MythenSLS:
  19. ╭────────────┬─────────────┬──────┬────────┬──────────┬──────────┬───────────┬────────────╮
  20. Host IP Port Type #Modules │ Settings │ Threshold │ Dyn. Range │
  21. ├────────────┼─────────────┼──────┼────────┼──────────┼──────────┼───────────┼────────────┤
  22. bl04mythen 172.95.4.10 1952 MYTHEN 6 STANDARD 9071 32
  23. ╰────────────┴─────────────┴──────┴────────┴──────────┴──────────┴───────────┴────────────╯

Here you can see 3 simulated Basler cameras, an
Eiger camera and a Mythen SLS camera are available.

Common camera commands

As mentioned above, each camera provides its own set of specific sub-commands.
The sub-commands info and acquire are common to all cameras (altough the specific
sub-command options could vary).

The set of options which identify a camera are specific to each camera. For example,
to identify an eiger you must provide the --url=<hostname> option.

Note that there is nothing enforcing a specific camera to implement any of the
common sub-commands. But it is considered good taste if a plugin does it (for the sake
of coherency).

A camera plugin may optionally implement the scan command. It should provide the same
result as the global scan with results restricted to the camera type.

Camera information

Basic information about a camera can be retrieved with the info sub-command.

Examples:

  1. $ limatb eiger --url=bl04eiger info
  2. CurrImageType: 10
  3. DefImageType: 10
  4. DetectorImageSize: <3110x3269>
  5. DetectorModel: Dectris Eiger 9M
  6. DetectorType: E-18-0102
  7. InstrumentName: instrument
  8. MaxImageSize: <3110x3269>
  9. PixelSize: (7.5e-05, 7.5e-05)
  10. UserDetectorName: E-18-0102
  11. $ limatb mythensls --url bl04mythen info
  12. CurrImageType 10
  13. DefImageType 10
  14. DetectorImageSize <7680x1>
  15. DetectorModel Mythen-II
  16. DetectorType MythenSLS
  17. InstrumentName instrument
  18. MaxImageSize <7680x1>
  19. PixelSize (1.0, 1.0)
  20. UserDetectorName MythenSLS
  21. Detector type MYTHEN
  22. Serial number 1719109785
  23. Software version 1867412
  24. Status IDLE
  25. Dynamic range 32
  26. Energy threshold 9071
  27. Exposure time 1.0
  28. Number of frames 0
  29. Number of cycles 0
  30. Number of gates 0
  31. Master NO_MASTER
  32. Synchronization NONE
  33. Timing AUTO_TIMING
  34. Delay after triger 0.0
  35. Readout NORMAL_READOUT
  36. Settings STANDARD
  37. External signals ['GATE_OUT_ACTIVE_HIGH', 'TRIGGER_IN_RISING_EDGE', 'OFF',
  38. 'OFF']

Camera acquisition

Aquisitions can be made with the acquire sub-command.

The common options include -nb-frames, --exposure-time, --latency-time. You
can see the complete list of options with lima <camera> acquire --help.

Here is an example performing an acquisition on an eiger camera:

eiger acquisition

How to write a plug-in for your camera

You have two options:

1. Add a plug-in extension to Lima-toolbox

Write a PR to this repo with the camera you intend to add. This should always be
possible independently of the type of camera you are writing the plug-in for.

Let’s say you want to create a plugin for the
Simulator camera.

First, create a new file in src/limatb/camera called simulator.py.
The lima toolbox CLI uses the click library
to help create a powerful command line interface.

To create a simulator sub-command you can simply use the lima toolbox camera
decorator (which is a click.group helper) and write a function that should
return a Lima.Interface object:

  1. # src/limatb/camera/simulator.py
  2. from limatb.cli import camera
  3. from Lima.Simulator import Camera, Interface
  4. @camera(name='simulator')
  5. def simulator():
  6. camera = Simulator.Camera()
  7. interface = Interface(camera)
  8. return interface

The second and last thing to do is to register the new command in the lima
toolbox setup.py like this:

  1. extras_require = {
  2. "simulator": [] # add any extra python dependencies if necessary
  3. }
  4. setup(
  5. ...,
  6. entry_points={
  7. "lima.cli.camera": [
  8. ...
  9. "Simulator = limatb.camera.simulator:simulator [simulator]"
  10. ]
  11. }
  12. )

That’s it. Next time you install lima-toolbox there should be a simulator
camera available with the default info and acquire sub-commands available
out of the box.

Congratulations! You are now ready to make a PR to this repo with your new camera.

Read further to find how to implement camera options, details about the camera
decorator and how to implement your own camera specific sub-commands.

Examples of existing cameras can be found in the src/limatb/camera directory.

Custom options

If you need to add any option to the command line to identify or configure your
camera you can do it using click.option. Here is an example extending the
previous one:

  1. import click
  2. @camera(name='simulator')
  3. @click.option(
  4. '--fill-type',
  5. click.Choice(['gauss', 'diffraction'],
  6. case_sensitive=False),
  7. default='gauss')
  8. def simulator(fill_type):
  9. camera = Simulator.Camera()
  10. interface = Interface(camera)
  11. fill_type = getattr(Lima.Simulator.FrameBuilder, fill_type.capitalize())
  12. frame_getter = camera.getFrameGetter()
  13. frame_getter.setFillType(fill_type)
  14. return interface

The camera decorator

The @camera decorator helper provides a click.group decorator enhanced with
the info and acquire sub-commands by default and the facility that the
returned interface gets inserted into the click context object
ctx.obj['interface'] which can be accessed by any camera sub-commands you
decide to implement.

Here is an example on how to implement a specific sub-command:

  1. @simulator.command("initialize")
  2. @click.pass_context
  3. def initialize(ctx):
  4. # Initialization code here
  5. interface = ctx.obj['interface']

scan command

The lima toolbox CLI implements global scan command which has the purpose
of discovering all the cameras in the system.

To make the specific scan command of your system visible to the global scan
command you need to register a scan function with the signature:

  1. [async] def scan(timeout: float = None) -> beautifultable.BeautifulTable

and register the entry point in setup.py with:

  1. setup(
  2. ...,
  3. entry_points={
  4. "lima.cli.camera.scan": [
  5. ...
  6. "Simulator = limatb.camera.simulator:scan [simulator]"
  7. ]
  8. }
  9. )

The scan function can have any name you which. You can provide a coroutine
(with async keyword).

If now you type lima scan on the command line, it should execute the
scan command of all registered cameras.

2. Write a Lima-toolbox entry point in an external project

Another option, if your camera plugin is installable via a setup.py, is to apply the
same recipes above, where the only difference resides in implementing the code in your
own python detector package and modifying your setup.py instead.

An example of a project which following this phylosophy is the
SLS Mythen.

Supported cameras

Provided inside lima toolbox

Known third party cameras

Feel free to make a PR adding your own camera to this list. They are most welcome!