Skip to content

Commit

Permalink
Autoupdate pre-commit hooks (#1124)
Browse files Browse the repository at this point in the history
* Autoupdate pre-commit hooks

updates:
- [github.com/psf/black: 23.10.1 → 23.11.0](psf/black@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>
  • Loading branch information
pre-commit-ci[bot] authored Nov 14, 2023
1 parent 86b0fa3 commit 9fc7357
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 4 additions & 6 deletions docs/examples/plot_include_exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
12 changes: 5 additions & 7 deletions src/torchio/data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions src/torchio/data/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions src/torchio/datasets/slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
84 changes: 40 additions & 44 deletions tests/data/test_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 4 additions & 6 deletions tests/transforms/augmentation/test_oneof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 9 additions & 13 deletions tests/transforms/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down

0 comments on commit 9fc7357

Please sign in to comment.