NiChart_DLMUSE package

Submodules

NiChart_DLMUSE.CalcROIVol module

NiChart_DLMUSE.CalcROIVol.append_derived_rois(df_in: DataFrame, derived_roi_map: Any) DataFrame[source]

Calculates a dataframe with the volumes of derived rois.

Parameters:
  • df_in (pd.DataFrame) – the passed dataframe

  • derived_roi_map (Any) – derived roi map file

Returns:

ROI dataframe

Return type:

pd.DataFrame

NiChart_DLMUSE.CalcROIVol.apply_create_roi_csv(df_img: DataFrame, in_dir: str, in_suff: str, dict_single_roi: str, dict_derived_roi: str, out_dir: str, out_suff: str) None[source]

Apply roi volume calc to all images

Parameters:
  • df_img (pd.DataFrame) – the passed dataframe

  • in_dir (str) – the input directory

  • in_suff (str) – the input suffix

  • out_dir (str) – the output directory

  • out_suff (str) – the output suffix

Return type:

None

NiChart_DLMUSE.CalcROIVol.calc_roi_volumes(mrid: Any, in_img: Any, label_indices: ndarray) DataFrame[source]

Creates a dataframe with the volumes of rois

Parameters:
  • mrid (Any) – the input mrid

  • in_img (niftii image) – the input image

  • label_indices (np.ndarray) – passed label indices

Returns:

Dataframe with details of images

Return type:

pd.DataFrame

NiChart_DLMUSE.CalcROIVol.combine_roi_csv(df_img: DataFrame, in_dir: str, in_suff: str, out_dir: str, out_name: str) None[source]

Combine csv files

Parameters:
  • df_img (pd.DataFrame) – passed dataframe

  • in_dir (str) – the input directory

  • in_suff (str) – the input suffix

  • out_dir (str) – the output directory

  • out_name (str) – the desired output filename

Return type:

None

NiChart_DLMUSE.CalcROIVol.create_roi_csv(mrid: Any, in_roi: Any, list_single_roi: Any, map_derived_roi: Any, out_csv: str) None[source]

Creates a csv file with the results of the roi calculations

Parameters:
  • mrid (Any) – the input mrid

  • in_roi (Any) – the input ROI

  • map_derived_roi (Any) – derived roi map file

  • out_csv (str) – output csv filename

Return type:

None

NiChart_DLMUSE.MaskImage module

NiChart_DLMUSE.MaskImage.apply_combine_masks(df_img: DataFrame, dlmuse_dir: str, dlmuse_suff: str, dlicv_dir: str, dlicv_suff: str, out_dir: str, out_suff: str) None[source]

Apply reorientation to all images

Parameters:
  • df_img (pd.DataFrame) – the passed dataframe

  • dlmuse_dir (str) – the passed dlmuse directory

  • dlmuse_suff (str) – the passed dlmuse suffix

  • dlicv_dir (str) – the passed dlicv directory

  • dlicv_suff (str) – the passed dlicv suffix

  • out_dir (str) – the output directory

  • out_suff (str) – the output suffix

Return type:

None

NiChart_DLMUSE.MaskImage.apply_mask_img(df_img: DataFrame, in_dir: str, in_suff: str, mask_dir: str, mask_suff: str, out_dir: str, out_suff: str) None[source]

Apply reorientation to all images

Parameters:
  • df_img (pd.DataFrame) – The passed dataframe

  • in_dir (str) – the input directory

  • in_suff (str) – the passed input suffix

  • mask_dir (str) – the passed mask directory

  • out_dir (str) – the passed output directory

  • out_suff (str) – the passed output suffix

Return type:

None

NiChart_DLMUSE.MaskImage.calc_bbox_with_padding(img: ndarray, perc_pad: int = 10) ndarray[source]

Finds bounding box for the foreground values in img, with a given padding percentage

Parameters:
  • img (np.ndarray) – the passed image

  • perc_pad (int) – the given padding percentage

Returns:

an array with the coordinates of the bounding box

Return type:

np.ndarray

NiChart_DLMUSE.MaskImage.combine_masks(dlmuse_mask: Any, dlicv_mask: Any, out_img: str) None[source]

‘ Combine icv and muse masks

Parameters:
  • dlmuse_mask – The passed dlmuse mask

  • dlicv_mask – The passed dlicv mask

  • out_img (str) – the output filename

Return type:

None

NiChart_DLMUSE.MaskImage.mask_img(in_img: Any, mask_img: Any, out_img: str) None[source]

Applies the input mask to the input image Crops the image around the mask

Parameters:
  • in_img – the passed image

  • mask_img – the input mask

  • out_img (str) – the output filename

Return type:

None

NiChart_DLMUSE.RelabelROI module

NiChart_DLMUSE.RelabelROI.apply_relabel_rois(df_img: DataFrame, in_dir: str, in_suff: str, out_dir: str, out_suff: str, roi_map: Any, label_from: Any, label_to: Any) None[source]

Apply relabeling to all images

Parameters:
  • df_img (pd.DataFrame) – the passed dataframe

  • in_dir (str) – the input directory

  • in_suff (str) – the input suffix

  • out_dir (str) – the output directory

  • out_suff (str) – the output suffix

  • roi_map (Any) – the roi map

  • label_from (Any) – input roi image

  • label_to (Any) – output roi image

Return type:

None

NiChart_DLMUSE.RelabelROI.relabel_rois(in_img: Any, roi_map: str, label_from: Any, label_to: Any, out_img: str) None[source]

Convert labels in input roi image to new labels based on the mapping The mapping file should contain numeric indices for the mapping between the input roi image (from) and output roi image (to)

Parameters:
  • in_img (niftii image) – the passed image

  • roi_map (str) – the passed roi map

  • label_from (Any) – input roi image

  • label_to (Any) – output roi image

  • out_img (str) – the desired filename for the output image

Return type:

None

NiChart_DLMUSE.ReorientImage module

NiChart_DLMUSE.ReorientImage.apply_reorient_img(df_img: DataFrame, ref_orient: Any, out_dir: str, out_suffix: str) None[source]

Apply reorientation to all images

Parameters:
  • df_img (pd.DataFrame) – the passed dataframe

  • out_dir (str) – the output directory

  • out_suffix (str) – the output suffix

Return type:

None

NiChart_DLMUSE.ReorientImage.apply_reorient_to_init(df_img: DataFrame, in_dir: str, in_suff: str, out_dir: str, out_suff: str) None[source]

Apply reorientation to init img to all images

Parameters:
  • df_img (pd.DataFrame) – the passed dataframe

  • in_dir (str) – the input directory

  • in_suff – the input suffix

  • in_suff – str

  • out_dir (str) – the output directory

  • out_suff (str) – the output suffix

Return type:

None

NiChart_DLMUSE.ReorientImage.reorient_img(in_img: Any, ref: Any, out_img: str) None[source]

Reorient image

Parameters:
  • in_img (niftii image) – the input image

  • out_img (str) – the desired filename for the output image

Return type:

None

NiChart_DLMUSE.SegmentImage module

NiChart_DLMUSE.SegmentImage.run_dlicv(in_dir: str, in_suff: str, out_dir: str, out_suff: str, device: str, extra_args: str = '') None[source]

Run dlicv with the passed images

Parameters:
  • in_dir (str) – the input directory

  • in_suff (str) – the input suffix

  • out_dir (str) – the output directory

  • out_suff (str) – the output suffix

  • device (str) – cuda/mps for GPU acceleration otherwise cpu

  • extra_args (str) – extra arguments for DLICV package

Return type:

None

NiChart_DLMUSE.SegmentImage.run_dlmuse(in_dir: str, in_suff: Any, out_dir: str, out_suff: Any, device: str, extra_args: str = '') None[source]

Run dlmuse with the passed images

Parameters:
  • in_dir (str) – the input directory

  • in_suff (str) – the input suffix

  • out_dir (str) – the output directory

  • out_suff (str) – the output suffix

  • device (str) – cuda/mps for GPU acceleration otherwise cpu

  • extra_args (str) – extra arguments for DLMUSE package

Return type:

None

NiChart_DLMUSE.dlmuse_pipeline module

NiChart_DLMUSE.dlmuse_pipeline.run_pipeline(in_data: str, out_dir: str, device: str, dlmuse_extra_args: str = '', dlicv_extra_args: str = '', sub_fldr: int = 1, progress_bar=None) None[source]

NiChart pipeline

Parameters:
  • in_data (str) – the input directory

  • out_dir (str) – the output directory

  • device (str) – conda/mps for GPU acceleration otherwise cpu

  • dlmuse_extra_args (str) – extra arguments for DLMUSE package

  • dlicv_extra_args (str) – extra arguments for DLICV package

  • sub_fldr (int) – the number of subfolders(default = 1)

  • progress_bar (tqdm) – tqdm/stqdm progress bar for DLMUSE (default: None)

Return type:

None

NiChart_DLMUSE.utils module

NiChart_DLMUSE.utils.collect_T1(in_dir: str, out_dir: str) None[source]

This function collects all the raw T1 images from the passed BIDS input dir and it creates a temporary folder that will act as a generic dataset with only T1 images

Parameters:
  • in_dir (str) – the input directory

  • out_dir (str) – the output directory

Return type:

None

NiChart_DLMUSE.utils.dir_foldercount(in_dir: str) int[source]

Returns the number of subfolders that the input directory has

Parameters:

in_dir (str) – the input directory

Returns:

the number of folders in the input directory

Return type:

int

NiChart_DLMUSE.utils.dir_size(in_dir: str) int[source]

Returns the number of images the user passed

Parameters:

in_dir (str) – the input directory

Returns:

The size of the passsed directory

Return type:

int

NiChart_DLMUSE.utils.get_basename(in_file: str, suffix_to_remove: str, ext_to_remove: list = ['.nii', '.nii.gz']) str[source]

Get file basename - Extracts the base name from the input file - Removes a given suffix + file extension

Parameters:
  • in_file (str) – the input file

  • suffix_to_remove (str) – passed suffix to be removed

  • ext_to_remove (list) – passed extensions to be removed.Default value: [‘.nii.gz’, ‘.nii’]

Returns:

the string without the suffix + file extension

Return type:

str

NiChart_DLMUSE.utils.get_bids_prefix(filename: str, folder: bool = False) str[source]

Returns the prefix of a bids file :param filename: The passed file :type filename: str

Parameters:

folder (bool) – True if the passed filename is a folder or False if it’s not

Returns:

The prefix of the bids i/o

Return type:

str

NiChart_DLMUSE.utils.make_img_list(in_data: str) DataFrame[source]

Make a list of images

Parameters:

in_data (str) – the input directory

Returns:

a dataframe with the information about the passed data

Return type:

pd.DataFrame

NiChart_DLMUSE.utils.merge_bids_output_data(out_data: str) None[source]

Move all the images on the s5_relabeled subfolder to the subfolder of their prefix

Parameters:

out_data (str) – the output_directory

Return type:

None

NiChart_DLMUSE.utils.merge_output_data(in_dir: str) None[source]

Takes all the results from the temp_working_fir and moves them into the output folder

Parameters:

in_dir (str) – the input directory

Return type:

None

NiChart_DLMUSE.utils.remove_common_suffix(list_files: list) list[source]

Detect common suffix to all images in the list and remove it to return a new list This list can be used as unique ids for input images (assumption: images have the same common suffix - example: Subj1_T1_LPS.nii.gz -> Subj1)

Parameters:

list_files (list) – a list with all the filenames

Returns:

a list with the removed common suffix files

Return type:

list

NiChart_DLMUSE.utils.remove_subfolders(in_dir: str) None[source]

Removes all the split_* subolders from the input folder

Parameters:

in_dir (str) – the input directory

Return type:

None

NiChart_DLMUSE.utils.split_data(in_dir: str, N: int) list[source]

Splits the input data directory into subfolders of size. N should be > 0 and the number of files in each subfolder should be > 0 as well.

Parameters:
  • in_dir (str) – the input directory

  • N (int) – the number of generated split folders

Returns:

a list of the subfolders name

Return type:

list

Module contents