# chaplab/patch-pdf-utility architecture

> Architecture diagram of the GitHub repository chaplab/patch-pdf-utility, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chaplab/patch-pdf-utility
- Repository: https://github.com/chaplab/patch-pdf-utility
- Video tour (about a minute): https://gitdiagram.com/chaplab/patch-pdf-utility/video

## Overview

PATCH PDF Utility is a desktop application for repairing saturated X-ray scattering data. Its main workflow pairs long-exposure saturated files with short-exposure repair files, scales the repair data, patches peak tips, lets users inspect the result, and exports restored files. The README documents the major capabilities; sampled excerpts show GUI, parsing, scaling-related helpers, and export code, but omit much of both large modules. Both core files are represented; the excerpts do not establish how the two implementations differ or connect.

Main entry points: [`src/pdf_patch.py`](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py) (Processing controls), [`src/PATCH_PDF.py`](https://github.com/chaplab/patch-pdf-utility/blob/main/src/PATCH_PDF.py) (Threshold selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Desktop interface"]
  node_app["PATCH application<br/>[pdf_patch.py]"]
  node_alternate["Alternate implementation<br/>[PATCH_PDF.py]"]
  node_pairing["File pairing<br/>[pdf_patch.py]"]
  node_parameters["Processing controls<br/>[pdf_patch.py]"]
end

subgraph group_processing["Data processing"]
  node_inputfiles["Scattering files"]
  node_ingestion["Load and regrid<br/>[pdf_patch.py]"]
  node_scaling["Robust scaling<br/>[pdf_patch.py]"]
  node_attenuation["Attenuation correction<br/>[pdf_patch.py]"]
  node_fixedscale["Fixed scaling<br/>[pdf_patch.py]"]
  node_patching["Peak-tip patching<br/>[pdf_patch.py]"]
  node_threshold["Threshold selection<br/>[PATCH_PDF.py]"]
end

subgraph group_output["Review and export"]
  node_preview["Preview plots<br/>[pdf_patch.py]"]
  node_restored["Restored datasets<br/>[pdf_patch.py]"]
  node_convergence["Scale convergence<br/>[pdf_patch.py]"]
  node_export["File export<br/>[pdf_patch.py]"]
end

node_user(("Operator"))
node_downstream(("PDF processing"))

node_user -->|"opens"| node_app
node_user -->|"loads and reorders"| node_pairing
node_user -->|"sets options"| node_parameters
node_inputfiles -->|"supplies pairs"| node_pairing
node_pairing -->|"provides matched files"| node_ingestion
node_parameters -->|"configures"| node_scaling
node_ingestion -->|"provides data"| node_scaling
node_parameters -->|"configures"| node_attenuation
node_parameters -->|"configures"| node_fixedscale
node_scaling -->|"provides scaled repair"| node_patching
node_attenuation -->|"provides scaled repair"| node_patching
node_fixedscale -->|"provides scaled repair"| node_patching
node_parameters -->|"sets threshold mode"| node_threshold
node_patching -->|"produces"| node_restored
node_restored -->|"displays"| node_preview
node_scaling -->|"reports convergence"| node_convergence
node_restored -->|"writes"| node_export
node_export -->|"supports"| node_downstream

click node_app "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_alternate "https://github.com/chaplab/patch-pdf-utility/blob/main/src/PATCH_PDF.py"
click node_pairing "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_parameters "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_ingestion "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_scaling "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_attenuation "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_fixedscale "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_patching "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_threshold "https://github.com/chaplab/patch-pdf-utility/blob/main/src/PATCH_PDF.py"
click node_preview "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_restored "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_convergence "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"
click node_export "https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_alternate,node_pairing,node_parameters toneBlue
class node_inputfiles,node_ingestion,node_scaling,node_attenuation,node_fixedscale,node_patching,node_threshold toneAmber
class node_preview,node_restored,node_convergence,node_export toneMint
class node_user,node_downstream toneIndigo
```

## Components

### Desktop interface

- [PATCH application](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Alternate implementation](https://github.com/chaplab/patch-pdf-utility/blob/main/src/PATCH_PDF.py): `src/PATCH_PDF.py`
- [File pairing](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Processing controls](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`

### Data processing

- **Scattering files**
- [Load and regrid](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Robust scaling](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Attenuation correction](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Fixed scaling](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Peak-tip patching](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Threshold selection](https://github.com/chaplab/patch-pdf-utility/blob/main/src/PATCH_PDF.py): `src/PATCH_PDF.py`

### Review and export

- [Preview plots](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Restored datasets](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [Scale convergence](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`
- [File export](https://github.com/chaplab/patch-pdf-utility/blob/main/src/pdf_patch.py): `src/pdf_patch.py`

### Other components

- **Operator**
- **PDF processing**

## Connections

- Operator → PATCH application: opens (evidence: `README.md`)
- Operator → File pairing: loads and reorders (evidence: `README.md`)
- Operator → Processing controls: sets options (evidence: `README.md`)
- Scattering files → File pairing: supplies pairs (evidence: `README.md`)
- File pairing → Load and regrid: provides matched files (evidence: `README.md`)
- Processing controls → Robust scaling: configures (evidence: `README.md`)
- Load and regrid → Robust scaling: provides data (evidence: `README.md`)
- Processing controls → Attenuation correction: configures (evidence: `README.md`)
- Processing controls → Fixed scaling: configures (evidence: `README.md`)
- Robust scaling → Peak-tip patching: provides scaled repair (evidence: `README.md`)
- Attenuation correction → Peak-tip patching: provides scaled repair (evidence: `README.md`)
- Fixed scaling → Peak-tip patching: provides scaled repair (evidence: `README.md`)
- Processing controls → Threshold selection: sets threshold mode (evidence: `README.md`)
- Peak-tip patching → Restored datasets: produces (evidence: `README.md`)
- Restored datasets → Preview plots: displays (evidence: `README.md`)
- Robust scaling → Scale convergence: reports convergence (evidence: `README.md`)
- Restored datasets → File export: writes (evidence: `README.md`)
- File export → PDF processing: supports (evidence: `README.md`)
