Reference
A lightweight, serialisable version of a Metrics instance.
This dataclass is designed to capture and store the purely numeric, non-NaN
scalar values from a live Metrics object, making it suitable for JSON
serialization, saving to disk, or comparing historical simulation runs.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
A human-readable identifier or name for this specific snapshot. |
values |
dict
|
A dictionary containing the numeric scalar metrics extracted from a
|
Source code in src/stroke_ward_model/metrics.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
diff(other)
Computes the numerical difference between the metric values of this
snapshot and another Metrics or MetricsSnapshot instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Metrics or MetricsSnapshot
|
The target object to compare against. Must contain compatible
numeric attributes or a |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary where each key is a metric name, mapping to a nested dictionary containing 'self' (current snapshot value), 'other' (comparison value), and 'difference' (self - other). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided |
Source code in src/stroke_ward_model/metrics.py
from_dict(data)
classmethod
Constructs a MetricsSnapshot instance from a dictionary representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing at least the keys 'label' (str) and 'values' (dict). |
required |
Returns:
| Type | Description |
|---|---|
MetricsSnapshot
|
A newly initialized snapshot instance populated with the provided data. |
Source code in src/stroke_ward_model/metrics.py
from_metrics(metrics, label)
classmethod
Builds a lightweight snapshot from a live Metrics instance.
Iterates through the attributes of a Metrics object, extracting only
the valid (non-NaN) integer and floating-point values, casting them to
standard Python floats to ensure JSON compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
Metrics
|
The live |
required |
label
|
str
|
A string identifier to assign to the newly created snapshot. |
required |
Returns:
| Type | Description |
|---|---|
MetricsSnapshot
|
A snapshot instance containing the extracted numeric values. |
Source code in src/stroke_ward_model/metrics.py
to_dict()
Serializes the snapshot instance into a standard Python dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary representation of the snapshot, containing the 'label' and 'values' keys. |