Skip to main content

metrics-petri

PyPI PyPI - Python Version PyPI - License CI Docs

Petri dish colony segmentation and morphometric analysis.

metrics-petri measures how a biological sample grows on a petri dish: area, diameter, edge roughness, crack burden, texture entropy, and time-series growth rates โ€” all in physical units calibrated from the dish geometry.


Workflow

  ๐Ÿ“ Image folder
       โ”‚
       โ–ผ
  metrics-petri-metadata          โ† optional but recommended
       Step 1 ยท select folder (dates auto-detected)
       Step 2 ยท experiment name ยท start date ยท plates
       Step 3 ยท review and assign day codes per image
       Step 4 ยท export
       โ”‚
       โ”‚ writes
       โ–ผ
  image_metadata.csv
       โ”‚ --metadata
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                               โ”‚
  ๐Ÿ“ Image folder โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ metrics-petri
                                               โ”‚
                                               โ–ผ
                                          results.zip
                                          โ”œโ”€โ”€ analysis_full.csv
                                          โ”œโ”€โ”€ analysis_full.json
                                          โ”œโ”€โ”€ provenance.json
                                          โ”œโ”€โ”€ overlays/
                                          โ””โ”€โ”€ charts/  โ† growth curves with day codes

metrics-petri-metadata is optional โ€” metrics-petri can run on images alone, but supplying metadata enables growth-rate calculations and day-coded charts.


Four entry points, one package

Entry point Install Use
metrics-petri pip install metrics-petri CLI batch pipeline
metrics-petri-gui pip install "metrics-petri[gui]" Browser-based analysis GUI; public network binding requires --auth
metrics-petri-metadata pip install metrics-petri Desktop GUI for building image_metadata.csv
metrics-petri-crop pip install metrics-petri CLI crop multi-dish images into per-dish PNGs

Model checkpoint

The package bundles the SmallUNet checkpoint (best_area_w_0.7.pt, ~23 MB) inside the wheel. No separate download is needed after pip install. The bundled and downloaded checkpoint is verified against its packaged SHA-256 before use. The model was trained and validated using petrimodel โ€” a companion repository covering training, annotation, sweep evaluation, and manual diameter validation against model-generated masks.

At run time the checkpoint is located in this order:

  1. UNET_MODEL environment variable or --model flag
  2. metrics_petri/models/best_area_w_0.7.pt in the current working directory
  3. The installed package location (bundled in the wheel)
  4. Hugging Face Hub fallback download from the pinned model revision, followed by SHA-256 verification

CLI batch pipeline

Use Python 3.10โ€“3.13. If your system python3 is newer than that, call a supported interpreter explicitly, such as python3.12.

python3.12 -m venv petrienv
source petrienv/bin/activate
python -m pip install --upgrade pip
python -m pip install metrics-petri
metrics-petri input_images/

Processes every image in the folder and writes a ZIP containing result tables, provenance, overlays, and charts.

Images are resized internally to 256 ร— 256 RGB for SmallUNet inference, then the mask is mapped back to the source image. The default mask-confidence threshold is 0.5; lower values can include weaker colony signal but may add false positives, while higher values are stricter and may under-segment faint edges.

# With metadata for growth rate calculations and day-code charts
metrics-petri input_images/ --metadata input_images/image_metadata.csv

# JSON metadata is also accepted
metrics-petri input_images/ --metadata input_images/image_metadata.json

# Custom output path
metrics-petri input_images/ --output results/run01.zip

# Adjust segmentation threshold (default: 0.5)
metrics-petri input_images/ --threshold 0.45

# Use the actual outside diameter for non-standard dishes
metrics-petri input_images/ --dish-size-mm 60

# Set the PyTorch seed recorded in provenance (default: 0)
metrics-petri input_images/ --seed 123

# Custom model checkpoint
metrics-petri input_images/ --model /path/to/checkpoint.pt

Output ZIP

<user_or_experiment_name>.zip
โ”œโ”€โ”€ analysis_full.csv         one row per image, all metrics
โ”œโ”€โ”€ analysis_full.json        same data as a JSON array
โ”œโ”€โ”€ provenance.json           run settings, versions, device, and model checksum
โ”œโ”€โ”€ image_metadata.csv        copy of the input metadata (if supplied)
โ”œโ”€โ”€ image_metadata.json       same metadata as JSON
โ”œโ”€โ”€ overlays/                 per-image colony mask composites
โ””โ”€โ”€ charts/                   growth-rate charts (requires dates in metadata)

Example dataset

The source repository includes three example images under input_images/06FEB for smoke-testing and tutorials:

metrics-petri input_images/06FEB --output /tmp/metrics-petri-06feb.zip --seed 0

Metadata desktop GUI

metrics-petri-metadata is a native tkinter application for creating the image_metadata.csv that drives growth rate calculations and chart labelling.

Requirements: tkinter is part of the Python standard library.

  • macOS / Windows: bundled with the official Python installer.
  • Linux: sudo apt install python3-tk (or sudo dnf install python3-tkinter)
metrics-petri-metadata

Four-step flow:

  1. Select Folder โ€” browse to the image folder; dates are auto-detected from filenames, EXIF data, or file modification time.
  2. Settings โ€” enter experiment name, experiment start date, user name, and plate count.
  3. Review & Edit Dates โ€” a table lists every image with its date and day code (d01, d02, โ€ฆ); click any row to correct a date or set a reminder.
  4. Export โ€” writes image_metadata.csv, image_metadata.json, and optionally reminders.ics into the image folder.

Pass the exported file to the CLI with --metadata.


Dish cropper

metrics-petri-crop automatically detects and crops individual petri dishes from photos where several dishes were captured together in a single image (2โ€“8+ per photo). It is a standalone utility โ€” independent of the analysis pipeline.

metrics-petri-crop -i input_images/
Flag Description
-i, --input Image file or directory
-o, --output Output directory (default: <input>/cropped/)
-p, --padding Extra space around each dish (default: 0.05 = 5% of radius)
-d, --debug Save debug overlays showing detection circles
-D, --date Prefix output filenames: DD/MM/YYYY, DD/Mon, or DD Mon

Only fully visible dishes are extracted. Output filenames follow the pattern {stem}_dish_{NN}.png (or {YYYYMMDD}_{stem}_dish_{NN}.png with --date).


Measured metrics

Metric Unit Description
area_mm2 mmยฒ Colony area
diameter_mm mm Equivalent circle diameter
perimeter_mm mm Colony perimeter
eccentricity โ€” Shape elongation (0 = circle, 1 = line)
edge_roughness โ€” Perimeter / ideal-circle perimeter
centre_delta_mm mm Colony centroid offset from dish centre
entropy bits Shannon entropy of pixel intensities
texture_std โ€” Standard deviation of pixel intensities
crack_area_mm2 mmยฒ Crack area
crack_coverage_pct % Crack area as percentage of colony area
crack_count โ€” Number of discrete crack regions
hyph_frangi_mm mm Hyphal length (Frangi filter)
hyph_meijering_mm mm Hyphal length (Meijering filter)
hyph_hybrid_mm mm Hyphal length (hybrid filter)
rgr_per_day dayโปยน Relative growth rate (requires dates)
relative_growth_per_day mmยฒ dayโปยน Absolute area growth rate (requires dates)

Scale is derived from the detected dish circumference and the configured outside dish diameter. The default is 90 mm; pass --dish-size-mm when using another size. No separate calibration target is required.


Diagnostics

metrics-petri doctor

Checks Python, NumPy, Torch, accelerator (MPS/CUDA/CPU), model path, and all dependencies. Exits with code 1 on any issue.

At run time the pipeline selects CUDA first when available, then Apple MPS, then CPU.


Notebook walkthrough

An interactive notebook is available in the GitHub repository at notebooks/example_metrics-petri.ipynb. It traces the full pipeline โ€” mask inference, dish detection, crack analysis, and growth metrics โ€” with inline plots at each step.

The notebook is not distributed with the pip package. Clone the repository to use it.


Requirements

  • Python โ‰ฅ 3.10
  • PyTorch โ‰ฅ 2.1 (CPU works; MPS used automatically on Apple Silicon)
  • tkinter โ€” stdlib, bundled on macOS/Windows; sudo apt install python3-tk on Linux

License

MIT โ€” full text

Citation

@software{Rohan_R_Metrics_Petri,
author = {{Rohan R}},
title = {{Metrics Petri: petri dish colony segmentation and morphometric analysis}},
url = {https://github.com/rotsl/metrics-petri},
version = {3.0.0},
year = {2026}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metrics_petri-3.0.0.tar.gz (24.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metrics_petri-3.0.0-py3-none-any.whl (22.0 MB view details)

Uploaded Python 3

File details

Details for the file metrics_petri-3.0.0.tar.gz.

File metadata

  • Download URL: metrics_petri-3.0.0.tar.gz
  • Upload date:
  • Size: 24.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for metrics_petri-3.0.0.tar.gz
Algorithm Hash digest
SHA256 7ba4e61503b05cf7e6ada412e1bbfa13fa3aab3d67ce2c984d29b431137979f9
MD5 ea3e2b5a0c9195036841e0f1482ec263
BLAKE2b-256 d3513d54a41b6c81117a103033c61eaff23a9ec7a346969bc43088f252bbaf67

See more details on using hashes here.

Provenance

The following attestation bundles were made for metrics_petri-3.0.0.tar.gz:

Publisher: publish.yml on rotsl/metrics-petri

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metrics_petri-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: metrics_petri-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for metrics_petri-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bad88d08a6c8164b3a03c51eb3db8f702f21209e5e73a66826efbbc184295d6
MD5 cfc0f655c5fe544475b036abc9ffac3a
BLAKE2b-256 009e5c65e27d65619f7b8510a4428534531698908c7b54b794917a13a74c2d23

See more details on using hashes here.

Provenance

The following attestation bundles were made for metrics_petri-3.0.0-py3-none-any.whl:

Publisher: publish.yml on rotsl/metrics-petri

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 files

2.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page