Skip to content

Concentration round trip#34

Open
finsberg wants to merge 14 commits intomainfrom
inverse-concentration
Open

Concentration round trip#34
finsberg wants to merge 14 commits intomainfrom
inverse-concentration

Conversation

@finsberg
Copy link
Copy Markdown
Member

@finsberg finsberg commented Mar 24, 2026

  • Move functions voxel_fit_function, curve_fit_wrapper, and fit_voxel from utils.py to lookclocker.py (because they are only used here).
  • Move functions estimate_se_free_relaxation_time and T1_lookup_table from utils.py to mixed.py
  • Refactored Mixed module to use classes similar to LookLocker (see Test looklocker #39)
  • Implement test for concentration round trip, i.e start with a known concentration compute t1/ r1 values and then concentration again. To do this I also had to implement a few more functions e.g R1_from_concentration_expr and T1_from_concentration_expr.
  • Add an example of how to propagate noise through the concentration process, e.g start with a known concentration -> compute the t1 value -> compute the looklocker / mixed signal -> add noise (assuming some signal to noise ratio(SNR)) -> compute new t1 value -> compute new concentration. This way the user can play with how the SNR affects the uncertainty in the concentration estimates.

I also improved the typing in some of these function. For example consider the following function

def concentration_from_T1_expr(t1: np.ndarray, t1_0: np.ndarray, r1: float) -> np.ndarray:
    return (1.0 / r1) * ((1.0 / t1) - (1.0 / t1_0))

According to the type-annotation, t1 needs to by a numpy array. However we know that t1 can also by a float, but in that case t1_0 and the return value should also by a float. We can specify this using a type variable as follows

import typing

T  = typing.TypeVar("T", np.ndarray, float)

def concentration_from_T1_expr(t1: T, t1_0: T, r1: float) -> T:
    return (1.0 / r1) * ((1.0 / t1) - (1.0 / t1_0))

Here we also explicity bound the type variable to either a numpy array or a float (meaning that these are the only accepted types).

@finsberg finsberg marked this pull request as ready for review April 17, 2026 07:42
@finsberg finsberg changed the title Inverse concentration Concentration round trip Apr 17, 2026
@finsberg finsberg requested a review from cdaversin April 17, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant