Skip to content

controller: add Planktoscope unit number to metadata - #942

Merged
sonnyp merged 2 commits into
mainfrom
feature/ecotaxa-serial-number
Apr 27, 2026
Merged

sonnyp merged 2 commits into
mainfrom
feature/ecotaxa-serial-number

Conversation

@babo989

@babo989 babo989 commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the FairScope HAT serial number (e.g. U383) to every acquisition's metadata so the produced data can be traced back to the
specific physical instrument that produced it.

The serial number is already stored in the HAT EEPROM (read from /proc/device-tree/hat/custom_0, base64-decoded JSON) and previously
surfaced only in the JS layer via lib/hardware.js. Until now, EcoTaxa exports identified the instrument only by software model
(acq_instrument) and machine name (acq_instrument_id), so two different physical units sharing the same machine name (or a unit
later renamed) couldn't be distinguished in the archive.

What changed

  • controller/imager/main.py
    • New _read_hat_serial_number() helper — reads /proc/device-tree/hat/custom_0, strips the trailing NUL, base64-decodes,
      JSON-parses, returns the serial_number value, or None on any failure.
    • In _start_acquisition, when the read succeeds, set metadata["acq_instrument_serial_number"] = serial. The key is omitted
      entirely on read failure
      so non-FairScope HATs do not get a misleading column.

No segmenter changes are needed — the existing acq_* prefix filter in segmenter/planktoscope/segmenter/__init__.py already
forwards every acq_ key from metadata.json straight to the EcoTaxa TSV.

Why this injection point

Reading at acquisition start (rather than at segmentation time) binds the serial to the data at capture, not at processing. If someone
later segments on a different machine or swaps HATs between capture and segmentation, the serial in the TSV still reflects the
instrument that produced the images. The value also lands in metadata.json next to the images, so it travels with the acquisition
folder regardless of EcoTaxa export.

Field naming

  • Column name: acq_instrument_serial_number
  • Follows EcoTaxa's acq_* prefix convention for instrument-related metadata
  • Distinct from the existing acq_instrument_id (which is the human-friendly machine name like sponge-care-xxx)
  • EcoTaxa type marker resolves to [t] (text) automatically

Test plan

  • Helper returns the serial on a v3.0 HAT (U383) and None for missing/garbage/empty EEPROM blobs
  • Imager service restarts cleanly with the change deployed
  • Real acquisition writes "acq_instrument_serial_number": "U383" into metadata.json
  • Segmenter output (ecotaxa_testerunit_1_A_1.zip) contains the column in the TSV header (col 47), type marker [t], value
    U383 consistent across all 68 object rows
  • No regression — all 35 existing acq_* / sample_* columns still populate correctly (acq_uuid, sample_uuid, acq_id,
    etc.)
  • Confirm behavior on a non-FairScope HAT or unit with no custom_0 (should silently omit the column — verified via local helper,
    not on hardware)

sonnyp pushed a commit that referenced this pull request Apr 27, 2026
## Summary

`build-controller.yml` runs `sudo apt install -y libcap-dev` without
first refreshing the apt index. When Ubuntu rotates a security update
for `libcap2`/`libcap-dev` (as happened with `2.66-5ubuntu2.2`), the
runner's cached index points to a `.deb` that's no longer on the mirror
and the install fails with `404 Not Found` → `exit code 100`.

Hit on PR #942 (run 24971308570) twice in a row.

## Change

Prepend `sudo apt-get update` to the install step so the runner pulls
the current package version every time.

## Test plan

- [ ] CI passes on this PR
- [ ] Re-trigger CI on PR #942 once this lands; the libcap-dev step
succeeds

@sonnyp sonnyp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for doing this in backend instead of frontend

@sonnyp sonnyp changed the title added Planktoscope unit number to metadata controller: add Planktoscope unit number to metadata Apr 27, 2026

@sonnyp sonnyp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be improved by

  • read the serial number once at startup
  • differentiate between no serial number (None e.g. 2.6) and an unexpected error happened

@sonnyp
sonnyp merged commit 972d654 into main Apr 27, 2026
1 check passed
@sonnyp
sonnyp deleted the feature/ecotaxa-serial-number branch April 27, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants