PyrateShield 3
A radiation shielding dose-rate calculator for hospital environments (radiology and nuclear medicine).
Introduction
PyrateShield is a Python application that performs radiation shielding calculations for nuclear medicine and radiology departments in hospitals. The application has a user-friendly graphical interface; no Python coding or command-line interaction is needed.
The application is intended to calculate the (necessary) radiation shielding in entire radiology and nuclear medicine departments. Nuclear medicine sources, CT sources, and X-ray sources can be defined and positioned on a floorplan in the GUI. Walls with defined thickness and material can be drawn and radiation dose rate can be visualised as a colour heatmap with isodose contour lines on the floorplan. Critical points can be added to calculate the exact dose rate at specific locations. Critical point results can be exported to Excel.
Intended users
Medical physicists and radiation protection officers working at a nuclear medicine or radiology department in a hospital.
Installation
Install PyrateShield from PyPI:
pip install pyrateshield
pyrateshield
Alternatively, install the latest source code directly from Codeberg:
git clone https://codeberg.org/MedPhysNL/Pyrateshield.git
cd Pyrateshield
pip install .
pyrateshield
Requires Python 3.10+.
Using PyrateShield
Menu bar
Commands live in the menu bar at the top: File, Edit, View, Tools and Help. Each menu shows the keyboard shortcut for the commands that have one.
| Menu | Contents |
|---|---|
| File | New, Open, Open Example (the bundled example projects), Save, Save As, Floorplan & Scale…, Export Canvas as Image, Export Report (.xlsx), Exit |
| Edit | Undo (Ctrl+Z), Redo (Ctrl+Y / Ctrl+Shift+Z), Copy, Paste, Delete Selected |
| View | Show Labels (L), Snap to Grid (G), Zoom In, Zoom Out, Fit to Window, Fill Window |
| Tools | Shielding Calculator, Isotope Reference, YAML editor, Project Notes, Settings |
| Help | Documentation (F1), About PyrateShield |
Show Labels and Snap to Grid are checkboxes showing the current state; both are stored in the project.
Canvas tools
Everything that puts the canvas into a mode lives in the tool strip along the left edge of the drawing area. Only one is active at a time. Clicking an active placement tool again returns to Select.
| Tool | Key | Description |
|---|---|---|
| Select | V | Select and move items |
| Pan | H | Click and drag to pan the canvas |
| Zoom to area | Z | Drag a rectangle to fit that region |
| Wall | W | Click and drag to draw a wall |
| NM Source | N | Click to place a nuclear medicine source |
| CT Source | C | Click to place a CT source |
| X-ray Source | X | Click to place an X-ray source |
| Critical Point | P | Click to place a critical evaluation point |
| Ruler | R | Draw a ruler over a known distance for scale calibration |
Canvas navigation:
- Scroll wheel — zoom in/out (anchored to the mouse cursor)
- Ctrl+scroll — fine zoom
- Two-finger trackpad scroll — pan
- Trackpad pinch — zoom in/out on macOS and supported Wayland compositors
- Space+drag or Alt+drag — temporary pan in any mode
- Middle mouse drag — pan
- Ctrl++ / Ctrl+- — zoom in / out, centred on the view
- Ctrl+0 — fit the whole floorplan in the window
- Ctrl+Shift+0 — fill the window with the floorplan, cropping the side that overflows
- Escape or right-click — cancel the current placement / deselect
- L — show or hide labels
- G — toggle grid snapping
- Delete / Backspace — delete the selected item(s)
The zoom buttons in the lower-right corner of the canvas duplicate zoom in, zoom out, fit and fill. A full list of key bindings is in the Keyboard Shortcuts page of the Documentation window (F1).
Floorplan and scale
A typical project starts by loading a floorplan image. Floorplan images are bitmaps and carry no scale information, so the pixel size (real-world length in cm per pixel) must be set before placing objects. PyrateShield can also be used without a floorplan, drawing on a blank canvas.
Both are done in the Floorplan & Scale window, opened from File → Floorplan & Scale…. It opens automatically for a new project, and stays above the main window so the canvas remains usable while it is open.
Ruler calibration (the usual route): draw a ruler on the canvas over a feature whose real length you know, enter that length, and click Apply calibration. All existing coordinates are rescaled, so nothing moves on the canvas. A newly drawn ruler is selected in the window automatically, and the distance box shows the ruler's current length — reopening a calibrated project shows the distance it was calibrated with.
Direct entry: type the pixel size directly under Direct entry (advanced). This takes effect immediately.
Left panel — item properties
On the left side of the interface a panel displays the PyrateShield objects of one kind at a time. The icon rail selects which: walls and shieldings, the three source types, critical points, and rulers — the same six kinds as the placement tools, in the same order. Selecting an object on the canvas switches to its panel automatically.
NM Sources
Select the NM Source tool (N) and then click on the floorplan to place a new nuclear medicine source.
| Property | Description |
|---|---|
| Name | Name of the source |
| Isotope | Radionuclide |
| Activity (MBq) | Source activity in MBq |
| Duration (h) | Duration for which the source (or patient) is present in the room |
| No. of exams/week | Number of exams performed per week |
| Apply decay correction | Correct for physical decay during the exam duration |
| Clearance model | Biological clearance model (see Clearance section) |
| Self-shielding | Patient self-shielding: None, Body, or Factor. The two engines model Body differently — the Pre-computed engine uses a separately simulated LUT with the source inside a 15 cm-radius water sphere; the Point Kernel engine adds a uniform 20 cm water layer to every path. Neither depends on the project's material list. |
| SS factor | Manual self-shielding correction factor (shown when Self-shielding is set to Factor) |
| Occupancy factor | Fractional occupancy correction (use 1 to apply no correction) |
| Enabled | When unchecked the source is excluded from all calculations |
The Activity graph ↗ button opens a graph showing the source activity as a function of time, including the effect of physical decay, biological clearance, and the decay correction toggle. A vertical line marks the configured Duration.
The View isotope spectrum ↗ button opens the Isotope Browser focused on the selected isotope.
Clearance
Clearance models are optional and are mainly used to represent therapy patients who stay overnight in a nuclear medicine therapy facility. The model corrects for biological excretion of radioactivity.
The model can be mono-exponential or bi-exponential. Physical decay is always applied (if the decay correction option is checked on the NM source). The two exponentials can be split by fraction or by time. When split by fraction and the fractions do not sum to 1, the remainder is assumed to be cleared only by physical decay. When split by time, the first exponential is integrated from zero to the split time and the second from the split time onward; integration always ends at the source duration. By default a set of clearance models is included as prescribed by the Dutch guidelines (Werken met therapeutische hoeveelheden radionucliden).
| Property | Description |
|---|---|
| Name | Name of the clearance model |
| Fraction 1 | Fraction (0–1) for the first exponential |
| Half-life 1 (h) | Biological half-life for the first exponential |
| Fraction 2 | Fraction for the second exponential. Derived, not entered: it is always 1 − Fraction 1, so the field is shown but not editable |
| Half-life 2 (h) | Biological half-life for the second exponential |
| Split fractions by time | Time at which the two exponentials split; when enabled, both fractions are treated as 1 |
CT Sources
CT scatter dose is calculated using the scatter model from Wallace et al. (2012), extended with direction-dependent scatter fractions. Three angular sectors are defined relative to the gantry orientation:
| Sector | Angle from front | Body (μGy/(mGy·cm)) | Head (μGy/(mGy·cm)) |
|---|---|---|---|
| Front (patient table side) | 0–70° | 0.36 | 0.14 |
| Gantry ring (lateral) | 70–130° | 0.04 | 0.014 |
| Rear (electronics) | 130–180° | 0.30 | 0.14 |
The CT marker on the canvas is a T-shaped symbol: the stem indicates the front of the scanner (patient table side) and points in the direction of the gantry angle; the crossbar represents the rear of the gantry ring.
Select the CT Source tool (C) and then click on the floorplan to place a source.
| Property | Description |
|---|---|
| Name | Name of the source |
| kVp | Tube voltage (120 or 140 kVp) |
| Body part | CTDI phantom: Body or Head |
| Patients/week | Number of patients scanned per week |
| DLP/exam (mGy·cm) | Dose–length product per exam |
| Occupancy factor | Fractional occupancy correction |
| Gantry angle (°) | Direction the patient table faces, measured counter-clockwise from East (+X). Adjustable via spinbox or slider; the T marker on the canvas updates in real time |
| Enabled | When unchecked the source is excluded from all calculations |
All Archer-equation parameters and scatter fractions are visible under Reference data → Archer Parameters in the Documentation window, with full literature references.
X-ray Sources
X-ray scatter dose is calculated using the secondary scatter model from NCRP Report 147, Figure C.1.
| Property | Description |
|---|---|
| Name | Name of the source |
| kVp | Tube voltage |
| Patients/week | Number of patients per week |
| DAP/exam (Gy·cm²) | Dose–area product per exam |
| Scatter fraction | Fraction of primary dose converted to scatter at 1 m, 90° |
| Occupancy factor | Fractional occupancy correction |
| Enabled | When unchecked the source is excluded from all calculations |
Walls
Draw a wall by selecting the Wall tool (W), then click-and-drag on the floorplan. Each wall has a shielding preset assigned to it.
| Property | Description |
|---|---|
| Name | Name of the wall |
| Shielding | The shielding preset assigned to this wall |
| X1, Y1, X2, Y2 | End-point coordinates in cm |
| Enabled | When unchecked the wall is excluded from all calculations |
When multiple walls are selected, the multi-wall panel shows additional bulk actions: Apply shielding to all selected, Enable all, and Disable all.
Right-clicking on a selected wall endpoint opens a context menu with additional options:
| Action | Description |
|---|---|
| Delete | Delete the selected wall |
| Continue wall here | Continue drawing from this wall endpoint |
| Snap to | Snap this endpoint to the nearest wall endpoint within range |
Endpoint snapping: wall and ruler endpoints automatically snap to nearby endpoints within 14 px; a green ring indicator appears when snapping is active.
Grid snapping: press G to toggle snap-to-grid with a configurable pitch (set in the Settings dialog).
Shieldings
Shieldings are presets consisting of one or two material layers with defined thicknesses. They are assigned to walls. Changing a shielding definition updates all walls that use it immediately.
| Property | Description |
|---|---|
| Name | Name of the shielding |
| Material 1 | First material (set to None to disable) |
| Thickness 1 (cm) | Thickness of the first material layer |
| Material 2 | Second material (set to None to disable) |
| Thickness 2 (cm) | Thickness of the second material layer |
| Colour | Display colour for walls with this shielding |
| Linewidth (pt) | Display line width for walls with this shielding |
Click Add to create a new shielding definition or Delete to remove the selected one. A shielding can only be deleted when no walls are currently using it.
Materials
The Materials section shows the properties of all available materials and how they are mapped to the two calculation engines. Materials can be added or modified to a limited extent.
| Property | Description |
|---|---|
| Name | Name of the material |
| Density (g/cm³) | Material density |
| Att. table | Attenuation table (µ/ρ) used by the Point Kernel engine — dropdown listing available sheets from attenuation.xlsx |
| Buildup table | Buildup factor table used by the Point Kernel engine — dropdown listing available sheets from buildup.xlsx |
| MCNP material | Material used by the Pre-computed (MCNP) engine — Water, Lead, Concrete, Concrete-Barite, Gypsum, Brick or Tungsten; None makes this material transparent to that engine |
| CT material | Lead or Concrete Archer reference used for CT barriers; None makes this material transparent to CT |
| X-ray material | Lead, Concrete, or Gypsum Archer reference used for X-ray barriers; None makes this material transparent to X-ray |
Modifying density is the most common use case: both engines handle user-defined densities by scaling the effective thickness. CT and X-ray each scale the physical thickness directly from the project material density to the density of their selected Archer reference.
A material can only be deleted when no shielding layer is using it, and a clearance model only when no source is using it — the same rule as for shieldings. Deleting a referenced item would leave the reference pointing at nothing, which the engines read as "no shielding" or "no clearance", so the wall or source would silently stop being modelled as drawn.
The Materials pane also provides buttons to save unmodified copies of the
Point Kernel attenuation and buildup workbooks and the CT/X-ray Archer
constants.yml file for inspection and project documentation.
Rulers
Draw a ruler by selecting the Ruler tool (R), then click-and-drag on the floorplan. Rulers can be named and managed in the Rulers panel. Use Locate beside the calibration ruler selector, or double-click a ruler in the Rulers pane, to centre and temporarily highlight it on the canvas. The same Locate button and double-click behaviour is available in the NM, CT and X-ray source lists and in the Critical Points pane.
| Property | Description |
|---|---|
| Name | Optional label shown on the canvas alongside the measurement |
| Length | Computed length in cm (read-only) |
| p1 x, p1 y | Start point coordinates in cm |
| p2 x, p2 y | End point coordinates in cm |
Critical points
Select the Critical Point tool (P) and then click on the floorplan to place a critical evaluation point.
| Property | Description |
|---|---|
| Name | Name of the critical point |
| Occupancy factor | Fractional occupancy correction (use 1 to apply no correction) |
| Position | Position in cm on the floorplan |
| Enabled | When unchecked the point is excluded from the critical point report |
Right panel — calculation and display
The right panel controls the calculation engines, dosemap styling, and displays results.
Engine selection and dosemap calculation
Select either Pre-computed (MCNP) or Point Kernel and click Calculate to run the dosemap. Progress is reported live. Grid resolution (nx × ny) and the number of parallel worker threads can be configured in the Settings dialog.
The engine choice applies to NM sources only. CT and X-ray sources are computed with the same Archer scatter model whichever engine is selected, so switching engines does not change their contribution.
Dosemap style
| Option | Description |
|---|---|
| Colormap | Colour scale (jet, hot, viridis, plasma, inferno, YlOrRd, RdYlBu_r) |
| Min / Max (mSv) | Dose range for the colour scale |
| Log scale | Use a logarithmic colour scale |
| Opacity | Transparency of the dosemap overlay |
| Alpha gradient | Fade out low-dose regions for clarity |
| Show legend | Display the colour scale bar |
| Show contours | Overlay isodose contour lines |
Isodose contours
The contour table lets you define any number of isodose levels, each with its own colour, line style (solid, dashed, dotted, dashdot), line width, and an enable/disable toggle.
Critical point report
After running a calculation, the critical point table shows the interpolated dose rate at each enabled critical point, including the occupancy-corrected value. Click any row to see a per-source dose breakdown (using the currently selected engine) in a summary label below the table. Selected rows can be copied directly into a spreadsheet with Ctrl+C (Cmd+C on macOS), or with the table's right-click Copy action. Use Export to Excel to save the full report, which includes a CP Breakdown sheet with per-source contributions at each critical point for both engines side by side.
Note: the table does not update automatically. After modifying the project, recalculate explicitly by clicking Calculate again.
Floating tool windows
The following tool windows are opened from the Tools menu and stay open alongside the main window:
- Isotope Browser — decay data, gamma spectra, transmission curves through all shielding materials, and H*(10) dose rate constants for all supported isotopes. Both the Pre-computed (MCNP) and Point Kernel results are shown.
- Shielding Calculator — point-kernel transmission calculator for a user-defined stack of material layers; useful for quick checks and for comparing Point Kernel and Pre-computed (MCNP) results.
- YAML editor — view and live-edit the current project as raw YAML text. Changes are validated against the project schema before being applied. Useful for bulk edits and for copy-pasting configurations between projects.
- Project Notes — a free-text notes field (Markdown, with preview) attached to the project file.
- Floorplan & Scale — opened from File → Floorplan & Scale…. Loads or removes the floorplan image and calibrates the pixel size. Unlike the other tool windows it stays above the main window, since calibrating means drawing a ruler on the canvas while it is open.
- Documentation (F1) — user manual, keyboard shortcuts, calculation methods, read-only physics parameters and tables, and Point Kernel sources and provenance, organised with navigation by subject.
- About PyrateShield — version and developer contacts, Safety & Disclaimer, Limitations, and Open-source Licences. Its About page also links directly to Documentation.
- Activity graph — opened via the Activity graph ↗ button in the NM Sources panel. Shows the source activity as a function of time for the selected source, including physical decay, biological clearance components, and the effect of the decay correction toggle.
Developer notes
Subprocess isolation — worker process state
Calculations run in persistent subprocesses managed by ProcessPoolExecutor
pools in app/calc_worker.py. Workers are started with the spawn context
(multiprocessing.get_context("spawn")) on all platforms. This means:
- Workers start as fresh Python interpreters — no inherited file descriptors, no fork-related issues on Linux, and consistent behaviour with Windows (which has always used spawn).
- Each worker process has its own independent copy of every module's global state, completely separate from the main process. This has one important consequence that is easy to miss:
Any module-level configuration set in the main process is invisible to the workers.
The concrete case is physics/isotope_data.py, which exposes a _config
object (set by configure()) that controls spectrum filtering and line
grouping. Calling configure() in the main process does not affect the
workers — they start with default settings and never see changes unless
explicitly told.
The fix is to send a small task to each worker pool that calls configure()
and pre-warms the cache inside the worker process. This is implemented as
_configure_isotopes_worker() / _push_isotope_config_to_workers() in
calc_worker.py, called from init_pool() and from the settings-change
handlers in main_window.py and right_panel.py.
Rule of thumb: if you add global state to any module used by the engine,
and that state needs to match between the main process and the workers, you
must propagate it explicitly via a task submitted to every slot pool — the
same pattern used by _push_isotope_config_to_workers.
References
[1] Shimizu A, Onda T, Sakamoto Y. Calculation of gamma-ray buildup factors up to depths of 100 mfp by the method of invariant embedding, (III) Generation of an improved data set. J Nucl Sci Technol 41: 413–424; 2004.
[2] Wallace AB et al. Establishment of scatter factors for use in shielding calculations and risk assessment for computed tomography facilities. J Radiol Prot 32(4): 389–402; 2012.
[3] NCRP Report No. 147. Structural Shielding Design for Medical X-Ray Imaging Facilities. 2004.
[4] Simpkin DJ. Shielding requirements for CT facilities. Health Phys 58(3): 363–367; 1990.
[5] Simpkin DJ. Transmission data for shielding diagnostic x-ray facilities. Health Phys 68(5): 704–709; 1995.
[6] Harima Y, Sakamoto Y, Tanaka S, Kawai M. Data Library of Gamma-Ray Buildup Factors and Its Application to Calculation of Transmission Function. JAERI-M 87-210; 1988. Table 3.5.
[7] Stettner C, Hranitzky C, Poljanc K, Strebl F, Streli C. Catalogue of dose rate constants for more than 400 radionuclides in terms of ambient dose H* and comparison of figures to ambient dose equivalent H*(10). Appl Radiat Isot 184: 110159; 2022.
License and disclaimer
PyrateShield is licensed under the Apache License 2.0 and is provided without warranties or conditions of any kind. Before using the software or its results, read the full Safety and liability notice.
Bundled dependencies and assets remain under their respective licences. See the third-party notices and the LGPL corresponding-source offer, particularly for Qt and PySide6 redistribution information.
Maintainers preparing binaries must follow the legal inventory checklist in RELEASING.md.
Contact
Developers: Marcel Segbers (m.segbers@erasmusmc.nl) Rob van Rooij (r.vanrooij-3@umcutrecht.nl)
Special thanks: Maxime Imperatori — CT directional scatter model (maxime.imperatori@mumc.nl) Claude (Anthropic) — v3 rewrite and code architecture
Metadata
Release files for pyrateshield 3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyrateshield-3.2.tar.gz | 2.2 MB | Without provenance | Details for pyrateshield-3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyrateshield-3.2-py3-none-any.whl | Python 3 | none | any | Details for pyrateshield-3.2-py3-none-any.whl |
Total release size: 4.3 MB
Release files / pyrateshield-3.2.tar.gz
| Download URL | pyrateshield-3.2.tar.gz |
|---|---|
| Size | 2.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
593e6c61157f54793ba2250601412b1f2399ef9ccd3593195d0c0acf05493213
|
|
BLAKE2b-256 checksum How to use checksums |
d764b88e510c9a011b8560aac274b6790bbdb23e02eafc7829d004c46c12c759
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Release files / pyrateshield-3.2-py3-none-any.whl
| Download URL | pyrateshield-3.2-py3-none-any.whl |
|---|---|
| Size | 2.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f2cf35029bfbeae7620529739b83539ef586101c6b78a6624f411d6513b597f
|
|
BLAKE2b-256 checksum How to use checksums |
188428da4286629a3fafea47fa264612d25af364905ca8ecdba7dc8f46004b29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Security for pyrateshield 3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.