Skip to content

0.1.0: read, show, label, store

Open
Due by December 4, 2026
•Last updated Dec 2, 2026

Goal. Open a real 200-frame EIGER run, see faint peaks and ice rings, label frames (good / ice / empty), store the labels, and find them again the next day. Measure read and prepare speed against the 1 s verdict target.

Infrastructure in this release

  • Reader for EIGER2 NXmx master files (h5py + hdf5plugin), one frame at a time
  • Geometry from the header: wavelength, distance, beam centre, pixel mask
  • Sample ID (puck, position, run) from the file name
  • Ice-ring and resolution-ring maths
  • Display prep for faint peaks
  • Keyboard labeling window (matplotlib)
  • JSON Lines label store, schema v1
  • Query, plot and label strip along omega
  • Replay mode for saved runs
  • bench command: times opening a run, reading a frame and preparing a frame, and reports how many frames fit in 1 s
  • Packaging fixes: entry point, dependencies, synthetic test data, docs

feat: open a run from its master file (UC-1.1)

labels: use-case

Problem

As a labeler, I give the path to a master file and see how many frames it has and the omega angle of each frame, without waiting for all the data to load.

Proposed solution

  • Run(master_path) follows external links in entry/data to the data files.
  • len(run) gives the number of frames across all data files (200 for screening runs, 1,800 for testcrystal_0008).
  • run.omega_deg is an array of start angles from entry/sample/goniometer/omega.
  • run.frame(i) reads one frame only.
  • A missing or incomplete data file raises a clear RunNotReadyError naming the file, not an HDF5 traceback.

Done when

  • Unit tests on the synthetic run
  • realdata test on A07/L_A07_0007_master.h5 gives 200 frames, omega 0.0 to 19.9
  • diffpy-diffchooser info RUN prints sample, frames, omega range, geometry
  • News file added

feat: read geometry and pixel mask from the header (UC-1.2)

labels: use-case

Problem

As a labeler, I want the wavelength, distance and beam centre of each run read from its own header, so ice-ring positions are right for that run.

Proposed solution

  • Geometry dataclass fields: wavelength_A, distance_mm, beam_center_px (x, y), pixel_size_mm, shape (rows, columns), detector, saturation, collection_date.
  • Geometry.energy_eV is a property computed from the wavelength.
  • The pixel mask is stored on the run (run.mask, True = bad pixel).
  • Paths: entry/instrument/beam/incident_wavelength, entry/instrument/detector/detector_distance (metres), beam_center_x, beam_center_y, x_pixel_size, detectorSpecific/pixel_mask, saturation_value, description, detectorSpecific/data_collection_date.
  • Missing pixel mask gives a warning, and the mask falls back to "frame value == uint32 max".

Done when

  • Unit tests on the synthetic run
  • realdata test on A07: λ ≈ 0.9537 Å, distance ≈ 250.0 mm, beam centre ≈ (1502.1, 1659.8)
  • News file added

feat: read puck, position and run from the file name (UC-1.3)

labels: use-case

Problem

As the beamline scientist, I want every result to say which puck and position it belongs to, for example "Puck A, position 07".

Proposed solution

  • parse_sample_id(path, pattern=None) returns SampleId(puck, position, run), which has a sample_id property.
  • Default pattern matches L_A07_0007_master.h5: puck A, position 07, run 0007, sample_id A07. The pattern is a setting, because the beamline scientist has not confirmed the naming yet.
  • No match gives puck, position and run as None and sample_id unknown.
  • str(sample_id) gives "Puck A, position 07, run 0007".

Done when

  • Parametrized tests: real-style names, testcrystal_0008_master.h5, a custom pattern
  • News file added

feat: ice-ring and resolution-ring positions (UC-1.4)

labels: use-case

Problem

As a labeler, I want ice rings drawn where they really fall for this run, so I can tell ice from protein spots.

Proposed solution

  • ICE_RINGS_A = (3.897, 3.669, 3.441, 2.671, 2.249, 2.072, 1.948, 1.918, 1.883, 1.721).
  • radius_px(d_A, geometry): 2θ = 2·asin(λ / 2d), r = distance·tan(2θ) / pixel size. Returns nan when λ / 2d > 1.
  • d_spacing_map(geometry, binning=1): d-spacing of every pixel, flat detector, no tilt.
  • Check: for A07 geometry, the 3.669 Å ring is about 889 px from the beam centre.

Done when

  • Unit tests with hand-computed values
  • News file added

feat: prepare a frame so faint peaks are visible (UC-1.5)

labels: use-case

Problem

As a labeler, I want to see faint Bragg peaks and ice rings that are invisible on a plain linear scale.

Proposed solution

  • prepare(frame, mask=None, saturation=None, binning=4) returns a float32 image:
    1. masked pixels and pixels at or above saturation become NaN
    2. shrink by keeping the maximum in each binning x binning block (nanmax)
    3. subtract the background: the median of each block of the shrunken image (nanmedian, block size background_block, default 16, numpy only)
    4. clip at a high percentile and scale to 0..1
  • show CLI draws the prepared frame with optional ice and resolution rings.
  • Prepare one full 3262 x 3108 frame in under 0.3 s on the lab Mac (measured with bench, UC-1.10).

Done when

  • Unit tests: masked pixels never become bright; output shape is input shape // binning
  • Screenshot of A07 frame 0 with rings in the PR
  • News file added

feat: label frames with the keyboard (UC-1.6)

labels: use-case

Problem

As a labeler, I step through a run and press one key per frame to label it.

Proposed solution

  • diffpy-diffchooser label RUN --db labels.jsonl --user NAME [--every N]
  • Keys: g good, i ice (then l light / h heavy), e empty, arrow keys move, u go back to the last labeled frame to relabel it (nothing is deleted), q quit.
  • A frame that is not good, ice or empty is skipped with the arrow keys and stays unlabeled.
  • Title shows "Puck A, position 07 · frame 153 · 15.3° · label: ice (light)".
  • Every key press writes one record at once (no loss on crash).
  • On restart, opens at the first unlabeled frame.
  • Window logic and key handling are separate from matplotlib, so they can be tested without a display.

Done when

  • Tests drive the key handler with fake events and check the records
  • Manual check: label 200 frames of A07
  • News file added

feat: store labels in a JSON Lines file (UC-1.7)

labels: use-case

Problem

As a developer, I want labels in a plain file that I can read, diff and append to safely.

Proposed solution

  • LabelStore(path): add(record), latest() (newest record per image_id), history(image_id), query(**filters).
  • Records follow schema version 1 (below). Unknown fields are kept. Missing required fields raise ValueError.
  • image_id = f"{run_stem}_f{frame_index:04d}" where run_stem is the master file name without _master.h5.
  • Appends use one write call per record and flush.

Schema version 1:

{
  "schema": 1,
  "image_id": "L_A07_0007_f0153",
  "sample_id": "A07",
  "puck": "A",
  "position": "07",
  "run": "0007",
  "master_file": "/data/A07/L_A07_0007_master.h5",
  "frame_index": 153,
  "omega_deg": 15.3,
  "label": "ice",
  "ice_severity": "light",
  "note": "",
  "source": "human",
  "labeled_by": "adib",
  "confidence": null,
  "datetime": "2026-12-03T21:14:03+11:00",
  "beamline": "MX2",
  "detector": "Dectris EIGER2 Si 9M",
  "wavelength_A": 0.9537,
  "distance_mm": 250.01,
  "beam_center_px": [1502.10, 1659.76]
}

label is one of good, ice, empty. ice_severity is null
unless the label is ice. source is human or model. beam_center_px is
(x = column, y = row).

Done when

  • Unit tests for add, latest, history, query, bad records
  • News file added

feat: query, plot and label strip (UC-1.8)

labels: use-case

Problem

As the beamline scientist, I ask "show me the ice frames from puck A" and see them. I also see a strip of labels along omega for one run, so I know where ice starts.

Proposed solution

  • diffpy-diffchooser query --db labels.jsonl [--puck] [--position] [--label] [--source] [--since] [--until] [--plot] [--max N]
  • Plotting reopens each frame from its master file and uses prepare.
  • diffpy-diffchooser strip --db labels.jsonl RUN draws one coloured cell per frame along omega (good, light ice, heavy ice, empty, unlabeled).

Done when

  • Unit tests for filters
  • Strip and query plots shown in the PR
  • News file added

feat: replay saved runs (UC-1.9)

labels: use-case

Problem

As a developer, I want to feed saved runs one by one as if they were arriving at the beamline, to test later releases without beamtime.

Proposed solution

  • replay(folder, delay_s=0) yields master file paths in collection order (data_collection_date from the header, then file name).
  • CLI prints one line per run: time, sample, frames.

Done when

  • Unit test with three synthetic runs in a temp folder
  • News file added

feat: benchmark read and prepare time (UC-1.10)

labels: use-case

Problem

As the developer, I want to measure how long frames take to process, so I know how many fit in the 1 s verdict budget.

Proposed solution

diffpy-diffchooser bench RUN [--frames 10] [--binning 4] times frames spread across the whole run (not only the first ones, so caching does not hide the cost). --binning is the shrink factor used to prepare a frame (UC-1.5).

It prints:

Output Meaning
Open time time to open the run
Read time, mean and max time to load one frame from disk
Prepare time, mean time to make faint peaks visible in one frame (UC-1.5)
Frames in budget 1 s / (mean read time + mean prepare time), rounded down
Image shape and frame count size of one frame and number of frames in the run

Example of the calculation (made-up times): 0.11 s to read + 0.20 s to prepare = 0.31 s per frame, so 3 frames fit in 1 s.

bench measures speed only. It gives no verdict, and "frames in budget" leaves out the open time.

Done when

  • Unit test runs bench on the synthetic run
  • Numbers for run A07 on the lab Mac are posted in the release issue and included in the release notes
  • News file added

Milestone 0.1.0 Done when

  • All 200 frames of at least three runs are labeled, and found and plotted the next day
  • bench numbers for run A07 are in the release notes
  • CI passes without real data
  • 0.1.0-rc.0 installs from PyPI, then 0.1.0 is tagged
12% complete

Issues