Skip to content

Commit

Permalink
Merge pull request #58 from CBICA/spiros-dev
Browse files Browse the repository at this point in the history
Documentation update
  • Loading branch information
AlexanderGetka-cbica authored Nov 28, 2024
2 parents d6dc3b9 + 467467d commit ee6bb1f
Show file tree
Hide file tree
Showing 20 changed files with 673 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: pre-commit
on:
pull_request:
push:
branches: [main]
branches: ["main", "spiros-dev"]

jobs:
pre-commit:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sphinx-docs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Deploy static content to Pages
on:
push:
branches: ["main"]
branches: ["main", "spiros-dev"]

jobs:
build-docs:
Expand Down
57 changes: 56 additions & 1 deletion NiChart_DLMUSE/CalcROIVol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@
logging.basicConfig(filename="pipeline.log", encoding="utf-8", level=logging.DEBUG)


def calc_roi_volumes(mrid: Any, in_img: Any, label_indices: Any) -> pd.DataFrame:
def calc_roi_volumes(mrid: Any, in_img: Any, label_indices: np.ndarray) -> pd.DataFrame:
"""
Creates a dataframe with the volumes of rois
:param mrid: the input mrid
:type mrid: Any
:param in_img: the input image
:type in_img: niftii image
:param label_indices: passed label indices
:type label_indices: np.ndarray
:return: Dataframe with details of images
:rtype: pd.DataFrame
"""

# Keep input lists as arrays
Expand Down Expand Up @@ -56,6 +66,14 @@ def calc_roi_volumes(mrid: Any, in_img: Any, label_indices: Any) -> pd.DataFrame
def append_derived_rois(df_in: pd.DataFrame, derived_roi_map: Any) -> pd.DataFrame:
"""
Calculates a dataframe with the volumes of derived rois.
:param df_in: the passed dataframe
:type df_in: pd.DataFrame
:param derived_roi_map: derived roi map file
:type derived_roi_map: Any
:return: ROI dataframe
:rtype: pd.DataFrame
"""

# Read derived roi map file to a dictionary
Expand Down Expand Up @@ -91,6 +109,17 @@ def create_roi_csv(
) -> None:
"""
Creates a csv file with the results of the roi calculations
:param mrid: the input mrid
:type mrid: Any
:param in_roi: the input ROI
:type in_roi: Any
:param map_derived_roi: derived roi map file
:type map_derived_roi: Any
:param out_csv: output csv filename
:type out_csv: str
:rtype: None
"""

# Calculate MUSE ROIs
Expand Down Expand Up @@ -122,6 +151,19 @@ def apply_create_roi_csv(
) -> None:
"""
Apply roi volume calc to all images
:param df_img: the passed dataframe
:type df_img: pd.DataFrame
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the input suffix
:type in_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_suff: the output suffix
:type out_suff: str
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand All @@ -140,6 +182,19 @@ def combine_roi_csv(
) -> None:
"""
Combine csv files
:param df_img: passed dataframe
:type df_img: pd.DataFrame
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the input suffix
:type in_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_name: the desired output filename
:type out_name: str
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand Down
49 changes: 47 additions & 2 deletions NiChart_DLMUSE/MaskImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ def calc_bbox_with_padding(img: np.ndarray, perc_pad: int = 10) -> np.ndarray:
return bcoors


def mask_img(in_img: Any, mask_img: Any, out_img: Any) -> None:
def mask_img(in_img: Any, mask_img: Any, out_img: str) -> None:
"""
Applies the input mask to the input image
Crops the image around the mask
:param in_img: the passed image
:param mask_img: the input mask
:param out_img: the output filename
:type out_img: str
:rtype: None
"""

# Read input image and mask
Expand Down Expand Up @@ -99,9 +105,16 @@ def mask_img(in_img: Any, mask_img: Any, out_img: Any) -> None:
nii_out.to_filename(out_img)


def combine_masks(dlmuse_mask: Any, dlicv_mask: Any, out_img: Any) -> None:
def combine_masks(dlmuse_mask: Any, dlicv_mask: Any, out_img: str) -> None:
"""'
Combine icv and muse masks
:param dlmuse_mask: The passed dlmuse mask
:param dlicv_mask: The passed dlicv mask
:param out_img: the output filename
:type out_img: str
:rtype: None
"""

# Read input images
Expand Down Expand Up @@ -146,6 +159,21 @@ def apply_mask_img(
) -> None:
"""
Apply reorientation to all images
:param df_img: The passed dataframe
:type df_img: pd.DataFrame
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the passed input suffix
:type in_suff: str
:param mask_dir: the passed mask directory
:type mask_dir: str
:param out_dir: the passed output directory
:type out_dir: str
:param out_suff: the passed output suffix
:type out_suff: str
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand All @@ -170,6 +198,23 @@ def apply_combine_masks(
) -> None:
"""
Apply reorientation to all images
:param df_img: the passed dataframe
:type df_img: pd.DataFrame
:param dlmuse_dir: the passed dlmuse directory
:type dlmuse_dir: str
:param dlmuse_suff: the passed dlmuse suffix
:type dlmuse_suff: str
:param dlicv_dir: the passed dlicv directory
:type dlicv_dir: str
:param dlicv_suff: the passed dlicv suffix
:type dlicv_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_suff: the output suffix
:type out_suff: str
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand Down
34 changes: 32 additions & 2 deletions NiChart_DLMUSE/RelabelROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ def relabel_rois(
) -> None:
"""
Convert labels in input roi image to new labels based on the mapping
print()
The mapping file should contain numeric indices for the mapping
irint()
between the input roi image (from) and output roi image (to)
:param in_img: the passed image
:type in_img: niftii image
:param roi_map: the passed roi map
:type roi_map: str
:param label_from: input roi image
:type label_from: Any
:param label_to: output roi image
:type label_to: Any
:param out_img: the desired filename for the output image
:type out_img: str
:rtype: None
"""

# Read image
Expand Down Expand Up @@ -52,6 +63,25 @@ def apply_relabel_rois(
) -> None:
"""
Apply relabeling to all images
:param df_img: the passed dataframe
:type df_img: pd.DataFrame
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the input suffix
:type in_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_suff: the output suffix
:type out_suff: str
:param roi_map: the roi map
:type roi_map: Any
:param label_from: input roi image
:type label_from: Any
:param label_to: output roi image
:type label_to: Any
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand Down
33 changes: 31 additions & 2 deletions NiChart_DLMUSE/ReorientImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
logging.basicConfig(filename="pipeline.log", encoding="utf-8", level=logging.DEBUG)


def reorient_img(in_img: Any, ref: Any, out_img: Any) -> None:
def reorient_img(in_img: Any, ref: Any, out_img: str) -> None:
"""
Reorient image
:param in_img: the input image
:type in_img: niftii image
:param out_img: the desired filename for the output image
:type out_img: str
:rtype: None
"""
if os.path.exists(out_img):
logging.info("Out file exists, skip reorientation ...")
Expand Down Expand Up @@ -50,6 +57,15 @@ def apply_reorient_img(
) -> None:
"""
Apply reorientation to all images
:param df_img: the passed dataframe
:type df_img: pd.DataFrame
:param out_dir: the output directory
:type out_dir: str
:param out_suffix: the output suffix
:type out_suffix: str
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand All @@ -61,10 +77,23 @@ def apply_reorient_img(


def apply_reorient_to_init(
df_img: pd.DataFrame, in_dir: str, in_suff: Any, out_dir: str, out_suff: str
df_img: pd.DataFrame, in_dir: str, in_suff: str, out_dir: str, out_suff: str
) -> None:
"""
Apply reorientation to init img to all images
:param df_img: the passed dataframe
:type df_img: pd.DataFrame
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the input suffix
:param in_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_suff: the output suffix
:type out_suff: str
:rtype: None
"""
if not os.path.exists(out_dir):
os.makedirs(out_dir)
Expand Down
40 changes: 38 additions & 2 deletions NiChart_DLMUSE/SegmentImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@

def run_dlicv(
in_dir: str,
in_suff: Any,
in_suff: str,
out_dir: str,
out_suff: Any,
out_suff: str,
device: str,
extra_args: str = "",
) -> None:
"""
Run dlicv with the passed images
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the input suffix
:type in_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_suff: the output suffix
:type out_suff: str
:param device: cuda/mps for GPU acceleration otherwise cpu
:type device: str
:param extra_args: extra arguments for DLICV package
:type extra_args: str
:rtype: None
"""
# Call DLICV
os.system(f"DLICV -i {in_dir} -o {out_dir} -device {device} " + extra_args)

Expand All @@ -28,6 +46,24 @@ def run_dlmuse(
device: str,
extra_args: str = "",
) -> None:
"""
Run dlmuse with the passed images
:param in_dir: the input directory
:type in_dir: str
:param in_suff: the input suffix
:type in_suff: str
:param out_dir: the output directory
:type out_dir: str
:param out_suff: the output suffix
:type out_suff: str
:param device: cuda/mps for GPU acceleration otherwise cpu
:type device: str
:param extra_args: extra arguments for DLMUSE package
:type extra_args: str
:rtype: None
"""
# Call DLMUSE
os.system(f"DLMUSE -i {in_dir} -o {out_dir} -device {device} " + extra_args)

Expand Down
15 changes: 15 additions & 0 deletions NiChart_DLMUSE/dlmuse_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ def run_pipeline(
) -> None:
"""
NiChart pipeline
:param in_data: the input directory
:type in_data: str
:param out_dir: the output directory
:type out_dir: str
:param device: conda/mps for GPU acceleration otherwise cpu
:type device: str
:param dlmuse_extra_args: extra arguments for DLMUSE package
:type dlmuse_extra_args: str
:param dlicv_extra_args: extra arguments for DLICV package
:type dlicv_extra_args: str
:param sub_fldr: the number of subfolders(default = 1)
:type sub_fldr: int
:rtype: None
"""
logging.info(f"Starting the pipeline on folder {sub_fldr}")
logging.info(f"Detecting input images for batch [{sub_fldr}]...")
Expand Down
Loading

0 comments on commit ee6bb1f

Please sign in to comment.