Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Leverage new spun-off apply interface #1313

Merged
merged 3 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions mriqc/data/testdata/group_bold.tsv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
bids_name aor aqi dummy_trs dvars_nstd dvars_std dvars_vstd efc fber fd_mean fd_num fd_perc fwhm_avg fwhm_x fwhm_y fwhm_z gcor gsr_x gsr_y size_t size_x size_y size_z snr spacing_tr spacing_x spacing_y spacing_z summary_bg_k summary_bg_mad summary_bg_mean summary_bg_median summary_bg_n summary_bg_p05 summary_bg_p95 summary_bg_stdv summary_fg_k summary_fg_mad summary_fg_mean summary_fg_median summary_fg_n summary_fg_p05 summary_fg_p95 summary_fg_stdv tsnr
sub-ds205s03_task-functionallocalizer_run-01_bold 0.0038873170731707324 0.007676269512195123 0 23.556566426419753 1.111688350987654 1.037835274938272 0.5480388108408939 946.6738891601562 0.26118389619646404 32 39.02439024390244 2.460305 2.3309525 2.749775 2.3001875 0.0680646 -0.009326859377324581 0.05734974890947342 82 53 53 27 4.452167473312103 2.200000047683716 4.0 4.0 4.0 32.7759659672557 7.720380258975168 49.68507569151857 24.975608825683594 55688.0 2.341463327407837 179.5365753173828 79.87659545341923 1.3897322764135298 138.87641036027622 767.1765602872674 768.451171875 20155.0 461.5243835449219 1042.731689453125 172.5973051795346 60.897049377672374
sub-ds205s03_task-view_run-01_bold 0.004324782608695651 0.008262664456521738 0 21.120018382857136 1.0831709981318685 1.0370256236263742 0.5459090166346154 1002.2031860351562 0.16520736608810047 18 19.565217391304348 2.342805 2.234215 2.613075 2.181125 0.0235103 -0.0050179013051092625 0.04793250188231468 92 53 53 27 4.4829699247170405 2.200000047683716 4.0 4.0 4.0 29.71988008857921 7.139052847581331 46.66574967004908 24.7608699798584 55362.0 0.032608695328235626 164.9891357421875 71.66784333938988 1.596677545134333 133.64368600192023 779.8773281882851 783.8695678710938 20481.0 457.5434875488281 1054.61962890625 174.85070038268285 62.58223795099184
sub-ds205s03_task-view_run-02_bold 0.0012682608695652171 0.007114478586956522 0 33.47404192791209 1.3371308202197805 0.9764774098901093 0.5494999624875053 955.73681640625 0.22854716046970905 44 47.82608695652174 2.4598116666666665 2.3444425 2.7437 2.2912925 0.359354 -0.009432817809283733 0.052887145429849625 92 53 53 27 4.419438774661141 2.200000047683716 4.0 4.0 4.0 29.03249120482654 7.7192010499810335 49.54353785439428 24.934783935546875 55415.0 0.20652174949645996 181.78260803222656 80.45599936028407 1.4009872052560288 139.07454009400536 768.1427012059421 770.8587036132812 20428.0 459.5326232910156 1046.8260498046875 174.42029972293017 45.2559957196936
sub-ds205s07_task-functionallocalizer_run-01_bold 0.006487361111111111 0.006664996805555556 0 26.95528650943662 1.4143280252112678 1.3278985984507037 0.5345065899755163 1009.7532348632812 0.1550487344317312 15 20.833333333333332 2.2598908333333334 2.16087 2.40925 2.2095525 0.0386767 -0.005986093543469906 0.03482493385672569 72 53 53 27 4.598492679701605 2.200000047683716 4.0 4.0 4.0 35.90517987432788 6.32165175453679 43.5521938439157 22.56944465637207 56450.0 0.0 157.3333282470703 77.35003442698779 1.656221989802022 134.60795658544046 716.0395720200634 717.1805419921875 19393.0 440.0694580078125 951.6666870117188 155.95589707318132 73.35539675597101
sub-ds205s07_task-view_run-01_bold 0.005007608695652174 0.010561140108695653 0 26.932940011208803 1.2896941338461543 1.168551503516483 0.5321868933927048 1023.4715576171875 0.1520993052375479 15 16.304347826086957 2.266245 2.184035 2.4189475 2.1957525 0.0478984 -0.006112692411988974 0.03277275711297989 92 53 53 27 4.595802249004055 2.200000047683716 4.0 4.0 4.0 33.63529478261993 6.2365988314754315 42.79862974194479 22.380435943603516 56588.0 0.3804347813129425 153.56521606445312 75.85331035278197 1.585165284213823 135.14239559316104 713.6245609062549 715.9891357421875 19255.0 437.3913269042969 947.5869750976562 155.78793525432897 63.332828449318185
sub-ds205s07_task-view_run-02_bold 0.0027991304347826083 0.008415782065217392 0 27.396022419560428 1.345632817142857 1.2136871409890106 0.5333849667366366 1016.1077880859375 0.15451170465747024 18 19.565217391304348 2.271710833333333 2.1726275 2.433375 2.20913 0.0505144 -0.005830460228025913 0.03532366082072258 92 53 53 27 4.598664236595992 2.200000047683716 4.0 4.0 4.0 36.078683930448996 6.575017673595487 43.39332640278381 22.565217971801758 56589.0 1.22826087474823 155.56521606445312 75.49560044499137 1.6540993322199018 136.17376514793506 717.751513360383 719.2989501953125 19254.0 443.8260803222656 952.5978393554688 156.41069531029106 64.89047080953605
sub-ds205s09_task-view_acq-LR_run-01_bold 0.003159041095890411 0.010028379999999998 0 20.396152721388898 1.090989740416667 1.0059027894444443 0.5048353890125871 1243.320556640625 0.3258302280827085 45 61.64383561643836 2.0852608333333333 2.0588275 2.2995125 1.8974425 0.0461463 -0.0019858605228364468 0.021903924643993378 73 53 53 27 5.292682271102816 2.200000047683716 4.0 4.0 4.0 33.98009379704732 5.949264906571304 39.07313696894552 22.956466674804688 58369.0 1.0936830043792725 132.37034606933594 62.99641049623399 2.7398312528413937 115.58686871143783 791.6591133225957 809.4622802734375 17474.0 483.6707458496094 994.6715698242188 152.93552051211557 66.51667785644531
sub-ds205s09_task-view_acq-LR_run-02_bold 0.005322328767123288 0.012026137260273973 0 33.41256753611111 1.7174510266666663 1.7695175424999998 0.5052536160578726 1231.6690673828125 0.3345943377548133 47 64.38356164383562 2.0866866666666666 2.0591175 2.3078075 1.893135 0.0393612 -0.0014911222970113158 0.021568207070231438 73 53 53 27 5.293464753553317 2.200000047683716 4.0 4.0 4.0 33.28261057706237 6.199152583273201 39.20170865624716 23.102066040039062 58361.0 1.1750245094299316 131.959716796875 62.4980652302799 2.7186948010130694 115.65690863557867 792.8781950379683 810.7703247070312 17482.0 484.3922119140625 996.912109375 153.16001398016576 59.753475189208984
sub-ds205s09_task-view_acq-RL_run-01_bold 0.015073150684931508 0.015836369041095893 0 34.205267455972226 1.4370176472222222 1.2820233763888884 0.5044353080190683 1274.420654296875 0.5699059645824405 53 72.6027397260274 2.08056 2.068795 2.288455 1.88443 0.0560156 -0.0013055995805189013 0.018262900412082672 73 53 53 27 5.229556365898414 2.200000047683716 4.0 4.0 4.0 31.57766555712935 5.840893620522815 38.89056185642749 22.814455032348633 58350.0 3.888171911239624 132.03933715820312 61.89358205002823 2.599912401497959 117.24294190485038 794.526159305144 814.4539184570312 17493.0 471.96441650390625 999.9562377929688 155.73608576273267 52.76657485961914
sub-ds205s03_task-functionallocalizer_run-01_bold 0.006812560975609757 0.0115670556097561 0 25.1070652945679 1.097686276419753 1.0416085834567903 0.549 939.7262 0.26118389619646404 32 39.02439024390244 2.4148566666666667 2.3126025 2.6542 2.2777675 0.0530274 -0.0060755726881325245 0.05317099019885063 82 53 53 27 4.302882006355157 2.200000047683716 4.0 4.0 4.0 34.9329 6.8706 47.6781 25.0 55237.0 0.0 166.0 74.859 1.3937 141.0732 761.3085 766.0 20606.0 433.0 1043.0 178.0159 54.188138624303974
sub-ds205s03_task-view_run-01_bold 0.005475217391304348 0.013897893369565218 0 21.735744036263725 1.010356766043956 0.9669979157142857 0.5465 989.9058 0.16520736608810047 18 19.565217391304348 2.3125358333333335 2.223185 2.54445 2.1699725 0.0183059 -0.002810143167153001 0.046066656708717346 92 53 53 27 4.270553474790369 2.200000047683716 4.0 4.0 4.0 32.4062 6.9134 44.6849 25.0 54949.0 0.0 151.0 65.9059 1.6759 136.8668 773.1685 781.0 20894.0 421.0 1055.0 182.8759 53.13771811965853
sub-ds205s03_task-view_run-02_bold 0.0006215217391304349 0.010315522826086956 0 24.14205940978022 0.9597649761538458 0.8938210656043953 0.5485 943.6607 0.22854716046970905 44 47.82608695652174 2.3873583333333332 2.2945375 2.63535 2.2321875 0.328611 -0.00470705283805728 0.05208124592900276 92 53 53 27 4.292060341610993 2.200000047683716 4.0 4.0 4.0 33.8004 6.9296 46.8711 25.0 55158.0 0.0 163.0 72.0558 1.4929 140.0737 764.2329 769.0 20685.0 434.0 1045.0 179.1637 42.4139485983178
sub-ds205s07_task-functionallocalizer_run-01_bold 0.0097325 0.008122680138888888 0 22.073046106619717 1.1242277719718308 1.0418761863380284 0.5321 1003.9077 0.1550487344317312 15 20.833333333333332 2.2189575 2.116755 2.370535 2.1695825 0.0295023 -0.003530273912474513 0.0362667478621006 72 53 53 27 4.409949445356891 2.200000047683716 4.0 4.0 4.0 40.4268 6.6305 40.5373 23.0 56224.0 0.0 143.0 67.4229 1.8008 135.9876 712.2398 716.0 19619.0 415.0 952.0 162.356 65.09344540000893
sub-ds205s07_task-view_run-01_bold 0.005717500000000001 0.015141807826086954 0 21.867432625934065 0.9809244036263738 0.9361462984615384 0.5298 1015.919 0.1520993052375479 15 16.304347826086957 2.1996341666666663 2.110345 2.336455 2.1521025 0.028804 -0.0024572680704295635 0.03488033637404442 92 53 53 27 4.467323221209426 2.200000047683716 4.0 4.0 4.0 39.4612 5.8821 39.4347 22.0 56329.0 0.0 137.0 65.029 1.8043 135.4567 710.9964 715.0 19514.0 423.0 948.0 160.047 50.81706294429023
sub-ds205s07_task-view_run-02_bold 0.0019280434782608694 0.01469097902173913 0 21.71987449747252 0.9869364002197802 0.9372538456043953 0.5315 1012.3607 0.15451170465747024 18 19.565217391304348 2.2102749999999998 2.1198225 2.355215 2.1557875 0.0282757 -0.003044865559786558 0.03623408451676369 92 53 53 27 4.502285066407165 2.200000047683716 4.0 4.0 4.0 37.252 6.7362 40.3357 23.0 56296.0 0.0 141.0 66.2132 1.742 136.9312 715.2621 719.0 19547.0 425.0 953.0 159.6926 54.497344811446965
sub-ds205s09_task-view_acq-LR_run-01_bold 0.005411917808219178 0.02228016890410959 0 22.789714455277778 1.0361108005555557 0.9880990412500006 0.5046 1243.5212 0.3258302280827085 45 61.64383561643836 2.0211908333333333 1.9766875 2.2314 1.855485 0.037065 -0.00114234269130975 0.020379802212119102 73 53 53 27 5.088720189319215 2.200000047683716 4.0 4.0 4.0 41.6293 5.6235 36.982 23.0 57997.0 0.0 119.0 58.2122 2.5735 118.3639 786.0496 807.0 17846.0 457.0 994.0 158.5816 55.06427192687988
sub-ds205s09_task-view_acq-LR_run-02_bold 0.006466849315068492 0.023947604931506848 0 35.58600070722225 1.5587390695833334 1.6208429509722224 0.5051 1232.5525 0.3345943377548133 47 64.38356164383562 2.02274 1.97389 2.2416425 1.8526875 0.0323589 -0.0008835982298478484 0.02095068246126175 73 53 53 27 5.084970245127033 2.200000047683716 4.0 4.0 4.0 42.4942 5.7296 37.2487 23.0 57995.0 0.0 119.0 58.4499 2.5301 118.1555 787.196 808.0 17848.0 457.0 995.0 158.8952 50.56220245361328
sub-ds205s09_task-view_acq-RL_run-01_bold 0.04121205479452055 0.051308654931506846 0 34.42111142402777 1.1784485243055556 1.1142821890277776 0.5037 1259.7075 0.5699059645824405 53 72.6027397260274 2.088614166666667 2.02464 2.2896075 1.951595 0.0262465 -5.7171993830706924e-05 0.019421251490712166 73 53 53 27 5.22544217847827 2.200000047683716 4.0 4.0 4.0 39.0221 5.5174 37.1308 23.0 58112.0 0.0 119.0 58.7922 2.4832 116.4866 790.9759 811.0 17731.0 466.0 993.0 155.1978 36.441200256347656
17 changes: 14 additions & 3 deletions mriqc/workflows/functional/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,16 @@ def hmc(name='fMRI_HMC', omp_nthreads=None):

# Apply transforms to other echos
apply_hmc = pe.MapNode(
niu.Function(function=_apply_transforms, input_names=['in_file', 'in_xfm']),
niu.Function(
function=_apply_transforms,
input_names=['in_file', 'in_xfm', 'max_concurrent'],
),
name='apply_hmc',
iterfield=['in_file'],
# NiTransforms is a memory hog, so ensure only one process is running at a time
n_procs=config.environment.cpu_count,
)
apply_hmc.inputs.max_concurrent = 4

# fmt: off
workflow.connect([
Expand Down Expand Up @@ -764,14 +768,21 @@ def _parse_tout(in_file):
return data.mean()


def _apply_transforms(in_file, in_xfm):
def _apply_transforms(in_file, in_xfm, max_concurrent):
from pathlib import Path

from nitransforms.linear import load
from nitransforms.resampling import apply

from mriqc.utils.bids import derive_bids_fname

realigned = load(in_xfm, fmt='afni', reference=in_file, moving=in_file).apply(in_file)
realigned = apply(
load(in_xfm, fmt='afni', reference=in_file, moving=in_file),
in_file,
dtype_width=4,
serialize_nvols=2,
max_concurrent=max_concurrent,
)
out_file = derive_bids_fname(
in_file,
entity='desc-realigned',
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"nilearn >= 0.5.1",
"nipype ~= 1.4",
"nireports ~= 23.1",
"nitransforms ~= 23.0",
"nitransforms ~= 24.0",
"niworkflows ~=1.10.1",
"numpy ~=1.20",
"pandas",
Expand Down
Loading