Work directory

All state lives in the work directory (default ./review_work), which preprocess creates.

review_work/
  manifest.tsv        # Master list of images
  skipped.tsv         # Inputs that produced no image
  notes.tsv           # Notable things written inputs hold
  preprocess.json     # How it was made
  review.tsv          # Verdicts (created later during review)
  review.lock         # Present while review or serve has it open
  batch_001/
    img_00001.jpg      # Individual preprocessed images
    img_00002.jpg
    ...
  batch_002/
    ...

File

Format

Description

manifest.tsv

TSV

Master image list, written by preprocess

skipped.tsv

TSV

Inputs that produced no image, written by preprocess

notes.tsv

TSV

What rendered inputs hold that downstream tools should know about or strip, written by preprocess

preprocess.json

JSON

How the work directory was made

review.tsv

TSV

Review decisions, appended by review and serve

review.lock

JSON

Present while a writer (review or serve) has the work directory open; names the holder

batch_NNN/img_NNNNN.jpg

JPG

Preprocessed individual images, numbered in order within each batch

The TSV files are tab-separated UTF-8 with \r\n line endings, and review.tsv also accepts \n. Every file except the JPGs holds source paths, which may carry patient identifiers: treat them as PHI (see Local disk). How the tool reads and writes them internally is in the specification’s Data Files.

manifest.tsv

One row per image, in the order the inputs were found.

Column

Description

batch

Batch subdirectory name (e.g. batch_001)

preprocessed_path

Path of the JPG within the work directory; unique

image_id

The image’s source (see below)

source_sha256

SHA-256 (64 lowercase hex characters) of the source file’s bytes, or of the ZIP entry’s bytes. One per source (in a work directory made by an older version, a DICOM and its #icon row share it)

jpeg_sha256

SHA-256 (64 lowercase hex characters) of the JPG as written

An image_id is an absolute path:

  • a file named as a SOURCE: its fully-resolved path, so a symlink named on the command line is recorded under its target’s path;

  • a file found inside a directory: the resolved directory SOURCE’s path plus the names below it, so a symlinked file there keeps its link path;

  • a ZIP entry: <zip path>::<entry name>; when several entries share a name, the later ones get #2, #3, …;

  • a DICOM’s embedded icon image: <path>#icon, a second row beside the main image, only in a work directory made by an older version (preprocess no longer renders icons);

  • a name that is not UTF-8 or holds a control character or line separator never reaches the manifest: it is a failed row in skipped.tsv, under an escaped name.

The same image_id can appear on more than one row when one file was reached through overlapping SOURCES; one verdict covers all of them. Such rows have the same source_sha256.

Work directories from older versions have only the first three columns (batch, preprocessed_path, image_id). They still load; their images are not hash-checked.

Strict parsing. review, status, serve and export read the file when they open the work directory, and stop (exit 1) with

Cannot read work directory: <file>:<line>: <problem>

if the header is not exactly one of the two above, a row has a missing or empty field, a hash is not 64 lowercase hex characters, or a preprocessed_path repeats, or one image_id has two different source_sha256 values (the error names the later line and the first). A file that is not valid UTF-8 is named with a byte offset instead of a line (<file>: not valid UTF-8 at byte N), and a field longer than 131072 characters (csv’s field limit) is a parse error at its line (field larger than field limit). The tool never repairs the file: fix or remove the line it names.

Hash check. Each JPG is checked against its jpeg_sha256 whenever it is loaded. A JPG changed or cut short after preprocessing is shown as an unloadable placeholder, which can only be marked DIRTY, never as an image that could be marked CLEAN.

skipped.tsv

One row per input that produced no image. It is always written, with only its header when nothing was skipped. Every input ends up in exactly one of manifest.tsv or skipped.tsv.

Column

Description

image_id

The input, in the same form as in manifest.tsv: <path>#icon for an icon that failed to render (only in a work directory made by an older version), the source path if a whole source could not be opened, or, for a name that is not UTF-8 or holds a control character or line separator, the escaped name (\xNN for a non-UTF-8 byte or ASCII control, \uNNNN for any other character)

kind

failed (an input that was not rendered; preprocess exits 1 unless --allow-skipped) or ignored (not an image: unrecognized content, AppleDouble, DICOMDIR, a ZIP without files, a symlink to an enclosing directory or to a directory inside a SOURCE, a non-regular file inside a directory)

reason

<ExceptionClass>: <message>, unsupported: ... for inputs this tool does not render, or the ignored reason

What each kind covers, with example reasons, is in Skipped inputs. status counts the rows and export reports them. Both read the file strictly and stop with an error naming the file and line if it is malformed, including a field longer than 131072 characters. status and serve treat an absent file as no skipped inputs, but export refuses a work directory without it, unless the manifest has rows and no hash columns (an older version); see Refusals.

notes.tsv

One row per note on an input that was written to manifest.tsv: something the input holds that downstream tools should know about or strip, whether or not its image shows it. It is always written, with only its header when there are no notes. Rows follow manifest.tsv order; an input with several notes has one row each. A failed or ignored input, including one whose image_id collides, has no notes.

Column

Description

image_id

The input, as in manifest.tsv

kind

overlay-plane, overlay-unused-bits, icon-image, alpha, embedded-thumbnail or trailing-data

detail

One line describing it, e.g. groups 0x6000, 0x6002, bit 15, IconImageSequence: 64x64 MONOCHROME2 or 120 of 2400 pixels not opaque

It is encoded like skipped.tsv, and the detail is cleaned like a skipped reason (no tabs, newlines or other control characters). What each kind means, with example details, is in Input notes. It holds source paths, so it is as sensitive as manifest.tsv. Only export reads it, to deny files holding content their review image does not show (see What is allowlisted); it refuses a malformed notes.tsv, naming the file and line, and a missing one under the same rule as skipped.tsv (so work directories made before 0.4.0, which have none, cannot be exported). The server never sends it.

preprocess.json

One JSON object recording how the work directory was made:

Key

Description

tool_version

The image-review version ("unknown" if not installed)

created

UTC time the run finished, ISO 8601 (YYYY-MM-DDTHH:MM:SSZ)

sources

The SOURCES as resolved absolute paths, in the order given, escaped like an image_id

parameters

batch_size, colormap, clahe_kernel_size, outlier_percentile, intensity_margin, range_trim, jpeg_quality, jpeg_subsampling, max_input_bytes, max_render_bytes and render_bytes_per_pixel (the size limits: bytes of an input, and estimated bytes to render one, above which an input is failed as too large, and the estimate’s bytes per pixel for each way of rendering; absent from work dirs made by older versions, which had none), draw_overlays (true if --draw-overlays drew the DICOM overlay planes onto the images, else false; absent from work dirs made by older versions, which drew overlays), access, jobs (recorded only: the output does not depend on it). Work dirs made by 0.4.0 also have tail_fraction, which is no longer written

libraries

Versions of pydicom, numpy, scikit-image, Pillow, matplotlib, imagecodecs, tifffile, plus gdcm, pylibjpeg, openjpeg when installed

counts

inputs (N of the summary line), written, skipped_failed, skipped_ignored, and notes: an object with the number of notes.tsv rows of each kind, every kind present (zero included), e.g. {"overlay-plane": 1, "overlay-unused-bits": 0, "icon-image": 0, "alpha": 0, "embedded-thumbnail": 0, "trailing-data": 0}

It holds source paths, so it is as sensitive as manifest.tsv. The tool never reads it back, and the server never sends it.

review.tsv

Every verdict is appended to review.tsv, with who gave it and how. The file is created by the first verdict.

Column

Description

image_id

As in manifest.tsv

batch

Batch the image belongs to

status

CLEAN or DIRTY; UNREVIEWED only in an undo row (see Undo rows)

pass_number

Pass (an integer from 1 to 1000000) in which the verdict was given; in an undo row, the restored verdict’s pass, or for a tombstone the undone mark’s pass

timestamp

ISO 8601 UTC time

reviewer

Who gave the verdict: the name from the browser page’s name box (rows from earlier versions may hold the name given to the old review --reviewer option). The rules are in Recorded verdicts

mode

single or grid: the display mode the verdict was given in; undo for a row written by z

grid_size

How many images the one keypress covered (1 in single mode); in an undo row, how many images the undo covered

tool_version

The image-review version that wrote the row (unknown if not installed)

source_sha256

The source file’s SHA-256, as manifest.tsv recorded it when the verdict was given: which content the verdict is about. Empty when the manifest had no hashes (a 3-column manifest). A verdict whose hash differs from the one manifest.tsv records now counts as no verdict (see Verdicts on changed content below)

reviewer, mode, grid_size, tool_version and source_sha256 are empty in rows carried over from an older file (see Upgrading an older file). An upgrade never fills in source_sha256 from the current manifest: the file at that path may have changed since the verdict was given.

Verdicts on changed content. A row whose source_sha256 is not empty and differs from the one manifest.tsv records now for its image_id is a verdict on other content: the file at that path was replaced and preprocessed again, or review.tsv was copied into a work directory rebuilt from different files. Such a row counts as no verdict: the image is UNREVIEWED in review, serve and status (and keeps the pass at 1 until it is marked again), and export reports it UNREVIEWED with the reason verdict recorded for different content (the file changed since it was reviewed). The row stays in the file, and an undo can restore it. A row with an empty source_sha256 (from before this column, or carried over by an upgrade) cannot be checked and is trusted by image_id alone, as is any row when the manifest has no hashes: those verdicts are not protected against a replaced file.

Last row wins. The file is an append-only log: every rating action appends a line per image and syncs it to disk, and when an image appears more than once its last line wins. Only images that have been marked appear; an image with no row, or whose last row is an undo’s UNREVIEWED, is UNREVIEWED. FLAGGED (marked DIRTY in an earlier pass; see Passes) is worked out when the file is read and is never written.

Strict parsing. A malformed file stops the tool with the same Cannot read work directory: <file>:<line>: <problem> message as manifest.tsv, instead of being skipped or rewritten, so a hand edit cannot silently lose decisions (a file that is not UTF-8 is named with a byte offset instead of a line). The header must be exactly these ten columns (or an older header: the first nine, or the first five), and every row has as many fields as its header, with:

  • a non-empty image_id;

  • a status of CLEAN or DIRTY, or UNREVIEWED with mode undo;

  • a pass_number from 1 to 1000000;

  • a mode of single, grid, undo or empty;

  • a grid_size that is empty or at least 1;

  • a source_sha256 that is empty or exactly 64 lowercase hex characters.

The other columns are free text and may be empty.

A line cut short by a crash. It is safe to kill the process at any time. An empty file holds no decisions. A last line cut short by a crash is skipped with a warning and dropped on the next rating, unless all of its fields made it to disk. In a current file that means its whole source_sha256: a last line with no line ending whose hash is empty or incomplete counts as cut short, so a verdict never loses its hash to a crash. In an older file (nine or five columns, before its upgrade), such a line is kept, and its last field (tool_version in a nine-column file, timestamp in a five-column one) may be cut short or empty. A crash in the middle of a grid mark can record only some of its images, cut at a line ending; the rows that landed are kept and loading logs a warning when the last mark has fewer rows than its grid_size. export refuses only until the next verdict is recorded, so re-check that grid first. A bad line anywhere else is still an error. A last line with no line ending that holds a field longer than 131072 characters (for example the zero-filled tail some file systems leave after a crash) counts as cut short; the same field on a complete line is a parse error. export refuses a file whose last line or last mark was cut short; see Refusals.

Undo rows

An undo (z) appends one row for each image of the mark it undoes, with mode undo, the time of the undo and the undoing reviewer. Where the image had a verdict before that mark, the row restores that verdict’s batch, status, pass_number and source_sha256 exactly, so the pass can go down. That includes a verdict given on other content (see Verdicts on changed content above): undoing a mark over it restores that row, not a tombstone, so the image reads UNREVIEWED again. Where it had none, the row is a tombstone: status UNREVIEWED, keeping the undone row’s batch, pass_number and source_sha256, which makes the image read as never reviewed until it is marked again.

Upgrading an older file

Upgrade everyone sharing a work directory together. A review.tsv from an older version has only the first nine columns (0.3.0 and 0.4.0) or the first five (earlier versions). It is upgraded in place the first time review or serve opens it, with the new columns left empty for its existing rows. status and export read it as is, without upgrading it.

  • Older image-review versions cannot read the upgraded file: 0.4.0 and earlier refuse a ten-column review.tsv.

  • Versions before wire API v5 (before undo) reject a review.tsv that holds undo rows, so upgrade everyone sharing a work directory before anyone presses z.

If the upgrade is interrupted, a .review.tsv.*.tmp file may be left in the work directory; see Leftover temporary files.

review.lock

Only one writer (review or serve) can use a work directory at a time. It holds review.lock while the work directory is open and removes it when it exits. status takes no lock and always works. export takes none either, but refuses while a writer holds the lock unless given --allow-live.

The lock is a JSON object naming the holder: host, boot_id (the machine’s boot id, "" where unavailable), user, pid and started (UTC, ISO 8601). It has the work directory’s file mode, so teammates in a group work directory can read who holds it.

A second writer exits 1 with:

work directory is in use by USER on HOST (pid PID) since STARTED; lock file PATH. If that process is gone, delete PATH by hand

A lock file that cannot be read or is malformed counts as held, and the message names it with the same advice.

Reclaiming. A lock is cleared automatically only when the tool can verify that its process is gone: same host name, same machine boot, and no process with that pid. A lock left on another node (for example by a serve job that was killed), one from before a reboot, or one whose process id has since been reused is not cleared. Nor is a lock without a boot id: one written on a system that has none (such as macOS, which has no /proc/sys/kernel/random/boot_id) or by an older version.

Deleting it by hand. Delete review.lock only when you are sure its process is gone: check squeue, or ps -p PID on that node, and compare the start time. Browser review over SSH shows the command.

If it was still running and a second writer starts, each checks before every verdict that review.tsv is exactly the file it last read or wrote, and refuses the verdict if not. So once one writer has recorded a verdict, the other’s next one is refused (a verdict recorded at the same moment can still land, but then both writers refuse their next). What each command does then is in Another writer on the work directory; review serves the same page and behaves the same way.

Leftover temporary files

Each of these is normally removed when the command exits, but an abrupt kill (e.g. kill -9, a node crash) can leave it behind. They hold the same data as the files they stand in for, source paths included, so delete any you find. Apart from .NAME.partial, the tool ignores them:

  • .NAME.partial, next to the work directory: preprocess’s staging directory. The next run into that work directory refuses and names it.

  • .review.tsv.*.tmp, inside the work directory: an interrupted upgrade of review.tsv.

  • review.lock.<host>.<boot id>.<pid>.<random>, inside the work directory: a writer killed while taking the lock. The next writer on the same machine removes those whose process is gone, unless the machine has no boot id; others are safe to delete by hand.

  • .FILE.<random>.tmp, beside an export --output or --report file: an interrupted export.