Skip to content

Commit a7f0862

Browse files
committed
Style: Run black formatter
Signed-off-by: karllandheer <[email protected]>
1 parent 1a16247 commit a7f0862

File tree

2 files changed

+83
-33
lines changed

2 files changed

+83
-33
lines changed

monai/transforms/intensity/array.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ class StdShiftIntensity(Transform):
488488

489489
backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
490490

491-
def __init__(self, factor: float, nonzero: bool = False, channel_wise: bool = False, dtype: DtypeLike = np.float32) -> None:
491+
def __init__(
492+
self, factor: float, nonzero: bool = False, channel_wise: bool = False, dtype: DtypeLike = np.float32
493+
) -> None:
492494
self.factor = factor
493495
self.nonzero = nonzero
494496
self.channel_wise = channel_wise
@@ -578,7 +580,9 @@ def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTen
578580
if not self._do_transform:
579581
return img
580582

581-
shifter = StdShiftIntensity(factor=self.factor, nonzero=self.nonzero, channel_wise=self.channel_wise, dtype=self.dtype)
583+
shifter = StdShiftIntensity(
584+
factor=self.factor, nonzero=self.nonzero, channel_wise=self.channel_wise, dtype=self.dtype
585+
)
582586
return shifter(img=img)
583587

584588

@@ -1268,16 +1272,12 @@ def _clip(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
12681272
(
12691273
lower_percentile
12701274
if lower_percentile is None
1271-
else lower_percentile.item()
1272-
if hasattr(lower_percentile, "item")
1273-
else lower_percentile
1275+
else lower_percentile.item() if hasattr(lower_percentile, "item") else lower_percentile
12741276
),
12751277
(
12761278
upper_percentile
12771279
if upper_percentile is None
1278-
else upper_percentile.item()
1279-
if hasattr(upper_percentile, "item")
1280-
else upper_percentile
1280+
else upper_percentile.item() if hasattr(upper_percentile, "item") else upper_percentile
12811281
),
12821282
)
12831283
)
@@ -1401,7 +1401,9 @@ def __init__(
14011401

14021402
if isinstance(gamma, (int, float)):
14031403
if gamma <= 0.5:
1404-
raise ValueError(f"if gamma is a number, must greater than 0.5 and value is picked from (0.5, gamma), got {gamma}")
1404+
raise ValueError(
1405+
f"if gamma is a number, must greater than 0.5 and value is picked from (0.5, gamma), got {gamma}"
1406+
)
14051407
self.gamma = (0.5, gamma)
14061408
elif len(gamma) != 2:
14071409
raise ValueError("gamma should be a number or pair of numbers.")
@@ -1412,7 +1414,9 @@ def __init__(
14121414
self.invert_image: bool = invert_image
14131415
self.retain_stats: bool = retain_stats
14141416

1415-
self.adjust_contrast = AdjustContrast(self.gamma_value, invert_image=self.invert_image, retain_stats=self.retain_stats)
1417+
self.adjust_contrast = AdjustContrast(
1418+
self.gamma_value, invert_image=self.invert_image, retain_stats=self.retain_stats
1419+
)
14161420

14171421
def randomize(self, data: Any | None = None) -> None:
14181422
super().randomize(None)
@@ -1538,7 +1542,9 @@ def _normalize(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
15381542
b_min = ((self.b_max - self.b_min) * (self.lower / 100.0)) + self.b_min
15391543
b_max = ((self.b_max - self.b_min) * (self.upper / 100.0)) + self.b_min
15401544

1541-
scalar = ScaleIntensityRange(a_min=a_min, a_max=a_max, b_min=b_min, b_max=b_max, clip=self.clip, dtype=self.dtype)
1545+
scalar = ScaleIntensityRange(
1546+
a_min=a_min, a_max=a_max, b_min=b_min, b_max=b_max, clip=self.clip, dtype=self.dtype
1547+
)
15421548
img = scalar(img)
15431549
img = convert_to_tensor(img, track_meta=False)
15441550
return img
@@ -1861,7 +1867,8 @@ def __call__(self, img: NdarrayTensor) -> NdarrayTensor:
18611867
img_t, *_ = convert_data_type(img, torch.Tensor, dtype=torch.float32)
18621868

18631869
gf1, gf2 = (
1864-
GaussianFilter(img_t.ndim - 1, sigma, approx=self.approx).to(img_t.device) for sigma in (self.sigma1, self.sigma2)
1870+
GaussianFilter(img_t.ndim - 1, sigma, approx=self.approx).to(img_t.device)
1871+
for sigma in (self.sigma1, self.sigma2)
18651872
)
18661873
blurred_f = gf1(img_t.unsqueeze(0))
18671874
filter_blurred_f = gf2(blurred_f)
@@ -2219,7 +2226,9 @@ def __init__(self, loc: tuple | Sequence[tuple], k_intensity: Sequence[float] |
22192226
# assert one-to-one relationship between factors and locations
22202227
if isinstance(k_intensity, Sequence):
22212228
if not isinstance(loc[0], Sequence):
2222-
raise ValueError("If a sequence is passed to k_intensity, then a sequence of locations must be passed to loc")
2229+
raise ValueError(
2230+
"If a sequence is passed to k_intensity, then a sequence of locations must be passed to loc"
2231+
)
22232232
if len(k_intensity) != len(loc):
22242233
raise ValueError("There must be one intensity_factor value for each tuple of indices in loc.")
22252234
if isinstance(self.loc[0], Sequence) and k_intensity is not None and not isinstance(self.k_intensity, Sequence):
@@ -2559,7 +2568,9 @@ def __init__(
25592568
max_spatial_size: Sequence[int] | int | None = None,
25602569
prob: float = 0.1,
25612570
) -> None:
2562-
super().__init__(holes=holes, spatial_size=spatial_size, max_holes=max_holes, max_spatial_size=max_spatial_size, prob=prob)
2571+
super().__init__(
2572+
holes=holes, spatial_size=spatial_size, max_holes=max_holes, max_spatial_size=max_spatial_size, prob=prob
2573+
)
25632574
self.dropout_holes = dropout_holes
25642575
if isinstance(fill_value, (tuple, list)):
25652576
if len(fill_value) != 2:
@@ -2772,7 +2783,10 @@ def __call__(self, img: torch.Tensor) -> torch.Tensor:
27722783
if self._do_transform:
27732784
if self.channel_wise:
27742785
img = torch.stack(
2775-
[IntensityRemap(self.kernel_size, self.R.choice([-self.slope, self.slope]))(img[i]) for i in range(len(img))]
2786+
[
2787+
IntensityRemap(self.kernel_size, self.R.choice([-self.slope, self.slope]))(img[i])
2788+
for i in range(len(img))
2789+
]
27762790
)
27772791
else:
27782792
img = IntensityRemap(self.kernel_size, self.R.choice([-self.slope, self.slope]))(img)
@@ -2828,7 +2842,9 @@ def __init__(
28282842

28292843
self.thresholds = {k: v for k, v in self.thresholds.items() if v is not None}
28302844
if self.thresholds.keys().isdisjoint(set("RGBHSV")):
2831-
raise ValueError(f"Threshold for at least one channel of RGB or HSV needs to be set. {self.thresholds} is provided.")
2845+
raise ValueError(
2846+
f"Threshold for at least one channel of RGB or HSV needs to be set. {self.thresholds} is provided."
2847+
)
28322848
self.invert = invert
28332849

28342850
def _set_threshold(self, threshold, mode):
@@ -2839,7 +2855,9 @@ def _set_threshold(self, threshold, mode):
28392855
elif isinstance(threshold, (float, int)):
28402856
self.thresholds[mode] = float(threshold)
28412857
else:
2842-
raise ValueError(f"`threshold` should be either a callable, string, or float number, {type(threshold)} was given.")
2858+
raise ValueError(
2859+
f"`threshold` should be either a callable, string, or float number, {type(threshold)} was given."
2860+
)
28432861

28442862
def _get_threshold(self, image, mode):
28452863
threshold = self.thresholds.get(mode)
@@ -2961,7 +2979,9 @@ def __init__(
29612979
raise ValueError(f"Unknown mode: {self.mode}. Supported modes are 'B' and 'RF'.")
29622980

29632981
if self.sink_mode not in ["all", "mid", "min", "mask"]:
2964-
raise ValueError(f"Unknown sink mode: {self.sink_mode}. Supported modes are 'all', 'mid', 'min' and 'mask'.")
2982+
raise ValueError(
2983+
f"Unknown sink mode: {self.sink_mode}. Supported modes are 'all', 'mid', 'min' and 'mask'."
2984+
)
29652985

29662986
self._compute_conf_map = UltrasoundConfidenceMap(
29672987
self.alpha, self.beta, self.gamma, self.mode, self.sink_mode, self.use_cg, self.cg_tol, self.cg_maxiter

monai/transforms/intensity/dictionary.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ def __init__(
211211
RandomizableTransform.__init__(self, prob)
212212
self.rand_gaussian_noise = RandGaussianNoise(mean=mean, std=std, prob=1.0, dtype=dtype, sample_std=sample_std)
213213

214-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandGaussianNoised:
214+
def set_random_state(
215+
self, seed: int | None = None, state: np.random.RandomState | None = None
216+
) -> RandGaussianNoised:
215217
super().set_random_state(seed, state)
216218
self.rand_gaussian_noise.set_random_state(seed, state)
217219
return self
@@ -293,7 +295,9 @@ def __init__(
293295
dtype=dtype,
294296
)
295297

296-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandNonCentralChiNoised:
298+
def set_random_state(
299+
self, seed: int | None = None, state: np.random.RandomState | None = None
300+
) -> RandNonCentralChiNoised:
297301
super().set_random_state(seed, state)
298302
self.rand_non_central_chi_noise.set_random_state(seed, state)
299303
return self
@@ -496,7 +500,9 @@ def __init__(
496500
self.meta_key_postfix = ensure_tuple_rep(meta_key_postfix, len(self.keys))
497501
self.shifter = RandShiftIntensity(offsets=offsets, safe=safe, prob=1.0, channel_wise=channel_wise)
498502

499-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandShiftIntensityd:
503+
def set_random_state(
504+
self, seed: int | None = None, state: np.random.RandomState | None = None
505+
) -> RandShiftIntensityd:
500506
super().set_random_state(seed, state)
501507
self.shifter.set_random_state(seed, state)
502508
return self
@@ -595,9 +601,13 @@ def __init__(
595601
"""
596602
MapTransform.__init__(self, keys, allow_missing_keys)
597603
RandomizableTransform.__init__(self, prob)
598-
self.shifter = RandStdShiftIntensity(factors=factors, nonzero=nonzero, channel_wise=channel_wise, dtype=dtype, prob=1.0)
604+
self.shifter = RandStdShiftIntensity(
605+
factors=factors, nonzero=nonzero, channel_wise=channel_wise, dtype=dtype, prob=1.0
606+
)
599607

600-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandStdShiftIntensityd:
608+
def set_random_state(
609+
self, seed: int | None = None, state: np.random.RandomState | None = None
610+
) -> RandStdShiftIntensityd:
601611
super().set_random_state(seed, state)
602612
self.shifter.set_random_state(seed, state)
603613
return self
@@ -694,7 +704,9 @@ def __init__(
694704
RandomizableTransform.__init__(self, prob)
695705
self.scaler = RandScaleIntensity(factors=factors, dtype=dtype, prob=1.0, channel_wise=channel_wise)
696706

697-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandScaleIntensityd:
707+
def set_random_state(
708+
self, seed: int | None = None, state: np.random.RandomState | None = None
709+
) -> RandScaleIntensityd:
698710
super().set_random_state(seed, state)
699711
self.scaler.set_random_state(seed, state)
700712
return self
@@ -764,7 +776,9 @@ def __init__(
764776
factors=factors, fixed_mean=self.fixed_mean, preserve_range=preserve_range, dtype=dtype, prob=1.0
765777
)
766778

767-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandScaleIntensityFixedMeand:
779+
def set_random_state(
780+
self, seed: int | None = None, state: np.random.RandomState | None = None
781+
) -> RandScaleIntensityFixedMeand:
768782
super().set_random_state(seed, state)
769783
self.scaler.set_random_state(seed, state)
770784
return self
@@ -1074,7 +1088,9 @@ def __init__(
10741088
self.adjuster = RandAdjustContrast(gamma=gamma, prob=1.0, invert_image=invert_image, retain_stats=retain_stats)
10751089
self.invert_image = invert_image
10761090

1077-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandAdjustContrastd:
1091+
def set_random_state(
1092+
self, seed: int | None = None, state: np.random.RandomState | None = None
1093+
) -> RandAdjustContrastd:
10781094
super().set_random_state(seed, state)
10791095
self.adjuster.set_random_state(seed, state)
10801096
return self
@@ -1310,9 +1326,13 @@ def __init__(
13101326
) -> None:
13111327
MapTransform.__init__(self, keys, allow_missing_keys)
13121328
RandomizableTransform.__init__(self, prob)
1313-
self.rand_smooth = RandGaussianSmooth(sigma_x=sigma_x, sigma_y=sigma_y, sigma_z=sigma_z, approx=approx, prob=1.0)
1329+
self.rand_smooth = RandGaussianSmooth(
1330+
sigma_x=sigma_x, sigma_y=sigma_y, sigma_z=sigma_z, approx=approx, prob=1.0
1331+
)
13141332

1315-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandGaussianSmoothd:
1333+
def set_random_state(
1334+
self, seed: int | None = None, state: np.random.RandomState | None = None
1335+
) -> RandGaussianSmoothd:
13161336
super().set_random_state(seed, state)
13171337
self.rand_smooth.set_random_state(seed, state)
13181338
return self
@@ -1427,7 +1447,9 @@ def __init__(
14271447
prob=1.0,
14281448
)
14291449

1430-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandGaussianSharpend:
1450+
def set_random_state(
1451+
self, seed: int | None = None, state: np.random.RandomState | None = None
1452+
) -> RandGaussianSharpend:
14311453
super().set_random_state(seed, state)
14321454
self.rand_sharpen.set_random_state(seed, state)
14331455
return self
@@ -1475,7 +1497,9 @@ def __init__(
14751497
RandomizableTransform.__init__(self, prob)
14761498
self.shifter = RandHistogramShift(num_control_points=num_control_points, prob=1.0)
14771499

1478-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandHistogramShiftd:
1500+
def set_random_state(
1501+
self, seed: int | None = None, state: np.random.RandomState | None = None
1502+
) -> RandHistogramShiftd:
14791503
super().set_random_state(seed, state)
14801504
self.shifter.set_random_state(seed, state)
14811505
return self
@@ -1702,7 +1726,9 @@ def __init__(
17021726
RandomizableTransform.__init__(self, prob=prob)
17031727
self.rand_noise = RandKSpaceSpikeNoise(prob=1.0, intensity_range=intensity_range, channel_wise=channel_wise)
17041728

1705-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandKSpaceSpikeNoised:
1729+
def set_random_state(
1730+
self, seed: int | None = None, state: np.random.RandomState | None = None
1731+
) -> RandKSpaceSpikeNoised:
17061732
super().set_random_state(seed, state)
17071733
self.rand_noise.set_random_state(seed, state)
17081734
return self
@@ -1778,7 +1804,9 @@ def __init__(
17781804
prob=1.0,
17791805
)
17801806

1781-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandCoarseDropoutd:
1807+
def set_random_state(
1808+
self, seed: int | None = None, state: np.random.RandomState | None = None
1809+
) -> RandCoarseDropoutd:
17821810
super().set_random_state(seed, state)
17831811
self.dropper.set_random_state(seed, state)
17841812
return self
@@ -1849,7 +1877,9 @@ def __init__(
18491877
holes=holes, spatial_size=spatial_size, max_holes=max_holes, max_spatial_size=max_spatial_size, prob=1.0
18501878
)
18511879

1852-
def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandCoarseShuffled:
1880+
def set_random_state(
1881+
self, seed: int | None = None, state: np.random.RandomState | None = None
1882+
) -> RandCoarseShuffled:
18531883
super().set_random_state(seed, state)
18541884
self.shuffle.set_random_state(seed, state)
18551885
return self

0 commit comments

Comments
 (0)