From 9fc7357e6edc23bf10c80029f1590b0b9691fb44 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Nov 2023 19:21:33 +0000 Subject: [PATCH] Autoupdate pre-commit hooks (#1124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Autoupdate pre-commit hooks updates: - [github.com/psf/black: 23.10.1 → 23.11.0](https://github.com/psf/black/compare/23.10.1...23.11.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- docs/examples/plot_include_exclude.py | 10 +-- src/torchio/data/image.py | 12 ++- src/torchio/data/subject.py | 10 +-- src/torchio/datasets/slicer.py | 8 +- tests/data/test_subject.py | 84 ++++++++++----------- tests/transforms/augmentation/test_oneof.py | 10 +-- tests/transforms/test_transforms.py | 22 +++--- tests/utils.py | 14 ++-- 9 files changed, 76 insertions(+), 96 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b5cba24c..c6508f2f3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: exclude: setup.cfg - repo: https://github.com/psf/black - rev: 23.10.1 + rev: 23.11.0 hooks: - id: black diff --git a/docs/examples/plot_include_exclude.py b/docs/examples/plot_include_exclude.py index bfc8aeb04..9c08b2d91 100644 --- a/docs/examples/plot_include_exclude.py +++ b/docs/examples/plot_include_exclude.py @@ -14,11 +14,9 @@ subject = tio.datasets.Pediatric(years=(4.5, 8.5)) subject.plot() -transform = tio.Compose( - [ - tio.RandomAffine(degrees=(20, 30), exclude='t1'), - tio.RandomBlur(std=(3, 4), include='t2'), - ] -) +transform = tio.Compose([ + tio.RandomAffine(degrees=(20, 30), exclude='t1'), + tio.RandomBlur(std=(3, 4), include='t2'), +]) transformed = transform(subject) transformed.plot() diff --git a/src/torchio/data/image.py b/src/torchio/data/image.py index 4429a1086..7d8c020c4 100644 --- a/src/torchio/data/image.py +++ b/src/torchio/data/image.py @@ -181,13 +181,11 @@ def __init__( def __repr__(self): properties = [] - properties.extend( - [ - f'shape: {self.shape}', - f'spacing: {self.get_spacing_string()}', - f'orientation: {"".join(self.orientation)}+', - ] - ) + properties.extend([ + f'shape: {self.shape}', + f'spacing: {self.get_spacing_string()}', + f'orientation: {"".join(self.orientation)}+', + ]) if self._loaded: properties.append(f'dtype: {self.data.type()}') natural = humanize.naturalsize(self.memory, binary=True) diff --git a/src/torchio/data/subject.py b/src/torchio/data/subject.py index e30760a26..804bda036 100644 --- a/src/torchio/data/subject.py +++ b/src/torchio/data/subject.py @@ -273,12 +273,10 @@ def check_consistent_attribute( ) if not all_close: message = message.format( - pprint.pformat( - { - first_image: first_attribute, - image_name: current_attribute, - } - ), + pprint.pformat({ + first_image: first_attribute, + image_name: current_attribute, + }), ) raise RuntimeError(message) except TypeError: diff --git a/src/torchio/datasets/slicer.py b/src/torchio/datasets/slicer.py index 5ac39abd8..b848d997e 100644 --- a/src/torchio/datasets/slicer.py +++ b/src/torchio/datasets/slicer.py @@ -70,8 +70,6 @@ def __init__(self, name='MRHead'): download_root, filename=filename, ) - super().__init__( - { - stem: ScalarImage(download_root / filename), # use last filename - } - ) + super().__init__({ + stem: ScalarImage(download_root / filename), # use last filename + }) diff --git a/tests/data/test_subject.py b/tests/data/test_subject.py index 3336bb674..4bf72d890 100644 --- a/tests/data/test_subject.py +++ b/tests/data/test_subject.py @@ -71,52 +71,48 @@ def test_plot_one_image(self): def test_same_space(self): # https://github.com/fepegar/torchio/issues/381 - affine1 = np.array( + affine1 = np.array([ [ - [ - 4.27109375e-14, - -8.71264808e-03, - 9.99876633e-01, - -3.39850907e01, - ], - [ - -5.54687500e-01, - -2.71630469e-12, - 8.75148028e-17, - 1.62282930e02, - ], - [ - 2.71575000e-12, - -5.54619070e-01, - -1.57073092e-02, - 2.28515784e02, - ], - [0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00], - ] - ) - affine2 = np.array( + 4.27109375e-14, + -8.71264808e-03, + 9.99876633e-01, + -3.39850907e01, + ], [ - [ - 3.67499773e-08, - -8.71257665e-03, - 9.99876635e-01, - -3.39850922e01, - ], - [ - -5.54687500e-01, - 3.67499771e-08, - 6.73024385e-08, - 1.62282928e02, - ], - [ - -3.73318194e-08, - -5.54619071e-01, - -1.57071802e-02, - 2.28515778e02, - ], # noqa: B950 - [0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00], - ] - ) + -5.54687500e-01, + -2.71630469e-12, + 8.75148028e-17, + 1.62282930e02, + ], + [ + 2.71575000e-12, + -5.54619070e-01, + -1.57073092e-02, + 2.28515784e02, + ], + [0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00], + ]) + affine2 = np.array([ + [ + 3.67499773e-08, + -8.71257665e-03, + 9.99876635e-01, + -3.39850922e01, + ], + [ + -5.54687500e-01, + 3.67499771e-08, + 6.73024385e-08, + 1.62282928e02, + ], + [ + -3.73318194e-08, + -5.54619071e-01, + -1.57071802e-02, + 2.28515778e02, + ], # noqa: B950 + [0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00], + ]) t = torch.rand(1, 2, 3, 4) subject = tio.Subject( im1=tio.ScalarImage(tensor=t, affine=affine1), diff --git a/tests/transforms/augmentation/test_oneof.py b/tests/transforms/augmentation/test_oneof.py index 49ea2d5f6..3d9f41ba6 100644 --- a/tests/transforms/augmentation/test_oneof.py +++ b/tests/transforms/augmentation/test_oneof.py @@ -32,10 +32,8 @@ def test_not_transform(self): tio.OneOf({tio.RandomAffine: 1, tio.RandomElasticDeformation: 2}) def test_one_of(self): - transform = tio.OneOf( - { - tio.RandomAffine(): 0.2, - tio.RandomElasticDeformation(max_displacement=0.5): 0.8, - } - ) + transform = tio.OneOf({ + tio.RandomAffine(): 0.2, + tio.RandomElasticDeformation(max_displacement=0.5): 0.8, + }) transform(self.sample_subject) diff --git a/tests/transforms/test_transforms.py b/tests/transforms/test_transforms.py index e07b654de..8132c1cef 100644 --- a/tests/transforms/test_transforms.py +++ b/tests/transforms/test_transforms.py @@ -46,12 +46,10 @@ def get_transform(self, channels, is_3d=True, labels=True): tio.HistogramStandardization(landmarks_dict), elastic, tio.RandomAffine(), - tio.OneOf( - { - tio.RandomAffine(): 3, - elastic: 1, - } - ), + tio.OneOf({ + tio.RandomAffine(): 3, + elastic: 1, + }), tio.RemapLabels(remapping=remapping, masking_method='Left'), tio.RemoveLabels([1, 3]), tio.SequentialLabels(), @@ -283,13 +281,11 @@ def test_non_invertible(self): def test_batch_history(self): # https://github.com/fepegar/torchio/discussions/743 subject = self.sample_subject - transform = tio.Compose( - [ - tio.RandomAffine(), - tio.CropOrPad(5), - tio.OneHot(), - ] - ) + transform = tio.Compose([ + tio.RandomAffine(), + tio.CropOrPad(5), + tio.OneHot(), + ]) dataset = tio.SubjectsDataset([subject], transform=transform) loader = torch.utils.data.DataLoader( dataset, diff --git a/tests/utils.py b/tests/utils.py index fe50dbdcc..b1d7ea5fd 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -23,14 +23,12 @@ def setUp(self): random.seed(42) np.random.seed(42) - registration_matrix = np.array( - [ - [1, 0, 0, 10], - [0, 1, 0, 0], - [0, 0, 1.2, 0], - [0, 0, 0, 1], - ] - ) + registration_matrix = np.array([ + [1, 0, 0, 10], + [0, 1, 0, 0], + [0, 0, 1.2, 0], + [0, 0, 0, 1], + ]) subject_a = tio.Subject( t1=tio.ScalarImage(self.get_image_path('t1_a')),