Skip to content

Commit

Permalink
Formatting (#113)
Browse files Browse the repository at this point in the history
* formatting and autoformat

* autoformat workflow

* Format code with black

* Format code with black

---------

Co-authored-by: louisblankemeier <[email protected]>
  • Loading branch information
louisblankemeier and louisblankemeier authored Sep 25, 2023
1 parent 5f4e282 commit 0d063ee
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Format code

on:
push:
branches: [ 'master' ]
pull_request:
branches: [ 'master' ]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Format code with black
run: |
pip install black
black .
- name: Sort imports with isort
run: |
pip install isort
isort .
- name: Remove unused imports with autoflake
run: |
pip install autoflake
autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
- name: Commit changes
uses: EndBug/add-and-commit@v4
with:
author_name: ${{ github.actor }}
author_email: ${{ github.actor }}@users.noreply.github.com
message: "Format code with black"
add: "."
branch: ${{ github.ref }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ docs/_build
# ignore yml file
*.yml
*.yaml
!.github/workflows/format.yml

# ignore images
*.png
Expand Down
10 changes: 3 additions & 7 deletions comp2comp/aaa/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import pandas as pd
import pydicom
import wget
from totalsegmentator.libs import (
nostdout,
)
from totalsegmentator.libs import nostdout

from comp2comp.inference_class_base import InferenceClass

Expand Down Expand Up @@ -142,7 +140,6 @@ def spine_seg(
from totalsegmentator.nnunet import nnUNet_predict_image

with nostdout():

img, seg = nnUNet_predict_image(
input_path,
output_path,
Expand Down Expand Up @@ -189,7 +186,6 @@ def normalize_img(self, img: np.ndarray) -> np.ndarray:
return (img - img.min()) / (img.max() - img.min())

def __call__(self, inference_pipeline):

axial_masks = (
inference_pipeline.axial_masks
) # list of 2D numpy arrays of shape (512, 512)
Expand Down Expand Up @@ -223,7 +219,6 @@ def __call__(self, inference_pipeline):
diameterDict = {}

for i in range(len(ct_img)):

mask = axial_masks[i].astype("uint8")

img = ct_img[i]
Expand All @@ -236,10 +231,11 @@ def __call__(self, inference_pipeline):
contours, _ = cv2.findContours(mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)

if len(contours) != 0:

areas = [cv2.contourArea(c) for c in contours]
sorted_areas = np.sort(areas)

areas = [cv2.contourArea(c) for c in contours]
sorted_areas = np.sort(areas)
contours = contours[areas.index(sorted_areas[-1])]

img.copy()
Expand Down
2 changes: 0 additions & 2 deletions comp2comp/aortic_calcium/aortic_calcium_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def __init__(self):
super().__init__()

def __call__(self, inference_pipeline):

self.output_dir = inference_pipeline.output_dir
self.output_dir_images_organs = os.path.join(self.output_dir, "images/")
inference_pipeline.output_dir_images_organs = self.output_dir_images_organs
Expand All @@ -26,7 +25,6 @@ def __init__(self):
super().__init__()

def __call__(self, inference_pipeline):

metrics = inference_pipeline.metrics

inference_pipeline.csv_output_dir = os.path.join(
Expand Down
1 change: 0 additions & 1 deletion comp2comp/contrast_phase/contrast_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def run_segmentation(
from totalsegmentator.nnunet import nnUNet_predict_image

with nostdout():

img, seg = nnUNet_predict_image(
input_path,
output_path,
Expand Down
12 changes: 10 additions & 2 deletions comp2comp/hip/hip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def compute_rois(medical_volume, segmentation, model, output_dir, save=False):
) = get_femural_head_roi(
right_femur_mask, medical_volume, output_dir, "right_intertrochanter"
)
(left_neck_roi, left_neck_centroid, left_neck_hu,) = get_femural_neck_roi(
(
left_neck_roi,
left_neck_centroid,
left_neck_hu,
) = get_femural_neck_roi(
left_femur_mask,
medical_volume,
left_intertrochanter_roi,
Expand All @@ -50,7 +54,11 @@ def compute_rois(medical_volume, segmentation, model, output_dir, save=False):
left_head_centroid,
output_dir,
)
(right_neck_roi, right_neck_centroid, right_neck_hu,) = get_femural_neck_roi(
(
right_neck_roi,
right_neck_centroid,
right_neck_hu,
) = get_femural_neck_roi(
right_femur_mask,
medical_volume,
right_intertrochanter_roi,
Expand Down
3 changes: 0 additions & 3 deletions comp2comp/spine/spine.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def spine_seg(
from totalsegmentator.nnunet import nnUNet_predict_image

with nostdout():

img, seg = nnUNet_predict_image(
input_path,
output_path,
Expand Down Expand Up @@ -295,7 +294,6 @@ def __init__(self):
super().__init__()

def __call__(self, inference_pipeline):

dicom_files, names, inferior_superior_centers = spine_utils.find_spine_dicoms(
inference_pipeline.centroids_3d,
inference_pipeline.dicom_series_path,
Expand All @@ -321,7 +319,6 @@ def __init__(self, format="png"):
self.format = format

def __call__(self, inference_pipeline):

output_path = inference_pipeline.output_dir
spine_model_type = inference_pipeline.spine_model_type

Expand Down

0 comments on commit 0d063ee

Please sign in to comment.