UML diagrams¶
Every diagram is written in Mermaid (rendered natively by GitHub
and by the MkDocs site) or in Graphviz/dot (rendered to SVG, source next to it in
docs/uml/). They describe the architecture (packages, components, classes), the
behaviour (sequences, activities, states), the material (data files, see
Data model) and the deployment.
| Kind | Diagram |
|---|---|
| Use case | 1. Use cases |
| Structure | 2. Packages, 3. Components, 4. Classes, 5. Objects |
| Behaviour | 6. Sequences, 7. Activities, 8. States |
| Physical | 9. Deployment |
1. Use case diagram¶
Who uses the package and for what. Mermaid has no native use-case notation: actors are the round nodes, use cases the stadium-shaped nodes inside the system boundary.
flowchart LR
researcher((Researcher<br/>thesis author))
supervisor((Supervisor))
developer((Developer))
ci((GitHub Actions))
subgraph system["sidenor_ladle (sAIfety UPM)"]
uc1([Run the whole pipeline])
uc2([Run one step again])
uc3([Run a data check])
uc4([Read a report<br/>HTML / Markdown / PDF])
uc5([Change a parameter<br/>config file or --set])
uc6([Rebuild a report<br/>from saved results])
uc7([Read ladle numbers by eye])
uc8([Run the tests and<br/>the regression check])
uc9([Publish the documentation])
end
researcher --> uc1 & uc2 & uc3 & uc5 & uc6
supervisor --> uc4 & uc7
researcher --> uc4
developer --> uc8 & uc5
ci --> uc8 & uc9
uc3 -. includes .-> uc7
uc1 -. includes .-> uc4
2. Package diagram¶
Layers of the Model-View-Presenter architecture and their dependencies (an arrow means "imports"). The model never imports the view nor the presenter; the view only reads the model's result objects.
flowchart TB
subgraph cli_pkg["sidenor_ladle.cli"]
app["app (typer)"]
end
subgraph pres_pkg["sidenor_ladle.presenter"]
pipeline["pipeline"]
end
subgraph view_pkg["sidenor_ladle.view"]
vfig["figures (plotly)"]
doc["document"]
rend["renderers: markdown, html, pdf"]
con["console"]
end
subgraph model_pkg["sidenor_ladle.model"]
steps["steps (01-13)"]
checks["checks"]
domain["domain services"]
io["io (.bin, file names)"]
core["results, figures (specs), workspace"]
end
subgraph cfg_pkg["sidenor_ladle.config"]
models["models (pydantic)"]
loader["loader (toml / yaml / json)"]
settings["settings (.env)"]
end
testing["sidenor_ladle.testing"]
app --> pipeline & loader & con & testing
pipeline --> steps & checks & core & rend & vfig & con & doc
rend --> doc & vfig
vfig --> core
doc --> core
steps --> domain & io & core
checks --> domain & io & core & steps
domain --> models
steps --> models
loader --> models & settings
The module-level dependency graph, drawn with Graphviz (docs/uml/modules.dot):
3. Component diagram (MVP)¶
Provided and required interfaces between the components. The presenter is the only component that talks to both the model and the views.
flowchart LR
user((user)) -->|arguments| CLI
CLI["<<component>><br/>CLI<br/>sidenor_ladle.cli"] -->|PipelineConfig| Presenter
CLI -->|reads| Config["<<component>><br/>Configuration<br/>config + .env"]
Presenter["<<component>><br/>Presenter<br/>PipelinePresenter"] -->|"run(**options)"| Model
Model["<<component>><br/>Model<br/>steps, checks, domain"] -->|StepResult| Presenter
Presenter -->|ReportDocument| Views["<<component>><br/>Views<br/>Markdown / HTML / PDF"]
Presenter -->|StepResult| Console["<<component>><br/>Console view"]
Model -->|"read / write"| Store[("Workspace<br/>output_root")]
Model -->|read only| Data[("Plant data<br/>.bin + Excel")]
Views -->|FigureSpec| Plotly["<<library>><br/>plotly + Kaleido"]
Views -->|write| Reports[("reports/")]
4. Class diagrams¶
4.1 Configuration¶
classDiagram
direction LR
class BaseModel {
<<pydantic>>
}
class _Block {
<<abstract>>
model_config: extra=forbid
}
class _ParallelBlock {
workers: int | None
effective_workers() int
}
class PipelineConfig {
paths: PathsConfig
steps: StepFoldersConfig
bin_format: BinFormatConfig
masks: MasksConfig
split: SplitConfig
report: ReportConfig
... 22 blocks
folder_of(step) str
}
class PathsConfig {
data_root: Path
thickness_dir: Path
output_root: Path
}
class MasksConfig {
t_shell: float
t_hot: float
bit_used_for_features: int
trim: TrimConfig
}
class SplitConfig {
test_ladles: list~int~
val_ladles: list~int~
not_train() list~int~
}
class ReportConfig {
formats: list~md|html|pdf~
image_downsample: int
plotlyjs: inline|cdn
figure_files: png|html|none
}
class EnvSettings {
<<pydantic-settings>>
data_root: Path | None
output_root: Path | None
config: Path | None
load(env_file) EnvSettings
as_overrides() dict
}
class ConfigLoader {
source: Path | None
settings: EnvSettings
read_file(path) dict
find_default() Path | None
load(path, overrides, **cli) PipelineConfig
}
BaseModel <|-- _Block
_Block <|-- _ParallelBlock
_Block <|-- PipelineConfig
_Block <|-- PathsConfig
_Block <|-- SplitConfig
_Block <|-- ReportConfig
_ParallelBlock <|-- MasksConfig
_ParallelBlock <|-- InventoryConfig
PipelineConfig *-- PathsConfig
PipelineConfig *-- MasksConfig
PipelineConfig *-- SplitConfig
PipelineConfig *-- ReportConfig
PipelineConfig *-- InventoryConfig
MasksConfig *-- TrimConfig
ConfigLoader --> EnvSettings : uses
ConfigLoader ..> PipelineConfig : creates
4.2 Model: steps, registry, workspace and results¶
classDiagram
direction TB
class PipelineStep {
<<abstract>>
+key: str$
+number: int | None$
+kind: step | check$
+title: str$
+requires: tuple~str~$
+cli_name: str$
+cfg: PipelineConfig
+ws: Workspace
+run(**options) StepResult
+execute(**options)* StepResult
+new_result() StepResult
+progress(done, total)
}
class StepRegistry {
-_steps: dict
+add(cls) cls
+get(name) type
+pipeline() list
+checks() list
}
class Workspace {
+root: Path
+step_dir(step, create) Path
+require(step, name) Path
+read_csv(step, name) DataFrame
+write_csv(df, step, name) Path
+load_array(step, name) ndarray
-_cache: dict
}
class StepResult {
<<pydantic>>
+key: str
+number: int | None
+summary: list~str~
+metrics: dict
+tables: list~TableSpec~
+figures: list~FigureSpec~
+warnings: list~str~
+data: Any
+save() Path
+load(path)$ StepResult
}
class TableSpec {
<<pydantic>>
+columns: list~str~
+rows: list~list~
+from_frame(df)$ TableSpec
}
class FigureSpec {
<<pydantic>>
+name: str
+title: str
+panels: list~Panel~
+ncols: int
}
class Panel {
+traces: list~Trace~
+ref_lines: list~RefLine~
+image: bool
}
class Trace {
<<union>>
LineTrace
HistogramTrace
HeatmapTrace
OutlineTrace
}
StepRegistry o-- "18" PipelineStep : registers
PipelineStep --> Workspace
PipelineStep ..> StepResult : creates
StepResult *-- TableSpec
StepResult *-- FigureSpec
FigureSpec *-- Panel
Panel *-- Trace
Workspace --> MissingInputError : raises
4.3 Model: the steps and checks and the domain services they use¶
classDiagram
direction LR
PipelineStep <|-- InventoryStep
PipelineStep <|-- ThicknessRecordsStep
PipelineStep <|-- CampaignsStep
PipelineStep <|-- ImagesMasksStep
PipelineStep <|-- FeaturesStep
PipelineStep <|-- BandsStep
PipelineStep <|-- SequencesSplitStep
PipelineStep <|-- CenteringStep
PipelineStep <|-- ThicknessTargetStep
PipelineStep <|-- SignalDiagnosticStep
PipelineStep <|-- BaselinesStep
PipelineStep <|-- AuditStep
PipelineStep <|-- BandEvolutionStep
PipelineStep <|-- LadleNumberCheck
PipelineStep <|-- AttributionCheck
PipelineStep <|-- LadleIdentityCheck
PipelineStep <|-- _ImageCheck
_ImageCheck <|-- DataQualityCheck
_ImageCheck <|-- MaskTrimCheck
class ThermalImageReader {
+read(path) ndarray
+read_raw(path)
+to_image(data)
}
class PlantFileName {
<<pydantic>>
+parse(name)$ PlantFileName
+empty_time_h: float
}
class MaskSegmenter {
+threshold(t)
+contour(t)
+largest_blob(t, d)
+trimmed(t, e)
+all_masks(t, camera) list
+stats(t, masks) dict
}
class ShellFeatureExtractor {
+extract(t, m) dict
}
class BandFeatureExtractor {
+extract(t, m) dict
}
class ThicknessSheetParser {
+parse(ws)
+parse_cells(cells)
}
class ImageEnhancer {
+enhance(t) ndarray
}
class SequenceBuilder {
+build(img) DataFrame
}
class ModelFactory {
+algorithms() dict
}
class LadleIdentityClassifier {
+build(n)
+augment(x, gen)$
+fit_predict(...) ndarray
}
InventoryStep ..> ThermalImageReader
InventoryStep ..> BinHeader
ThicknessRecordsStep ..> ThicknessSheetParser
CampaignsStep ..> PlantFileName
ImagesMasksStep ..> ThermalImageReader
ImagesMasksStep ..> MaskSegmenter
FeaturesStep ..> ShellFeatureExtractor
BandsStep ..> BandFeatureExtractor
SequencesSplitStep ..> SequenceBuilder
BaselinesStep ..> ModelFactory
AuditStep ..> ThermalImageReader
LadleNumberCheck ..> ImageEnhancer
AttributionCheck ..> ImageEnhancer
LadleIdentityCheck ..> LadleIdentityClassifier
MaskTrimCheck ..> MaskSegmenter
4.4 View and presenter¶
classDiagram
direction LR
class PipelinePresenter {
+cfg: PipelineConfig
+view: ConsoleView
+ws: Workspace
+exporter: FigureExporter
+select(start, only, stop)$ list
+run_step(cls, **options) StepResult
+run(steps, options, formats) tuple
+persist(result)
+document(results) ReportDocument
+write_reports(results, formats) list~Path~
+saved_results(keys) list~StepResult~
}
class ConsoleView {
+step_started(label)
+step_finished(result)
+step_failed(label, error)
+reports_written(paths)
}
class ReportDocument {
<<pydantic>>
+title: str
+meta: dict
+results: list~StepResult~
+stem: str
}
class ReportRenderer {
<<abstract>>
+suffix: str
+render(doc, out_dir)* Path
+static_figures(doc, dir) dict
}
class MarkdownRenderer
class HtmlRenderer
class PdfRenderer
class FigureExporter {
+figure(spec) Figure
+html_div(spec) str
+write_png(spec, path) Path | None
+write_html(spec, path) Path
}
class PlotlyFigureFactory {
+build(spec) Figure
}
ReportRenderer <|-- MarkdownRenderer
ReportRenderer <|-- HtmlRenderer
ReportRenderer <|-- PdfRenderer
ReportRenderer --> FigureExporter
FigureExporter --> PlotlyFigureFactory
PipelinePresenter --> ConsoleView
PipelinePresenter --> FigureExporter
PipelinePresenter ..> ReportDocument : builds
PipelinePresenter ..> ReportRenderer : renderer_for(fmt)
PipelinePresenter ..> StepRegistry : reads
5. Object diagram (one configured run)¶
The objects alive during sidenor-ladle -r html,pdf run --only 8.
flowchart LR
cfg["cfg : PipelineConfig<br/>paths.output_root = ~/tfm_outputs/pipeline_v4<br/>masks.bit_used_for_features = 5<br/>report.formats = [html, pdf]"]
loader["loader : ConfigLoader<br/>source = config/config.toml"]
env["settings : EnvSettings<br/>data_root = /home/.../imgs"]
p["presenter : PipelinePresenter"]
ws["ws : Workspace<br/>root = ~/tfm_outputs/pipeline_v4"]
step["step : CenteringStep<br/>key = centering, number = 8"]
res["result : StepResult<br/>key = centering<br/>figures = [fig_centering_check]"]
doc["doc : ReportDocument<br/>results = [result]"]
html["r1 : HtmlRenderer"]
pdf["r2 : PdfRenderer"]
loader --- env
loader -- creates --- cfg
p --- cfg & ws
p -- creates --- step
step --- ws
step -- returns --- res
p -- builds --- doc
doc --- res
p -- uses --- html & pdf
6. Sequence diagrams¶
6.1 sidenor-ladle run¶
sequenceDiagram
autonumber
actor U as User
participant CLI as cli.app
participant L as ConfigLoader
participant P as PipelinePresenter
participant S as PipelineStep (each)
participant W as Workspace
participant V as ConsoleView
participant R as Renderer (md/html/pdf)
U->>CLI: sidenor-ladle -r html run --from 5
CLI->>L: load(config, overrides, cli values)
L-->>CLI: PipelineConfig (validated)
CLI->>P: run(select(5), options, formats)
loop steps 05 .. 13
P->>V: step_started(label)
P->>S: run(**options)
S->>W: read_csv / load_array (inputs of earlier steps)
W-->>S: tables, memory-mapped arrays
S->>W: write_csv / npy (outputs)
S-->>P: StepResult (summary, metrics, tables, FigureSpecs)
P->>P: persist(result): summary.txt, figures, <key>.result.json
P->>V: step_finished(result)
end
P->>P: document(results)
P->>R: render(ReportDocument, reports/)
R-->>P: report path
P->>V: reports_written(paths)
6.2 Configuration loading (order of precedence)¶
sequenceDiagram
participant CLI as cli.app
participant L as ConfigLoader
participant D as python-dotenv
participant E as EnvSettings
participant F as config file
participant M as PipelineConfig
CLI->>L: ConfigLoader(env_file=".env")
L->>D: load_dotenv(.env, override=False)
L->>E: EnvSettings() reads TFM_* variables
CLI->>L: load(path, --set ..., --data-root ...)
L->>F: read toml / yaml / json, strip "_comment" keys
L->>L: merge: file < .env < CLI options < --set
L->>M: model_validate(merged)
alt invalid value or unknown key
M-->>CLI: ValidationError (exit code 2)
else valid
M-->>CLI: PipelineConfig
end
6.3 Step 04 - parallel reading and segmentation¶
sequenceDiagram
participant S as ImagesMasksStep
participant W as Workspace
participant X as ProcessPool (forkserver)
participant K as worker k
S->>W: read_csv(campaigns, images_v2.csv)
S->>S: open_memmap(tensors_raw_fp16.npy, masks_bits_u8.npy)
S->>X: process_pool(workers, init_worker, cfg_json)
X->>K: init_worker(cfg_json): ThermalImageReader + MaskSegmenter (once)
loop chunks of 32 images
S->>X: map(process_image, jobs)
X->>K: (row, path, camera)
K->>K: read .bin, all_masks(), pack_masks(), stats()
K-->>S: (row, image fp16, bits, stats, error)
S->>S: write row i of both memory maps
end
S->>W: tensors_index.csv, mask_comparison.csv
6.4 Report rendering with the Kaleido fallback¶
sequenceDiagram
participant P as PipelinePresenter
participant R as MarkdownRenderer / PdfRenderer
participant E as FigureExporter
participant F as PlotlyFigureFactory
participant K as Kaleido + Chrome
P->>R: render(doc, out_dir)
loop every FigureSpec
R->>E: figure(spec)
E->>F: build(spec) (once per spec)
R->>E: write_png(spec, path)
alt already exported in this run
E-->>R: copy of the PNG
else Chrome available
E->>K: write_image (persistent server)
K-->>E: PNG
else static export unavailable
E-->>R: None (one warning)
R->>E: write_html(spec) (interactive file)
end
end
R-->>P: report path
7. Activity diagrams¶
7.1 Data flow of the pipeline¶
Which step reads which file (the material of the method). Rectangles are steps,
cylinders are files in output_root, parallelograms are the plant data.
flowchart TB
bin[/".bin images<br/>Termografiak/"/]
xls[/"thickness Excel files"/]
s01["01 Inventory"] --> f01[("index_all.csv")]
s02["02 Thickness records"] --> f02[("thickness_events.csv<br/>thickness_rows.csv")]
f01 & f02 --> s03["03 Campaigns + RUL"] --> f03[("images_v2.csv")]
f03 --> s04["04 Images + masks"] --> f04[("tensors_raw_fp16.npy<br/>masks_bits_u8.npy<br/>tensors_index.csv")]
f04 --> s05["05 Features"] --> f05[("features_E.csv")]
f04 & f03 --> s06["06 Bands"] --> f06[("features_bands.csv")]
f04 --> s07["07 Sequences + split"] --> f07[("sequences_W5.csv")]
f05 --> s08["08 Camera centering"] --> f08[("features_E_centered.csv")]
f03 & f02 --> s09["09 Thickness target"] --> f09[("images_thickness.csv")]
f08 & f03 --> s10["10 Signal diagnostic"]
f08 & f03 & f09 & f06 --> s11["11 Baselines"] --> f11[("cv_results.csv")]
f04 & f05 & f03 & bin --> s12["12 Audit"]
f06 & f03 --> s13["13 Band evolution"]
bin --> s01 & s04
xls --> s02
f04 -.-> idc["check identity"] -.-> fid[("passage_predictions.csv")] -.->|"flag_identity_suspect"| s03
7.2 Step 03 - is an image usable for training?¶
flowchart TD
a([image of Termografiak/Sarrera or Irteera]) --> b{file name matches<br/>the plant pattern?}
b -- no --> bad[bad_names.csv] --> z([not in images_v2])
b -- yes --> c[parse fields, one row per id + time + camera]
c --> d[attach the first demolition on or after the image date]
d --> e[RUL = heats at demolition + trasvases - heat counter]
e --> f[set flags: camera mismatch, unreadable, two ladles,<br/>empty frame, setup period, first of repeated,<br/>identity suspect, no demolition after,<br/>counter above length, counter vs repair]
f --> g{RUL known and<br/>no flag set?}
g -- yes --> u([usable_for_training = True])
g -- no --> n([usable_for_training = False<br/>kept with its flags])
7.3 Step 04 - segmentation of one image (masks A to F)¶
flowchart LR
t[temperature image] --> A["A: T >= t_shell, closing"]
A --> B["B: A minus hot steel<br/>dilated 21 px x2"]
t --> C["C: Otsu + largest contour"]
A --> D["D: A minus hot steel<br/>dilated 5 px"]
D --> E["E: opening, largest blob,<br/>geodesic reconstruction,<br/>holes filled, 80-600 degC"]
E --> q{camera in<br/>trim.cameras?}
q -- yes --> F["F: cut necks (hook), cool<br/>ground rows, side limits,<br/>largest object"]
q -- no --> F2["F = E"]
F & F2 --> pack["pack as bits 0..5 of uint8"]
7.4 Step 09 - thickness label of an image (methods A and B)¶
flowchart TD
s([image: heat h in campaign]) --> k{thickness sheet<br/>for the campaign?}
k -- no --> nf([flag_no_thickness_sheet])
k -- yes --> r{REP sheet<br/>and repair heat?}
r -- yes --> b1["B: h <= repair: start -> before repair<br/>h > repair: after repair -> demolition<br/>(row by row, then min over the zone)"]
r -- no --> b2["B: start -> demolition"]
b1 & b2 --> a{"h within K heats of<br/>a known point?"}
a -- yes --> A["A: value of that point<br/>(start, before repair,<br/>after repair, demolition)"]
a -- no --> A0["A: empty"]
8. State machine diagrams¶
8.1 Life of one image through the pipeline¶
stateDiagram-v2
[*] --> Indexed: 01 inventory
Indexed --> Unreadable: header or size error
Indexed --> Named: 03 name parsed
Indexed --> BadName: 03 pattern not matched
Named --> Attributed: campaign + RUL
Attributed --> Flagged: any flag
Attributed --> Usable: no flag
Flagged --> Segmented: 04 (kept, never dropped)
Usable --> Segmented: 04 masks A-F
Segmented --> Described: 05 features, 06 bands
Described --> Centred: 08 camera centering
Centred --> Labelled: 09 thickness A/B
Labelled --> Train: ladle not in val/test
Labelled --> Validation: ladle in split.val_ladles
Labelled --> Test: ladle in split.test_ladles
Test --> [*]: used once, final test
Train --> [*]
Validation --> [*]
Unreadable --> [*]
BadName --> [*]
8.2 One step run (presenter)¶
stateDiagram-v2
[*] --> Selected
Selected --> Running: run_step()
Running --> Failed: exception (missing input, error)
Failed --> [*]: run stops, exit code 3/4
Running --> Computed: StepResult returned
Computed --> Persisted: summary.txt, figures, result.json
Persisted --> Reported: included in the report
Persisted --> [*]: next step
Reported --> [*]
9. Deployment diagram¶
flowchart LR
subgraph laptop["Developer workstation"]
repo["git clone<br/>poetry install --with docs"]
env1[".env (local paths)"]
end
subgraph github["GitHub"]
gr[("repository<br/>sAIfety-UPM")]
act["Actions:<br/>tests.yml, docs.yml"]
pages["Pages: documentation<br/>(MkDocs, built from /docs)"]
end
subgraph vm["Plant virtual machine (GPU)"]
venv["venv / poetry env<br/>sidenor-ladle (+ extra identity)"]
torch["torch + CUDA<br/>(installed separately)"]
data[("/home/.../imgs<br/>.bin + Excel (read only)")]
out[("~/tfm_outputs/pipeline_v4")]
env2[".env (VM paths)"]
end
repo -- git push --> gr
gr --> act --> pages
gr -- git pull --> venv
venv --> torch
venv -- reads --> data
venv -- writes --> out
env2 -.-> venv
env1 -.-> repo