Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ on:
pull_request:
branches: [ main ]

permissions:
contents: write

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-python@v5
- run: pip install ruff
- run: ruff check . #--fix
#- uses: chartboost/ruff-action@v1
# with:
# fix_args: --fix
# with:
# args: --check .
- uses: stefanzweifel/git-auto-commit-action@v4
- name: Apply ruff auto-fixes
run: |
ruff check . --fix
ruff format .
- name: Commit auto-fixes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'style fixes by ruff'
- name: Gate on remaining lint errors
run: ruff check .
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ nii.get_array() # get numpy array
nii.affine # Affine matrix
nii.header # NIFTY header
nii.orientation # Orientation in 3-Letters
nii.zoom # Scale of the three image axis
nii.shape #shape
nii.zoom # Scale of the three image axis
nii.shape # shape
```


Expand Down
3 changes: 2 additions & 1 deletion TPTBox/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Numpy functionalities that a lot of NII functions above utilize under the hood.
```python
from TPTBox.core.np_utils import np_unique, np_center_of_mass

a = np.array([0,1,2,3], [4,5,6,7], dtype=np.uint8)
a = np.array([0, 1, 2, 3], [4, 5, 6, 7], dtype=np.uint8)

label = np_unique(a)
center_of_mass_of_label_four = np_center_of_mass(a)[4]
Expand All @@ -59,6 +59,7 @@ center_of_mass_of_label_four = np_center_of_mass(a)[4]

```python
from TPTBox import NII, Location

# Segmentation
seg = NII.load("path/to/seg.nii.gz", seg=True)

Expand Down
7 changes: 1 addition & 6 deletions TPTBox/core/README_BIDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ from TPTBox import BIDS_FILE
root = Path("path/to/dataset-dsname")

# Example BIDS-compliant input file
example_file = (
root
/ "rawdata/sub-Max-Mustermann/ses-01012026/anat/"
"sub-Max-Mustermann_ses-01012026_acq-sag_ce-GBCA_T1w.nii.gz"
)
example_file = root / "rawdata/sub-Max-Mustermann/ses-01012026/anat/sub-Max-Mustermann_ses-01012026_acq-sag_ce-GBCA_T1w.nii.gz"

# Create a BIDS_FILE object
bf_file = BIDS_FILE(example_file, root)
Expand Down Expand Up @@ -85,5 +81,4 @@ seg_path = bf_file.get_changed_path(
# If True, disables strict validation against predefined key--value pairs
non_strict_mode=False,
)

```
1 change: 1 addition & 0 deletions TPTBox/core/README_NII.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The `core` subpackage is the foundation of TPTBox. It provides the three primary

```python
from TPTBox import NII

# Image
nii = NII.load("path/to/img.nii.gz", seg=False)
# Segmentation
Expand Down
12 changes: 3 additions & 9 deletions TPTBox/core/README_POI.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ Compute a full set of anatomical landmarks. The registry of supported non-centro
from TPTBox.core.poi_fun.vertebra_pois_non_centroids import all_poi_functions

poi_full = calc_poi_from_subreg_vert(
instance_nii, semantic_nii,
instance_nii,
semantic_nii,
subreg_id=list(all_poi_functions.keys()),
)
# export as a 3D Slicer markup file
poi_full.to_global().save_mrk(
"poi_as_markup.mrk.json",
split_by_region=True,
pointLabelsVisibility=True
)
poi_full.to_global().save_mrk("poi_as_markup.mrk.json", split_by_region=True, pointLabelsVisibility=True)
```


Expand Down Expand Up @@ -136,7 +133,4 @@ poi.save(poi_path)
# Loading local/global Poi
poi = POI.load(poi_path)
poi = POI_Global.load(poi_path)



```
3 changes: 2 additions & 1 deletion TPTBox/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ from TPTBox import Logger, Print_Logger, No_Logger, String_Logger, Log_Type
## Example

```python
logger.print() # logs/prints empty line
logger.print() # logs/prints empty line

logger.print("Started logging to path: ./logs/test.log", lt.LOG)
logger.print()
Expand Down Expand Up @@ -69,6 +69,7 @@ log.print("Missing T2w for sub-007", Log_Type.WARNING)

# Suppress all output (e.g. in a library function)
from TPTBox import No_Logger

log = No_Logger()
log.print("This is silently discarded")
```
5 changes: 2 additions & 3 deletions TPTBox/registration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ from TPTBox.registration import (
ridged_points_from_subreg_vert,
Deformable_Registration,
Template_Registration,
General_Registration, # requires hf-deepali
Rigid_Elements_Registration, # requires hf-deepali
General_Registration, # requires hf-deepali
Rigid_Elements_Registration, # requires hf-deepali
)
```

Expand Down Expand Up @@ -49,5 +49,4 @@ reg_obj = Point_Registration(poi_fixed, poi_moving)
nii_moving = NII.load("path/to/moving_img.nii.gz", False)
nii_moved = reg_obj.transform_nii(nii_moving)
poi_moved = reg_obj.transform_poi(poi_moving)

```
28 changes: 17 additions & 11 deletions TPTBox/spine/snapshot2D/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,44 @@ poi = calc_poi_from_subreg_vert(vert, subreg)
create_snapshot(
out_path,
[
Snapshot_Frame(img, vert, poi, sagittal=True, coronal=True,
mode="CT"),
Snapshot_Frame(img, subreg, poi, sagittal=True, coronal=True,
axial=True, mode="CTs", axial_heights=[0.20, 0.4, 0.6, 0.8]),
Snapshot_Frame(img, vert, poi, sagittal=True, coronal=True, mode="CT"),
Snapshot_Frame(img, subreg, poi, sagittal=True, coronal=True, axial=True, mode="CTs", axial_heights=[0.20, 0.4, 0.6, 0.8]),
],
)
create_snapshot(
out_path2,
[
Snapshot_Frame(
img, subreg, poi,
sagittal=True, coronal=True,
img,
subreg,
poi,
sagittal=True,
coronal=True,
mode="MINMAX",
only_mask_area=True,
hide_segmentation=True,
),
Snapshot_Frame(
img, subreg, poi,
sagittal=True, coronal=True,
img,
subreg,
poi,
sagittal=True,
coronal=True,
mode="MINMAX",
only_mask_area=True,
visualization_type=Visualization_Type.Maximum_Intensity,
hide_segmentation=True,
),
Snapshot_Frame(
img, subreg, poi,
sagittal=True, coronal=True,
img,
subreg,
poi,
sagittal=True,
coronal=True,
mode="MINMAX",
visualization_type=Visualization_Type.Maximum_Intensity,
hide_segmentation=True,
),
],
)

```
4 changes: 2 additions & 2 deletions TPTBox/spine/spinestats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ collector = ExcelCollector(out_folder="/tmp/nako_summary")
collector.start()
for nako_id in ids:
f = get_nako_paths(nako_id)
run_all(f) # writes the per-subject json
run_all(f) # writes the per-subject json
collector.submit(nako_id, _final_json_path(f))
collector.close() # flushes and joins
collector.close() # flushes and joins
```

The collector re-writes the Excel files every `flush_every` submissions
Expand Down
6 changes: 5 additions & 1 deletion TPTBox/stitching/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ pip install TPTBox
```python
from TPTBox.stitching import stitching

list_of_files = ["File_A.nii.gz", "File_B.nii.gz", "File_C.nii.gz",]
list_of_files = [
"File_A.nii.gz",
"File_B.nii.gz",
"File_C.nii.gz",
]

# Call the stitching function
# This will combine your images into a single NIfTI file
Expand Down
5 changes: 4 additions & 1 deletion docs/modules/stitching.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ pip install TPTBox
```python
from TPTBox import NII
from TPTBox.stitching import stitching
out_nii,_ = stitching([NII.load("a.nii.gz",seg=False), NII.load("b.nii.gz",seg=False), NII.load("c.nii.gz",seg=False)], out="out.nii.gz")

out_nii, _ = stitching(
[NII.load("a.nii.gz", seg=False), NII.load("b.nii.gz", seg=False), NII.load("c.nii.gz", seg=False)], out="out.nii.gz"
)
```

or


```python
from TPTBox.stitching import stitching_raw

stitching_raw(["a.nii.gz", "b.nii.gz", "c.nii.gz"], "out.nii.gz", is_segmentation=False)
```

Expand Down
8 changes: 4 additions & 4 deletions unit_tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
class TestZipStrict(unittest.TestCase):
def test_equal_length_lists(self):
a = [1, 2, 3]
b = ['a', 'b', 'c']
expected = [(1, 'a'), (2, 'b'), (3, 'c')]
b = ["a", "b", "c"]
expected = [(1, "a"), (2, "b"), (3, "c")]
result = list(zip_strict(a, b))
self.assertEqual(result, expected)

def test_unequal_length_lists(self):
a = [1, 2, 3]
b = ['a', 'b']
b = ["a", "b"]
with self.assertRaises(ValueError) as context:
list(zip_strict(a, b))
self.assertIn("Length mismatch", str(context.exception))
Expand All @@ -41,6 +41,6 @@ def test_multiple_iterables(self):
def test_generator_iterables(self):
a = (x for x in range(3))
b = (chr(97 + x) for x in range(3))
expected = [(0, 'a'), (1, 'b'), (2, 'c')]
expected = [(0, "a"), (1, "b"), (2, "c")]
result = list(zip_strict(a, b))
self.assertEqual(result, expected)
Loading