Others¶
neurora.stuff module¶
a module for some simple but important processes
- neurora.stuff.cluster_fdr_correct(p, p_threshold1, p_threshold2)¶
Cluster-wise FDR correction for fMRI RSA results
- Parameters
p (array) – The p-value map (3-D).
p_threshold1 (string) – The voxel-wise p threshold.
p_threshold2 (string) – The cluster-wise p threshold
- Returns
clusterfdrp – The Cluster-wise FDR corrected p-value map.
- Return type
array.
- neurora.stuff.cluster_fwe_correct(p, p_threshold1, p_threshold2)¶
Cluster-wise FWE correction for fMRI RSA results
- Parameters
p (array) – The p-value map (3-D).
p_threshold1 (string) – The voxel-wise p threshold.
p_threshold2 (string) – The cluster-wise p threshold
- Returns
clusterfwep – The Cluster-wise FWE corrected p-value map.
- Return type
array.
- neurora.stuff.clusterbased_permutation_1d_1samp_1sided(results, level=0, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=2, iter=1000)¶
1-sample & 1-sided cluster based permutation test for 2-D results
- Parameters
results (array) – A result matrix. The shape of results should be [n_subs, x]. n_subs represents the number of subjects.
level (float. Default is 0.) – An expected value in null hypothesis. (Here, results > level)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 2.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
ps – The permutation test resultz, p-values. The shape of ps is [x]. The values in ps should be 0 or 1, which represent not significant point or significant point after cluster-based permutation test, respectively.
- Return type
float
- neurora.stuff.clusterbased_permutation_1d_1samp_2sided(results, level=0, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=2, iter=1000)¶
1-sample & 2-sided cluster based permutation test for 2-D results
- Parameters
results (array) – A result matrix. The shape of results should be [n_subs, x]. n_subs represents the number of subjects.
level (float. Default is 0.) – An expected value in null hypothesis. (Here, results > level)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 2.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
ps – The permutation test resultz, p-values. The shape of ps is [x]. The values in ps should be 0 or 1 or -1, which represent not significant point or significantly greater point or significantly less point after cluster-based permutation test, respectively.
- Return type
float
- neurora.stuff.clusterbased_permutation_1d_1sided(results1, results2, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=2, iter=1000)¶
1-sample & 1-sided cluster based permutation test for 2-D results
- Parameters
results1 (array) – A result matrix under condition1. The shape of results1 should be [n_subs, x]. n_subs represents the number of subjects.
results2 (array) – A result matrix under condition2. The shape of results2 should be [n_subs, x]. n_subs represents the number of subjects. (Here, results1 > results2)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 2.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
ps – The permutation test resultz, p-values. The shape of ps is [x]. The values in ps should be 0 or 1, which represent not significant point or significant point after cluster-based permutation test, respectively.
- Return type
float
- neurora.stuff.clusterbased_permutation_1d_2sided(results1, results2, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=2, iter=1000)¶
1-sample & 2-sided cluster based permutation test for 2-D results
- Parameters
results1 (array) – A result matrix under condition1. The shape of results1 should be [n_subs, x]. n_subs represents the number of subjects.
results2 (array) – A result matrix under condition2. The shape of results2 should be [n_subs, x]. n_subs represents the number of subjects. (Here, results1 > results2)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 2.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
ps – The permutation test resultz, p-values. The shape of ps is [x]. The values in ps should be 0 or 1 or -1, which represent not significant point or significantly greater point or significantly less point after cluster-based permutation test, respectively.
- Return type
float
- neurora.stuff.clusterbased_permutation_2d_1samp_1sided(results, level=0, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=4, iter=1000)¶
1-sample & 1-sided cluster based permutation test for 2-D results
- Parameters
results (array) – A result matrix. The shape of results should be [n_subs, x1, x2]. n_subs represents the number of subjects.
level (float. Default is 0.) – An expected value in null hypothesis. (Here, results > level)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 4.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
p – The permutation test result, p-value. The shape of p is [x1, x2]. The values in ps should be 0 or 1, which represent not significant point or significant point after cluster-based permutation test, respectively.
- Return type
float
- neurora.stuff.clusterbased_permutation_2d_1samp_2sided(results, level=0, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=4, iter=1000)¶
1-sample & 2-sided cluster based permutation test for 2-D results
- Parameters
results (array) – A result matrix. The shape of results should be [n_subs, x1, x2]. n_subs represents the number of subjects.
level (float. Default is 0.) – A expected value in null hypothesis. (Here, results > level)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 4.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
p – The permutation test result, p-value. The shape of p is [x1, x2]. The values in ps should be 0 or 1 or -1, which represent not significant point or significantly greater point or significantly less point after cluster-based permutation test, respectively.
- Return type
float
- neurora.stuff.clusterbased_permutation_2d_1sided(results1, results2, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=4, iter=1000)¶
1-sided cluster based permutation test for 2-D results
- Parameters
results1 (array) – A result matrix under condition1. The shape of results1 should be [n_subs, x1, x2]. n_subs represents the number of subjects.
results2 (array) – A result matrix under condition2. The shape of results2 should be [n_subs, x1, x2]. n_subs represents the number of subjects. (Here, results1 > results2)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 4.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
p – The permutation test result, p-value. The shape of p is [x1, x2]. The values in ps should be 0 or 1, which represent not significant point or significant point after cluster-based permutation test.
- Return type
float
- neurora.stuff.clusterbased_permutation_2d_2sided(results1, results2, p_threshold=0.05, clusterp_threshold=0.05, n_threshold=4, iter=1000)¶
2-sided cluster based permutation test for 2-D results
- Parameters
results1 (array) – A result matrix under condition1. The shape of results1 should be [n_subs, x1, x2]. n_subs represents the number of subjects.
results2 (array) – A result matrix under condition2. The shape of results2 should be [n_subs, x1, x2]. n_subs represents the number of subjects. (Here, results1 > results2)
p_threshold (float. Default is 0.05.) – The threshold of p-values.
clusterp_threshold (float. Default is 0.05.) – The threshold of cluster-defining p-values.
n_threshold (int. Default is 4.) – The threshold of number of values in one cluster (number of values per cluster > n_threshold).
iter (int. Default is 1000.) – The times for iteration.
- Returns
p – The permutation test result, p-value. The shape of p is [x1, x2]. The values in ps should be 0 or 1 or -1, which represent not significant point or significantly greater point or significantly less point after cluster-based permutation test.
- Return type
float
- neurora.stuff.correct_by_threshold(img, threshold)¶
correct the fMRI RSA results by threshold
- Parameters
img (array) – A 3-D array of the fMRI RSA results. The shape of img should be [nx, ny, nz]. nx, ny, nz represent the shape of the fMRI-img.
threshold (int) – The number of voxels used in correction. If threshold=n, only the similarity clusters consisting more than n voxels will be visualized.
- Returns
img – A 3-D array of the fMRI RSA results after correction. The shape of img should be [nx, ny, nz]. nx, ny, nz represent the shape of the fMRI-img.
- Return type
array
- neurora.stuff.datamask(fmri_data, mask_data)¶
filter the data by a ROI mask
- Parameters
fmri_data (array) – The fMRI data. The shape of fmri_data is [nx, ny, nz]. nx, ny, nz represent the size of the fMRI data.
mask_data (array) – The mask data. The shape of mask_data is [nx, ny, nz]. nx, ny, nz represent the size of the fMRI data.
- Returns
newfmri_data – The new fMRI data. The shape of newfmri_data is [nx, ny, nz]. nx, ny, nz represent the size of the fMRI data.
- Return type
array
- neurora.stuff.fdr_correct(p, p_threshold)¶
FDR correction for fMRI RSA results
- Parameters
p (array) – The p-value map (3-D).
p_threshold (string) – The p threshold.
- Returns
fdrp – The FDR corrected p-value map.
- Return type
array.
- neurora.stuff.fwe_correct(p, p_threshold)¶
FWE correction for fMRI RSA results
- Parameters
p (array) – The p-value map (3-D).
p_threshold (string) – The p threshold.
- Returns
fwep – The FWE corrected p-value map.
- Return type
array.
- neurora.stuff.get_HOcort()¶
get HarvardOxford-cort-maxprob-thr0-1mm.nii.gz
- Returns
path – The absolute file path of ‘HarvardOxford-cort-maxprob-thr0-1mm.nii.gz’
- Return type
string
- neurora.stuff.get_affine(file_name)¶
get the affine of the fMRI-img
- Parameters
file_name (string) – The filename of a sample fMRI-img in your experiment
- Returns
affine – The position information of the fMRI-image array data in a reference space.
- Return type
array
- neurora.stuff.get_bg_ch2()¶
get ch2.nii.gz
- Returns
path – The absolute file path of ‘ch2.nii.gz’
- Return type
string
- neurora.stuff.get_bg_ch2bet()¶
get ch2bet.nii.gz
- Returns
path – The absolute file path of ‘ch2bet.nii.gz’
- Return type
string
- neurora.stuff.get_cluster_index_1d_1sided(m)¶
Get 1-D & 1-sided cluster-index information from a vector
- Parameters
m (array) – A significant vector. The values in m should be 0 or 1, which represent not significant point or significant point, respectively.
- Returns
index_v (array) – The cluster-index vector.
index_n (int) – The number of clusters.
- neurora.stuff.get_cluster_index_1d_2sided(m)¶
Get 1-D & 2-sided cluster-index information from a vector
- Parameters
m (array) – A significant vector. The values in m should be 0 or 1 or -1, which represent not significant point or significantly higher point or significantly less point, respectively.
- Returns
index_v1 (array) – The “greater” cluster-index vector.
index_n1 (int) – The number of “greater” clusters.
index_v2 (array) – The “less” cluster-index vector.
index_n2 (int) – The number of “less” clusters.
- neurora.stuff.get_cluster_index_2d_1sided(m)¶
Get 2-D & 1-sided cluster-index information from a matrix
- Parameters
m (array) – A significant matrix. The values in m should be 0 or 1, which represent not significant point or significant point, respectively.
- Returns
index_m (array) – The cluster-index matrix.
index_n (int) – The number of clusters.
- neurora.stuff.get_cluster_index_2d_2sided(m)¶
Get 2-D & 2-sided cluster-index information from a matrix
- Parameters
m (array) – A significant matrix. The values in m should be 0 or 1 or -1, which represent not significant point or significantly higher point or significantly less point, respectively.
- Returns
index_m1 (array) – The “greater” cluster-index matrix.
index_n1 (int) – The “greater” number of clusters.
index_m2 (array) – The “less” cluster-index matrix.
index_n2 (int) – The “less” number of clusters.
- neurora.stuff.limtozero(x)¶
zero the value close to zero
- Parameters
x (float) –
- Return type
0
- neurora.stuff.mask_to(mask, size, affine, filename=None)¶
convert mask data of certain template to your data template
- Parameters
mask (string) – The file path+filename for the mask of certain template.
size (array or list [nx, ny, nz]) – The size of the fMRI-img in your experiments.
affine (array or list) – The position information of the fMRI-image array data in a reference space.
filename (string. Default is None - 'newmask.nii'.) – The file path+filename for the mask for your data template .nii file.
Notes
A result .nii file of new mask will be generated at the corresponding address of filename.
- neurora.stuff.mniposition_to(mnipoint, affine)¶
project the position in MNI coordinate system to the position of a point in matrix coordinate system
- Parameters
point (list or array) – The position in MNI coordinate system.
affine (array or list) – The position information of the fMRI-image array data in a reference space.
- Returns
newpoint – The position in matrix coordinate system.
- Return type
array
- neurora.stuff.package_root = '/Users/zitonglu/opt/anaconda3/lib/python3.9/site-packages/neurora'¶
a function for zeroing the value close to zero
- neurora.stuff.permutation_corr(v1, v2, method='spearman', iter=1000)¶
Conduct Permutation test for correlation coefficients
- Parameters
v1 (array) – Vector 1.
v2 (array) – Vector 2.
method (string 'spearman' or 'pearson' or 'kendall' or 'similarity' or 'distance'. Default is 'spearman'.) – The method to calculate the similarities. If method=’spearman’, calculate the Spearman Correlations. If method=’pearson’, calculate the Pearson Correlations. If methd=’kendall’, calculate the Kendall tau Correlations. If method=’similarity’, calculate the Cosine Similarities. If method=’distance’, calculate the Euclidean Distances.
iter (int. Default is 1000.) – The times for iteration.
- Returns
p – The permutation test result, p-value.
- Return type
float
- neurora.stuff.permutation_test(v1, v2, iter=1000)¶
Conduct Permutation test
- Parameters
v1 (array) – Vector 1.
v2 (array) – Vector 2.
iter (int. Default is 1000.) – The times for iteration.
- Returns
p – The permutation test result, p-value.
- Return type
float
- neurora.stuff.position_to_mni(point, affine)¶
project the position in matrix coordinate system to the position in MNI coordinate system
- Parameters
point (list or array) – The position in matrix coordinate system.
affine (array or list) – The position information of the fMRI-image array data in a reference space.
- Returns
newpoint – The position in MNI coordinate system.
- Return type
array
- neurora.stuff.show_progressbar(str, cur, total=100)¶
- neurora.stuff.smooth_1d(x, n=5)¶
smoothing for 1-D results
- Parameters
x (array) – The results. The shape of x should be [n_sub, n_ts]. n_subs, n_ts represent the number of subjects and the number of time-points.
n (int. Default is 5.) – The smoothing step is n.
- Returns
x_smooth – The results after smoothing. The shape of x_smooth should be [n_subs, n_ts]. n_subs, n_ts represent the number of subjects and the number of time-points.
- Return type
array
- neurora.stuff.smooth_2d(x, n=5)¶
smoothing for 2-D results
- Parameters
x (array) – The results. The shape of x should be [n_sub, n_ts1, n_ts2]. n_subs represents the number of subjects. n_ts1 & n_ts2 represent the numbers of time-points.
n (int. Default is 5.) – The smoothing step is n.
- Returns
x_smooth – The results after smoothing. The shape of x should be [n_sub, n_ts1, n_ts2]. n_subs represents the number of subjects. n_ts1 & n_ts2 represent the numbers of time-points.
- Return type
array