<jupyter_start><jupyter_text>Seed-voxel functional connectivity  Load libraries<jupyter_code>import numpy as np
from nilearn import datasets
from nilearn import input_data
from nilearn.connectome import ConnectivityMeasure
from nilearn import plotting<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code># Load fMRI data
dataset = datasets.fetch_development_fmri(n_subjects=1)
func_filename = dataset.func[0]
confounds_filename = dataset.confounds[0]<jupyter_output><empty_output><jupyter_text>Create a seed<jupyter_code>pcc_coords = [(0, -52, 18)]
seed_masker = input_data.NiftiSpheresMasker(
    pcc_coords, radius=8,
    detrend=True, standardize=True)<jupyter_output><empty_output><jupyter_text>Extract timeseries from a seed<jupyter_code>seed_timeseries = seed_masker.fit_transform(func_filename,
                                             confounds=confounds_filename)
seed_timeseries = np.squeeze(seed_timeseries)<jupyter_output><empty_output><jupyter_text>Estract timeseries from the whole brain<jupyter_code>brain_masker = input_data.NiftiMasker(
    smoothing_fwhm=8,
    detrend=True, standardize=True,
    memory='nilearn_cache', memory_level=1, verbose=0)

brain_timeseries = brain_masker.fit_transform(func_filename,
                                               confounds=confounds_filename)
# Print shape of seed time-series
print(seed_timeseries.shape)

# Print shape of brain time-series
print(brain_timeseries.shape)<jupyter_output>(168,)
(168, 32504)<jupyter_text>Calculate seed to voxel correlations<jupyter_code># Calculate Pearson product-moment correlation coefficient between seed and all voxel trime-series
from scipy import stats

corr_map = np.zeros(brain_timeseries.shape[1])

for i in range(brain_timeseries.shape[1]):
    corr_map[i] = stats.pearsonr(seed_timeseries, brain_timeseries[:,i])[0]<jupyter_output><empty_output><jupyter_text>Plot correlation using statistical map plot<jupyter_code>seed_to_voxel_correlations_img = brain_masker.inverse_transform(corr_map.T)

# Plot correlation map using plot_stat_map
display = plotting.plot_stat_map(seed_to_voxel_correlations_img, threshold=0.4)

# Add seed ROI marker with display.add_markers()
display.add_markers(pcc_coords, marker_color='g', marker_size=100)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08479020979020979, 'fraction_numerical': 0.013548951048951048, 'mean_word_length': 6.63, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '81998', 'license': 'MIT', 'n_tokens_mistral': 803, 'n_tokens_neox': 752, 'n_words': 133, 'path': 'solutions/seed-voxel_connectivity_solution.ipynb', 'repo_name': 'fMRIAnalysisCource/fmri-analysis-course', 'size': '2288'}