<commit_before>from neuroimaging.neurospin import register 
from neuroimaging.neurospin import neuro

import numpy as np
from os.path import join
import sys
import time

rootpath = 'D:\\data\\fiac'
runnames = ['run1', 'run1']

im1 = neuro.image(join(rootpath, runnames[0]+'.nii'))
im2 = neuro.image(join(rootpath, runnames[1]+'.nii'))

run1 = register.TimeSeries(im1.array, toworld=im1.transform, tr=2.5, 
                           slice_order='ascending', interleaved=True)
run2 = register.TimeSeries(im2.array, toworld=im2.transform, tr=2.5, 
                           slice_order='ascending', interleaved=True)

"""
transforms = register.realign4d(run1, within_loops=1) 
corr_run1 = register.resample4d(run1, transforms=transforms)
"""

transforms = register.realign4d([run1, run2], within_loops=0) 
corr_run1 = register.resample4d(run1, transforms=transforms[0])
corr_run2 = register.resample4d(run2, transforms=transforms[1])
<commit_msg>Updated space time realignment example to use Matthew's volumeimages module<commit_after>from neuroimaging.neurospin import register 

# Use Matthew's volumeimages for I/O. 
import volumeimages

import numpy as np
from os.path import join
import sys
import time

rootpath = 'D:\\data\\fiac'
runnames = ['run1', 'run1']

# Create Nifti1Image instances from both input files
im1 = volumeimages.load(join(rootpath, runnames[0]+'.nii'))
im2 = volumeimages.load(join(rootpath, runnames[1]+'.nii'))

# Create TimeSeries instances -- this is a local class representing a
# series of 3d images
run1 = register.TimeSeries(im1.get_data(), toworld=im1.get_affine(), tr=2.5, 
                           slice_order='ascending', interleaved=True)
run2 = register.TimeSeries(im2.get_data(), toworld=im2.get_affine(), tr=2.5, 
                           slice_order='ascending', interleaved=True)

# Correct motion within- and between-sessions
transforms = register.realign4d([run1, run2]) 

# Resample data on a regular space+time lattice using 4d interpolation
corr_im1 = volumeimages.nifti1.Nifti1Image(affine=im1.get_affine(), 
                                           data=register.resample4d(run1, transforms=transforms[0]))
corr_im2 = volumeimages.nifti1.Nifti1Image(affine=im2.get_affine(), 
                                           data=register.resample4d(run2, transforms=transforms[1]))

# Save images 
corr_im1.to_files('corr_run1.nii')
corr_im2.to_files('corr_run2.nii')
{'fraction_non_alphanumeric': 0.11786600496277916, 'fraction_numerical': 0.030603804797353185, 'mean_word_length': 4.071278825995807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2220855', 'n_tokens_mistral': 822, 'n_tokens_neox': 788, 'n_words': 165}