Contributing#
This page is for people who change Isocenter itself. It covers the development environment, the code-quality rules, how to run the tests, the release process, and the internals that a contributor needs and a user does not.
Work is planned in GitHub Issues and milestones. Good places to start are the good first issue and help wanted labels.
1. Environment Setup#
Isocenter requires Python 3.12+. The floor is not arbitrary. entities.py
and privacy.py use @dataclass(slots=True) (3.10+), and the declared
dependency set resolves only on 3.12 and later.
# Clone the repository
git clone https://github.com/kvnlng/Isocenter.git
cd Isocenter
# Install the library, the test suite's dependencies, pylint and coverage
pip install -e ".[dev]"
The dev extra is contributor tooling only. It pulls in tests plus
pylint and coverage. Somebody who installs Isocenter to use it gets
none of it. pip install isocenter never installs a linter or a test runner.
2. Code Quality#
These rules keep the code reliable and maintainable.
Pylint#
We use pylint to lint our codebase. The configuration is strict (pylintrc.toml) and we aim to keep the score above 8.5/10 for the main package.
Run Pylint:
# Lint the main package
pylint isocenter
# Lint tests (slightly more lenient)
pylint tests
Common Rules:
Imports: All imports must be at the top-level (except for strictly necessary circular dependency breaking or rare optional heavy dependencies).
Docstrings: All public modules, classes, and methods must have docstrings, in Google style. A docstring documents the code. It holds a summary,
Args:(one entry per parameter),Returns:/Yields:,Raises:(one entry per exception the function raises) and what a caller needs to know to use it. It is rendered in the API reference. Change history belongs inCHANGELOG.md. Reasoning for someone who edits the body belongs in a#comment at the line it explains.pylint.extensions.docparamsis enabled inpylintrc.toml. It reports a missing parameter, return, yield or raise entry in the docstring of every function and method whose name does not start with_. Private names (_x), dunders and__init__are not checked and need no docstring. So constructor parameters are not checked either, whether they are documented on the class or on__init__. Module docstrings are not checked. Keep constructor parameters and module docstrings complete by hand.Encodings: All
open()calls must specifyencoding='utf-8'to prevent cross-platform issues.
Formatting#
(Optional) We recommend using black for formatting, though it is not enforced.
3. Testing#
We use pytest for our test suite.
Run the tests that exercise what your branch changed:
pytest -v --changed
It prints which selection it used. The whole suite (pytest) runs when a release is cut. RELEASING.md says when each is required.
Run specific tests:
pytest tests/test_session.py
Every test runs in its own temporary directory, so a test that writes relative paths does not touch the checkout.
Benchmarks#
We have a dedicated benchmark suite in tests/benchmarks/.
# Run the stress test; --input and --output are required
python -m tests.benchmarks.run_stress_test --input <dicom-dir> --output <out-dir>
Performance records the one benchmark run with its machine and date.
Documentation#
The site is built with Sphinx and pydata-sphinx-theme, from MyST Markdown pages under docs/ and the package’s docstrings. Install the docs extra and build into a directory outside the checkout:
pip install -e ".[docs]"
sphinx-build -W --keep-going -b dirhtml -d /tmp/isocenter-doctrees docs /tmp/isocenter-docs
python .github/scripts/check_api_pages.py /tmp/isocenter-docs
-W is what the deploy uses: a warning fails the build. The third command is the deploy’s check of the API pages. It checks that each class’s attributes table matches its docstring, that Session is named as such, and that “On this page” lists the members. It prints each problem and exits 1. Never build into the checkout’s root or beside a running pytest, because pytest fails on any new entry in the root. Open /tmp/isocenter-docs/index.html to read the result. The version switcher reads the live site’s list, so it shows the published versions, not this build.
4. Release Process#
The procedure lives in
RELEASING.md
in the repository root, next to the code it releases. It says how changes
reach main, how a release branch is cut, tagged and published, and how
patch releases work. In short:
mainis the development branch.Each minor line is cut to a frozen
release/X.Ybranch.A version is the tag
vX.Y.Zon that branch.Nothing publishes itself.
Publishing is a manual run of .github/workflows/publish.yml against the
tag. It uploads to PyPI by Trusted Publishing. GitHub authenticates over
OIDC, and PyPI matches the request against a publisher pinned to this
repository, the workflow’s filename, and its environment name. There is
no API token in repository secrets, in CI, or on anyone’s machine.
Renaming publish.yml or its environments breaks publishing until PyPI’s
publisher configuration is updated to match.
Before anything is uploaded, the build job checks the run. The target must
be exactly pypi or testpypi. The built wheel must match
isocenter/_version.py, the one place the version is declared. A run to
pypi must be dispatched from a v* tag that matches both. A TestPyPI
rehearsal may run from the release branch. If it runs from a tag, the tag
must match too. The build job then installs the built wheel into a clean
environment outside the source tree, and asserts that the wheel carries
its own resources/*.json. That gate exists because those resources once
shipped in no distribution at all, and nothing failed. Every loader
guards on os.path.exists and degrades to a default. So a published
release audited against an empty PHI policy and reported clean.
If test-supported (3.13, 3.14) is red, that is a decision, not a
formality. It only reports. It cannot block the upload. Either fix it,
or delete that classifier from setup.py before you release. setup.py
says outright that a classifier that CI does not back is the same
unbacked promise that the old python_requires=">=3.9" was. A red job
here is more likely to be a flake than a real break (v0.9.1’s publish
had 3.13 fail and pass on rerun). That is exactly what makes it
dangerous: “just rerun it” is the reading that ships a real break. Rerun
to learn whether it is deterministic, not to make it disappear. That is
why RELEASING.md rehearses on TestPyPI, from the release branch, before
tagging.
Archiving and DOIs#
When the Zenodo GitHub integration is enabled for this repository, each
published GitHub Release is archived and issued a version DOI. That
version DOI sits under a concept DOI that always resolves to the latest.
.zenodo.json supplies the deposit metadata, and CITATION.cff is what
GitHub’s “Cite this repository” button reads.
Zenodo only archives releases created after the integration is
switched on. It does not backfill. Its own guide says “once connected,
new releases from the repository will be automatically ingested and
archived”. So enabling it does nothing to the releases already
published. The first deposit comes from the next release, or from
deleting and re-creating an existing GitHub Release. Creating a GitHub
Release uploads nothing. Publishing is a separate manual run
(RELEASING.md), so the Release can be made, or re-made for Zenodo,
without touching PyPI.
The integration is enabled and the first deposit exists, from v0.8.1.
The concept DOI is 10.5281/zenodo.22104298. That is what
CITATION.cff and the README badge carry, and it always resolves to the
latest version. Zenodo also mints a per-version DOI for each release, one
digit away. Do not substitute it, or the citation stops following the
work. tests/test_version_contract.py pins both the value and the
agreement between the two files.
.zenodo.json supplies the metadata the record is minted from. Two
things about it are easy to get wrong and are pinned by
tests/test_version_contract.py:
licenseis a Zenodo vocabulary id, not an SPDX id, and those are lowercase.apache-2.0resolves atzenodo.org/api/vocabularies/licenses/. The SPDX spellingApache-2.0returns 404, and would have gone into the record as a licence Zenodo could not match. (The same held foragpl-3.0-or-laterbefore #348 changed the licence.)No
versionfield. The GitHub integration fills it in from the release tag. Pinning it here would add a third place for the number to drift.
Record metadata can be corrected on Zenodo after publication. The DOI itself cannot be reissued.
Storage schema#
The session store is <name>.db (SQLite) plus <name>_pixels.bin, an append-only sidecar. The layout below is internal. It is not part of the frozen API, and a release may change it. Architecture has the user’s view.
Why the split#
DICOM metadata comes in two shapes. Standard tags are well-defined and present on most instances. Private tags are vendor-specific, sparse and numerous. One table with a column per tag is impossible, and a single entity-attribute-value table is too slow to load in bulk. So values are split by group parity and type when they are saved:
Where |
Table / file |
What |
Why |
|---|---|---|---|
Core attributes |
|
Every standard (even-group) tag, and every binary value that is kept, private ones included |
One JSON document per instance, read back whole: no SQL reads inside it and no joins, so 10,000 instances load without 10,000 joins. |
Private attributes |
|
Private (odd-group) tags that are not binary |
Sparse, vendor-specific. Keeps the core document small. |
Pixel and waveform data |
|
Raw frame bytes |
Keeps gigabytes out of the database. |
The real split for private values is whether a value serializes to text. A kept binary value is base64-encoded into attributes_json even when it is private, and its VR is recorded in the document’s root __vrs__. DS and IS values are stored as tagged text ({"__type__": "DS", "data": ...}) because json writes a float or int subclass as a bare number.
There is no fourth tier for large binary values. Only Pixel Data and Waveform Data go to the sidecar. Any other binary value over 65534 bytes is dropped at ingest with a DATA_LOSS row, because an unbounded value would stay resident for the life of the session. The pixel lookup tables (io_handlers.LUT_DATA_TAGS: LUT Data, Gray LUT Data and the six palette data elements) are kept up to 393216 bytes instead (LUT_RETENTION_MAX_BYTES). A full 16-bit table is 131072 bytes, so three palettes are 384 KiB raw or about 512 KiB as base64. Three segmented palettes at the cap are 1.125 MiB raw, about 1.5 MiB as base64. Private Tags gives the reasoning users see.
Tables#
Every table has an integer id primary key. The natural keys are UNIQUE columns.
Table |
Holds |
Key columns |
|---|---|---|
|
One row per patient |
|
|
The one per-project secret ( |
|
|
One row per study |
|
|
One row per series |
|
|
One row per instance (one file) |
|
|
Private, non-binary values |
|
|
Sidecar references other than the instance’s own Pixel Data: waveform samples, and pixel data inside a sequence item such as an icon image |
|
|
Every action the pipeline records, read by the compliance report |
|
|
Findings saved by |
|
persistence.py holds the CREATE TABLE statements and the ALTER TABLE steps that add a column to a store created without it. Nothing is back-filled. A column added later is NULL in older rows, and the loader reads NULL as “not recorded”.
erDiagram
PATIENTS ||--|{ STUDIES : contains
STUDIES ||--|{ SERIES : contains
SERIES ||--|{ INSTANCES : contains
INSTANCES ||--o{ INSTANCE_ATTRIBUTES : "private tags"
INSTANCES ||--o{ INSTANCE_BLOBS : "waveform, nested pixels"
INSTANCES ||--o| SIDECAR : "primary frame"
INSTANCE_BLOBS ||--|| SIDECAR : "offset, length"
PATIENTS {
int id PK
string patient_id UK
string patient_name
}
STUDIES {
int id PK
int patient_id_fk FK
string study_instance_uid UK
string study_date
}
SERIES {
int id PK
int study_id_fk FK
string series_instance_uid UK
string modality
}
INSTANCES {
int id PK
int series_id_fk FK
string sop_instance_uid UK
string attributes_json
int pixel_offset
int pixel_length
}
INSTANCE_ATTRIBUTES {
int id PK
string instance_uid FK
string group_id
string element_id
string value_rep
string value_text
}
INSTANCE_BLOBS {
int id PK
string instance_uid
string kind
int offset
int length
}
SIDECAR {
bytes frames
}
audit_log, phi_findings and project_secret stand alone: they refer to entities by UID in their text columns, not by foreign key.
Tests behind the documented defaults#
Several numbers in Environment Variables are pinned by tests, so the page and the code cannot drift apart silently:
tests/test_documented_env_vars.pyfails when the package reads anISOCENTER_*variable that has no row in the table. Such a row is a table row whose first cell is the variable’s name in bold code.tests/test_parallel_contract.pyholds the default worker count (one per CPU), the order the threads-or-processes levers resolve in, and the rule that only the literal1switches a flag on.tests/test_redaction_worker_count.pyholdsredact()’s own default (half the CPUs, capped at eight) at fixed CPU counts, so the cap is exercised on any machine.tests/test_shared_executor_lifecycle.pyholds theWARNINGsingest()logs whenISOCENTER_FORCE_THREADSorISOCENTER_MAX_TASKS_PER_CHILDis set.
Change the page and the test together.
Measuring coverage in worker processes#
ingest() and export() always run in worker processes, so a debugger or a plain coverage run in the calling process does not see them. .coveragerc measures the spawned workers too. Its comments say why each setting is there:
coverage run -m pytest tests/ && coverage combine && coverage report
Coverage is not run in CI and has no threshold.
ISOCENTER_WORKER_FAULTHANDLER=1 makes every worker process dump its threads’ tracebacks to stderr if it is still alive after 240 s. The test workflow (.github/workflows/tests.yml) sets it, so a stall inside a pool child appears as a stack trace rather than a silent hang.
Dependency and codec notes#
Dependencies#
Dependencies are declared in one place, setup.py. There is deliberately no requirements.txt. Two lists drift apart, and only install_requires is consulted when you pip install. .[tests] is enough to run the suite. .[dev] adds pylint and coverage.
pylibjpeg-libjpeg on the free-threaded build#
Measured with pylibjpeg-libjpeg 2.4.0, which has no free-threaded wheel. On CPython 3.14t, pip install builds it from the sdist. Depending on the compiler that pip picks, the build either fails or produces a wheel with no extension module in it. The second was measured here. The install reported success, and import libjpeg then failed with ModuleNotFoundError: No module named '_libjpeg'. Built from the sdist by hand, it imports, with RuntimeWarning: The global interpreter lock (GIL) has been enabled to load module '_libjpeg', which has not declared that it can run safely without the GIL. So a 3.14t process that imports it runs with the GIL back on, unless PYTHON_GIL=0 is set. Codec support carries the user-facing summary.
Decode limits: the evidence#
Codec support states each limit. The measurements behind the precision limits:
A precision-12 JPEG Lossless stream under BitsStored 16 reads
0..4970throughimagecodecs(lj92) and0..4095through pydicom withpylibjpeg-libjpeg, which saturates.A JPEG 2000 codestream written by
imagecodecs.jpeg2k_encode(a, level=0, codecformat="J2K", bitspersample=12)over unsigned samples up to 4970 declares precision 12 and holds 4970. With the SIZ segment’s precision byte (Ssiz) changed from 0x0b to 0x0f, 16 bits,imagecodecs.jpeg2k_decodereturns the input plus 30720. That is the difference between the two precisions’ level shifts (32768 − 2048): 35690 where the input holds 4970, and the input exactly once 30720 is subtracted. As written, the codestream reads0..4095through Pillow and throughimagecodecs, the two decoders that install with Isocenter, both openjpeg.ingest()of a.90file that holds it stores0..4095and writes no row. Measured on imagecodecs 2026.8.16 and 2026.10.10 (openjpeg 2.5.4). Through pydicom’spylibjpeg-openjpegplugin (2.6.0, also openjpeg) it reads0..4095as well. GDCM was not tried, and neither was any JPEG 2000 decoder that is not openjpeg (#1057).No JPEG-LS stream was found that decodes beyond its declared precision (#684). For a 16-bit array holding 4970,
imagecodecs.jpegls_encodedeclares precision 16. Withbitspersample=12(2026.10.10, while 2026.8.16 refuses the keyword), it declares 12 and decodes to the array masked to 12 bits, 3570 at most. DCMTK’sdcmcjpls3.7.0 over the same samples in a native file (BitsAllocated 16, BitsStored 12) writes the same two streams.+prwrites precision 16, which decodes to the input.+pcwrites precision 12, byte for byte thebitspersample=12stream. Both encoders write an LSE segment stating MAXVAL 65535 into a precision-16 stream.imagecodecswrites none into an 8-bit one.When the SOF55 precision byte of that array’s precision-16 stream (8 by 8,
0..4970) is rewritten to any value from 2 to 15,imagecodecs.jpegls_decode(CharLS 2.4.4) raisesJpeglsError. While an LSE states a MAXVAL above 2^P − 1, the error isInvalid JPEG-LS stream: JPEG-LS preset parameters segment contains invalid values(4096 at precision 12 is refused and 4095 is not). Once the LSE is taken out or states 2^P − 1, the error is, for this array, a refusal of the scan (the encoded bit stream contains a general structural problem, orthe decoding process is ready but the source buffer still contains encoded data).The scan’s refusal depends on the samples, not on the width. A 16-bit stream of one row of 64 samples, each 4970, rewritten to precision 12, is refused with its LSE as written or stating 4096. With the LSE out or stating 4095, it decodes to
31..4031, with no cell equal to the source (455..1896at precision 11). One pixel of 65535 with the LSE out decodes to 4095, 2047 and 255 at precisions 12, 11 and 8._decode_pixelson the fallback returns the row’s array, and the check returns None.ingest()of a.80file that holds it (BitsAllocated 16, BitsStored 12) stores31..4031and writes no row (found by the review of #1099).Over 400 arrays were tried (8-bit and 16-bit, one and three samples per pixel). Each was encoded lossless and near-lossless, and rewritten to every lower precision in five ways. None of 28,000 rewritten 16-bit streams decoded. (A near-lossless stream rewritten to precision 2 is refused for its NEAR value instead.) Of the 2,400 rewritten 8-bit streams of each way, 781 decoded with no LSE and 781 with an LSE stating 2^P − 1, each to samples inside the rewritten precision. None decoded with an LSE stating more. One 8-bit stream of samples up to 245, rewritten to precision 7, decodes to
0..127with 1 cell of 64 equal to the source._decode_pixelsreturns that array, and the check returns None.ingest()of a.80file that holds it stores0..127and writes no row. The results are identical on imagecodecs 2026.8.16 and 2026.10.10, 3.12.14 and 3.14.7t.tests/test_a_stream_narrower_than_its_own_samples_is_said.pyholds the+pcstream as bytes, runs the rewrites of the 8 by 8 array, and holds the two streams that decode.pydicom’s JPEG-LS plugins were run on the same rewritten streams, on 3.12.14 only. The plugins were
pylibjpeg2.1.0 withpylibjpeg-libjpeg2.4.0, andpyjpegls1.5.1. pydicom 3.0.2 registerspylibjpeg,pyjpeglsandgdcmfor JPEG-LS, and takespylibjpegfirst.There were 29 streams. They were the 8 by 8 array’s and the row’s at precisions 12 and 11, and the pixel’s at 12, 11 and 8, each with the LSE as written, out, stating 2^P − 1 and stating 2^P. The set also held the 8-bit stream at precision 7.
libjpeg.decodedecodes all 29, none beyond its precision. The 8 by 8 array’s stream at precision 12 reads0..4095with the LSE as written, equal to the source clamped to 4095 in all 64 cells. It reads0..4029with the LSE out. CharLS refuses both.jpeg_ls.decode(CharLS) refuses and decodes asimagecodecsdoes, in the same words and to the same ranges, except that it refuses the one-pixel streamsimagecodecsdecodes.With the plugins importable,
_decode_pixelsreturns a decode for each of the 29, withlibjpeg.decode’s range, and the check returns None.ingest()of four.80files (the 8 by 8 array’s at precision 12 with the LSE as written and out, the row’s with the LSE out, the 8-bit stream at 7) stores0..4095,0..4029,31..4031and0..127and writes no row. GDCM was not tried, and neither was any other JPEG-LS decoder. The plugins were not tried on 3.14t, wherepylibjpeg-libjpeghas no wheel.The signed arm is measured unreachable for JPEG Baseline and Extended (
.50/.51), whose decode is not sign-extended at all.693_J2KR.dcmfrom pydicom’s test data (a signed JPEG 2000 codestream) readsint16 [-2000, 2492]identically through Pillow and throughimagecodecs, and writes no row.An unsigned JPEG 2000 codestream under PixelRepresentation 1 is sign-extended at the codestream’s own precision. Measured at BitsStored 12, 13 and 16, it reads
int16 [-1996, 1470]on both routes, with no row.12-bit JPEG Extended decodes through
imagecodecs.jpeg_decodevalue for value as DCMTK decodes pydicom’sJPEG-lossy.dcm.
DicomExporter.write_tree() and session.export()#
The patient, study and series tags written over each instance’s own are the same on both write paths. Equipment comes from the instance, which is what anonymize() edits, and so does Study Time. Neither path writes Study.study_time, and an instance with no Study Time of its own is written with an empty one (#953). Both paths run the same Type 1 check (IODValidator, CT, MR and PET Image Storage only). session.export() withholds a failing instance with an ERROR row, and write_tree() raises RuntimeError. write_tree() applies none of the export’s gates (redaction zones, the nested-icon drop, the de-identification markers). It is the serializer that the fixture generators in scripts/ use.
Configuration and storage internals#
The user guides describe behaviour. The names behind it are here.
Profiles.
basic@2026cisprofiles.BASIC_PROFILE(649 rules, frozen for 1.x, andtests/test_profile_editions.pypins its digest). The floor isprofiles.FLOOR_POLICY, the same table with the three research defaultscreate_config()writes. Resolution of a file’sprivacy_profilelives inconfig_manager._resolved_policy, not inprofiles.py.The 65534-byte limit on held binary values is
io_handlers.BINARY_RETENTION_MAX_BYTES, the largest value an explicit-VR 16-bit length field can carry.io_handlers._retention_limit_for(tag)reads it at the two retention gates and in the drop row. It returnsLUT_RETENTION_MAX_BYTES(393216) for the pixel lookup tables inLUT_DATA_TAGS(#902), and the 65534 limit for everything else. Two other readers read the constant directly: the odd-groupSCAN_GAPsize test, and the #692UN-decode pre-check, which never decodes a LUT tag.Why large private values are not stored. Holding a megabyte vendor blob in
attributesmakes it permanently resident. Memory scaling on 100GB+ datasets depends on heavy arrays never being resident by default. The cap bounds what retention can cost per element. Routing large values to the sidecar instead means giving private tags an offset/length representation that the EAV table does not have, plus a lazy loader and an export re-merge path.session.compact()rewrites the sidecar and rewires every offset it knows about. So a class of offset it does not know about is silent corruption after the first compaction.compact()also holds the sidecar gate for the whole rewrite, so any writer of such an offset would have to take that gate too. Andcompact()refuses outright while aredact()oringest()pass is open. That is design work, not a flag (#125).Data-loss rows are read with
session.store_backend.get_audit_losses(). The compliance report’s section 3.1 is the user-facing view.
Mechanisms behind the API#
The API reference describes what a caller sees. The mechanisms behind four of those descriptions are here.
ingest() and a worker that dies. When a worker process ends while
reading a file (the out-of-memory killer, a decoder crash, SIGKILL),
the results already returned are kept. The files not yet returned are
read again one at a time on a fresh one-worker process pool. A file is
rejected only when a fresh worker ends on it as the first file it was
given. The reason is “An ingest worker process ended before this file
was returned, and a fresh worker process given this file alone, as its
first file, ended while reading it”. The rest are read at full width,
the call saves as usual, and the session’s pool is replaced. A death
that does not recur costs no file and writes no row. A WARNING log
line records it. If two fresh workers in a row cannot run a trivial
task, every file left is rejected as “Not read” and the call returns. A
worker that ends on a later file had read others first, so that file is
not blamed. Reading starts again from that file on another fresh worker.
Each worker death costs a fresh pool, a few tenths of a second. A fatal
file costs two or three, and up to 2 x ISOCENTER_MAX_WORKERS + 1 files
read one at a time.
compact(), ingest() and redact() locks. Every frame writer, and
compact() for the whole rewrite, holds the sidecar lock
(<sidecar>.lock, a cross-process fcntl.flock). A writer that cannot
take it within 180 s raises RuntimeError naming the lock file. An
ingest or a redaction pass holds the pass-lock (<sidecar>.pass.lock)
shared for the whole pass. compact() takes the pass-lock exclusively
and without waiting, which is how compact() refuses while a pass is
open. Neither file name is frozen.
redact(force=). An instance is skipped as already redacted when its
_ISOCENTER_REDACTION_HASH attribute matches the configuration’s zones.
force=True ignores the match. A failed instance gets no hash.
Instance.unload_waveform_data(). It unloads only when the instance
has a _waveform_loader (set when the store holds the samples), because
get_waveform_data() has no file fallback.