diff --git a/dosma/core/numpy_routines.py b/dosma/core/numpy_routines.py index a96e9a4..b887d64 100644 --- a/dosma/core/numpy_routines.py +++ b/dosma/core/numpy_routines.py @@ -161,7 +161,7 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None): return x._partial_clone(volume=vol) -@implements(np.around, np.round, np.round_) +@implements(np.around, np.round, np.round) def around(x, decimals=0, affine=False): """Round medical image pixel data (and optionally affine) to the given number of decimals. diff --git a/dosma/models/model_loading_util.py b/dosma/models/model_loading_util.py index 55c7310..faad8a7 100644 --- a/dosma/models/model_loading_util.py +++ b/dosma/models/model_loading_util.py @@ -72,7 +72,7 @@ def _gen_mask(func, *_args, **_kwargs): if isinstance(cfg_file_or_dict, str): with open(cfg_file_or_dict, "r") as f: - cfg = yaml.load(f) + cfg = yaml.load(f, Loader=yaml.FullLoader) else: cfg = cfg_file_or_dict diff --git a/dosma/models/oaiunet2d.py b/dosma/models/oaiunet2d.py index 5a919f7..05fba69 100644 --- a/dosma/models/oaiunet2d.py +++ b/dosma/models/oaiunet2d.py @@ -79,6 +79,7 @@ def __load_keras_model__(self, input_shape, force_weights=False): padding="same", activation="relu", kernel_initializer="he_normal", + name=f"conv2d_down_{depth_cnt}_1" # Unique name for each layer )(pool) conv = Conv2D( nfeatures[depth_cnt], @@ -86,6 +87,7 @@ def __load_keras_model__(self, input_shape, force_weights=False): padding="same", activation="relu", kernel_initializer="he_normal", + name=f"conv2d_down_{depth_cnt}_2" # Unique name for each layer )(conv) conv = BN(axis=-1, momentum=0.95, epsilon=0.001)(conv) @@ -134,6 +136,7 @@ def __load_keras_model__(self, input_shape, force_weights=False): padding="same", activation="relu", kernel_initializer="he_normal", + name=f"conv2d_up_{depth_cnt}_1" # Unique name for each layer )(up) conv = Conv2D( nfeatures[depth_cnt], @@ -141,6 +144,7 @@ def __load_keras_model__(self, input_shape, force_weights=False): padding="same", activation="relu", kernel_initializer="he_normal", + name=f"conv2d_up_{depth_cnt}_2" # Unique name for each layer )(conv) conv = BN(axis=-1, momentum=0.95, epsilon=0.001)(conv) diff --git a/dosma/scan_sequences/mri/qdess.py b/dosma/scan_sequences/mri/qdess.py index a308a39..341c864 100644 --- a/dosma/scan_sequences/mri/qdess.py +++ b/dosma/scan_sequences/mri/qdess.py @@ -107,6 +107,7 @@ def generate_t2_map( tissue: Tissue = None, suppress_fat: bool = False, suppress_fluid: bool = False, + b1map: MedicalVolume = None, beta: float = 1.2, gl_area: float = None, tg: float = None, @@ -211,9 +212,16 @@ def generate_t2_map( # Flip Angle (degree -> radians) alpha = float(ref_dicom.FlipAngle) if alpha is None else alpha - alpha = math.radians(alpha) - if np.allclose(math.sin(alpha / 2), 0): - warnings.warn("sin(flip angle) is close to 0 - t2 map may fail.", stacklevel=2) + + if b1map: + alpha_nominal = deepcopy(alpha) + alpha = np.multiply(b1map.volume, math.radians(alpha)) + if np.allclose(np.sin(alpha_nominal / 2), 0): + warnings.warn("sin(flip angle) is close to 0 - t2 map may fail.") + else: + alpha = math.radians(alpha) + if np.allclose(math.sin(alpha / 2), 0): + warnings.warn("sin(flip angle) is close to 0 - t2 map may fail.") mask = xp.ones([r, c, num_slices]) @@ -244,7 +252,7 @@ def generate_t2_map( / (1 - xp.cos(alpha) * xp.exp(-TR / T1)) ) c1 = 0 - + # have to divide division into steps to avoid overflow error t2map = -2000 * (TR - TE) / (xp.log(abs(ratio) / k) + c1) t2map = xp.nan_to_num(t2map)