From 72b6a4bfb834354c45e98775806910fcae839f6f Mon Sep 17 00:00:00 2001 From: Tristan Kuehn Date: Wed, 25 Jan 2023 10:40:15 -0500 Subject: [PATCH 1/2] Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46c0d93..262cf90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # Local poetry config poetry.toml +**/__pycache__ From a173e24424e4e1d21c7c7f0d5f4b0295e09e624e Mon Sep 17 00:00:00 2001 From: Tristan Kuehn Date: Wed, 25 Jan 2023 16:53:25 -0500 Subject: [PATCH 2/2] Use source metadata instead of images to build metadata Also, pre-commit went off on the workflows --- .github/release-drafter.yml | 27 ++++++----------------- .github/workflows/deploy.yml | 6 ++--- .github/workflows/quality.yml | 8 ++----- labelmerge/workflow/scripts/labelmerge.py | 20 +++++++++++++---- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index e6cc139..ffb42f5 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -8,22 +8,15 @@ template: | $CHANGES categories: - title: 🚀 Features - labels: - - breaking - - enhancement + labels: [breaking, enhancement] - title: 🐛 Bug Fixes - labels: - - bug + labels: [bug] - title: 🧰 Maintenance - labels: - - maintenance - - test + labels: [maintenance, test] - title: 📝 Documentation - labels: - - documentation + labels: [documentation] -exclude-labels: - - skip_changelog +exclude-labels: [skip_changelog] change-template: '- $TITLE @$AUTHOR (#$NUMBER)' change-title-escapes: \<*_& # You can add # and @ to disable mentions, and add ` to disable code blocks. @@ -33,13 +26,7 @@ version-resolver: # labels: # - 'breaking' minor: - labels: - - breaking - - enhancement + labels: [breaking, enhancement] patch: - labels: - - maintenance - - bug - - test - - documentation + labels: [maintenance, bug, test, documentation] default: patch diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 234d86b..b3e2354 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -91,9 +91,9 @@ jobs: # with: # python-version: '3.9' - # #---------------------------------------------- - # # ----- install & configure poetry ----- - # #---------------------------------------------- + # #---------------------------------------------- + # # ----- install & configure poetry ----- + # #---------------------------------------------- # - name: Install Poetry # uses: snok/install-poetry@v1 # with: diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index ac472f9..ffe18b2 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -3,13 +3,9 @@ name: Lint workflow on: push: - branches: - - '*' - - '!push-action/*' + branches: ['*', '!push-action/*'] pull_request: - branches: - - '*' - - '!push-action/*' + branches: ['*', '!push-action/*'] jobs: quality: diff --git a/labelmerge/workflow/scripts/labelmerge.py b/labelmerge/workflow/scripts/labelmerge.py index 1e8d150..4a39fbb 100644 --- a/labelmerge/workflow/scripts/labelmerge.py +++ b/labelmerge/workflow/scripts/labelmerge.py @@ -4,6 +4,7 @@ from argparse import ArgumentParser from os import PathLike from pathlib import Path +from typing import Optional import nibabel as nib import numpy as np @@ -15,7 +16,7 @@ def load_atlas(atlas_path: PathLike): """Loading relevant atlas data""" atlas = nib.load(atlas_path) - data = atlas.get_fdata().astype(np.ushort) + data = atlas.get_fdata().astype(np.int_) header = atlas.header affine = atlas.affine @@ -49,14 +50,25 @@ def split_labels( atlas: np.ndarray, metadata: pd.DataFrame, prefix: str = "", - exceptions: list[str] = [], + exceptions: Optional[list[str]] = None, ) -> list[xr.Dataset]: + if exceptions is None: + exceptions = [] unique_vals = np.unique(atlas[atlas > 0]) + all_labels: pd.Series[int] = metadata["index"] + if not set(unique_vals) <= set(all_labels): + unlabeled_vals = ", ".join( + str(val) for val in set(unique_vals) - set(all_labels) + ) + raise MetadataError( + f"Labels with indices {unlabeled_vals} from {prefix}atlas not " + "found in metadata table" + ) normal_ds = xr.Dataset( dict( [ assemble_mask(atlas, metadata, label, prefix) - for label in unique_vals + for label in all_labels if label not in exceptions ] ) @@ -67,7 +79,7 @@ def split_labels( dict( [ assemble_mask(atlas, metadata, label, prefix) - for label in unique_vals + for label in all_labels if label in exceptions ] )