Skip to content

Commit 29005ca

Browse files
committed
more docstrings
1 parent 8a316f7 commit 29005ca

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

bioimageio/core/prediction_pipeline/_processing.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Here pre- and postprocessing operations are implemented according to their definitions in bioimageio.spec:
2+
see https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/preprocessing_spec_latest.md
3+
and https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/postprocessing_spec_latest.md
4+
"""
15
from dataclasses import dataclass, field, fields
26
from typing import Mapping, Optional, Sequence, Type, Union
37

@@ -33,7 +37,7 @@ def _get_fixed(
3337

3438
@dataclass
3539
class Processing:
36-
"""base class for all Pre- and Postprocessing transformations"""
40+
"""base class for all Pre- and Postprocessing transformations."""
3741

3842
tensor_name: str
3943
# todo: in python>=3.10 we should use dataclasses.KW_ONLY instead of MISSING (see child classes) to make inheritance work properly
@@ -103,11 +107,7 @@ def ensure_dtype(tensor: xr.DataArray, *, dtype) -> xr.DataArray:
103107

104108
@dataclass
105109
class Binarize(Processing):
106-
"""'output = tensor > threshold' (returns float array)
107-
108-
Args:
109-
threshold : threshold.
110-
"""
110+
"""'output = tensor > threshold' (note: returns float array)."""
111111

112112
threshold: float = MISSING # make dataclass inheritance work for py<3.10 by using an explicit MISSING value.
113113

@@ -117,7 +117,7 @@ def apply(self, tensor: xr.DataArray) -> xr.DataArray:
117117

118118
@dataclass
119119
class Clip(Processing):
120-
"""Limit tensor values to [min, max]"""
120+
"""Limit tensor values to [min, max]."""
121121

122122
min: float = MISSING
123123
max: float = MISSING
@@ -128,6 +128,8 @@ def apply(self, tensor: xr.DataArray) -> xr.DataArray:
128128

129129
@dataclass
130130
class EnsureDtype(Processing):
131+
"""Helper Processing to cast dtype if needed."""
132+
131133
dtype: str = MISSING
132134

133135
def apply(self, tensor: xr.DataArray) -> xr.DataArray:
@@ -136,7 +138,7 @@ def apply(self, tensor: xr.DataArray) -> xr.DataArray:
136138

137139
@dataclass
138140
class ScaleLinear(Processing):
139-
"""scale the tensor with a fixed multiplicative and additive factor"""
141+
"""Scale the tensor with a fixed multiplicative and additive factor."""
140142

141143
gain: Union[float, Sequence[float]] = MISSING
142144
offset: Union[float, Sequence[float]] = MISSING
@@ -162,6 +164,8 @@ def __post_init__(self):
162164

163165
@dataclass
164166
class ScaleMeanVariance(Processing):
167+
"""Scale the tensor s.t. its mean and variance match a reference tensor."""
168+
165169
mode: Literal[SampleMode, DatasetMode] = PER_SAMPLE
166170
reference_tensor: TensorName = MISSING
167171
axes: Optional[Sequence[str]] = None
@@ -190,6 +194,8 @@ def apply(self, tensor: xr.DataArray) -> xr.DataArray:
190194

191195
@dataclass
192196
class ScaleRange(Processing):
197+
"""Scale with percentiles."""
198+
193199
mode: Literal[SampleMode, DatasetMode] = PER_SAMPLE
194200
axes: Optional[Sequence[str]] = None
195201
min_percentile: float = 0.0
@@ -217,12 +223,16 @@ def __post_init__(self):
217223

218224
@dataclass
219225
class Sigmoid(Processing):
226+
"""1 / (1 + e^(-tensor))."""
227+
220228
def apply(self, tensor: xr.DataArray) -> xr.DataArray:
221229
return 1.0 / (1.0 + np.exp(-tensor))
222230

223231

224232
@dataclass
225233
class ZeroMeanUnitVariance(Processing):
234+
"""normalize to zero mean, unit variance."""
235+
226236
mode: Mode = PER_SAMPLE
227237
mean: Optional[Union[float, Sequence[float]]] = None
228238
std: Optional[Union[float, Sequence[float]]] = None

0 commit comments

Comments
 (0)