Metadata-Version: 2.4
Name: guiskindose
Version: 1.1.0
Summary: Tools and script for calculating peak skin dose and create dose maps for fluoroscopic exams from RDSR data (fork of PySkinDose)
Author-email: Max Hellström <max.hellstrom@gmail.com>, Josef Lundman <josef@lundman.eu>
Maintainer: Kevin Grizzard
Project-URL: Homepage, https://github.com/kgrizz-git/GUISkinDose
Project-URL: Bug Tracker, https://github.com/kgrizz-git/GUISkinDose/issues
Project-URL: Documentation, https://github.com/kgrizz-git/GUISkinDose/tree/main/docs
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=2.2.3
Requires-Dist: numpy>=2.2.4
Requires-Dist: pydicom>=2.3
Requires-Dist: numpy-stl>=3.2.0
Requires-Dist: plotly>=4.13.3
Requires-Dist: scipy>=1.15.2
Requires-Dist: tqdm>=4.66
Requires-Dist: psutil>=5.9
Requires-Dist: pillow>=13.0.0
Requires-Dist: kaleido>=0.2.1
Requires-Dist: rich>=13.0
Requires-Dist: openpyxl>=3.1
Requires-Dist: pypdf>=6.20.1
Requires-Dist: reportlab>=4.0.4
Requires-Dist: python-docx>=1.1
Provides-Extra: gui
Requires-Dist: nicegui>=3.18.0; extra == "gui"
Requires-Dist: itsdangerous<3,>=2.1.2; extra == "gui"
Requires-Dist: pytest-asyncio>=0.24; extra == "gui"
Requires-Dist: certifi>=2026.10.19; extra == "gui"
Provides-Extra: gui-native
Requires-Dist: nicegui>=3.18.0; extra == "gui-native"
Requires-Dist: itsdangerous<3,>=2.1.2; extra == "gui-native"
Requires-Dist: pywebview; extra == "gui-native"
Requires-Dist: pytest-asyncio>=0.24; extra == "gui-native"
Requires-Dist: certifi>=2026.10.19; extra == "gui-native"
Provides-Extra: export
Requires-Dist: reportlab>=4.0.4; extra == "export"
Requires-Dist: python-docx>=1.1; extra == "export"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: sphinx-rtd-theme; extra == "docs"
Requires-Dist: pydata-sphinx-theme; extra == "docs"
Requires-Dist: myst-parser; extra == "docs"
Requires-Dist: nbsphinx; extra == "docs"
Requires-Dist: ipykernel; extra == "docs"
Requires-Dist: ipywidgets; extra == "docs"
Requires-Dist: pandoc; extra == "docs"
Requires-Dist: tornado>=6.6; extra == "docs"
Requires-Dist: nbconvert>=7.17.2; extra == "docs"
Provides-Extra: notebooks
Requires-Dist: jupyterlab>=4.6.2; extra == "notebooks"
Requires-Dist: ipykernel; extra == "notebooks"
Requires-Dist: ipywidgets; extra == "notebooks"
Requires-Dist: tornado>=6.6; extra == "notebooks"
Requires-Dist: nbconvert>=7.17.2; extra == "notebooks"
Provides-Extra: phantom-gen
Requires-Dist: trimesh>=4; extra == "phantom-gen"
Requires-Dist: fast-simplification; extra == "phantom-gen"
Requires-Dist: networkx>=3; extra == "phantom-gen"
Requires-Dist: scikit-image>=0.22; extra == "phantom-gen"
Provides-Extra: dev
Requires-Dist: PyYAML>=6; extra == "dev"
Requires-Dist: basedpyright>=1.23; extra == "dev"
Requires-Dist: defusedxml>=0.7.1; extra == "dev"
Requires-Dist: pandas-stubs>=2.2; extra == "dev"
Requires-Dist: types-Pillow; extra == "dev"
Requires-Dist: pip-audit>=2.7; extra == "dev"
Requires-Dist: bandit>=1.8; extra == "dev"
Requires-Dist: shellcheck-py>=0.11; extra == "dev"
Requires-Dist: pre-commit>=4.0; extra == "dev"
Requires-Dist: virtualenv>=21.14.13; extra == "dev"
Requires-Dist: filelock>=4.2.1; extra == "dev"
Requires-Dist: msgpack>=1.2.3; extra == "dev"
Requires-Dist: pytest<10,>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: pytest-xdist>=3.5; extra == "dev"
Requires-Dist: diff-cover>=10.0; extra == "dev"
Requires-Dist: ruff<0.18,>=0.15; extra == "dev"
Requires-Dist: playwright>=1.40; extra == "dev"
Requires-Dist: pytest-playwright>=0.4; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/kgrizz-git/GUISkinDose/main/src/guiskindose/gui/static/guiskindose_icon.svg" alt="GUISkinDose icon" width="96" height="96">
</p>

<h1 align="center">GUISkinDose</h1>

<p align="center">
  Peak skin dose and 3D skin dose maps for fluoroscopic X-ray procedures.
</p>

<p align="center">
  <a href="https://github.com/kgrizz-git/GUISkinDose/actions/workflows/ci.yml"><img src="https://github.com/kgrizz-git/GUISkinDose/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
  <a href="https://github.com/kgrizz-git/GUISkinDose/actions/workflows/dependency-audit.yml"><img src="https://github.com/kgrizz-git/GUISkinDose/actions/workflows/dependency-audit.yml/badge.svg?branch=main" alt="Dependency audit"></a>
  <a href="https://sonarcloud.io/summary/new_code?id=kgrizz-git_GUISkinDose"><img src="https://sonarcloud.io/api/project_badges/measure?project=kgrizz-git_GUISkinDose&amp;metric=alert_status" alt="SonarCloud quality gate"></a>
  <br>
  <img src="https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fkgrizz-git%2FGUISkinDose%2Fmain%2Fpyproject.toml&amp;logo=python&amp;logoColor=white&amp;color=3776AB" alt="Supported Python versions (from pyproject.toml)">
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0D9488" alt="MIT license"></a>
  <a href="https://nicegui.io"><img src="https://img.shields.io/badge/GUI-NiceGUI-4338CA" alt="NiceGUI"></a>
  <a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
  <a href="#intended-use-and-responsibility"><img src="https://img.shields.io/badge/use-research%20%2F%20QA%20only-831843" alt="Research and QA use only; not FDA-cleared"></a>
</p>

<p align="center">
  <a href="#quick-launch-gui">Quick launch</a> ·
  <a href="#installation">Installation</a> ·
  <a href="#headless-use">Headless use</a> ·
  <a href="docs/source/user/user_guide.md">User guide</a> ·
  <a href="CHANGELOG.md">Changelog</a> ·
  <a href="https://github.com/kgrizz-git/GUISkinDose/discussions">Discussions</a>
</p>

**Independently maintained fork** of [PySkinDose](https://github.com/rvbCMTS/PySkinDose).
Original author: Max Hellström. This fork is **not** an official or endorsed
PySkinDose release unless upstream maintainers say otherwise.

Current maintainer: [@kgrizz-git](https://github.com/kgrizz-git) — see
[SUPPORT.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/SUPPORT.md) and [GOVERNANCE.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/GOVERNANCE.md).

GUISkinDose estimates **peak skin dose (PSD)** and **3D skin dose maps** for
fluoroscopic X-ray procedures. Load a DICOM RDSR (or a tabular event-table
export), preview the examination geometry, run the dose calculation, and export
an audit report — from a graphical interface or headlessly from scripts.

The distribution and import package name is `guiskindose` (distinct from upstream).

| Upload | Geometry |
|---|---|
| ![Upload tab: load a DICOM RDSR or tabular event table](https://raw.githubusercontent.com/kgrizz-git/GUISkinDose/main/docs/source/user/figures/readme/upload.png) | ![Geometry preview: beam, phantom, and event selector](https://raw.githubusercontent.com/kgrizz-git/GUISkinDose/main/docs/source/user/figures/readme/geometry.png) |
| Results | Export |
| ![Results tab: peak skin dose cards and 3D dose map](https://raw.githubusercontent.com/kgrizz-git/GUISkinDose/main/docs/source/user/figures/readme/results.png) | ![Export tab: JSON, HTML, PNG, and rich-report downloads](https://raw.githubusercontent.com/kgrizz-git/GUISkinDose/main/docs/source/user/figures/readme/export.png) |

*Captured with the bundled example data; no patient data.*

## Intended use and responsibility

GUISkinDose is intended for **research, education, development, and
institutional quality-assurance** workflows. It is **not FDA-cleared** (or
otherwise certified) as a medical device, and results are **not** independently
validated for making patient-care decisions on their own.

**Physicists and physicians remain responsible** for reviewing outputs,
confirming that inputs and geometry settings are appropriate, and making any
clinical or patient-care decisions. Do not treat dose maps or PSD values as a
substitute for professional judgment, institutional policy, or regulatory
clearance.

Never commit or attach real patient data to issues, pull requests, or the
repository — see [CONTRIBUTING.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/CONTRIBUTING.md) and
[dev-docs/PRIVACY_AND_SENSITIVE_ASSETS.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/dev-docs/PRIVACY_AND_SENSITIVE_ASSETS.md).

## Quick launch (GUI)

The typical way to use GUISkinDose is the NiceGUI-based graphical interface:
**Upload** (RDSR DICOM or tabular CSV/TSV/XLSX) → **Data** review →
**Settings** (phantom, per-exam offsets) → **Corrections** (patient-support
transmission, kerma-meter factors) → **Geometry** preview →
**Calculate** → **Results** (PSD, dose map) → **Export** (JSON, dose-map
HTML/PNG, rich XLSX/PDF/DOCX report).

After installing `guiskindose[gui]` (see [Installation](#installation)), start the GUI:

```bash
guiskindose --mode gui            # opens in your browser
guiskindose --mode gui --native   # own window; needs guiskindose[gui-native]
```

From a source checkout, the launcher scripts below also set up the environment.

**macOS / Linux:**

```bash
chmod +x run_gui.sh   # one-time setup, enables executing the sh script
./run_gui.sh
```

**Windows:**

```bat
run_gui.bat
```

Both scripts prompt you to run in browser mode (option 1) or native
window mode (option 2, default).

**Double-click launchers.** After the first run, each OS has a file you can
double-click, with the GUISkinDose icon:

| OS | Double-click | Created by |
|----|--------------|------------|
| macOS | `GUISkinDose.command` (opens Terminal) | Tracked; its icon is set on first run |
| Windows | `GUISkinDose.lnk` | The first `run_gui.bat` run |
| Linux | `GUISkinDose.desktop` (GNOME: allow launching if asked) | The first `./run_gui.sh` run |

The shortcuts stay inside the checkout and are git-ignored (on Linux, GNOME records
the "allow launching" trust flag in its own metadata store under your home folder). Set
`GUISKINDOSE_NO_LAUNCHER_SETUP=1` to skip creating them. On macOS, a checkout
downloaded as a ZIP is quarantined: allow it under System Settings → Privacy &
Security → Open Anyway. A `git clone` is not quarantined.

Or launch directly:

```bash
python -m guiskindose --mode gui              # browser mode
python -m guiskindose --mode gui --native     # native window (requires pywebview)

# or the equivalent installed console command:
guiskindose --mode gui [--native]
```

Example RDSR files ship under `src/guiskindose/example_data/RDSR/`. In-app
help on each tab mirrors `docs/source/gui_help/` (mirrored into the package
by `scripts/sync_gui_help.py`, enforced by pre-commit + CI).

Feature highlights: multi-exam aggregation with per-exam offsets, tabular
DoseTrack/Radimetrics imports with schema auto-detection, kerma-meter
correction keyed by equipment × tube, rich audit reports, and a human phantom
library with habitus scaling. Details in
[dev-docs/FEATURE_INVENTORY.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/dev-docs/FEATURE_INVENTORY.md) and the
[User guide](https://github.com/kgrizz-git/GUISkinDose/blob/main/docs/source/user/user_guide.md).

### Privacy / network

The GUI has **no user accounts** and loads PHI-derived RDSR data into a single
shared, process-global state. It always binds to `127.0.0.1` (localhost only)
and refuses any non-loopback host. There is no LAN/remote mode: do not try to
expose it with a proxy; move the computation to the machine where the data may
reside instead.

Loopback binding is not an authentication boundary, so browser mode adds
three controls (see `src/guiskindose/gui/loopback_security.py`):

- A **per-launch token**: the console prints a launch URL with a random secret (valid until the
  server restarts — deliberately reusable, so a second browser profile or a
  cleared cookie doesn't lock you out), and the browser opens it automatically.
  Only that URL bootstraps a session (session cookie); every other request —
  HTTP and websocket alike — needs the cookie. Stale tabs and old URLs stop working after each restart — relaunch
  and use the new console URL.
- **Strict Host validation**: only the loopback authority is accepted, so DNS
  rebinding (`evil.com` resolving to `127.0.0.1`) is rejected.
- **Origin validation**: a present-but-foreign `Origin` on websockets and
  HTTP is a cross-site page (browsers always send `Origin`). Sockets need
  the session whenever tokens are on — an allowlisted origin alone proves
  nothing against local processes, which can forge it.

Anyone logged into the same machine who obtains the launch URL (or an active
session) sees the same shared state — OS accounts alone do not protect it, so
shared workstations need their own access story (e.g. one operator at a time,
or per-operator machines). **Native** mode enforces the same Host/Origin
checks but no launch token (the embedded window is the trusted client), so
another local user can still reach its port.

### Logging & privacy

The CLI and GUI log to the console (stderr) by default. **Native** mode has no
visible terminal, so diagnostic output is still emitted to stderr but may not be
easy to read unless you launch from a shell. No log file is written unless
`configure_logging(log_file=...)` is wired at startup (the optional file sink in
`guiskindose.debug` supports rotation and size caps when enabled).

To protect PHI, the app **does not log file names or paths** (RDSR filenames
often contain patient name/MRN/accession) — only file type, size, and event
counts. Verbose `DEBUG` output is opt-in per category via a `debug.json` in the
working directory, e.g.:

```json
{ "GUI": true, "PROCESSING": true, "CALCULATION": true, "RENDERING": true }
```

Even with debug enabled, identifiers are still redacted. Do not paste console
output into issues or commits without reviewing it for PHI first.

### Platform notes (Tkinter)

The GUI works fully without Tkinter, but uses it for two niceties: the native
**Save As** file dialog when exporting, and detecting your screen size to size
the native window. If Tkinter is missing you'll see a log line like
`No module named '_tkinter'`, exports fall back to a browser-style download, and
the window opens at a default size — nothing crashes.

Tkinter ships with Python but is only built when the Tcl/Tk libraries are present
at build time, so it can be absent (commonly with `pyenv` builds). It is **not** a
pip package — do not add it to the project dependencies. To install it:

| Platform | Command |
|---|---|
| macOS, Homebrew Python | `brew install python-tk` (or `python-tk@3.12` for a specific version) |
| macOS, pyenv Python | `brew install tcl-tk`, then reinstall the interpreter: `pyenv install 3.12.9` |
| Debian / Ubuntu | `sudo apt install python3-tk` |
| Fedora | `sudo dnf install python3-tkinter` |
| Windows | Included with the python.org installer — keep "tcl/tk and IDLE" checked |

Verify with: `python -c "import tkinter; print(tkinter.TkVersion)"`.

Native window mode remembers the last window size, position, and maximized state in
`~/.guiskindose/gui.json` (first launch opens maximized; Restore returns to the saved
normal size). Existing `~/.mypyskindose/gui.json` is still read when the new file is
absent.

## What this code is for

Within the intended-use boundary above, GUISkinDose is meant to be used in a few different ways:

1. Inspect or debug the examination geometry before doing dose calculations.
2. Step through irradiation events from an RDSR study to understand beam orientation and positioning.
3. Calculate a skin dose map on a mathematical or human phantom.
4. Export the calculation result as HTML, JSON, XLSX, PDF, or DOCX rich audit report, or as a Python dictionary for downstream processing.
5. Run the analysis headlessly from your own Python scripts.

## Installation

Install GUISkinDose from PyPI:

```bash
pip install "guiskindose[gui]"          # library, CLI, and browser GUI
pip install "guiskindose[gui-native]"   # adds the native window (pywebview)
pip install guiskindose                 # library and CLI only; no GUI
```

With `[gui]`, run `guiskindose --mode gui` to open the GUI in your browser.
With `[gui-native]`, run `guiskindose --mode gui --native` to open it in its own window.

To work on the code, clone the repository and install it in editable mode:

```bash
git clone https://github.com/kgrizz-git/GUISkinDose.git
cd GUISkinDose
pip install -e .
```

With [uv](https://docs.astral.sh/uv/), `uv sync --extra gui` creates the
environment from the pinned `uv.lock` instead.

To include the GUI dependencies:

```bash
pip install -e ".[gui]"          # browser mode
pip install -e ".[gui-native]"   # native window mode (includes pywebview)
```

For full development setup (linting, testing, docs, Jupyter), install the
optional extras you need:

```bash
pip install -e ".[dev,gui]"             # lint/type/test toolchain + GUI
pip install -e ".[dev,gui,docs,notebooks]"   # everything (docs + JupyterLab)
```

If you only need the documentation tooling as well:

```bash
pip install -e ".[docs]"
```

## Requirements

- Python 3.11 or above
- A settings configuration, typically based on [src/guiskindose/settings_example.json](https://github.com/kgrizz-git/GUISkinDose/blob/main/src/guiskindose/settings_example.json)
- A DICOM RDSR file (`.dcm`), a pre-parsed JSON export, or a supported tabular event-table export (`.csv`, `.tsv`, `.xlsx`)

## Headless use

### Command-line flags

Run `guiskindose --help` for the full list. Common headless examples:

```bash
guiskindose --file-path study.dcm
guiskindose --file-path events.csv --input-schema auto
guiskindose --file-path workbook.xlsx --sheet-name "Sheet1"
guiskindose --file-path study.dcm --export-format xlsx --export-path report.xlsx
```

Notable flags: `--input-schema` (default `auto` for tabular files), `--input-preview-only`,
`--export-format {xlsx,pdf,html,docx}`, `--export-path`, `--include-source-identifiers` (opt-in;
may include PHI-bearing source filenames in reports), `--kerma-meter-correction` and related
kerma-meter options, `--equipment-profile` (repeatable custom-profile file) and
`--equipment-profile-sheet` (XLSX sheet name or 0-based index).

### Scripted example

```python
from guiskindose import PyskindoseSettings, get_path_to_example_rdsr_files, load_settings_example_json
from guiskindose.main import main

settings = PyskindoseSettings(settings=load_settings_example_json())
settings.mode = "calculate_dose"
settings.output_format = "dict"
settings.phantom.model = "human"
settings.phantom.human_mesh = "hudfrid"

rdsr_dir = get_path_to_example_rdsr_files()
output = main(settings=settings, file_path=rdsr_dir / "siemens_axiom_example_procedure.dcm")

print(f"Estimated PSD: {output['psd']:.1f} mGy")
```

When `settings.output_format` is set to `dict` or `json`, the result can be used programmatically. The exported result includes items such as patient/table/pad data, event geometry, correction factors, dose map data, and peak skin dose. If you already have normalized RDSR data in a pandas `DataFrame`, use `analyze_normalized_data_with_custom_settings_object()` instead.

### Custom equipment profiles (experimental)

Validated manufacturer/model coordinate profiles can override vendor coordinate
handling for raw inputs, from Python (`assemble_session()`), a settings-file
`equipment_profiles` block, or `--equipment-profile`. See
[Custom equipment profiles](https://github.com/kgrizz-git/GUISkinDose/blob/main/docs/source/user/equipment_profiles.md) for the API,
CLI flags, and capture replay.

**New to GUISkinDose?** Prefer the GUI or the interactive getting-started notebook
([docs/source/getting_started/getting_started.ipynb](https://github.com/kgrizz-git/GUISkinDose/blob/main/docs/source/getting_started/getting_started.ipynb);
run it via `pip install -e ".[notebooks]"` + `python scripts/open_getting_started_notebook.py`, which
opens an ignored local copy so experiments never dirty the tracked source).

## Useful helpers

The package includes helper functions that make exploration easier:

- `load_settings_example_json()` loads a ready-made settings template.
- `print_available_human_phantoms()` lists available human phantom meshes.
- `get_path_to_example_rdsr_files()` returns the folder containing bundled example RDSR files.
- `print_example_rdsr_files()` prints the bundled example filenames.

## Settings and modes

Important settings live in [src/guiskindose/settings_example.json](https://github.com/kgrizz-git/GUISkinDose/blob/main/src/guiskindose/settings_example.json) and the settings classes under [src/guiskindose/settings](https://github.com/kgrizz-git/GUISkinDose/blob/main/src/guiskindose/settings).

| Mode | What it does |
|---|---|
| `plot_setup` | Plot the initial geometry without loading an irradiation sequence |
| `plot_event` | Inspect one irradiation event |
| `plot_procedure` | Inspect the full event sequence |
| `calculate_dose` | Compute the dose map and peak skin dose estimate |

Common phantom models: `plane`, `cylinder`, `human`.

## Documentation

Documentation sources live under [docs/source](https://github.com/kgrizz-git/GUISkinDose/blob/main/docs/source), including the getting-started notebook and user guide material.

To build the HTML documentation locally from this repository (use the `docs`
optional extra — there are no `requirements*.txt` files):

```bash
pip install -e ".[docs]"
python -m sphinx -b html docs/source docs/build/html
```

Then open the built site locally (path exists only after the Sphinx step above):

- `docs/build/html/index.html`

## Notes for this fork

- Independently maintained fork of [PySkinDose](https://github.com/rvbCMTS/PySkinDose); MIT license and upstream copyright preserved.
- Package identity: `guiskindose` (see [dev-docs/GUISKINDOSE_MIGRATION_STATUS.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/dev-docs/GUISKINDOSE_MIGRATION_STATUS.md)).
- How we maintain the fork: [dev-docs/FORK_MAINTAINER_GUIDE.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/dev-docs/FORK_MAINTAINER_GUIDE.md).
- Bugs and features: [GitHub Issues](https://github.com/kgrizz-git/GUISkinDose/issues) (templates require a no-PHI/PII confirmation; see [dev-docs/PRIVACY_AND_SENSITIVE_ASSETS.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/dev-docs/PRIVACY_AND_SENSITIVE_ASSETS.md)).
- Questions and contribution ideas: [GitHub Discussions](https://github.com/kgrizz-git/GUISkinDose/discussions). Ideas welcome — prefer Issues/Discussions over cold PRs ([CONTRIBUTING.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/CONTRIBUTING.md)).
- Security: [SECURITY.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/SECURITY.md). Support channels: [SUPPORT.md](https://github.com/kgrizz-git/GUISkinDose/blob/main/SUPPORT.md).
