Skip to content

Commit c78c74e

Browse files
committed
fix+sty: argument specification + run black
1 parent 2e72608 commit c78c74e

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

sdcflows/transform.py

+48-35
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ async def worker(
118118
"""Create one worker and attach it to the execution loop."""
119119
async with semaphore:
120120
loop = asyncio.get_running_loop()
121-
result = await loop.run_in_executor(None, func, data, coordinates, pe_info, hmc_xfm)
121+
result = await loop.run_in_executor(
122+
None, func, data, coordinates, pe_info, hmc_xfm
123+
)
122124
return result
123125

124126

@@ -204,14 +206,16 @@ async def unwarp_parallel(
204206
xfm = None if xfms is None else xfms[volid]
205207

206208
# IMPORTANT - the coordinates array must be copied every time anew per thread
207-
task = asyncio.create_task(worker(
208-
volume,
209-
coordinates.copy(),
210-
pe_info[volid],
211-
xfm,
212-
func,
213-
semaphore,
214-
))
209+
task = asyncio.create_task(
210+
worker(
211+
volume,
212+
coordinates.copy(),
213+
pe_info[volid],
214+
xfm,
215+
func,
216+
semaphore,
217+
)
218+
)
215219
tasks.append(task)
216220

217221
# Wait for all tasks to complete
@@ -295,15 +299,16 @@ def fit(
295299
finest_coeffs = listify(self.coeffs)[-1]
296300
approx &= not np.allclose(
297301
np.linalg.norm(
298-
np.cross(finest_coeffs.affine[:-1, :-1].T, target_reference.affine[:-1, :-1].T),
302+
np.cross(
303+
finest_coeffs.affine[:-1, :-1].T,
304+
target_reference.affine[:-1, :-1].T,
305+
),
299306
axis=1,
300307
),
301308
0,
302309
atol=1e-3,
303310
)
304311

305-
306-
307312
weights = []
308313
coeffs = []
309314
if approx:
@@ -342,7 +347,9 @@ def fit(
342347
from nitransforms.linear import Affine
343348

344349
_tmp_reference = nb.Nifti1Image(
345-
np.zeros(target_reference.shape[:3], dtype=target_reference.get_data_dtype()),
350+
np.zeros(
351+
target_reference.shape[:3], dtype=target_reference.get_data_dtype()
352+
),
346353
target_reference.affine,
347354
target_reference.header,
348355
)
@@ -364,7 +371,7 @@ def apply(
364371
mode: str = "constant",
365372
cval: float = 0.0,
366373
prefilter: bool = True,
367-
output_dtype: str, np.dtype | None = None,
374+
output_dtype: str | np.dtype | None = None,
368375
num_threads: int = None,
369376
allow_negative: bool = False,
370377
):
@@ -478,16 +485,20 @@ def apply(
478485
axis_flip = axcodes[pe_axis] in ("LPI")
479486
pe_flip = pe_dir[volid].endswith("-")
480487

481-
pe_info.append((
482-
pe_axis,
483-
# Displacements are reversed if either is true (after ensuring positive cosines)
484-
-ro_time[volid] if (axis_flip ^ pe_flip) else ro_time[volid]
485-
))
488+
pe_info.append(
489+
(
490+
pe_axis,
491+
# Displacements are reversed if either is true (after ensuring positive cosines)
492+
-ro_time[volid] if (axis_flip ^ pe_flip) else ro_time[volid],
493+
)
494+
)
486495

487496
# Reference image's voxel coordinates (in voxel units)
488-
voxcoords = nt.linear.Affine(
489-
reference=moving
490-
).reference.ndindex.reshape((ndim, *data.shape[:ndim])).astype("float32")
497+
voxcoords = (
498+
nt.linear.Affine(reference=moving)
499+
.reference.ndindex.reshape((ndim, *data.shape[:ndim]))
500+
.astype("float32")
501+
)
491502

492503
# Convert head-motion transforms to voxel-to-voxel:
493504
if xfms is not None:
@@ -507,19 +518,21 @@ def apply(
507518
)
508519

509520
# Resample
510-
resampled = asyncio.run(unwarp_parallel(
511-
data,
512-
voxcoords,
513-
self.mapped.get_fdata(dtype="float32"), # fieldmap in Hz
514-
pe_info,
515-
xfms,
516-
output_dtype=output_dtype,
517-
order=order,
518-
mode=mode,
519-
cval=cval,
520-
prefilter=prefilter,
521-
max_concurrent=num_threads or min(os.cpu_count(), 12),
522-
))
521+
resampled = asyncio.run(
522+
unwarp_parallel(
523+
data,
524+
voxcoords,
525+
self.mapped.get_fdata(dtype="float32"), # fieldmap in Hz
526+
pe_info,
527+
xfms,
528+
output_dtype=output_dtype,
529+
order=order,
530+
mode=mode,
531+
cval=cval,
532+
prefilter=prefilter,
533+
max_concurrent=num_threads or min(os.cpu_count(), 12),
534+
)
535+
)
523536

524537
if not allow_negative:
525538
resampled[resampled < 0] = cval

sdcflows/workflows/apply/registration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def init_coeff2epi_wf(
147147

148148
if write_coeff:
149149
warn(
150-
"SDCFlows does not tinker with the coefficients file anymore, "
150+
"SDCFlows does not tinker with the coefficients file anymore, "
151151
"the `write_coeff` parameter will be removed in a future release."
152152
)
153153

0 commit comments

Comments
 (0)