Configuration API#
A session’s configuration is session.configuration, an
IsocenterConfiguration. load_config() fills it from a YAML file.
The methods below change it in memory, and save() writes it back.
The file format is on Configuration. The class,
its fields and these six methods are frozen at 1.0
(API stability).
- IsocenterConfiguration(rules: List[Dict[str, Any]] = list(), phi_tags: Dict[str, Any] = ..., date_jitter: Dict[str, int] = ..., remove_private_tags: bool = True, config_path: str | None = None, privacy_profile: str | None = None, auto_save: bool = False)#
The configuration a session applies, reached as
session.configuration.load_config()fills it from a file. The methods below change it in memory, andsave()writes it.Attributes:
Name
Type
Description
rulesList[Dict[str, Any]]
List of machine redaction rules.
phi_tagsDict[str, Any]
PHI tag policies, keyed by lowercase
"gggg,eeee"tag. With none given, it is a copy of the floor policy (profiles.FLOOR_POLICY). The floor policy is the PS3.15basic@2026cprofile plus three research defaults, and a session applies it before any configuration is loaded (see the Configuration guide). Each instance holds its own copy, so one session’sset_phi_tagcannot reach the policy of another session or the module table.date_jitterDict[str, int]
The range, in days, from which the per-patient date offset is derived. Both ends are included. The default is
{"min_days": -365, "max_days": -1}.remove_private_tagsbool
Global flag to strip private tags.
config_pathOptional[str]
The file that
save()writes.load_config()sets it, or you can set it by hand.auto_savebool
If True, every
add_rule,update_rule,delete_ruleandset_phi_tagwritesconfig_path. The default is False.privacy_profileOptional[str]
The pinned name of the built-in profile whose rules were merged into
phi_tags, or an external profile’s path, or None. The pinned name isbasic@2026c, also when the file saidbasic. None means that no named profile was applied: the floor, orprivacy_profile: none. It is only ever set to a profile that resolved.- save() None#
Write the configuration to
config_pathas YAML.The file names the profile and does not copy the profile’s rules.
privacy_profileis the pinned name (basic@2026c), the external profile’s path ornone. For the floor, the file has noprivacy_profileline.phi_tagsholds only the rules that differ from the rules of that base.Then the file holds
date_jitter,remove_private_tagsand every machine rule, with each key kept (comment:as data).versionis always written, as this library’s configuration version. A file that this method writes loads to the configuration that it was written from.This method writes a new file, so it does not keep the comments and layout of an existing file.
- Raises:
ValueError – If there is no
config_path. Ifphi_tagshas no rule for a tag that its base supplies, because a file that names that base would bring the rule back on reload. Ifdate_jitteris a range that the loader would refuse (#731). Ifconfig_pathis a file that declares a newerversionminor than this library’s (#784). Ifburned_in_textholds a policy that the loader would refuse in a file (#1108). In each case, nothing is written.OSError – The write’s own error, unchanged.
- add_rule(serial_number: str, manufacturer: str = 'Unknown', model_name: str = 'Unknown', redaction_zones: List[Any] = None) None#
Add a machine redaction rule.
It replaces any existing rule for the same serial number. It changes memory, and it writes
config_pathonly whenauto_saveis on. The keywords have the same spelling as the rule’s keys in amachines:file.- Parameters:
serial_number (str) – The device serial number.
manufacturer (str, optional) – Metadata for reference.
model_name (str, optional) – Metadata for reference.
redaction_zones (List[Any], optional) – The zones to set to zero. Each zone is
[y1, y2, x1, x2]in pixels: rowsy1up toy2and columnsx1up tox2, with the end excluded. A zone with no area (y2 <= y1orx2 <= x1) makesredact()fail that instance. A zone that starts past the image’s edge is skipped.
- Raises:
ValueError – For a rule that
load_configwould refuse (a serial that is not a non-empty, non-blank string, a metadata field that is not a string, a malformed zone), before any rule or the file changes. Also underauto_save, if there is noconfig_pathor ifsave()refuses. The rules are then as they were.OSError – Under
auto_save, when the write fails. The rules are then as they were.
- update_rule(serial_number: str, updates: Dict[str, Any]) None#
Update the rule for
serial_number.It changes memory, and it writes
config_pathonly whenauto_saveis on.- Parameters:
serial_number (str) – The target rule’s serial number.
updates (Dict[str, Any]) – Dictionary of fields to update.
- Raises:
ValueError – If no rule is found, if the update changes the serial number, or if
load_configwould refuse the updated rule (an unknown key such asredaction_zone, a value of the wrong type, a malformed zone). It is raised before the rule or the file changes. Also underauto_save, if there is noconfig_pathor ifsave()refuses. The rule is then as it was.OSError – Under
auto_save, when the write fails. The rule is then as it was.
- delete_rule(serial_number: str) bool#
Remove the rule for a serial number.
It changes memory. It writes
config_pathonly whenauto_saveis on and a rule was removed.- Parameters:
serial_number (str) – The serial number to remove.
- Returns:
True if a rule was found and removed, False otherwise.
- Return type:
bool
- Raises:
ValueError – Under
auto_savewith noconfig_path(even when no rule matches), and whensave()refuses.OSError – Under
auto_save, when the write fails. The rules are then as they were.
- set_phi_tag(tag: str, action: str, value: str = None, target: Sequence[str] = None) None#
Set or replace the PHI rule for one tag.
It changes memory, and it writes
config_pathonly whenauto_saveis on. A private-creator key can have twins: other keys of the policy that name its element under another case or spacing of its creator. This method sets the same rule on every twin too, because all of these keys name one element (#1147).- Parameters:
tag (str) – The DICOM tag to target (e.g. “0010,0010”), stored lowercase. A private creator’s name keeps its case, and its surrounding spaces are stripped.
action (str) – One of
KEEP,REMOVE,EMPTY,REPLACE,SHIFT,JITTER(JITTERisSHIFT) orSCRUB.value (str, optional) – The value that
REPLACEwrites. It is stored as the rule’svalue, the key that a file spells it with. An empty value, or another value that is false in Python (None,0,False), is no value, on every tag.value=""stores novaluekey, so on a UI tag the rule writes the keyed replacement UID. But a file’svalue: ''on a UI tag is refused (#883).target (Sequence[str], optional) – The kinds that
SCRUBremoves. It is stored as the rule’starget, the key that a file spells it with. It is a list or tuple ofconfig_manager.SCRUB_KINDS, kept in the order given. That order decides how a span that two kinds find is counted (#1130). OnlySCRUBtakes it, andSCRUBrequires it.
- Raises:
ValueError – For an unknown action, and for a rule the pipeline cannot honour: a Patient ID rule other than KEEP or REPLACE with no value, a Study or Series Instance UID rule other than KEEP or REPLACE with no value (#877), a
valueunder an action other than REPLACE, SHIFT/JITTER on a standard tag that is not DA or DT, REPLACE on a standard tag whose VR cannot hold the value,SCRUBwith notargetor on a tag that does not hold text, and atargetthat is not a list of distinct kinds or is given with another action. It is raised before the policy or its file changes. Underauto_save, it is also raised if there is noconfig_pathor ifsave()refuses. The policy is then as it was.OSError – Under
auto_save, when the write fails. The policy is then as it was.
- get_rule(serial_number: str) Dict[str, Any] | None#
Return the rule for a serial number: the rule dictionary itself, not a copy.
It compares the spelling exactly, and it returns the first match. Redaction does not use this method:
redact()and the export apply every matching rule,"*"included. Amatch:rule (#1108) has no serial, and this method does not return one, andupdate_ruleanddelete_ruledo not see one either. Write amatch:rule in the file, or append it torules.- Parameters:
serial_number (str) – The serial number to find.
""finds the rule for series with no Device Serial Number.- Returns:
The rule dictionary if found, else None.
- Return type:
Optional[Dict[str, Any]]