Basic package

Submodules

Basic.Brain_Template module

class Basic.Brain_Template.Brain_Template[source]

Bases: object

file_FS_surf = '/home/docs/checkouts/readthedocs.org/user_builds/pnet/checkouts/latest/src/pnet/Brain_Template/FreeSurfer_fsaverage5/Brain_Template.json.zip'
file_HCP_surf = '/home/docs/checkouts/readthedocs.org/user_builds/pnet/checkouts/latest/src/pnet/Brain_Template/HCP_Surface/Brain_Template.json.zip'
file_HCP_surf_vol = '/home/docs/checkouts/readthedocs.org/user_builds/pnet/checkouts/latest/src/pnet/Brain_Template/HCP_Surface_Volume/Brain_Template.json.zip'
file_HCP_vol = '/home/docs/checkouts/readthedocs.org/user_builds/pnet/checkouts/latest/src/pnet/Brain_Template/HCP_Volume/Brain_Template.json.zip'
file_MNI_vol = '/home/docs/checkouts/readthedocs.org/user_builds/pnet/checkouts/latest/src/pnet/Brain_Template/MNI_Volume/Brain_Template.json.zip'

Basic.Cluster_Computation module

Basic.Cluster_Computation.setup_cluster(dir_pnet_result: str, dir_env: str, dir_pnet: str, dir_python: str, submit_command='qsub -terse -j y', thread_command='-pe threaded ', memory_command='-l h_vmem=', log_command='-o ', computation_resource=<class 'dict'>)[source]

Setup cluster environment and commands to submit jobs

Parameters:
  • dir_pnet_result – directory of pNet result folder

  • dir_env – directory of the desired virtual environment

  • dir_pnet – directory of the pNet toolbox

  • dir_python – absolute directory to the python folder, ex. /Users/YuncongMa/.conda/envs/pnet/bin/python

  • submit_command – command to submit a cluster job

  • thread_command – command to setup number of threads for each job

  • memory_command – command to setup memory allowance for each job

  • log_command – command to specify the logfile

  • computation_resource – None or a dict which specifies the number of threads and memory for different processes

Returns:

None

Yuncong Ma, 2/12/2024

Basic.Cluster_Computation.submit_bash_job(dir_pnet_result: str, python_command: str, memory=50, n_thread=4, logFile=None, bashFile=None, pythonFile=None, create_python_file=True)[source]

submit a bash job to the desired cluster environment Generate bash and python files automatically

Parameters:
  • dir_pnet_result – directory of pNet result folder

  • python_command – the Python function to run, with dir_pnet_result as a preset variable

  • memory – a real number in GB

  • n_thread – number of threads to use

  • logFile – full directory of a log file

  • bashFile – full directory of the bash file to generate

  • pythonFile – full directory of the python file to generate

  • create_python_file – bool, create a new Python file or not

Returns:

None

Yuncong Ma, 2/12/2024

Basic.Computation_Environment module

Basic.Computation_Environment.default_computation_environment()[source]
Basic.Computation_Environment.set_computation_environment()[source]

Basic.Cropping module

Basic.Cropping.fApply_Cropped_FOV(Image_3D_4D: ndarray, Crop_Parameter: dict)[source]

Apply predefined Crop_Parameter to crop a 3D or 4D image.

Parameters: Image_3D_4D : ndarray

The input 3D or 4D image.

Crop_Parameterdict

Dictionary containing ‘FOV_Old’ and ‘FOV’ as keys.

Returns: Image_3D_4D : ndarray

The cropped image.

Basic.Cropping.fInverse_Crop_EPI_Image_3D_4D(EPI_Image_3D_4D: ndarray, Crop_Parameter: dict)[source]

An inverse function for cropping a 3D or 4D EPI image.

Parameters: EPI_Image_3D_4D : ndarray

The input 3D or 4D EPI image.

Crop_Parameterdict

Dictionary containing ‘FOV_Old’ and ‘FOV’ as keys.

Returns: EPI_Image_3D_4D : ndarray

The inverse cropped image.

Basic.Cropping.fMass_Center(Image_2D_3D: ndarray)[source]

To find the center of the largest connected region in a 2D or 3D image.

Parameters: Image_2D_3D : ndarray

The input 2D or 3D image.

Returns: Center : ndarray or None

The center of the largest connected region.

Basic.Cropping.fTruncate_Image_3D_4D(Image_3D_4D: ndarray, Voxel_Size: ndarray, Extend: ndarray)[source]

Truncate 3D or 4D image based on mask and extend parameters.

Parameters: Image_3D_4D : ndarray

The input 3D or 4D image.

Voxel_Sizendarray

The size of each voxel in the image.

Extendndarray

The extend parameters in each dimension, could be positive, negative, or inf.

Returns: Image_3D_4D_Truncated : ndarray

The truncated image.

Centerlist of length 3

The center of the FOV after truncation.

Crop_Parameterdict

Dictionary containing ‘FOV_Old’ and ‘FOV’ as keys.

Basic.Matrix_Computation module

Basic.Matrix_Computation.mat_corr(X, Y=None, dataPrecision='double')[source]

Perform corr as in MATLAB, pair-wise Pearson correlation between columns in X and Y

Parameters:
  • X – 1D or 2D matrix, numpy.ndarray or torch.Tensor

  • Y – 1D or 2D matrix, or None, numpy.ndarray or torch.Tensor

  • dataPrecision – ‘double’ or ‘single’

X and Y have the same number of rows :return: Corr

Note: this method will use memory as it concatenates X and Y along column direction. #modified version of the torch corr on 08/05/2024

Basic.Matrix_Computation.mat_corr_(X, Y=None, dataPrecision='double')[source]

mat_corr(X, Y=None, dataPrecision=’double’) Perform corr as in MATLAB, pair-wise Pearson correlation between columns in X and Y

Parameters:
  • X – 1D or 2D matrix

  • Y – 1D or 2D matrix, or None

  • dataPrecision – ‘double’ or ‘single’

X and Y have the same number of rows :return: Corr

Note: this method will use memory as it concatenates X and Y along column direction. By Yuncong Ma, 9/5/2023

Basic.Matrix_Computation.mat_corr_torch(X, Y=None, dataPrecision='double')[source]

Perform corr as in MATLAB, pair-wise Pearson correlation between columns in X and Y

Parameters:
  • X – 1D or 2D matrix, numpy.ndarray or torch.Tensor

  • Y – 1D or 2D matrix, or None, numpy.ndarray or torch.Tensor

  • dataPrecision – ‘double’ or ‘single’

X and Y have the same number of rows :return: Corr

Note: this method will use memory as it concatenates X and Y along column direction. By Yuncong Ma, 12/6/2023

Module contents