Adult lifespan effects on functional specialization along the hippocampal long axis.
The 1 match
- [1] § Methods › Data acquisition and processing › fMRI preprocessing ↔ fmriqa.py, lines 253–332 · score 0.51 · framewise displacement, DVARS, derivative, FD, timepoints, scores
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 336 lines · 11 KB · no license · 1 match
- #!/usr/bin/env python
- """
- fMRI quality control
- - adapted from fsld_raw.R and fBIRN QA tools
- USAGE: fmriqa.py bold_mcf.nii.gz <TR>
- """
- import ctypes, sys, os
- flags = sys.getdlopenflags()
- sys.setdlopenflags(flags|ctypes.RTLD_GLOBAL)
- import numpy as N
- import nibabel as nib
- from compute_fd import *
- from statsmodels.tsa.tsatools import detrend
- import statsmodels.api
- import matplotlib
- matplotlib.use('Agg')
- import matplotlib.pyplot as plt
- import sklearn.cross_validation
- from matplotlib.backends.backend_pdf import PdfPages
- from mk_slice_mosaic import *
- from matplotlib.mlab import psd
- from plot_timeseries import plot_timeseries
- from MAD import MAD
- from mk_report import mk_report
- sys.setdlopenflags(flags)
- # thresholds for scrubbing and spike detection
- FDthresh=0.5
- DVARSthresh=0.5
- AJKZ_thresh=25
- # number of timepoints forward and back to scrub
- nback=1
- nforward=2
- def error_and_exit(msg):
- print msg
- sys.stdout.write(__doc__)
- sys.exit(2)
- def main():
- verbose=True
- if len(sys.argv)>2:
- infile=sys.argv[1]
- TR=float(sys.argv[2])
- else:
- error_and_exit('')
- #infile='/corral-repl/utexas/poldracklab/openfmri/shared2/ds105/sub001/BOLD/task001_run001/bold_mcf.nii.gz'
- #TR=2.5
- qadir=fmriqa(infile,TR,verbose=verbose)
- def fmriqa(infile,TR,outdir=None,maskfile=None,motfile=None,verbose=False,plot_data=True):
- save_sfnr=True
- if os.path.dirname(infile)=='':
- basedir=os.getcwd()
- infile=os.path.join(basedir,infile)
- elif os.path.dirname(infile)=='.':
- basedir=os.getcwd()
- infile=os.path.join(basedir,infile.replace('./',''))
- else:
- basedir=os.path.dirname(infile)
- if outdir==None:
- outdir=basedir
- qadir=os.path.join(outdir,'QA')
- if not infile.find('mcf.nii.gz')>0:
- error_and_exit('infile must be of form XXX_mcf.nii.gz')
- if not os.path.exists(infile):
- error_and_exit('%s does not exist!'%infile)
- if maskfile==None:
- maskfile=infile.replace('mcf.nii','mcf_brain_mask.nii')
- if not os.path.exists(maskfile):
- error_and_exit('%s does not exist!'%maskfile)
- if motfile==None:
- motfile=infile.replace('mcf.nii.gz','mcf.par')
- if not os.path.exists(motfile):
- error_and_exit('%s does not exist!'%motfile)
- if not os.path.exists(qadir):
- os.mkdir(qadir)
- else:
- print 'QA dir already exists - overwriting!'
- if verbose:
- print 'infile:',infile
- print 'maskfile:',maskfile
- print 'motfile:',motfile
- print 'outdir:',outdir
- print 'computing image stats'
- img=nib.load(infile)
- imgdata=img.get_data()
- nslices=imgdata.shape[2]
- ntp=imgdata.shape[3]
- maskimg=nib.load(maskfile)
- maskdata=maskimg.get_data()
- maskvox=N.where(maskdata>0)
- nonmaskvox=N.where(maskdata==0)
- if verbose:
- print 'nmaskvox:',len(maskvox[0])
- # load motion parameters and compute FD and identify bad vols for
- # potential scrubbing (ala Power et al.)
- motpars=N.loadtxt(motfile)
- fd=compute_fd(motpars)
- N.savetxt(os.path.join(qadir,'fd.txt'),fd)
- voxmean=N.mean(imgdata,3)
- voxstd=N.std(imgdata,3)
- voxcv=voxstd/N.abs(voxmean)
- voxcv[N.isnan(voxcv)]=0
- voxcv[voxcv>1]=1
- # compute timepoint statistics
- maskmedian=N.zeros(imgdata.shape[3])
- maskmean=N.zeros(imgdata.shape[3])
- maskmad=N.zeros(imgdata.shape[3])
- maskcv=N.zeros(imgdata.shape[3])
- imgsnr=N.zeros(imgdata.shape[3])
- for t in range(imgdata.shape[3]):
- tmp=imgdata[:,:,:,t]
- tmp_brain=tmp[maskvox]
- tmp_nonbrain=tmp[nonmaskvox]
- maskmad[t]=MAD(tmp_brain)
- maskmedian[t]=N.median(tmp_brain)
- maskmean[t]=N.mean(tmp_brain)
- maskcv[t]=maskmad[t]/maskmedian[t]
- imgsnr[t]=maskmean[t]/N.std(tmp_nonbrain)
- # perform Greve et al./fBIRN spike detection
- #1. Remove mean and temporal trend from each voxel.
- #2. Compute temporal Z-score for each voxel.
- #3. Average the absolute Z-score (AAZ) within a each slice and time point separately.
- # This gives a matrix with number of rows equal to the number of slices (nSlices)
- # and number of columns equal to the number of time points (nFrames).
- #4. Compute new Z-scores using a jackknife across the slices (JKZ). For a given time point,
- # remove one of the slices, compute the average and standard deviation of the AAZ across
- # the remaining slices. Use these two numbers to compute a Z for the slice left out
- # (this is the JKZ). The final Spike Measure is the absolute value of the JKZ (AJKZ).
- # Repeat for all slices. This gives a new nSlices-by-nFrames matrix (see Figure 8).
- # This procedure tends to remove components that are common across slices and so rejects motion.
- if verbose:
- print 'computing spike stats'
- detrended_zscore=N.zeros(imgdata.shape)
- detrended_data=N.zeros(imgdata.shape)
- for i in range(len(maskvox[0])):
- tmp=imgdata[maskvox[0][i],maskvox[1][i],maskvox[2][i],:]
- tmp_detrended=detrend(tmp)
- detrended_data[maskvox[0][i],maskvox[1][i],maskvox[2][i],:]=tmp_detrended
- detrended_zscore[maskvox[0][i],maskvox[1][i],maskvox[2][i],:]=(tmp_detrended - N.mean(tmp_detrended))/N.std(tmp_detrended)
- loo=sklearn.cross_validation.LeaveOneOut(nslices)
- AAZ=N.zeros((nslices,ntp))
- for s in range(nslices):
- for t in range(ntp):
- AAZ[s,t]=N.mean(N.abs(detrended_zscore[:,:,s,t]))
- JKZ=N.zeros((nslices,ntp))
- if verbose:
- print 'computing outliers'
- for train,test in loo:
- for tp in range(ntp):
- train_mean=N.mean(AAZ[train,tp])
- train_std=N.std(AAZ[train,tp])
- JKZ[test,tp]=(AAZ[test,tp] - train_mean)/train_std
- AJKZ=N.abs(JKZ)
- spikes=[]
- if N.max(AJKZ)>AJKZ_thresh:
- print 'Possible spike: Max AJKZ = %f'%N.max(AJKZ)
- spikes=N.where(N.max(AJKZ,0)>AJKZ_thresh)[0]
- if len(spikes)>0:
- N.savetxt(os.path.join(qadir,'spikes.txt'),spikes)
- voxmean_detrended=N.mean(detrended_data,3)
- voxstd_detrended=N.std(detrended_data,3)
- voxsfnr=voxmean/voxstd
- meansfnr=N.mean(voxsfnr[maskvox])
- # create plots
- #
- #imgdata_flat=imgdata.reshape(N.prod(imgdata.shape))
- #imgdata_nonzero=imgdata_flat[imgdata_flat>0.0]
- scaledmean=(maskmean - N.mean(maskmean))/N.std(maskmean)
- mean_running_diff=N.zeros(maskmad.shape)
- mean_running_diff=(maskmean[1:]-maskmean[:-1])/((maskmean[1:]+maskmean[:-1])/2.0)
- DVARS=N.zeros(fd.shape)
- DVARS[1:]=N.sqrt(mean_running_diff**2)*100.0
- N.savetxt(os.path.join(qadir,'dvars.txt'),DVARS)
- badvol_index_orig=N.where((fd>FDthresh)*(DVARS>DVARSthresh))[0]
- #print badvol_index_orig
- badvols=N.zeros(len(DVARS))
- badvols[badvol_index_orig]=1
- badvols_expanded=badvols.copy()
- for i in badvol_index_orig:
- if i>(nback-1):
- start=i-nback
- else:
- start=0
- if i<(len(badvols)-nforward):
- end=i+nforward+1
- else:
- end=len(badvols)
- #print i,start,end
- badvols_expanded[start:end]=1
- badvols_expanded_index=N.where(badvols_expanded>0)[0]
- #print badvols_expanded_index
- if len(badvols_expanded_index)>0:
- N.savetxt(os.path.join(qadir,'scrubvols.txt'),badvols_expanded_index,fmt='%d')
- # make scrubing design matrix - one colum per scrubbed timepoint
- scrubdes=N.zeros((len(DVARS),len(badvols_expanded_index)))
- for i in range(len(badvols_expanded_index)):
- scrubdes[badvols_expanded_index[i],i]=1
- N.savetxt(os.path.join(qadir,'scrubdes.txt'),scrubdes,fmt='%d')
- else:
- scrubdes=[]
- # save out complete confound file
- confound_mtx=N.zeros((len(DVARS),14))
- confound_mtx[:,0:6]=motpars
- confound_mtx[1:,6:12]=motpars[:-1,:]-motpars[1:,:] # derivs
- confound_mtx[:,12]=fd
- confound_mtx[:,13]=DVARS
- if not scrubdes==[]:
- confound_mtx=N.hstack((confound_mtx,scrubdes))
- N.savetxt(os.path.join(qadir,'confound.txt'),confound_mtx)
- #plot_timeseries(scaledmean,'Mean in-mask signal (Z-scored)',
- # os.path.join(qadir,'scaledmaskmean.png'),spikes,'Potential spikes')
- datavars={'imgsnr':imgsnr,'meansfnr':meansfnr,'spikes':spikes,'badvols':badvols_expanded_index}
- if plot_data:
- print 'before plot'
- trend=plot_timeseries(maskmean,'Mean signal (unfiltered)',os.path.join(qadir,'maskmean.png'),
- plottrend=True,ylabel='Mean MR signal')
- print 'after plot'
- datavars['trend']=trend
- plot_timeseries(maskmad,'Median absolute deviation (robust SD)',
- os.path.join(qadir,'mad.png'),ylabel='MAD')
- plot_timeseries(DVARS,'DVARS (root mean squared signal derivative over brain mask)',
- os.path.join(qadir,'DVARS.png'),plotline=0.5,ylabel='DVARS')
- plot_timeseries(fd,'Framewise displacement',os.path.join(qadir,'fd.png'),
- badvols_expanded_index,'Timepoints to scrub (%d total)'%len(badvols),
- plotline=0.5,ylims=[0,1],ylabel='FD')
- psd=matplotlib.mlab.psd(maskmean,NFFT=128,noverlap=96,Fs=1/TR)
- plt.clf()
- fig=plt.figure(figsize=[10,3])
- fig.subplots_adjust(bottom=0.15)
- plt.plot(psd[1][2:],N.log(psd[0][2:]))
- plt.title('Log power spectrum of mean signal across mask')
- plt.xlabel('frequency (secs)')
- plt.ylabel('log power')
- plt.savefig(os.path.join(qadir,'meanpsd.png'),bbox_inches='tight')
- plt.close()
- plt.clf()
- plt.imshow(AJKZ,vmin=0,vmax=AJKZ_thresh)
- plt.xlabel('timepoints')
- plt.ylabel('slices')
- plt.title('Spike measure (absolute jackknife Z)')
- plt.savefig(os.path.join(qadir,'spike.png'),bbox_inches='tight')
- plt.close()
- if img.shape[0]<img.shape[1] and img.shape[0]<img.shape[2]:
- orientation='saggital'
- else:
- orientation='axial'
- mk_slice_mosaic(voxmean,os.path.join(qadir,'voxmean.png'),'Image mean (with mask)',contourdata=maskdata)
- mk_slice_mosaic(voxcv,os.path.join(qadir,'voxcv.png'),'Image CV')
- mk_slice_mosaic(voxsfnr,os.path.join(qadir,'voxsfnr.png'),'Image SFNR')
- mk_report(infile,qadir,datavars)
- # def save_vars(infile,qadir,datavars):
- datafile=os.path.join(qadir,'qadata.csv')
- f=open(datafile,'w')
- f.write('SNR,%f\n'%N.mean(datavars['imgsnr']))
- f.write('SFNR,%f\n'%datavars['meansfnr'])
- #f.write('drift,%f\n'%datavars['trend'].params[1])
- f.write('nspikes,%d\n'%len(datavars['spikes']))
- f.write('nscrub,%d\n'%len(datavars['badvols']))
- f.close()
- if save_sfnr:
- sfnrimg=nib.Nifti1Image(voxsfnr,img.get_affine())
- sfnrimg.to_filename(os.path.join(qadir,'voxsfnr.nii.gz'))
- return qadir
- if __name__=='__main__':
- main()
fmriqa.py at commit 2b217da, no license · at the source
Overview
Abstract
Introduction: There has been increasing attention to differences in function along the hippocampal long axis, with the posterior hippocampus proposed to have more variable signals that are well-suited to representing idiosyncratic details in memory, and the anterior hippocampus having less dynamic signals that are well-suited to integration. Whether long axis functional specialization persists into older age is not well-understood, despite known age-related declines in the level of detail in memories.
Methods: We used a large database of resting state fMRI data (n = 337 humans of both sexes included) from across the adult lifespan (ages 18–88) to determine the degree of functional differentiation across the hippocampal posterior-anterior axis. Our first approach was to measure the correlation of signals within hippocampal subregions. Our second approach was to measure functional connectivity between hippocampal subregions and the rest of the brain. For both approaches, we tested how well functional differences along the hippocampal long axis accounted for individual and age differences in episodic memory.
Results: Within the hippocampus, we found a more positive age slope (i.e., increasing similarity of signals) for the most posterior hippocampal region compared to the intermediate and anterior region, consistent with the posterior hippocampus losing some of its heterogeneous signaling in older age. Patterns of whole-brain connectivity showed significant differences in the age trajectories between hippocampal subregions for a number of target regions, including several frontal connections. Yet we did not find strong evidence that either within-hippocampal signals or differences in functional connectivity were associated with age-related episodic memory decline.
Conclusion: Age differences in hippocampal long axis functional organization were apparent during rest but were limited in how well they accounted for memory decline.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.
poldrack/fmriqa
2b217dad803e5fc0e3ddca3d7099d99b3b1db089, 13 July 2015Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
9 files
- MAD.py, Python, 36 lines
- compute_fd.py, Python, 33 lines
- fmriqa.py, Python, 336 lines, 1 match
- get_fd.py, Python, 48 lines
- mk_report.py, Python, 54 lines
- mk_slice_mosaic.py, Python, 93 lines
- plot_timeseries.py, Python, 47 lines
- scrub.py, Python, 25 lines
- README.md, Text, 25 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 8 scripts, each with its path and the digest of its content;
- 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
Data availability statement
The original contributions presented in the study are publicly available. This data can be found here: https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Data and code availability
The raw data come from a publicly available dataset (https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Authors: added Caitlin R. Bowman (0000-0002-5833-3591); removed Caitlin R. Bowman
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 3 authors, 6 keywords, 1 funder, 93 references.
Cite
This paper
Bowman, C. R., Charles, C. I., & Birr, S. M. (2026). Adult lifespan effects on functional specialization along the hippocampal long axis. Frontiers in cognition, 5, 1767179. https://
BibTeX
@article{bowman2026adult
author = {Bowman, Caitlin R. and Charles, Cara I. and Birr, Saisha M.},
title = {{Adult lifespan effects on functional specialization along the hippocampal long axis}},
journal = {Frontiers in cognition},
year = {2026},
month = may,
volume = {5},
pages = {1767179},
publisher = {Frontiers Media SA},
issn = {2813-4532},
doi = {10.3389/
url = {https://
pmid = {42338776},
pmcid = {PMC13271125}
}
RIS
TY - JOUR
AU - Bowman, Caitlin R.
AU - Charles, Cara I.
AU - Birr, Saisha M.
TI - Adult lifespan effects on functional specialization along the hippocampal long axis
T2 - Frontiers in cognition
J2 - Front Cognit
PY - 2026
DA - 2026/
VL - 5
SP - 1767179
SN - 2813-4532
PB - Frontiers Media SA
DO - 10.3389/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.3389/
"type": "article-journal",
"title": "Adult lifespan effects on functional specialization along the hippocampal long axis",
"container-title": "Frontiers in cognition",
"author": [
{
"family": "Bowman",
"given": "Caitlin R."
},
{
"family": "Charles",
"given": "Cara I."
},
{
"family": "Birr",
"given": "Saisha M."
}
],
"container-title-short":
"volume": "5",
"page": "1767179",
"DOI": "10.3389/
"PMID": "42338776",
"PMCID": "PMC13271125",
"ISSN": "2813-4532",
"publisher": "Frontiers Media SA",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
5
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1002/hbm.70475 [code]
- The Development of Hippocampal-Cortical Functional Connectivity in Infants and Toddlers.Journal: Human brain mappingIn common: fMRI, 8 references
- [2] doi:10.3389/fnbeh.2026.1895371 [code]
- Discrete and differentiated encoding of distinct components of spatial experience occurs within the proximodistal subfields of the dorsoventral axis of the hippocampus.Journal: Frontiers in behavioral neuroscienceIn common: Matplotlib, NumPy, 7 references
- [3] doi:10.1371/journal.pcbi.1013488 [code]
- Evaluating place cell detection methods in Rats and Humans: Implications for cross-species spatial coding.Journal: PLoS computational biologyIn common: statsmodels, scikit-learn, Matplotlib, 1 other tool, 5 references
- [4] doi:10.1002/hipo.70124 [code]
- Association Between Anterior Hippocampal Gyrification and Episodic Memory Performance in Neurotypical Young Adults.Journal: HippocampusIn common: NiBabel, scikit-learn, Matplotlib, 1 other tool, healthy, cognitive, 3 references
- [5] doi:10.21203/rs.3.rs-9326213/v1 [code]
- Multi-task fMRI outperforms resting-state fMRI for revealing task-invariant organization of the human brainJournal: Research Square (preprint)In common: NiBabel, scikit-learn, Matplotlib, 1 other tool, fMRI, cognitive, 5 references
- [6] doi:10.64898/2026.03.09.710558 [code]
- Multi-task fMRI outperforms resting-state fMRI for revealing task-invariant organization of the human brainJournal: bioRxiv (preprint)In common: NiBabel, scikit-learn, Matplotlib, 1 other tool, fMRI, cognitive, 5 references
- [7] doi:10.1002/agm2.70073 [code]
- Foreign Language Learning in Older Adults Modifies Resting-State Functional Connectivity Between the Subcortical Structures and the Cortex.Journal: Aging medicine (Milton (N.S.W))In common: NiBabel, statsmodels, scikit-learn, 2 other tools, fMRI, 3 references
- [8] doi:10.1038/s41467-026-71568-9 [code]
- Convergent and selective representations of pain, appetitive processes, aversive processes, and cognitive control in the insula.Journal: Nature communicationsIn common: NiBabel, statsmodels, scikit-learn, 2 other tools, cognitive, 4 references
- [9] doi:10.7554/elife.107933 [code]
- Modality-agnostic decoding of vision and language from fMRI.Journal: eLifeIn common: NiBabel, statsmodels, scikit-learn, 2 other tools, fMRI, cognitive, 4 references
- [10] doi:10.7554/elife.107273
- Neural representation of time across complementary reference frames.Journal: eLifeIn common: cognitive, 6 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 8 scripts, and 1 match between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:774520a5ab5083fd…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
