Skip to content

Commit

Permalink
Merge pull request #53 from CBICA/main
Browse files Browse the repository at this point in the history
Main to ge-dev
  • Loading branch information
gurayerus authored Nov 20, 2024
2 parents 7610142 + 345be98 commit 1dcff61
Show file tree
Hide file tree
Showing 33 changed files with 1,139 additions and 986 deletions.
35 changes: 0 additions & 35 deletions .gitattributes

This file was deleted.

15 changes: 7 additions & 8 deletions .github/workflows/macos_build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NiChart_DLMUSE building test for macos
name: MacOS Build

# workflow dispatch has been added for testing purposes
on: [push, pull_request, workflow_dispatch]
Expand All @@ -11,21 +11,20 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.12"
- name: Set-up miniconda for macos and ubuntu
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
python-version: 3.12
miniconda-version: "latest"
- name: Create conda env
run: conda create -n NCP python=3.8
run: conda create -n NCP python=3.12
- name: Install pip
run: conda run -n NCP conda install pip
- name: Build NiChart_DLMUSE from source
run: |
python -m pip cache purge
pip install setuptools twine wheel
python setup.py bdist_wheel
cd dist
WHEEL_FILE=$(ls NiChart_DLMUSE*)
pip install "$WHEEL_FILE"
pip install -r requirements.txt
python3 -m pip install -e .
28 changes: 28 additions & 0 deletions .github/workflows/macos_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: macos build

# workflow dispatch has been added for testing purposes
on: [push, pull_request, workflow_dispatch]

jobs:
build:
runs-on: ["macos-13"]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install spare scores
run: |
python -m pip cache purge
pip install -r requirements.txt
pip install setuptools twine wheel
python -m pip install .
- name: Run unit tests
run: |
cd tests/ && pytest --cov=../ --cov-report=xml
- name: Upload Coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: CBICA/NiChart_DLMUSE
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.12"
- run: pip3 install pre-commit
- run: pre-commit run --files NiChart_DLMUSE/*
40 changes: 40 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Upload Python Package

on: workflow_dispatch

permissions:
contents: read
id-token: write # Allow GitHub to mint tokens

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest # Can use macos-latest if needed

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.x"

- name: Install dependencies
run: |
pip install setuptools
pip install twine
pip install wheel
sudo apt-get install jq
- name: Clean previous builds
run: rm -rf dist

- name: Build package
run: python setup.py sdist bdist_wheel

- name: Publish package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
6 changes: 3 additions & 3 deletions .github/workflows/sphinx-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:

jobs:
build-docs:
runs-on: macos-13
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version: "3.12"
- name: Set-up miniconda for macos and ubuntu
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: |
pip install -r requirements.txt
brew install python-setuptools
pip install setuptools
pip install sphinx sphinx_rtd_theme sphinx-tabs sphinx_toolbox
- name: Sphinx build
run: |
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/ubuntu_build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NiChart_DLMUSE building test for ubuntu
name: Ubuntu Build

# workflow dispatch has been added for testing purposes
on: [push, pull_request, workflow_dispatch]
Expand All @@ -11,21 +11,20 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.12"
- name: Set-up miniconda for macos and ubuntu
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
python-version: 3.12
miniconda-version: "latest"
- name: Create conda env
run: conda create -n NCP python=3.8
run: conda create -n NCP python=3.12
- name: Install pip
run: conda run -n NCP conda install pip
- name: Build NiChart_DLMUSE from source
run: |
python -m pip cache purge
pip install setuptools twine wheel
python setup.py bdist_wheel
cd dist
WHEEL_FILE=$(ls NiChart_DLMUSE*)
pip install "$WHEEL_FILE"
pip install -r requirements.txt
python3 -m pip install -e .
23 changes: 23 additions & 0 deletions .github/workflows/ubuntu_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ubuntu tests

# workflow dispatch has been added for testing purposes
on: [push, pull_request, workflow_dispatch]

jobs:
build:
runs-on: ["ubuntu-latest"]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install spare scores
run: |
python -m pip cache purge
pip install -r requirements.txt
pip install setuptools twine wheel
python -m pip install .
- name: Run unit tests
run: |
cd tests && pytest
68 changes: 38 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime

LABEL IMAGE="NiChart_DLMUSE"
LABEL VERSION="0.1.7"
LABEL CI_IGNORE="True"

RUN apt-get update && \
apt-get -y install gcc \
mono-mcs \
gnupg2 \
git \
htop \
zip \
unzip \
g++ && \
apt-key del 3bf863cc && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub && \
rm -rf /var/lib/apt/lists/* && \
pip install --upgrade pip && \
pip install Cmake

# RUN mkdir /NiChart_DLMUSE
# COPY ./ /NiChart_DLMUSE/
# RUN cd /NiChart_DLMUSE && pip install .

RUN cd / && \
git clone https://github.com/CBICA/NiChart_DLMUSE && \
cd /NiChart_DLMUSE && pip install .

CMD ["NiChart_DLMUSE" ]

## Suggested pull command (run from anywhere):
## CUDA_VERSION=11.8 docker pull cbica/nichart_dlmuse:1.0.1-cuda${CUDA_VERSION}
## OR
## docker pull cbica/nichart_dlmuse:1.0.1

## Suggested automatic inference run time command
## Place input in /path/to/input/on/host.
## Replace -d cuda with -d mps or -d cpu as needed, or don't pass at all to automatically use CUDA.
## Each "/path/to/.../on/host" is a placeholder, use your actual paths!
## docker run -it --name DLMUSE_inference --rm
## --mount type=bind,source=/path/to/input/on/host,target=/input,readonly
## --mount type=bind,source=/path/to/output/on/host,target=/output
## --gpus all cbica/nichart_dlmuse:1.0.1 -d cuda

## Suggested build command (run from the top-level repo directory):
## CUDA_VERSION=11.8 docker build --build-arg CUDA_VERSION=${CUDA_VERSION}
## -t cbica/nichart_dlmuse:1.0.1-cuda${CUDA_VERSION} .
## OR
## docker build -t cbica/nichart_dlmuse:1.0.1 .

ARG NICHART_DLMUSE_VERSION="1.0.1"
ARG CUDA_VERSION="11.8"
ARG TORCH_VERSION="2.4.1"
ARG CUDNN_VERSION="9"

## This base image is generally the smallest with all prereqs.
FROM pytorch/pytorch:${TORCH_VERSION}-cuda${CUDA_VERSION}-cudnn${CUDNN_VERSION}-runtime

WORKDIR /app
COPY . /app/

RUN pip install .
RUN mkdir /dummyinput && mkdir /dummyoutput
## Cache DLMUSE and DLICV models with an empty job so no download is needed later
RUN DLMUSE -i /dummyinput -o /dummyoutput && DLICV -i /dummyinput -o /dummyoutput
ENTRYPOINT ["NiChart_DLMUSE", "-i", "/input", "-o", "/output"]
CMD ["-d", "cuda"]
6 changes: 5 additions & 1 deletion NiChart_DLMUSE/CalcROIVol.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import csv as csv
import logging
import os
from typing import Any

import nibabel as nib
import numpy as np
import pandas as pd

logger = logging.getLogger(__name__)
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:
"""
Expand Down Expand Up @@ -150,7 +154,7 @@ def combine_roi_csv(
df_tmp = pd.read_csv(in_csv)
dfs.append(df_tmp)
except:
print("Skip subject, out csv missing: " + in_csv)
logging.info("Skip subject, out csv missing: " + in_csv)
if len(dfs) > 0:
df_out = pd.concat(dfs)
df_out.to_csv(out_csv, index=False)
2 changes: 2 additions & 0 deletions NiChart_DLMUSE/RelabelROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ 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)
"""

Expand Down
6 changes: 5 additions & 1 deletion NiChart_DLMUSE/ReorientImage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from typing import Any

Expand All @@ -7,13 +8,16 @@

IMG_EXT = ".nii.gz"

logger = logging.getLogger(__name__)
logging.basicConfig(filename="pipeline.log", encoding="utf-8", level=logging.DEBUG)


def reorient_img(in_img: Any, ref: Any, out_img: Any) -> None:
"""
Reorient image
"""
if os.path.exists(out_img):
print("Out file exists, skip reorientation ...")
logging.info("Out file exists, skip reorientation ...")

else:
# Read input img
Expand Down
Loading

0 comments on commit 1dcff61

Please sign in to comment.