Exporter registry#
Provisional
The exporter registry (Exporter, register(), get_exporter(),
available_formats()) is provisional until 1.1. It is documented
but internal (see API stability).
Version 1.1 may replace these four names rather than extend them, with a
Breaking CHANGELOG entry that names both spellings. A plugin written against 1.0
should pin isocenter>=1.0,<1.1.
session.export(folder, format=...) finds the exporter registered for
format in this registry, and calls it. The two built-in formats, dicom and
wfdb, register themselves when isocenter.exporters is imported, which
session.export() does. Anything else
can be registered too:
from isocenter import exporters
class AcmeExporter(exporters.Exporter):
def export(self, session, folder, **options):
written = []
# ... write files under `folder`, reading the graph, never changing it
return written
exporters.register("acme", AcmeExporter)
print(exporters.available_formats()) # ['acme', 'dicom', 'wfdb']
What a third-party exporter receives#
The session’s graph and nothing else. That graph is not what the
built-in formats write. Every export-time gate lives inside the built-in
formats, and some of them change pixels and sequences on the way out.
Before it dispatches, export() itself runs no gate. It clears the
counts of the last export, which the report’s Instances Written row
reads. It finds the exporter for format in the registry. For an
exporter other than the two built-in classes, it writes one WARNING
audit row (see the next section) and logs the same text. So for any
exporter other than the two built-in classes, none of the following
runs:
The burned-in re-audit that withholds an instance still carrying an identifier (
check_burned_in).The configured redaction zones. The DICOM export reads each series’ zones from the configuration in force. It applies them to a copy of every frame it writes, whether or not
redact()ran. For a plugin,instance.get_pixel_data()holds only whatredact()changed. With zones configured andredact()not run, the pixels are unredacted.The drop of nested icons. An Icon Image Sequence
(0088,0200)item is a downsampled copy of a frame, and nothing scans or redacts one. The DICOM export drops an instance’s own icon when its pixels are redacted or have zones configured. It drops every other nested icon when any instance in the store is redacted, or any configured zone matches a series in the store. A plugin that copiesinstance.sequencesships a thumbnail of what redaction removed, even afterredact()ran.The recoverable-identity disclosure (
check_reversibility). Afterlock_identities(), the graph still carries the encrypted identity token at(0400,0500).The de-identification markers
(0012,0062),(0012,0063)and(0028,0303), which Isocenter decides per instance at export time and never puts in the graph.The filter on
attributeskeys. The DICOM writer writes only keys shapedgggg,eeeeand drops every_-prefixed bookkeeping key. One of those,_ISOCENTER_SOURCE_SOP_UID(entities.SOURCE_SOP_UID_ATTR), holds the source SOP Instance UID that UID replacement removed. A plugin that walksinstance.attributeswrites it.The owner stamps:
(0010,0010),(0010,0020),(0008,0020),(0020,000D)and(0020,000E)written from the patient, study and series rather than from an instance’s own copy.The rule for a subject with no Patient ID.
patient.patient_idcan be the synthetic key"\no-patient-id\<Study Instance UID>", andexported_patient_id()is the only reader for output.The
patient_ids/subsetcounting and the stale-policy notice, and theEXPORTand export-timeDATA_LOSSaudit rows.
How the report treats a third-party export#
Each run of an exporter that is not one of the two built-in classes writes
one WARNING audit row before export() calls the exporter. The row
names the format and the class, and says that Isocenter does not attest
the exporter’s output. The row is written even when the exporter then
raises.
So in 1.0, no third-party export grades PASS. A WARNING row grades
the report REVIEW_REQUIRED (condition 2 in
How the grade is decided),
however the plugin behaves. Isocenter writes no EXPORT row for a
third-party export. So the same report also carries the “generated
before any export” note, unless the store already holds an EXPORT row.
An earlier dicom or wfdb export on the same store, in any session,
can have written one.
The class decides, not the format name or the module. A subclass of a
built-in, or a different class registered as dicom, is third-party.
DicomFormatExporter registered again, under any name, is not.
Running the format-independent gates in export() before dispatch, so a
plugin can grade PASS, is planned for 1.1
(#783).
Writing DICOM without the pipeline#
DicomExporter.write_tree() is the serializer alone. It writes a graph as
it stands. It applies the owner stamps and the no-Patient-ID rule, which
both write paths share. It also drops nested icons by the redaction
already recorded on the graph. It drops an instance’s own icon when that
instance was redacted, and every other icon when any instance that it
writes was redacted. This half of the gate needs no configuration.
write_tree() also runs the export’s Type 1 check, which covers CT, MR
and PET Image Storage only. It raises RuntimeError for such an
instance that is missing one of the elements the check covers, or holds
it empty
(What the export changes on the way out).
It applies none of the rest: no burned-in
re-audit, no redaction zones, no patient_ids or subset selection, no
recoverable-identity disclosure, no de-identification markers, no notices,
and no EXPORT row. It writes DATA_LOSS rows only
to a store_backend you pass. Use session.export() to de-identify a
cohort. Use write_tree() for a graph you built by hand, with no session
behind it.
Reference#
Export format registry.
Each exporter writes a session’s in-memory object graph to files on
disk, in one output format. Each format registers itself here, and
session.export(folder, format=...) selects a format by its name.
- Exporter#
Interface every export format implements.
Provisional until 1.1. In 1.1, this interface may be replaced, not extended. A plugin written against 1.0 pins
isocenter>=1.0,<1.1.An implementation must not change the session’s object graph, because an export only reads it. For a class other than the two built-ins,
export()applies none of the built-ins’ gates before or after it calls the class. The Exporter registry page lists those gates under “What a third-party exporter receives”.export()also writes oneWARNINGaudit row, which says that Isocenter does not attest the output.- export(session, folder: str, **options)#
Write the session to
folder.- Parameters:
session (DicomSession) – The active session.
folder (str) – The output directory. It is created if it does not exist.
**options (dict) – Format-specific options.
- Returns:
The format’s own result object.
dicomreturns anExportSummary, andwfdbreturns aList[str]of paths. Whatever the shape, it must let a caller detect that nothing was written, for example by an empty list, a zero count or a raise.- Return type:
Any
- register(name: str, exporter_cls) None#
Register an export format under
name.Provisional until 1.1. This function checks only that
exporter_clshas anexportattribute, and 1.1 may check more.If you register any class other than the two built-ins, each export in that format writes one
WARNINGaudit row, because Isocenter cannot attest what the class writes. A subclass of a built-in is such a class too.- Parameters:
name (str) – The format name that
export(format=...)selects by. A registration under an existing name replaces the earlier one.exporter_cls (type) – A class whose instances have
export(session, folder, **options).
- Raises:
TypeError – If
exporter_clshas noexportattribute.
- get_exporter(name: str)#
Instantiate the exporter registered under
name.- Parameters:
name (str) – The format name, e.g.
'dicom'or'wfdb'.- Returns:
A new instance of the registered class.
- Return type:
- Raises:
ValueError – If no such format is registered.
- available_formats() List[str]#
Return the registered format names, sorted.
- Returns:
The names, sorted.
- Return type:
List[str]