Skip to content

Commit

Permalink
motion tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
paquiteau committed May 2, 2024
1 parent a955b17 commit 0e69a26
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/conf/scenario2-image-motion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ignore_patterns:

sim_params:
sim_tr: 0.1
sim_time: 300
sim_time: 1
shape: [-1,-1,-1] # shape will be determined with the bbox and the brainweb phantom.
fov: [-1,-1,-1]
n_coils: 8
Expand All @@ -41,11 +41,11 @@ handlers:
bold_strength: 0.02

motion-image:
ts_std_mm: [1.0, 1.0, 1.0]
rs_std_mm: [0.1, 0.1, 0.1]
ts_std_mms: [0.3, 0.1, 0.1]
rs_std_mms: [0.0115, 0.0277, 0.033]

noise-gaussian:
snr: 30
snr: 1000
acquisition-sos:
shot_time_ms: 50
acsz: 0.125
Expand Down Expand Up @@ -79,6 +79,7 @@ reconstructors:
# algorithm: otazo

stats:
disabled: true
contrast_name: block_on


Expand Down
11 changes: 8 additions & 3 deletions src/snkf/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ def main_app(cfg: ConfigSnakeFMRI) -> None:
np.save(f"data_rec_{rec_str}.npy", data_test)

logger.debug("Current simulation state: %s", sim)
with PerfLogger(logger, name="Analysis " + str(rec_str)):
zscore = contrast_zscore(data_test, sim, cfg.stats.contrast_name)
stats = get_scores(zscore, sim.roi)
if not cfg.stats.disabled:

with PerfLogger(logger, name="Analysis " + str(rec_str)):
zscore = contrast_zscore(data_test, sim, cfg.stats.contrast_name)
stats = get_scores(zscore, sim.roi)
else:
stats = {}
zscore = None

np.save(f"data_zscore_{rec_str}.npy", zscore)
results.append(
Expand Down
16 changes: 9 additions & 7 deletions src/snkf/handlers/motion/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,29 @@ class RandomMotionImageHandler(AbstractHandler):

__handler_name__ = "motion-image"

ts_std_mm: tuple[float, float, float] = None
rs_std_mm: tuple[float, float, float] = None
ts_std_mms: tuple[float, float, float] | None = None
rs_std_mms: tuple[float, float, float] | None = None

motion_file: str = None
motion_file_tr: float = None
motion_file: str | None = None
motion_file_tr: float | None = None

def __post_init__(self):
if (self.ts_std_mm is None or self.rs_std_mm is None) and (
super().__post_init__()
if (self.ts_std_mms is None or self.rs_std_mms is None) and (
self.motion_file is None or self.motion_file_tr is None
):
raise ValueError(
"At least one of ts_std_mm, rs_std_mm or motion_file must be provided."
)
self._motion_data = None
if self.motion_file is not None:
# load the motion file
self._motion_data = np.loadtxt(self.motion_file)

def _handle(self, sim: SimData) -> SimData:
n_frames = sim.data_acq.shape[0]
# update the translation to be in voxel units
ts_std_pix = np.array(self.ts_std_mm) / np.array(sim.res_mm)
ts_std_pix = np.array(self.ts_std_mms) / np.array(sim.res_mm)

if self._motion_data is not None:
# resample the motion data to match the simulation framerate.
Expand All @@ -76,7 +78,7 @@ def _handle(self, sim: SimData) -> SimData:
motion = motion_generator(
n_frames,
ts_std_pix,
self.rs_std_mm,
self.rs_std_mms,
sim.sim_tr,
sim.rng,
)
Expand Down

0 comments on commit 0e69a26

Please sign in to comment.