Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for PET analysis #215

Merged
merged 100 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
2aaa353
EX: Initialize script for PET vs. simulation example included in DarS…
jwboth Jul 5, 2023
17fb8d8
EX: USe suffix, add plot.
jwboth Jul 5, 2023
44e7b5c
ENH: More control on plotting of W1-dist results.
jwboth Jul 6, 2023
d70cb2d
EX: Add more advanced plots, and add 3d wasserstein.
jwboth Jul 6, 2023
6c989e4
EX: Fix plots and rename script.
jwboth Jul 6, 2023
f532876
ENH: init 3d version of wasserstein distance
jwboth Aug 22, 2023
7bf8261
ENH: Add restart and adaptive dimension to AA.
jwboth Aug 28, 2023
daf5932
ENH: Add possibility to use restarted AA.
jwboth Aug 28, 2023
6dc2d01
MAINT: Rename variables.
jwboth Aug 28, 2023
712c49c
ENH: Extend plotting capabilities and convergence monitoring.
jwboth Aug 28, 2023
e5e13f5
MAINT: rename edge -> face.
jwboth Aug 28, 2023
adb8514
DOC: Improve documentation of connectivity infrastructure.
jwboth Aug 28, 2023
80b255b
ENH: Add more grid operators for face restictions.
jwboth Aug 29, 2023
3efb8a6
MAINT: Move face-flux computations part of the common Wasserstein class.
jwboth Aug 29, 2023
6e5e827
ENH: Revise solver structure for Newton steps and add more monitoring.
jwboth Aug 30, 2023
721bc59
MAINT: Switch to fixing zero potential at the center of the grid.
jwboth Aug 30, 2023
dcb78b5
ENH: Add possibility to utilize true potential system through gauss
jwboth Sep 2, 2023
f71c1f6
DOC Improve documentation
jwboth Sep 2, 2023
e2e52c3
DOC: improve documentation
jwboth Sep 2, 2023
c82b5a9
ENH: Add two variants to project cell to face data.
jwboth Sep 2, 2023
d898b23
MAINT: Rename method
jwboth Sep 2, 2023
ffe8abe
MAINT: Change signature
jwboth Sep 2, 2023
13e3cf8
MAINT: Improve doc, naming
jwboth Sep 3, 2023
61abe8e
MAINT: Exclude for now redundant routine, and add some keywords.
jwboth Sep 3, 2023
9701661
MAINT: More precise error message
jwboth Sep 3, 2023
6366397
MAINT: Improve doc, and move code, improve efficiency.
jwboth Sep 3, 2023
fa297cd
MAINT: Restructure linear solver allowing for external control
jwboth Sep 3, 2023
083afd0
MAINT: adapt bregman algorithm and use similar monitoring as for Newton
jwboth Sep 9, 2023
d07ee0a
MAINT: add convergence criterion for Bregman split
jwboth Sep 9, 2023
7c57241
MAINT: reorganize code
jwboth Sep 10, 2023
fde2878
MAINT: Refactor shrink
jwboth Sep 10, 2023
e691189
BUG: Use correct mass matrix
jwboth Sep 12, 2023
cace02d
MAINT: Extend signature of l1 dissipation
jwboth Sep 12, 2023
420fbe1
Bug: Also use a name when not storing the plots
jwboth Sep 12, 2023
d1b3f96
MAINT: init implicit Bregman
jwboth Sep 12, 2023
c11d8b8
MAINT: Add flag for switching between implicit and explicit Bregman
jwboth Sep 13, 2023
24dd72c
MAINT: backup of all old code snippets
jwboth Sep 13, 2023
50f7d8d
MAINT: remove attempts to improve Bregman
jwboth Sep 13, 2023
9d43201
ENH: Add new Bregman type split, with updated weights and shrink factor.
jwboth Sep 14, 2023
26f2e4e
MAINT: Add missing import.
jwboth Sep 14, 2023
9e0861d
ENH: Add possibility to use AMG for Bregman as well.
jwboth Sep 14, 2023
91139ac
MAINT: Remove hardcoded plotting specifications.
jwboth Sep 15, 2023
4f338f2
MAINT: Make Bregman convergence criterion depending on distance
jwboth Sep 15, 2023
fdca8e2
TST: Add test for wasserstein computations.
jwboth Sep 15, 2023
52d0073
TST: Enhance wasserstein test and differ between different BRegman modes
jwboth Sep 15, 2023
c8cbf53
STY: black and flake8
jwboth Sep 16, 2023
aec4905
MAINT/STY: Add user-access to steer bregman modes.
jwboth Sep 16, 2023
5086f28
MAINT: Exclude 3d wasserstein file - soon obsolete.
jwboth Sep 16, 2023
120ffab
MAINT: Add pyamg to dev requirements.
jwboth Sep 16, 2023
c6b53da
STY: flake8
jwboth Sep 16, 2023
29c46c4
STY: black
jwboth Sep 16, 2023
7628b09
MAINT: Init extraction of a grid object to be used for Wasserstein di…
jwboth Sep 16, 2023
20161fc
MAINT: Copy tensor grid setup from Wasserstein file.
jwboth Sep 17, 2023
da6a404
MAINT: Provide basic FV utilities (copied from Wasserstein).
jwboth Sep 17, 2023
b6a9b56
MAINT: Adapt Wasserstein class to extracted grid and fv management.
jwboth Sep 17, 2023
4ae22e3
MAINT: Reorganize setup of Wasserstein distances
jwboth Sep 17, 2023
c1d8052
MAINT: basic maintanence
jwboth Sep 17, 2023
3a752a4
MAINT: Replace hardcoded slices.
jwboth Sep 17, 2023
935e325
MAINT: Reuse code
jwboth Sep 17, 2023
548ec88
MAINT: Add fv utils to darsia.
jwboth Sep 18, 2023
e81e290
MAINT: strip down code
jwboth Sep 18, 2023
739e8f6
MAINT: Reorganize setup
jwboth Sep 18, 2023
4fb928e
MAINT: Move FV type projections to fv file.
jwboth Sep 18, 2023
4fd167c
MAINT: init reorganization of solver setup
jwboth Sep 18, 2023
3ded585
DOC/MAINT: Reorganize definition of L
jwboth Sep 18, 2023
31f9490
MAINT: Reorganize linear solution - for Newton
jwboth Sep 18, 2023
bd2da63
MAINT: rename attribute
jwboth Sep 18, 2023
182a26b
MAINT: Reorganize and bundle linear solution.
jwboth Sep 18, 2023
04a1246
DOC: Add better documentation of attributes
jwboth Sep 18, 2023
8107c60
TST: Extend Wasserstein test - add more solvers, prepare for 3d
jwboth Sep 18, 2023
c56d12b
MAINT: Generalize grid as preparation for extension to 3d.
jwboth Sep 19, 2023
ca9764b
TST: Provide test capabilities for 2d grids.
jwboth Sep 19, 2023
255a612
BUG: Fix divergence - wrong sorting.
jwboth Sep 19, 2023
77fe1b9
ENH: Provide face volumes for grids.
jwboth Sep 19, 2023
4aaee27
TST: Enhance grid test, check nontrivial voxel size
jwboth Sep 19, 2023
2b962a6
TST: Provide test for fv divergence operator.
jwboth Sep 19, 2023
85b415f
DOC: Add better descriptions of FV ojects.
jwboth Sep 19, 2023
5c9ab25
MAINT: Generalize/adapt reconstruction of tangential fluxes on faces.
jwboth Sep 19, 2023
425875f
MAINT: Generalize/adapt vector reconstruction of fluxes on cells.
jwboth Sep 19, 2023
bbc163f
MAINT: Use updated tangential reconstruction in Wasserstein computati…
jwboth Sep 19, 2023
753899e
MAINT: Clean up file, rename cell index attribute
jwboth Sep 19, 2023
96478b3
MAINT: Use shorter names for attributes in Grid.
jwboth Sep 19, 2023
11f362d
DOC: Add more attribute descriptions.
jwboth Sep 19, 2023
cb7c0df
MAINT: Adapt variable renaming.
jwboth Sep 19, 2023
642c476
ENH: Extend tensor grid utilities to 3d
jwboth Sep 19, 2023
6e3f2dc
TST: Add 3d grid test
jwboth Sep 19, 2023
8eba560
MAINT: Apply consistent ordering of faces and cells.
jwboth Sep 19, 2023
1dfd86b
TST: Adapt test new consistent indexing.
jwboth Sep 19, 2023
6d4154c
TST: Adapt divergence test for new indexing, and add 3d test
jwboth Sep 19, 2023
723fa4d
TST: Add test for mass matrices.
jwboth Sep 19, 2023
0ca6534
MAINT: adapt renaming and fix error (use concatenate)
jwboth Sep 19, 2023
e82a308
BUG: Apply correct ordering in reshaping
jwboth Sep 19, 2023
a133057
TST: Add many more fv tests.
jwboth Sep 19, 2023
4f11109
ENH: Significanlty simplify code for tangential reconstruction and ad…
jwboth Sep 21, 2023
90ff148
TST: Cover tangential and full face reconstruction.
jwboth Sep 21, 2023
6310432
MAINT: Improve error message for compatibility check of coordinate sy…
jwboth Sep 21, 2023
6603ce4
MAINT: Move 2d requirement from general compatibiliity check
jwboth Sep 21, 2023
e6f11b9
MAINT: Adapt use of reconstruction operator.
jwboth Sep 21, 2023
6a90f04
TST: Add 3d wasserstein test
jwboth Sep 21, 2023
4ee5a38
MAINT: Remove obsolete 3d wasserstein file.
jwboth Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
894 changes: 894 additions & 0 deletions examples/paper/pet_simulations_comparison_block_b.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ flake8
mypy
meshio
deepdiff
pyamg
4 changes: 4 additions & 0 deletions src/darsia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from darsia.utils.linear_solvers.mg import *
from darsia.utils.andersonacceleration import *
from darsia.utils.dtype import *
from darsia.utils.grid import *
from darsia.utils.fv import *
from darsia.corrections.basecorrection import *
from darsia.corrections.shape.curvature import *
from darsia.corrections.shape.affine import *
Expand Down Expand Up @@ -67,3 +69,5 @@
from darsia.assistants.base_assistant import *
from darsia.assistants.rotation_correction_assistant import *
from darsia.assistants.subregion_assistant import *

# from darsia.assistants.curvature_correction_assistant import *
3 changes: 2 additions & 1 deletion src/darsia/image/arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def weight(img: darsia.Image, weight: Union[float, int, darsia.Image]) -> darsia
weighted_img.img *= weight

elif isinstance(weight, darsia.Image):
assert darsia.check_equal_coordinatesystems(
equal_coordinate_system, log = darsia.check_equal_coordinatesystems(
img.coordinatesystem, weight.coordinatesystem, exclude_size=True
)
assert equal_coordinate_system, f"{log}"
space_dim = img.space_dim
assert len(weight.img.shape) == space_dim

Expand Down
76 changes: 51 additions & 25 deletions src/darsia/image/coordinatesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def check_equal_coordinatesystems(
coordinatesystem1: CoordinateSystem,
coordinatesystem2: CoordinateSystem,
exclude_size: bool = False,
) -> bool:
) -> tuple[bool, dict]:
"""Check whether two coordinate systems are equivalent, i.e., they share basic
attributes.

Expand All @@ -236,38 +236,64 @@ def check_equal_coordinatesystems(

Returns:
bool: True iff the two coordinate systems are equivalent.
dict: log of the failed checks.

"""
success = True
success = success and coordinatesystem1.indexing == coordinatesystem2.indexing
success = success and coordinatesystem1.dim == coordinatesystem2.dim
failure_log = []

if not (coordinatesystem1.indexing == coordinatesystem2.indexing):
failure_log.append("indexing")

if not (coordinatesystem1.dim == coordinatesystem2.dim):
failure_log.append("dim")

if not exclude_size:
success = success and np.allclose(
coordinatesystem1.shape, coordinatesystem2.shape
)
success = success and np.allclose(
coordinatesystem1.dimensions, coordinatesystem2.dimensions
)
success = success and coordinatesystem1.axes == coordinatesystem2.axes
if not (np.allclose(coordinatesystem1.shape, coordinatesystem2.shape)):
failure_log.append("shape")

if not (np.allclose(coordinatesystem1.dimensions, coordinatesystem2.dimensions)):
failure_log.append("dimensions")

if not (coordinatesystem1.axes == coordinatesystem2.axes):
failure_log.append("axes")

if not exclude_size:
voxel_size_equal = True
for axis in coordinatesystem1.axes:
success = (
success
voxel_size_equal = (
voxel_size_equal
and coordinatesystem1.voxel_size[axis]
== coordinatesystem2.voxel_size[axis]
)
success = success and np.allclose(
coordinatesystem1._coordinate_of_origin_voxel,
coordinatesystem2._coordinate_of_origin_voxel,
)
success = success and np.allclose(
coordinatesystem1._coordinate_of_opposite_voxel,
coordinatesystem2._coordinate_of_opposite_voxel,
)
if not exclude_size:
success = success and np.allclose(
coordinatesystem1._voxel_of_origin_coordinate,
coordinatesystem2._voxel_of_origin_coordinate,
if not voxel_size_equal:
failure_log.append("voxel_size")

if not (
np.allclose(
coordinatesystem1._coordinate_of_origin_voxel,
coordinatesystem2._coordinate_of_origin_voxel,
)
):
failure_log.append("coordinate_of_origin_voxel")

if not (
np.allclose(
coordinatesystem1._coordinate_of_opposite_voxel,
coordinatesystem2._coordinate_of_opposite_voxel,
)
):
failure_log.append("coordinate_of_opposite_voxel")

if not exclude_size:
if not (
np.allclose(
coordinatesystem1._voxel_of_origin_coordinate,
coordinatesystem2._voxel_of_origin_coordinate,
)
):
failure_log.append("voxel_of_origin_coordinate")

success = len(failure_log) == 0

return success
return success, failure_log
10 changes: 6 additions & 4 deletions src/darsia/measure/emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def __call__(
float or array: distance between img_1 and img_2.

"""
# Two-dimensional
if not (img_1.space_dim == 2 and img_2.space_dim == 2):
raise NotImplementedError("EMD only implemented for 2d.")

# FIXME investigation required regarding resize preprocessing...
# Preprocess images
preprocessed_img_1 = self._preprocess(img_1)
Expand Down Expand Up @@ -116,13 +120,11 @@ def _compatibility_check(
# Series
assert img_1.time_num == img_2.time_num

# Two-dimensional
assert img_1.space_dim == 2 and img_2.space_dim == 2

# Check whether the coordinate system is compatible
assert darsia.check_equal_coordinatesystems(
equal_coordinate_system, log = darsia.check_equal_coordinatesystems(
img_1.coordinatesystem, img_2.coordinatesystem
)
assert equal_coordinate_system, f"{log}"
assert np.allclose(img_1.voxel_size, img_2.voxel_size)

# Compatible distributions - comparing sums is sufficient since it is implicitly
Expand Down
Loading
Loading