Skip to content

Commit 5c152a8

Browse files
fix missing v1 refactor from incoming #738
1 parent 87deb99 commit 5c152a8

File tree

1 file changed

+15
-41
lines changed

1 file changed

+15
-41
lines changed

fractal_tasks_core/tasks/cellpose_utils.py

+15-41
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
from typing import Optional
1717

1818
import numpy as np
19-
from pydantic import BaseModel
20-
from pydantic import Field
21-
from pydantic import root_validator
22-
from pydantic import validator
19+
from pydantic.v1 import BaseModel
20+
from pydantic.v1 import Field
21+
from pydantic.v1 import root_validator
22+
from pydantic.v1 import validator
2323

2424
from fractal_tasks_core.channels import ChannelInputModel
2525
from fractal_tasks_core.channels import ChannelNotFoundError
@@ -82,25 +82,13 @@ def validate_conditions(cls, values):
8282
# Verify that custom parameters are only provided when type="custom"
8383
if type != "custom":
8484
if lower_percentile is not None:
85-
raise ValueError(
86-
f"Type='{type}' but {lower_percentile=}. "
87-
"Hint: set type='custom'."
88-
)
85+
raise ValueError(f"Type='{type}' but {lower_percentile=}. " "Hint: set type='custom'.")
8986
if upper_percentile is not None:
90-
raise ValueError(
91-
f"Type='{type}' but {upper_percentile=}. "
92-
"Hint: set type='custom'."
93-
)
87+
raise ValueError(f"Type='{type}' but {upper_percentile=}. " "Hint: set type='custom'.")
9488
if lower_bound is not None:
95-
raise ValueError(
96-
f"Type='{type}' but {lower_bound=}. "
97-
"Hint: set type='custom'."
98-
)
89+
raise ValueError(f"Type='{type}' but {lower_bound=}. " "Hint: set type='custom'.")
9990
if upper_bound is not None:
100-
raise ValueError(
101-
f"Type='{type}' but {upper_bound=}. "
102-
"Hint: set type='custom'."
103-
)
91+
raise ValueError(f"Type='{type}' but {upper_bound=}. " "Hint: set type='custom'.")
10492

10593
# The only valid options are:
10694
# 1. Both percentiles are set and both bounds are unset
@@ -114,14 +102,9 @@ def validate_conditions(cls, values):
114102
upper_bound is not None,
115103
)
116104
if len(set(are_percentiles_set)) != 1:
117-
raise ValueError(
118-
"Both lower_percentile and upper_percentile must be set "
119-
"together."
120-
)
105+
raise ValueError("Both lower_percentile and upper_percentile must be set " "together.")
121106
if len(set(are_bounds_set)) != 1:
122-
raise ValueError(
123-
"Both lower_bound and upper_bound must be set together"
124-
)
107+
raise ValueError("Both lower_bound and upper_bound must be set together")
125108
if lower_percentile is not None and lower_bound is not None:
126109
raise ValueError(
127110
"You cannot set both explicit bounds and percentile bounds "
@@ -213,9 +196,7 @@ class CellposeChannel1InputModel(ChannelInputModel):
213196
Cellpose models
214197
"""
215198

216-
normalize: CellposeCustomNormalizer = Field(
217-
default_factory=CellposeCustomNormalizer
218-
)
199+
normalize: CellposeCustomNormalizer = Field(default_factory=CellposeCustomNormalizer)
219200

220201
def get_omero_channel(self, zarr_url) -> OmeroChannel:
221202
try:
@@ -252,9 +233,7 @@ class CellposeChannel2InputModel(BaseModel):
252233

253234
wavelength_id: Optional[str] = None
254235
label: Optional[str] = None
255-
normalize: CellposeCustomNormalizer = Field(
256-
default_factory=CellposeCustomNormalizer
257-
)
236+
normalize: CellposeCustomNormalizer = Field(default_factory=CellposeCustomNormalizer)
258237

259238
@validator("label", always=True)
260239
def mutually_exclusive_channel_attributes(cls, v, values):
@@ -265,8 +244,7 @@ def mutually_exclusive_channel_attributes(cls, v, values):
265244
label = v
266245
if wavelength_id and v:
267246
raise ValueError(
268-
"`wavelength_id` and `label` cannot be both set "
269-
f"(given {wavelength_id=} and {label=})."
247+
"`wavelength_id` and `label` cannot be both set " f"(given {wavelength_id=} and {label=})."
270248
)
271249
return v
272250

@@ -415,18 +393,14 @@ def normalized_img(
415393
i99 = np.percentile(img[k], upper_p)
416394
i1 = np.percentile(img[k], lower_p)
417395
if i99 - i1 > +1e-3: # np.ptp(img[k]) > 1e-3:
418-
img[k] = normalize_percentile(
419-
img[k], lower=lower_p, upper=upper_p
420-
)
396+
img[k] = normalize_percentile(img[k], lower=lower_p, upper=upper_p)
421397
if invert:
422398
img[k] = -1 * img[k] + 1
423399
else:
424400
img[k] = 0
425401
elif lower_bound is not None:
426402
if upper_bound - lower_bound > +1e-3:
427-
img[k] = normalize_bounds(
428-
img[k], lower=lower_bound, upper=upper_bound
429-
)
403+
img[k] = normalize_bounds(img[k], lower=lower_bound, upper=upper_bound)
430404
if invert:
431405
img[k] = -1 * img[k] + 1
432406
else:

0 commit comments

Comments
 (0)