Skip to content

Commit

Permalink
replaced BIDS with TPTBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik-code committed Feb 2, 2024
1 parent 306f578 commit b882788
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 36 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
uses: pypa/gh-action-pypi-publish@release/v1 #pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: Hendrik_Code
#user: Hendrik_Code
verbose: true
password: ${{ secrets.PYPI_API_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry]
name = "SPINEPS"
version = "0.0.0"
version = "1.0.0"
description = "Framework for out-of-the box whole spine MRI segmentation."
authors = ["Hendrik Möller <[email protected]>"]
repository = "https://github.com/Hendrik-code/spineps"
Expand All @@ -29,6 +29,7 @@ torchmetrics = "^1.1.2"
tqdm = "^4.66.1"
einops= "^0.6.1"
nnunetv2 = "2.2"
tptbox = "*"


[tool.poetry-dynamic-versioning]
Expand Down
6 changes: 3 additions & 3 deletions spineps/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from time import perf_counter

from BIDS import BIDS_FILE, Log_Type, No_Logger
from TPTBox import BIDS_FILE, Log_Type, No_Logger

from spineps.models import get_instance_model, get_segmentation_model, get_semantic_model, modelid2folder_instance, modelid2folder_semantic
from spineps.seg_run import process_dataset, process_img_nii
Expand Down Expand Up @@ -214,7 +214,7 @@ def run_sample(opt: Namespace):

start_time = perf_counter()
if opt.run_cprofiler:
from BIDS.logger.log_file import format_time_short, get_time
from TPTBox.logger.log_file import format_time_short, get_time

timestamp = format_time_short(get_time())
cprofile_out = bids_sample.get_changed_path(
Expand Down Expand Up @@ -286,7 +286,7 @@ def run_dataset(opt: Namespace):
}

if opt.run_cprofiler:
from BIDS.logger.log_file import format_time_short, get_time
from TPTBox.logger.log_file import format_time_short, get_time

start_time = get_time()
start_time_short = format_time_short(start_time)
Expand Down
2 changes: 1 addition & 1 deletion spineps/example/helper_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
sys.path.append(str(file.parents[1]))
sys.path.append(str(file.parents[2]))

from BIDS import (
from TPTBox import (
BIDS_FILE,
)
from spineps.models import get_segmentation_model
Expand Down
20 changes: 10 additions & 10 deletions spineps/example/template_roll_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
sys.path.append(str(file.parents[1]))
sys.path.append(str(file.parents[2]))

from BIDS import (
from TPTBox import (
BIDS_Global_info,
BIDS_FILE,
No_Logger,
Expand All @@ -14,12 +14,12 @@
)
import time
from spineps.seg_run import process_img_nii, ErrCode
from spineps.models import MODELS
from spineps.models import get_semantic_model, get_instance_model
import numpy as np

# INPUT
in_ds = Path("DATASET_PATH")
raw = "rawdata"
raw = "rawdata" # TODO
der = "derivatives" # TODO

head_logger = No_Logger() # (in_ds, log_filename="source-convert-to-unet-train", default_verbose=True)
Expand All @@ -29,8 +29,8 @@
parent_raw = str(Path(raw).joinpath(str(block)))
parent_der = str(Path(der).joinpath(str(block)))

model_subreg = MODELS.T2w_NAKOSPIDER_HIGHRES_CUT().load()
model_vert = MODELS.VERT_HIGHRES().load()
model_semantic = get_semantic_model("Model_name")
model_instance = get_instance_model("Model_name")

bids_ds = BIDS_Global_info(datasets=[in_ds], parents=[parent_raw, parent_der], verbose=False)

Expand Down Expand Up @@ -70,8 +70,8 @@ def injection_function(seg_nii: NII):
output_paths, errcode = process_img_nii(
img_ref=ref,
derivative_name=der,
model_semantic=model_subreg,
model_instance=model_vert,
model_semantic=model_semantic,
model_instance=model_instance,
override_semantic=False,
override_instance=False,
lambda_semantic=injection_function,
Expand All @@ -89,9 +89,9 @@ def injection_function(seg_nii: NII):

# Load Outputs
img_nii = ref.open_nii()
seg_nii = NII.load(output_paths["out_spine"], seg=True) # subregion mask
vert_nii = NII.load(output_paths["out_vert"], seg=True) # subregion mask
ctd = POI.load(output_paths["out_ctd"]) # subregion mask
seg_nii = NII.load(output_paths["out_spine"], seg=True) # semantic mask
vert_nii = NII.load(output_paths["out_vert"], seg=True) # instance mask
ctd = POI.load(output_paths["out_ctd"]) # centroid file

# TODO do something with outputs, potentially saving them again to the output paths

Expand Down
2 changes: 1 addition & 1 deletion spineps/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from pathlib import Path

from BIDS import Log_Type, No_Logger
from TPTBox import Log_Type, No_Logger

from spineps.seg_enums import Modality
from spineps.seg_model import Segmentation_Model, modeltype2class
Expand Down
5 changes: 2 additions & 3 deletions spineps/phase_instance.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# from utils.predictor import nnUNetPredictor
import numpy as np
from BIDS import NII, Location, Log_Type
from BIDS.core.np_utils import np_approx_center_of_mass, np_calc_crop_around_centerpoint, np_dice
from scipy.ndimage import center_of_mass
from TPTBox import NII, Location, Log_Type
from TPTBox.core.np_utils import np_calc_crop_around_centerpoint, np_dice
from tqdm import tqdm

from spineps.seg_enums import ErrCode, OutputType
Expand Down
4 changes: 2 additions & 2 deletions spineps/phase_post.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# from utils.predictor import nnUNetPredictor
import numpy as np
from BIDS import NII, Location, Log_Type, v_idx2name, v_name2idx
from BIDS.core.np_utils import np_bbox_nd, np_connected_components, np_dilate_msk, np_map_labels, np_approx_center_of_mass
from TPTBox import NII, Location, Log_Type, v_idx2name, v_name2idx
from TPTBox.core.np_utils import np_bbox_nd, np_connected_components, np_dilate_msk, np_map_labels, np_approx_center_of_mass
from scipy.ndimage import center_of_mass

from spineps.seg_pipeline import logger, vertebra_subreg_labels
Expand Down
2 changes: 1 addition & 1 deletion spineps/phase_semantic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from utils.predictor import nnUNetPredictor
from BIDS import NII, Location, Log_Type
from TPTBox import NII, Location, Log_Type
import numpy as np
from spineps.utils.proc_functions import clean_cc_artifacts, n4_bias
from spineps.seg_model import Segmentation_Model
Expand Down
2 changes: 1 addition & 1 deletion spineps/seg_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import os

from BIDS import Image_Reference, NII, to_nii, Logger, No_Logger, Zooms, Log_Type
from TPTBox import Image_Reference, NII, to_nii, Logger, No_Logger, Zooms, Log_Type
from spineps.utils.filepaths import search_path
import torch
from torch import from_numpy
Expand Down
2 changes: 1 addition & 1 deletion spineps/seg_modelconfig.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from BIDS import Zooms, Location, v_name2idx, Ax_Codes, Logger_Interface, Log_Type
from TPTBox import Zooms, Location, v_name2idx, Ax_Codes, Logger_Interface, Log_Type
import json
from spineps.seg_enums import Modality, Acquisition, ModelType, InputType

Expand Down
6 changes: 3 additions & 3 deletions spineps/seg_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# from utils.predictor import nnUNetPredictor
from BIDS import NII, Location, No_Logger, Zooms
from BIDS.core import poi
from BIDS.logger.log_file import get_time, format_time_short
from TPTBox import NII, Location, No_Logger, Zooms
from TPTBox.core import poi
from TPTBox.logger.log_file import get_time, format_time_short
from spineps.seg_model import Segmentation_Model
import subprocess

Expand Down
4 changes: 2 additions & 2 deletions spineps/seg_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import nibabel as nib
import numpy as np
from BIDS import BIDS_FILE, NII, BIDS_Global_info, Centroids, Location, Log_Type, Logger
from BIDS.snapshot2D.snapshot_templates import mri_snapshot
from TPTBox import BIDS_FILE, NII, BIDS_Global_info, Centroids, Location, Log_Type, Logger
from TPTBox.spine.snapshot2D.snapshot_templates import mri_snapshot

from spineps.phase_instance import predict_instance_mask
from spineps.phase_post import phase_postprocess_combined
Expand Down
2 changes: 1 addition & 1 deletion spineps/seg_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from utils.predictor import nnUNetPredictor
from BIDS import BIDS_FILE, Log_Type, Zooms
from TPTBox import BIDS_FILE, Log_Type, Zooms
from spineps.seg_model import Segmentation_Model
from spineps.seg_pipeline import logger
from spineps.seg_enums import Modality, Acquisition
Expand Down
4 changes: 2 additions & 2 deletions spineps/utils/inference_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import os.path
import torch
from spineps.utils.predictor import nnUNetPredictor
from BIDS import NII, No_Logger, Log_Type
from BIDS.core import sitk_utils
from TPTBox import NII, No_Logger, Log_Type
from TPTBox.core import sitk_utils
import nibabel as nib
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion spineps/utils/proc_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ants.utils.convert_nibabel import from_nibabel
from BIDS import Logger_Interface, NII, np_utils
from TPTBox import Logger_Interface, NII, np_utils
import numpy as np
from scipy.ndimage import center_of_mass
from tqdm import tqdm
Expand Down

0 comments on commit b882788

Please sign in to comment.