Skip to content

Commit

Permalink
fix: when n_coils=1 no smaps computation is required.
Browse files Browse the repository at this point in the history
  • Loading branch information
paquiteau committed Feb 11, 2025
1 parent 3a9b0d1 commit 0933df2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
39 changes: 21 additions & 18 deletions src/snake/core/handlers/fov.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ def get_static(self, phantom: Phantom, sim_conf: SimConfig) -> Phantom:
),
dtype=phantom.masks.dtype,
)
new_smaps = np.zeros(
(
phantom.smaps.shape[0],
*tuple(round(size_vox[i] / zoom_factor[i]) for i in range(3)),
),
dtype=phantom.smaps.dtype,
)

run_parallel(
_apply_transform,
Expand All @@ -149,17 +142,27 @@ def get_static(self, phantom: Phantom, sim_conf: SimConfig) -> Phantom:
angles=self.angles,
zoom_factor=zoom_factor,
)

run_parallel(
_apply_transform,
phantom.smaps,
new_smaps,
parallel_axis=0,
center=center_vox,
size=size_vox,
angles=self.angles,
zoom_factor=zoom_factor,
)
if phantom.smaps is not None:
return Phantom.from_masks(new_masks, sim_conf)
new_smaps = np.zeros(
(
phantom.smaps.shape[0],
*tuple(round(size_vox[i] / zoom_factor[i]) for i in range(3)),
),
dtype=phantom.smaps.dtype,
)
run_parallel(
_apply_transform,
phantom.smaps,
new_smaps,
parallel_axis=0,
center=center_vox,
size=size_vox,
angles=self.angles,
zoom_factor=zoom_factor,
)
else:
new_smaps = None

# Create a new phantom with updated masks
new_phantom = phantom.copy()
Expand Down
18 changes: 12 additions & 6 deletions src/snake/core/phantom/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,19 @@ def from_brainweb(
)
tissues_mask = tissue_resized

smaps = None
if sim_conf.hardware.n_coils > 1:
smaps = get_smaps(
tissues_mask.shape[1:],
n_coils=sim_conf.hardware.n_coils,
)

return cls(
"brainweb",
tissues_mask,
labels=np.array([t[0] for t in tissues_list]),
props=np.array([t[1:] for t in tissues_list]),
smaps=get_smaps(
tissues_mask.shape[1:],
n_coils=sim_conf.hardware.n_coils,
),
smaps=smaps,
)

@classmethod
Expand Down Expand Up @@ -202,7 +206,7 @@ def to_mrd_dataset(
meta_sr = mrd.Meta(
{
"name": self.name,
"labels": f'{",".join(self.labels)}',
"labels": f"{','.join(self.labels)}",
"props": serialize_array(self.props),
}
).serialize()
Expand Down Expand Up @@ -251,7 +255,9 @@ def from_shared_memory(
with array_from_shm(mask_prop, label_prop, properties_prop, smaps_prop) as arrs:
yield cls(name, *arrs)

def in_shared_memory(self, manager: SharedMemoryManager) -> tuple[
def in_shared_memory(
self, manager: SharedMemoryManager
) -> tuple[
tuple[str, ArrayProps, ArrayProps, ArrayProps, ArrayProps | None],
tuple[SharedMemory, SharedMemory, SharedMemory, SharedMemory | None],
]:
Expand Down

0 comments on commit 0933df2

Please sign in to comment.