Tutorial 2: Peak Detection

Peak detection relies on mlgidDETECT package. First, create the mlgidBASE class instance:

from mlgidbase import mlgidBASE
filename = '../../example/BA2PbI4.h5'
analysis = mlgidBASE(filename=filename)
INFO - Failed to extract font properties from /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf: Can not load face (unknown file format; error code 0x2)
INFO - generated new fontManager
2026-05-26 13:54:48.292842811 [W:onnxruntime:Default, device_discovery.cc:283 GetGpuDevices] Failed to detect devices under "/sys/class/drm/card0": device_discovery.cc:93 ReadFileContents Failed to open file: "/sys/class/drm/card0/device/vendor"

Then run detection:


Minimal Code Example

analysis.run_detection()
INFO - Model file does not exist.
INFO - Starting download of model file to /home/docs/.local/share/mlgiddetect/dino.onnx
  [######--------------------------------------------]  12.2%  117.9/968.4 MB  235.75 MB/s   
  [############--------------------------------------]  25.5%  246.7/968.4 MB  257.36 MB/s   
  [##################--------------------------------]  37.4%  361.9/968.4 MB  230.57 MB/s   
  [########################--------------------------]  49.8%  482.0/968.4 MB  240.16 MB/s   
  [###############################-------------------]  63.1%  611.4/968.4 MB  258.71 MB/s   
  [######################################------------]  76.5%  741.0/968.4 MB  259.04 MB/s   
  [############################################------]  88.8%  860.4/968.4 MB  238.06 MB/s   
  [#############################################-----]  90.5%  876.8/968.4 MB  32.84 MB/s   
  [#############################################-----]  91.3%  884.0/968.4 MB  11.62 MB/s   
  [##############################################----]  92.9%  899.9/968.4 MB  31.79 MB/s   
  [###############################################---]  94.6%  916.1/968.4 MB  32.15 MB/s   
  [################################################--]  96.2%  931.2/968.4 MB  30.26 MB/s   
  [################################################--]  97.9%  947.7/968.4 MB  32.82 MB/s   
  [#################################################-]  99.0%  958.5/968.4 MB  21.69 MB/s   
  [##################################################] 100.0%  968.4/968.4 MB  130.24 MB/s   
INFO - Model file downloaded successfully from https://huggingface.co/mlgid-project/mlgidDETECTdino/resolve/main/model.onnx?download=true to /home/docs/.local/share/mlgiddetect/dino.onnx
INFO - Loading model
INFO - Saved detected peaks to file: ../../example/BA2PbI4.h5, entry: entry_0000, frame: 0

Parameters

  • entry (str) — Data file entry to process. Defaults to None (all entries). OPTIONAL

  • frame_num (int/List[int]) — Frame number in each entry for detection / list of frames. Defaults to None (all frames).

  • config_file (str) — Path to detection configuration file. Defaults to None (default parameters). OPTIONAL

  • model_type (str) — Name of the model dino or faster_rcnn. OPTIONAL


Decription

The user can specify a single entry or process all entries in the file by setting entry=None. The frame_num parameter accepts either a single int or a list of frame indices to process.

The detection configuration can be loaded from a YAML file. Additionally, the detection model can be selected via the model_type parameter. Currently, two models are supported: dino and faster_rcnn, as described in the recent work by C. Völter.

Informational logs indicate whether the detection model is being loaded. After the initial load, both the model and its configuration remain fixed; any subsequent configuration inputs will be ignored. To apply a different configuration, a new mlgidBASE instance must be created with the desired settings.

analysis = mlgidBASE(filename=filename)
analysis.run_detection(
    entry='entry_0000',
    frame_num=0,
    config_detect='../../example/config.yaml',
    model_type = 'faster_rcnn')
ERROR - Configuration file not found: ../../example/config.yaml
An exception has occurred, use %tb to see the full traceback.

SystemExit
/home/docs/checkouts/readthedocs.org/user_builds/mlgidbase/envs/latest/lib/python3.11/site-packages/IPython/core/interactiveshell.py:3756: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

The results can be visualized using silx view or loaded from the saved file, as shown in Tutorial 8.