Skip to content

Commit 0933df2

Browse files
committed
fix: when n_coils=1 no smaps computation is required.
1 parent 3a9b0d1 commit 0933df2

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/snake/core/handlers/fov.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,6 @@ def get_static(self, phantom: Phantom, sim_conf: SimConfig) -> Phantom:
131131
),
132132
dtype=phantom.masks.dtype,
133133
)
134-
new_smaps = np.zeros(
135-
(
136-
phantom.smaps.shape[0],
137-
*tuple(round(size_vox[i] / zoom_factor[i]) for i in range(3)),
138-
),
139-
dtype=phantom.smaps.dtype,
140-
)
141134

142135
run_parallel(
143136
_apply_transform,
@@ -149,17 +142,27 @@ def get_static(self, phantom: Phantom, sim_conf: SimConfig) -> Phantom:
149142
angles=self.angles,
150143
zoom_factor=zoom_factor,
151144
)
152-
153-
run_parallel(
154-
_apply_transform,
155-
phantom.smaps,
156-
new_smaps,
157-
parallel_axis=0,
158-
center=center_vox,
159-
size=size_vox,
160-
angles=self.angles,
161-
zoom_factor=zoom_factor,
162-
)
145+
if phantom.smaps is not None:
146+
return Phantom.from_masks(new_masks, sim_conf)
147+
new_smaps = np.zeros(
148+
(
149+
phantom.smaps.shape[0],
150+
*tuple(round(size_vox[i] / zoom_factor[i]) for i in range(3)),
151+
),
152+
dtype=phantom.smaps.dtype,
153+
)
154+
run_parallel(
155+
_apply_transform,
156+
phantom.smaps,
157+
new_smaps,
158+
parallel_axis=0,
159+
center=center_vox,
160+
size=size_vox,
161+
angles=self.angles,
162+
zoom_factor=zoom_factor,
163+
)
164+
else:
165+
new_smaps = None
163166

164167
# Create a new phantom with updated masks
165168
new_phantom = phantom.copy()

src/snake/core/phantom/static.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,19 @@ def from_brainweb(
151151
)
152152
tissues_mask = tissue_resized
153153

154+
smaps = None
155+
if sim_conf.hardware.n_coils > 1:
156+
smaps = get_smaps(
157+
tissues_mask.shape[1:],
158+
n_coils=sim_conf.hardware.n_coils,
159+
)
160+
154161
return cls(
155162
"brainweb",
156163
tissues_mask,
157164
labels=np.array([t[0] for t in tissues_list]),
158165
props=np.array([t[1:] for t in tissues_list]),
159-
smaps=get_smaps(
160-
tissues_mask.shape[1:],
161-
n_coils=sim_conf.hardware.n_coils,
162-
),
166+
smaps=smaps,
163167
)
164168

165169
@classmethod
@@ -202,7 +206,7 @@ def to_mrd_dataset(
202206
meta_sr = mrd.Meta(
203207
{
204208
"name": self.name,
205-
"labels": f'{",".join(self.labels)}',
209+
"labels": f"{','.join(self.labels)}",
206210
"props": serialize_array(self.props),
207211
}
208212
).serialize()
@@ -251,7 +255,9 @@ def from_shared_memory(
251255
with array_from_shm(mask_prop, label_prop, properties_prop, smaps_prop) as arrs:
252256
yield cls(name, *arrs)
253257

254-
def in_shared_memory(self, manager: SharedMemoryManager) -> tuple[
258+
def in_shared_memory(
259+
self, manager: SharedMemoryManager
260+
) -> tuple[
255261
tuple[str, ArrayProps, ArrayProps, ArrayProps, ArrayProps | None],
256262
tuple[SharedMemory, SharedMemory, SharedMemory, SharedMemory | None],
257263
]:

0 commit comments

Comments
 (0)