This release is a pre-release and may not be stable for production use.
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
Compiled binaries and a PyPI package are planned for a future release. For now, install from source:
git clone https://codeberg.org/MedPhysNL/Pyrateshield.git
cd Pyrateshield
pip install .
pyrateshield
Requires Python 3.10+.
Using PyrateShield
Toolbar
At the top of PyrateShield is a toolbar with icons. File operations, editing actions, and item placement are all started from the toolbar.
| Item | Description |
|---|---|
| New | Start a new, blank PyrateShield project |
| Open | Load a PyrateShield project file (.zip) from disk |
| Save | Save the current project to disk |
| Save As | Save the current project to disk under a new filename |
| Load Image | Load a bitmap image as the floorplan background |
| Snapshot | Export the current canvas view (with dosemap overlay) as a PNG or JPEG image |
| Undo | Undo the last action (Ctrl+Z) |
| Redo | Redo the last undone action (Ctrl+Y / Ctrl+Shift+Z) |
| Delete | Delete the selected item(s) from the floorplan and project |
| Show/hide labels | Toggle source and ruler name labels on the canvas (L) |
| Wall | Draw a new wall on the floorplan (click and drag) |
| NM Source | Click on the floorplan to place a new nuclear medicine source |
| CT Source | Click on the floorplan to place a new CT source |
| X-ray Source | Click on the floorplan to place a new X-ray source |
| Critical Point | Click on the floorplan to place a new critical evaluation point |
| Ruler | Draw a ruler over a known distance for scale calibration |
| Calculator | Shielding transmission calculator — inspect a single material/thickness quickly |
| Isotopes | Open the Isotope Browser (decay data, gamma spectra, transmission curves) |
| YAML editor | View and edit the current project as raw YAML text |
| Notes | Open the project notes editor (supports Markdown preview) |
| About / Help | Open the About / Help window — version info, safety notice, user manual, keyboard shortcuts, physics parameters, limitations, and licences (F1) |
Canvas navigation:
- Pointer button (lower right) — select and move canvas items
- Hand button (lower right) — activate persistent click-and-drag panning
- Area-zoom button (lower right) — drag a rectangle to fit that region
- Scroll wheel — zoom in/out (anchored to mouse cursor)
- Two-finger trackpad scroll — pan
- Trackpad pinch — zoom in/out on macOS and supported Wayland compositors
- Ctrl+scroll — fine zoom
- Space+drag or Alt+drag — temporary pan in any mode
- Middle mouse drag — pan
- L — toggle labels
Left panel — item properties
On the left side of the interface a panel displays all PyrateShield objects. Select an object in the list to inspect or modify its properties.
Scale
A typical project starts with loading a floorplan image. Floorplan images are loaded as bitmap images and carry no scale information. The pixel size (real-world length in cm per pixel) must be set before placing objects.
Set manually: enter the pixel size directly in the Scale panel and click Confirm.
Ruler calibration: draw a ruler over a feature of known length, then enter the known distance in the Scale panel to compute the pixel size automatically.
Any change to the pixel size only takes effect after clicking Confirm.
NM Sources
Click the NM Source toolbar button 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 (MCNP water sphere), or Factor |
| 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 (0–1) for the second exponential |
| 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.
Click the CT Source toolbar button 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 in the Physics Parameters tab of the About / Help 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 clicking the Wall toolbar button, 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 — dropdown listing the materials available in the LUT |
| 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.
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 clicking the Ruler toolbar button, 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
Click the Critical Point toolbar button 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.
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 can be opened from the toolbar 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.
- About / Help (F1) — tabbed reference window: About (version and
developer contacts), Safety & Disclaimer, User Manual (this README
rendered as HTML), Keyboard Shortcuts, Implementation notes, Physics
Parameters (
constants.yml— Archer-equation and scatter-fraction parameters for the CT and X-ray models, with full literature references), Limitations, and Open-source Licences. - 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.2rc1
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.2rc1.tar.gz | 2.0 MB | Without provenance | Details for pyrateshield-3.2rc1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyrateshield-3.2rc1-py3-none-any.whl | Python 3 | none | any | Details for pyrateshield-3.2rc1-py3-none-any.whl |
Total release size: 3.9 MB
Release files / pyrateshield-3.2rc1.tar.gz
| Download URL | pyrateshield-3.2rc1.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
485c49c69827f1d57821542421b22e2855da8dddb6084d26b3b48041ff33978c
|
|
BLAKE2b-256 checksum How to use checksums |
47aee3d8f80476be09e326f8f55cfb55ce9f9ca8f94021e2bcfaa9bc57da792b
|
| 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.2rc1-py3-none-any.whl
| Download URL | pyrateshield-3.2rc1-py3-none-any.whl |
|---|---|
| Size | 1.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36bf141678dab2e8c638db8dd6767c1ba7878e3efeb112237df9c9b89eb29597
|
|
BLAKE2b-256 checksum How to use checksums |
4a97e5a42410dd7c31597a91f82e481eef968f4b537f281ac58c336f5d6752ee
|
| 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.2rc1
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.