Skip to content

Commit

Permalink
Some more small things (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolbPTB authored Jan 17, 2025
1 parent d43c1b2 commit f23103e
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"source": [
"## Set up density compensation operator $W$\n",
"We create a density compensation operator $W$ for weighting the loss. We use\n",
"Voronoi tesselation of the trajectory to calculate the `~mrpro.data.DcfData`.\n",
"Voronoi tessellation of the trajectory to calculate the `~mrpro.data.DcfData`.\n",
"\n",
"```{note}\n",
"Using a weighted loss in iterative SENSE is not necessary, and there has been some discussion about\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
# %% [markdown]
# ## Set up density compensation operator $W$
# We create a density compensation operator $W$ for weighting the loss. We use
# Voronoi tesselation of the trajectory to calculate the `~mrpro.data.DcfData`.
# Voronoi tessellation of the trajectory to calculate the `~mrpro.data.DcfData`.
#
# ```{note}
# Using a weighted loss in iterative SENSE is not necessary, and there has been some discussion about
Expand Down
4 changes: 2 additions & 2 deletions src/mrpro/algorithms/dcf/dcf_voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def dcf_1d(traj: torch.Tensor) -> torch.Tensor:
"""Calculate sample density compensation function for 1D trajectory.
This function operators on a single `other` sample.
See also `~mrpro.data.DCFData` and `mrpro.utils.smap`
See also `~mrpro.data.DcfData` and `mrpro.utils.smap`
Parameters
----------
Expand Down Expand Up @@ -72,7 +72,7 @@ def dcf_2d3d_voronoi(traj: torch.Tensor) -> torch.Tensor:
DCF is then computed based on the inverse of the area of these regions.
This function operators on a single `other` sample.
See also `~mrpro.data.DCFData` and `mrpro.utils.smap`
See also `~mrpro.data.DcfData` and `mrpro.utils.smap`
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/algorithms/optimizers/cg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def cg(
.. [Hestenes1952] Hestenes, M. R., & Stiefel, E. (1952). Methods of conjugate gradients for solving linear systems.
Journal of Research of the National Bureau of Standards , 49(6), 409-436
.. [Nocedal2006] Nocedal, J. (2006). *Numerical Optimization* (2nd ed.). Springer.
.. [WikipediaCG] `Wikipedia: Conjugate Gradient<https://en.wikipedia.org/wiki/Conjugate_gradient>_`
.. [WikipediaCG] Wikipedia: Conjugate Gradient https://en.wikipedia.org/wiki/Conjugate_gradient
"""
if initial_value is not None and (initial_value.shape != right_hand_side.shape):
raise ValueError(
Expand Down
7 changes: 3 additions & 4 deletions src/mrpro/algorithms/optimizers/lbfgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ def lbfgs(
References
----------
.. [NOC1980] Nocedal, J. (1980). "Updating quasi-Newton matrices with limited storage."
*Mathematics of Computation*, 35(151), 773-782.
`10.1090/S0025-5718-1980-0572855-7<https://doi.org/10.1090/S0025-5718-1980-0572855-7>_`
*Mathematics of Computation*, 35(151), 773-782. https://doi.org/10.1090/S0025-5718-1980-0572855-7
.. [LIU1989] Liu, D. C., & Nocedal, J. (1989). "On the limited memory BFGS method for large scale optimization."
*Mathematical Programming*, 45(1-3), 503-528. `10.1007/BF01589116<https://doi.org/10.1007/BF01589116>_`
.. [WIKI] Wikipedia: `Limited-memory_BFGS <https://en.wikipedia.org/wiki/Limited-memory_BFGS>`_
*Mathematical Programming*, 45(1-3), 503-528. https://doi.org/10.1007/BF01589116
.. [WIKI] Wikipedia: Limited-memory_BFGS https://en.wikipedia.org/wiki/Limited-memory_BFGS
Parameters
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/data/DcfData.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DcfData(MoveDataMixin):
"""Density compensation data (DcfData) class."""

data: torch.Tensor
"""Density compensation values. Shape (... other, k2, k1, k0)"""
"""Density compensation values. Shape `(... other, k2, k1, k0)`"""

@classmethod
def from_traj_voronoi(cls, traj: KTrajectory) -> Self:
Expand Down
16 changes: 7 additions & 9 deletions src/mrpro/data/Rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,8 @@ def align_vectors(
where :math:`w_i`'s are the `weights` corresponding to each vector.
The rotation is estimated with Kabsch algorithm [1]_, and solves what
is known as the "pointing problem", or "Wahba's problem" [2]_.
The rotation is estimated with Kabsch algorithm [KAB]_, and solves what
is known as the "pointing problem", or "Wahba's problem" [WAH]_.
There are two special cases. The first is if a single vector is given
for `a` and `b`, in which the shortest distance rotation that aligns
Expand All @@ -1781,7 +1781,7 @@ def align_vectors(
of these two rotations. The result via this process is the same as the
Kabsch algorithm as the corresponding weight approaches infinity in
the limit. For a single secondary vector this is known as the
"align-constrain" algorithm [3]_.
"align-constrain" algorithm [MAG2018]_.
For both special cases (single vectors or an infinite weight), the
sensitivity matrix does not have physical meaning and an error will be
Expand Down Expand Up @@ -1822,12 +1822,10 @@ def align_vectors(
References
----------
.. [1] https://en.wikipedia.org/wiki/Kabsch_algorithm
.. [2] https://en.wikipedia.org/wiki/Wahba%27s_problem
.. [3] Magner, Robert,
"Extending target tracking capabilities through trajectory and
momentum setpoint optimization." Small Satellite Conference,
2018.
.. [KAB] https://en.wikipedia.org/wiki/Kabsch_algorithm
.. [WAH] https://en.wikipedia.org/wiki/Wahba%27s_problem
.. [MAG2018] Magner R (2018), Extending target tracking capabilities through trajectory and momentum setpoint
optimization. Small Satellite Conference.
"""
a_tensor = torch.stack([torch.as_tensor(el) for el in a]) if isinstance(a, Sequence) else torch.as_tensor(a)
b_tensor = torch.stack([torch.as_tensor(el) for el in b]) if isinstance(b, Sequence) else torch.as_tensor(b)
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/operators/models/InversionRecovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def forward(self, m0: torch.Tensor, t1: torch.Tensor) -> tuple[torch.Tensor,]:
Returns
-------
signal with shape `(time *other, coils, z, y, x)`
signal with shape `(time, *other, coils, z, y, x)`
"""
ti = unsqueeze_right(self.ti, m0.ndim - (self.ti.ndim - 1)) # -1 for time
signal = m0 * (1 - 2 * torch.exp(-(ti / t1)))
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/operators/models/MOLLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def forward(self, a: torch.Tensor, c: torch.Tensor, t1: torch.Tensor) -> tuple[t
Returns
-------
signal with shape `(time *other, coils, z, y, x)`
signal with shape `(time, *other, coils, z, y, x)`
"""
ti = unsqueeze_right(self.ti, a.ndim - (self.ti.ndim - 1)) # -1 for time
signal = a * (1 - c * torch.exp(ti / t1 * (1 - c)))
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/operators/models/MonoExponentialDecay.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def forward(self, m0: torch.Tensor, decay_constant: torch.Tensor) -> tuple[torch
Returns
-------
signal with shape `(time *other, coils, z, y, x)`
signal with shape `(time, *other, coils, z, y, x)`
"""
decay_time = unsqueeze_right(self.decay_time, m0.ndim - (self.decay_time.ndim - 1)) # -1 for time
signal = m0 * torch.exp(-(decay_time / decay_constant))
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/operators/models/SaturationRecovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def forward(self, m0: torch.Tensor, t1: torch.Tensor) -> tuple[torch.Tensor,]:
Returns
-------
signal with shape `(time *other, coils, z, y, x)`
signal with shape `(time, *other, coils, z, y, x)`
"""
ti = unsqueeze_right(self.ti, m0.ndim - (self.ti.ndim - 1)) # -1 for time
signal = m0 * (1 - torch.exp(-(ti / t1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TransientSteadyStateWithPreparation(SignalModel[torch.Tensor, torch.Tensor
- Part B: Commonly after an inversion pulse a strong spoiler gradient is played out to compensate for non-perfect
inversion. During this time the magnetization :math:`M_z(t)` follows the signal model:
:math:`M_z(t) = M_0 + (s * M_0 - M_0)e^{(-t / T1)}` where :math:`s` is ``m0_scaling_preparation``.
:math:`M_z(t) = M_0 + (s * M_0 - M_0)e^{(-t / T1)}` where :math:`s` is `m0_scaling_preparation`.
- Part C: After the spoiler gradient the data acquisition starts and the magnetization :math:`M_z(t)` can be
described by the signal model: :math:`M_z(t) = M_0^* + (M_{init} - M_0^*)e^{(-t / T1^*)}`
Expand Down Expand Up @@ -101,7 +101,7 @@ def forward(self, m0: torch.Tensor, t1: torch.Tensor, flip_angle: torch.Tensor)
Returns
-------
signal with shape `(time *other, coils, z, y, x)`
signal with shape `(time, *other, coils, z, y, x)`
"""
m0_ndim = m0.ndim

Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/operators/models/WASABI.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def forward(
Returns
-------
signal with shape `(offsets *other, coils, z, y, x)`
signal with shape `(offsets, *other, coils, z, y, x)`
"""
offsets = unsqueeze_right(self.offsets, b0_shift.ndim - (self.offsets.ndim - 1)) # -1 for offset
delta_b0 = offsets - b0_shift
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/operators/models/WASABITI.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def forward(self, b0_shift: torch.Tensor, relative_b1: torch.Tensor, t1: torch.T
Returns
-------
signal with shape `(offsets *other, coils, z, y, x)`
signal with shape `(offsets, *other, coils, z, y, x)`
"""
delta_ndim = b0_shift.ndim - (self.offsets.ndim - 1) # -1 for offset
offsets = unsqueeze_right(self.offsets, delta_ndim)
Expand Down
2 changes: 1 addition & 1 deletion src/mrpro/utils/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def unsqueeze_left(x: torch.Tensor, n: int) -> torch.Tensor:
"""Unsqueze multiple times in the leftmost dimension.
Example:
tensor with shape `(1,2,3) `and `n=2` would result in tensor with shape `(1,1,1,2,3)`
tensor with shape `(1,2,3)` and `n=2` would result in tensor with shape `(1,1,1,2,3)`
Parameters
Expand Down

0 comments on commit f23103e

Please sign in to comment.