-
Notifications
You must be signed in to change notification settings - Fork 3
/
CsmData.py
84 lines (68 loc) · 2.69 KB
/
CsmData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Class for coil sensitivity maps (csm)."""
from __future__ import annotations
from typing import TYPE_CHECKING
import torch
from typing_extensions import Self
from mrpro.data.IData import IData
from mrpro.data.QData import QData
from mrpro.data.SpatialDimension import SpatialDimension
if TYPE_CHECKING:
from mrpro.operators.SensitivityOp import SensitivityOp
class CsmData(QData):
"""Coil sensitivity map class."""
@classmethod
def from_idata_walsh(
cls,
idata: IData,
smoothing_width: int | SpatialDimension[int] = 5,
chunk_size_otherdim: int | None = None,
) -> Self:
"""Create csm object from image data using iterative Walsh method.
Parameters
----------
idata
IData object containing the images for each coil element.
smoothing_width
width of smoothing filter.
chunk_size_otherdim:
How many elements of the other dimensions should be processed at once.
Default is None, which means that all elements are processed at once.
"""
from mrpro.algorithms.csm.walsh import walsh
# convert smoothing_width to SpatialDimension if int
if isinstance(smoothing_width, int):
smoothing_width = SpatialDimension(smoothing_width, smoothing_width, smoothing_width)
csm_fun = torch.vmap(
lambda img: walsh(img, smoothing_width),
chunk_size=chunk_size_otherdim,
)
csm_tensor = csm_fun(idata.data)
csm = cls(header=idata.header, data=csm_tensor)
return csm
@classmethod
def from_idata_inati(
cls,
idata: IData,
smoothing_width: int | SpatialDimension[int] = 5,
chunk_size_otherdim: int | None = None,
) -> Self:
"""Create csm object from image data using Inati method.
Parameters
----------
idata
IData object containing the images for each coil element.
smoothing_width
Size of the smoothing kernel.
chunk_size_otherdim:
How many elements of the other dimensions should be processed at once.
Default is None, which means that all elements are processed at once.
"""
from mrpro.algorithms.csm.inati import inati
csm_fun = torch.vmap(lambda img: inati(img, smoothing_width), chunk_size=chunk_size_otherdim)
csm_tensor = csm_fun(idata.data)
csm = cls(header=idata.header, data=csm_tensor)
return csm
def as_operator(self) -> SensitivityOp:
"""Create SensitivityOp using a copy of the CSMs."""
from mrpro.operators.SensitivityOp import SensitivityOp
return SensitivityOp(self)