vkit.mechanism.distortion_policy.photometric.streak

  1# Copyright 2022 vkit-x Administrator. All Rights Reserved.
  2#
  3# This project (vkit-x/vkit) is dual-licensed under commercial and SSPL licenses.
  4#
  5# The commercial license gives you the full rights to create and distribute software
  6# on your own terms without any SSPL license obligations. For more information,
  7# please see the "LICENSE_COMMERCIAL.txt" file.
  8#
  9# This project is also available under Server Side Public License (SSPL).
 10# The SSPL licensing is ideal for use cases such as open source projects with
 11# SSPL distribution, student/academic purposes, hobby projects, internal research
 12# projects without external distribution, or other projects where all SSPL
 13# obligations can be met. For more information, please see the "LICENSE_SSPL.txt" file.
 14from typing import Tuple
 15
 16import attrs
 17from numpy.random import Generator as RandomGenerator
 18
 19from vkit.mechanism import distortion
 20from ..type import DistortionConfigGenerator, DistortionPolicyFactory
 21from ..opt import sample_float
 22
 23
 24@attrs.define
 25class LineStreakConfigGeneratorConfig:
 26    thickness_min: int = 1
 27    thickness_max: int = 4
 28    gap_min: int = 5
 29    gap_ratio_min: float = 0.01
 30    gap_ratio_max: float = 0.5
 31    prob_dash: float = 0.25
 32    dash_thickness_ratio_min: float = 0.0
 33    dash_thickness_ratio_max: float = 0.05
 34    dash_to_thickness_gap_ratio_min: float = 0.5
 35    dash_to_thickness_gap_ratio_max: float = 1.0
 36    alpha_min: float = 0.2
 37    alpha_max: float = 1.0
 38
 39
 40class LineStreakConfigGenerator(
 41    DistortionConfigGenerator[
 42        LineStreakConfigGeneratorConfig,
 43        distortion.LineStreakConfig,
 44    ]
 45):  # yapf: disable
 46
 47    def __call__(self, shape: Tuple[int, int], rng: RandomGenerator):
 48        long_side_length = max(shape)
 49        gap_ratio = sample_float(
 50            level=self.level,
 51            value_min=self.config.gap_ratio_min,
 52            value_max=self.config.gap_ratio_max,
 53            prob_reciprocal=None,
 54            rng=rng,
 55            inverse_level=True,
 56        )
 57        gap = max(self.config.gap_min, round(gap_ratio * long_side_length))
 58
 59        thickness = rng.integers(self.config.thickness_min, self.config.thickness_max + 1)
 60
 61        dash_thickness = 0
 62        dash_gap = 0
 63        if rng.random() < self.config.prob_dash:
 64            dash_thickness_ratio = float(
 65                rng.uniform(
 66                    self.config.dash_thickness_ratio_min,
 67                    self.config.dash_thickness_ratio_max,
 68                )
 69            )
 70            dash_thickness = round(dash_thickness_ratio * long_side_length)
 71
 72            dash_to_thickness_gap_ratio = float(
 73                rng.uniform(
 74                    self.config.dash_to_thickness_gap_ratio_min,
 75                    self.config.dash_to_thickness_gap_ratio_max,
 76                )
 77            )
 78            dash_gap = round(dash_to_thickness_gap_ratio * dash_thickness)
 79
 80        alpha = rng.uniform(self.config.alpha_min, self.config.alpha_max)
 81
 82        mode = rng.integers(0, 3)
 83        if mode == 0:
 84            enable_vert = True
 85            enable_hori = False
 86        elif mode == 1:
 87            enable_vert = False
 88            enable_hori = True
 89        elif mode == 2:
 90            enable_vert = True
 91            enable_hori = True
 92        else:
 93            raise NotImplementedError()
 94
 95        return distortion.LineStreakConfig(
 96            thickness=thickness,
 97            gap=gap,
 98            dash_thickness=dash_thickness,
 99            dash_gap=dash_gap,
100            alpha=alpha,
101            enable_vert=enable_vert,
102            enable_hori=enable_hori,
103        )
104
105
106line_streak_policy_factory = DistortionPolicyFactory(
107    distortion.line_streak,
108    LineStreakConfigGenerator,
109)
110
111
112def sample_params_for_rectangle_and_ellipse_streak(
113    level: int,
114    thickness_min: int,
115    thickness_max: int,
116    aspect_ratio_min: float,
117    aspect_ratio_max: float,
118    short_side_min: int,
119    short_side_min_ratio_min: float,
120    short_side_min_ratio_max: float,
121    short_side_step_ratio_min: float,
122    short_side_step_ratio_max: float,
123    alpha_min: float,
124    alpha_max: float,
125    shape: Tuple[int, int],
126    rng: RandomGenerator,
127):
128    long_side_length = max(shape)
129    short_side_min_ratio = sample_float(
130        level=level,
131        value_min=short_side_min_ratio_min,
132        value_max=short_side_min_ratio_max,
133        prob_reciprocal=None,
134        rng=rng,
135        inverse_level=True,
136    )
137    short_side_min = max(
138        short_side_min,
139        round(short_side_min_ratio * long_side_length),
140    )
141
142    short_side_step_ratio = rng.uniform(
143        short_side_step_ratio_min,
144        short_side_step_ratio_max,
145    )
146    short_side_step = round(short_side_step_ratio * short_side_min)
147
148    thickness = rng.integers(thickness_min, thickness_max + 1)
149    aspect_ratio = rng.uniform(aspect_ratio_min, aspect_ratio_max)
150    alpha = rng.uniform(alpha_min, alpha_max)
151
152    return (
153        thickness,
154        aspect_ratio,
155        short_side_min,
156        short_side_step,
157        alpha,
158    )
159
160
161@attrs.define
162class RectangleStreakConfigGeneratorConfig:
163    thickness_min: int = 1
164    thickness_max: int = 4
165    aspect_ratio_min: float = 0.5
166    aspect_ratio_max: float = 1.5
167    prob_dash: float = 0.25
168    dash_thickness_ratio_min: float = 0.0
169    dash_thickness_ratio_max: float = 0.05
170    dash_to_thickness_gap_ratio_min: float = 0.5
171    dash_to_thickness_gap_ratio_max: float = 1.0
172    short_side_min: int = 5
173    short_side_min_ratio_min: float = 0.01
174    short_side_min_ratio_max: float = 0.25
175    short_side_step_ratio_min: float = 0.8
176    short_side_step_ratio_max: float = 3.0
177    alpha_min: float = 0.2
178    alpha_max: float = 1.0
179
180
181class RectangleStreakConfigGenerator(
182    DistortionConfigGenerator[
183        RectangleStreakConfigGeneratorConfig,
184        distortion.RectangleStreakConfig,
185    ]
186):  # yapf: disable
187
188    def __call__(self, shape: Tuple[int, int], rng: RandomGenerator):
189        (
190            thickness,
191            aspect_ratio,
192            short_side_min,
193            short_side_step,
194            alpha,
195        ) = sample_params_for_rectangle_and_ellipse_streak(
196            level=self.level,
197            thickness_min=self.config.thickness_min,
198            thickness_max=self.config.thickness_max,
199            aspect_ratio_min=self.config.aspect_ratio_min,
200            aspect_ratio_max=self.config.aspect_ratio_max,
201            short_side_min=self.config.short_side_min,
202            short_side_min_ratio_min=self.config.short_side_min_ratio_min,
203            short_side_min_ratio_max=self.config.short_side_min_ratio_max,
204            short_side_step_ratio_min=self.config.short_side_step_ratio_min,
205            short_side_step_ratio_max=self.config.short_side_step_ratio_max,
206            alpha_min=self.config.alpha_min,
207            alpha_max=self.config.alpha_max,
208            shape=shape,
209            rng=rng,
210        )
211
212        # Dash line.
213        long_side_length = max(shape)
214        dash_thickness = 0
215        dash_gap = 0
216        if rng.random() < self.config.prob_dash:
217            dash_thickness_ratio = float(
218                rng.uniform(
219                    self.config.dash_thickness_ratio_min,
220                    self.config.dash_thickness_ratio_max,
221                )
222            )
223            dash_thickness = round(dash_thickness_ratio * long_side_length)
224
225            dash_to_thickness_gap_ratio = float(
226                rng.uniform(
227                    self.config.dash_to_thickness_gap_ratio_min,
228                    self.config.dash_to_thickness_gap_ratio_max,
229                )
230            )
231            dash_gap = round(dash_to_thickness_gap_ratio * dash_thickness)
232
233        return distortion.RectangleStreakConfig(
234            thickness=thickness,
235            aspect_ratio=aspect_ratio,
236            dash_thickness=dash_thickness,
237            dash_gap=dash_gap,
238            short_side_min=short_side_min,
239            short_side_step=short_side_step,
240            alpha=alpha,
241        )
242
243
244rectangle_streak_policy_factory = DistortionPolicyFactory(
245    distortion.rectangle_streak,
246    RectangleStreakConfigGenerator,
247)
248
249
250@attrs.define
251class EllipseStreakConfigGeneratorConfig:
252    thickness_min: int = 1
253    thickness_max: int = 3
254    aspect_ratio_min: float = 0.5
255    aspect_ratio_max: float = 1.5
256    short_side_min: int = 5
257    short_side_min_ratio_min: float = 0.01
258    short_side_min_ratio_max: float = 0.25
259    short_side_step_ratio_min: float = 0.8
260    short_side_step_ratio_max: float = 3.0
261    alpha_min: float = 0.2
262    alpha_max: float = 1.0
263
264
265class EllipseStreakConfigGenerator(
266    DistortionConfigGenerator[
267        EllipseStreakConfigGeneratorConfig,
268        distortion.EllipseStreakConfig,
269    ]
270):  # yapf: disable
271
272    def __call__(self, shape: Tuple[int, int], rng: RandomGenerator):
273        (
274            thickness,
275            aspect_ratio,
276            short_side_min,
277            short_side_step,
278            alpha,
279        ) = sample_params_for_rectangle_and_ellipse_streak(
280            level=self.level,
281            thickness_min=self.config.thickness_min,
282            thickness_max=self.config.thickness_max,
283            aspect_ratio_min=self.config.aspect_ratio_min,
284            aspect_ratio_max=self.config.aspect_ratio_max,
285            short_side_min=self.config.short_side_min,
286            short_side_min_ratio_min=self.config.short_side_min_ratio_min,
287            short_side_min_ratio_max=self.config.short_side_min_ratio_max,
288            short_side_step_ratio_min=self.config.short_side_step_ratio_min,
289            short_side_step_ratio_max=self.config.short_side_step_ratio_max,
290            alpha_min=self.config.alpha_min,
291            alpha_max=self.config.alpha_max,
292            shape=shape,
293            rng=rng,
294        )
295
296        return distortion.EllipseStreakConfig(
297            thickness=thickness,
298            aspect_ratio=aspect_ratio,
299            short_side_min=short_side_min,
300            short_side_step=short_side_step,
301            alpha=alpha,
302        )
303
304
305ellipse_streak_policy_factory = DistortionPolicyFactory(
306    distortion.ellipse_streak,
307    EllipseStreakConfigGenerator,
308)
class LineStreakConfigGeneratorConfig:
26class LineStreakConfigGeneratorConfig:
27    thickness_min: int = 1
28    thickness_max: int = 4
29    gap_min: int = 5
30    gap_ratio_min: float = 0.01
31    gap_ratio_max: float = 0.5
32    prob_dash: float = 0.25
33    dash_thickness_ratio_min: float = 0.0
34    dash_thickness_ratio_max: float = 0.05
35    dash_to_thickness_gap_ratio_min: float = 0.5
36    dash_to_thickness_gap_ratio_max: float = 1.0
37    alpha_min: float = 0.2
38    alpha_max: float = 1.0
LineStreakConfigGeneratorConfig( thickness_min: int = 1, thickness_max: int = 4, gap_min: int = 5, gap_ratio_min: float = 0.01, gap_ratio_max: float = 0.5, prob_dash: float = 0.25, dash_thickness_ratio_min: float = 0.0, dash_thickness_ratio_max: float = 0.05, dash_to_thickness_gap_ratio_min: float = 0.5, dash_to_thickness_gap_ratio_max: float = 1.0, alpha_min: float = 0.2, alpha_max: float = 1.0)
 2def __init__(self, thickness_min=attr_dict['thickness_min'].default, thickness_max=attr_dict['thickness_max'].default, gap_min=attr_dict['gap_min'].default, gap_ratio_min=attr_dict['gap_ratio_min'].default, gap_ratio_max=attr_dict['gap_ratio_max'].default, prob_dash=attr_dict['prob_dash'].default, dash_thickness_ratio_min=attr_dict['dash_thickness_ratio_min'].default, dash_thickness_ratio_max=attr_dict['dash_thickness_ratio_max'].default, dash_to_thickness_gap_ratio_min=attr_dict['dash_to_thickness_gap_ratio_min'].default, dash_to_thickness_gap_ratio_max=attr_dict['dash_to_thickness_gap_ratio_max'].default, alpha_min=attr_dict['alpha_min'].default, alpha_max=attr_dict['alpha_max'].default):
 3    self.thickness_min = thickness_min
 4    self.thickness_max = thickness_max
 5    self.gap_min = gap_min
 6    self.gap_ratio_min = gap_ratio_min
 7    self.gap_ratio_max = gap_ratio_max
 8    self.prob_dash = prob_dash
 9    self.dash_thickness_ratio_min = dash_thickness_ratio_min
10    self.dash_thickness_ratio_max = dash_thickness_ratio_max
11    self.dash_to_thickness_gap_ratio_min = dash_to_thickness_gap_ratio_min
12    self.dash_to_thickness_gap_ratio_max = dash_to_thickness_gap_ratio_max
13    self.alpha_min = alpha_min
14    self.alpha_max = alpha_max

Method generated by attrs for class LineStreakConfigGeneratorConfig.

 41class LineStreakConfigGenerator(
 42    DistortionConfigGenerator[
 43        LineStreakConfigGeneratorConfig,
 44        distortion.LineStreakConfig,
 45    ]
 46):  # yapf: disable
 47
 48    def __call__(self, shape: Tuple[int, int], rng: RandomGenerator):
 49        long_side_length = max(shape)
 50        gap_ratio = sample_float(
 51            level=self.level,
 52            value_min=self.config.gap_ratio_min,
 53            value_max=self.config.gap_ratio_max,
 54            prob_reciprocal=None,
 55            rng=rng,
 56            inverse_level=True,
 57        )
 58        gap = max(self.config.gap_min, round(gap_ratio * long_side_length))
 59
 60        thickness = rng.integers(self.config.thickness_min, self.config.thickness_max + 1)
 61
 62        dash_thickness = 0
 63        dash_gap = 0
 64        if rng.random() < self.config.prob_dash:
 65            dash_thickness_ratio = float(
 66                rng.uniform(
 67                    self.config.dash_thickness_ratio_min,
 68                    self.config.dash_thickness_ratio_max,
 69                )
 70            )
 71            dash_thickness = round(dash_thickness_ratio * long_side_length)
 72
 73            dash_to_thickness_gap_ratio = float(
 74                rng.uniform(
 75                    self.config.dash_to_thickness_gap_ratio_min,
 76                    self.config.dash_to_thickness_gap_ratio_max,
 77                )
 78            )
 79            dash_gap = round(dash_to_thickness_gap_ratio * dash_thickness)
 80
 81        alpha = rng.uniform(self.config.alpha_min, self.config.alpha_max)
 82
 83        mode = rng.integers(0, 3)
 84        if mode == 0:
 85            enable_vert = True
 86            enable_hori = False
 87        elif mode == 1:
 88            enable_vert = False
 89            enable_hori = True
 90        elif mode == 2:
 91            enable_vert = True
 92            enable_hori = True
 93        else:
 94            raise NotImplementedError()
 95
 96        return distortion.LineStreakConfig(
 97            thickness=thickness,
 98            gap=gap,
 99            dash_thickness=dash_thickness,
100            dash_gap=dash_gap,
101            alpha=alpha,
102            enable_vert=enable_vert,
103            enable_hori=enable_hori,
104        )

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

def sample_params_for_rectangle_and_ellipse_streak( level: int, thickness_min: int, thickness_max: int, aspect_ratio_min: float, aspect_ratio_max: float, short_side_min: int, short_side_min_ratio_min: float, short_side_min_ratio_max: float, short_side_step_ratio_min: float, short_side_step_ratio_max: float, alpha_min: float, alpha_max: float, shape: Tuple[int, int], rng: numpy.random._generator.Generator):
113def sample_params_for_rectangle_and_ellipse_streak(
114    level: int,
115    thickness_min: int,
116    thickness_max: int,
117    aspect_ratio_min: float,
118    aspect_ratio_max: float,
119    short_side_min: int,
120    short_side_min_ratio_min: float,
121    short_side_min_ratio_max: float,
122    short_side_step_ratio_min: float,
123    short_side_step_ratio_max: float,
124    alpha_min: float,
125    alpha_max: float,
126    shape: Tuple[int, int],
127    rng: RandomGenerator,
128):
129    long_side_length = max(shape)
130    short_side_min_ratio = sample_float(
131        level=level,
132        value_min=short_side_min_ratio_min,
133        value_max=short_side_min_ratio_max,
134        prob_reciprocal=None,
135        rng=rng,
136        inverse_level=True,
137    )
138    short_side_min = max(
139        short_side_min,
140        round(short_side_min_ratio * long_side_length),
141    )
142
143    short_side_step_ratio = rng.uniform(
144        short_side_step_ratio_min,
145        short_side_step_ratio_max,
146    )
147    short_side_step = round(short_side_step_ratio * short_side_min)
148
149    thickness = rng.integers(thickness_min, thickness_max + 1)
150    aspect_ratio = rng.uniform(aspect_ratio_min, aspect_ratio_max)
151    alpha = rng.uniform(alpha_min, alpha_max)
152
153    return (
154        thickness,
155        aspect_ratio,
156        short_side_min,
157        short_side_step,
158        alpha,
159    )
class RectangleStreakConfigGeneratorConfig:
163class RectangleStreakConfigGeneratorConfig:
164    thickness_min: int = 1
165    thickness_max: int = 4
166    aspect_ratio_min: float = 0.5
167    aspect_ratio_max: float = 1.5
168    prob_dash: float = 0.25
169    dash_thickness_ratio_min: float = 0.0
170    dash_thickness_ratio_max: float = 0.05
171    dash_to_thickness_gap_ratio_min: float = 0.5
172    dash_to_thickness_gap_ratio_max: float = 1.0
173    short_side_min: int = 5
174    short_side_min_ratio_min: float = 0.01
175    short_side_min_ratio_max: float = 0.25
176    short_side_step_ratio_min: float = 0.8
177    short_side_step_ratio_max: float = 3.0
178    alpha_min: float = 0.2
179    alpha_max: float = 1.0
RectangleStreakConfigGeneratorConfig( thickness_min: int = 1, thickness_max: int = 4, aspect_ratio_min: float = 0.5, aspect_ratio_max: float = 1.5, prob_dash: float = 0.25, dash_thickness_ratio_min: float = 0.0, dash_thickness_ratio_max: float = 0.05, dash_to_thickness_gap_ratio_min: float = 0.5, dash_to_thickness_gap_ratio_max: float = 1.0, short_side_min: int = 5, short_side_min_ratio_min: float = 0.01, short_side_min_ratio_max: float = 0.25, short_side_step_ratio_min: float = 0.8, short_side_step_ratio_max: float = 3.0, alpha_min: float = 0.2, alpha_max: float = 1.0)
 2def __init__(self, thickness_min=attr_dict['thickness_min'].default, thickness_max=attr_dict['thickness_max'].default, aspect_ratio_min=attr_dict['aspect_ratio_min'].default, aspect_ratio_max=attr_dict['aspect_ratio_max'].default, prob_dash=attr_dict['prob_dash'].default, dash_thickness_ratio_min=attr_dict['dash_thickness_ratio_min'].default, dash_thickness_ratio_max=attr_dict['dash_thickness_ratio_max'].default, dash_to_thickness_gap_ratio_min=attr_dict['dash_to_thickness_gap_ratio_min'].default, dash_to_thickness_gap_ratio_max=attr_dict['dash_to_thickness_gap_ratio_max'].default, short_side_min=attr_dict['short_side_min'].default, short_side_min_ratio_min=attr_dict['short_side_min_ratio_min'].default, short_side_min_ratio_max=attr_dict['short_side_min_ratio_max'].default, short_side_step_ratio_min=attr_dict['short_side_step_ratio_min'].default, short_side_step_ratio_max=attr_dict['short_side_step_ratio_max'].default, alpha_min=attr_dict['alpha_min'].default, alpha_max=attr_dict['alpha_max'].default):
 3    self.thickness_min = thickness_min
 4    self.thickness_max = thickness_max
 5    self.aspect_ratio_min = aspect_ratio_min
 6    self.aspect_ratio_max = aspect_ratio_max
 7    self.prob_dash = prob_dash
 8    self.dash_thickness_ratio_min = dash_thickness_ratio_min
 9    self.dash_thickness_ratio_max = dash_thickness_ratio_max
10    self.dash_to_thickness_gap_ratio_min = dash_to_thickness_gap_ratio_min
11    self.dash_to_thickness_gap_ratio_max = dash_to_thickness_gap_ratio_max
12    self.short_side_min = short_side_min
13    self.short_side_min_ratio_min = short_side_min_ratio_min
14    self.short_side_min_ratio_max = short_side_min_ratio_max
15    self.short_side_step_ratio_min = short_side_step_ratio_min
16    self.short_side_step_ratio_max = short_side_step_ratio_max
17    self.alpha_min = alpha_min
18    self.alpha_max = alpha_max

Method generated by attrs for class RectangleStreakConfigGeneratorConfig.

182class RectangleStreakConfigGenerator(
183    DistortionConfigGenerator[
184        RectangleStreakConfigGeneratorConfig,
185        distortion.RectangleStreakConfig,
186    ]
187):  # yapf: disable
188
189    def __call__(self, shape: Tuple[int, int], rng: RandomGenerator):
190        (
191            thickness,
192            aspect_ratio,
193            short_side_min,
194            short_side_step,
195            alpha,
196        ) = sample_params_for_rectangle_and_ellipse_streak(
197            level=self.level,
198            thickness_min=self.config.thickness_min,
199            thickness_max=self.config.thickness_max,
200            aspect_ratio_min=self.config.aspect_ratio_min,
201            aspect_ratio_max=self.config.aspect_ratio_max,
202            short_side_min=self.config.short_side_min,
203            short_side_min_ratio_min=self.config.short_side_min_ratio_min,
204            short_side_min_ratio_max=self.config.short_side_min_ratio_max,
205            short_side_step_ratio_min=self.config.short_side_step_ratio_min,
206            short_side_step_ratio_max=self.config.short_side_step_ratio_max,
207            alpha_min=self.config.alpha_min,
208            alpha_max=self.config.alpha_max,
209            shape=shape,
210            rng=rng,
211        )
212
213        # Dash line.
214        long_side_length = max(shape)
215        dash_thickness = 0
216        dash_gap = 0
217        if rng.random() < self.config.prob_dash:
218            dash_thickness_ratio = float(
219                rng.uniform(
220                    self.config.dash_thickness_ratio_min,
221                    self.config.dash_thickness_ratio_max,
222                )
223            )
224            dash_thickness = round(dash_thickness_ratio * long_side_length)
225
226            dash_to_thickness_gap_ratio = float(
227                rng.uniform(
228                    self.config.dash_to_thickness_gap_ratio_min,
229                    self.config.dash_to_thickness_gap_ratio_max,
230                )
231            )
232            dash_gap = round(dash_to_thickness_gap_ratio * dash_thickness)
233
234        return distortion.RectangleStreakConfig(
235            thickness=thickness,
236            aspect_ratio=aspect_ratio,
237            dash_thickness=dash_thickness,
238            dash_gap=dash_gap,
239            short_side_min=short_side_min,
240            short_side_step=short_side_step,
241            alpha=alpha,
242        )

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default

class EllipseStreakConfigGeneratorConfig:
252class EllipseStreakConfigGeneratorConfig:
253    thickness_min: int = 1
254    thickness_max: int = 3
255    aspect_ratio_min: float = 0.5
256    aspect_ratio_max: float = 1.5
257    short_side_min: int = 5
258    short_side_min_ratio_min: float = 0.01
259    short_side_min_ratio_max: float = 0.25
260    short_side_step_ratio_min: float = 0.8
261    short_side_step_ratio_max: float = 3.0
262    alpha_min: float = 0.2
263    alpha_max: float = 1.0
EllipseStreakConfigGeneratorConfig( thickness_min: int = 1, thickness_max: int = 3, aspect_ratio_min: float = 0.5, aspect_ratio_max: float = 1.5, short_side_min: int = 5, short_side_min_ratio_min: float = 0.01, short_side_min_ratio_max: float = 0.25, short_side_step_ratio_min: float = 0.8, short_side_step_ratio_max: float = 3.0, alpha_min: float = 0.2, alpha_max: float = 1.0)
 2def __init__(self, thickness_min=attr_dict['thickness_min'].default, thickness_max=attr_dict['thickness_max'].default, aspect_ratio_min=attr_dict['aspect_ratio_min'].default, aspect_ratio_max=attr_dict['aspect_ratio_max'].default, short_side_min=attr_dict['short_side_min'].default, short_side_min_ratio_min=attr_dict['short_side_min_ratio_min'].default, short_side_min_ratio_max=attr_dict['short_side_min_ratio_max'].default, short_side_step_ratio_min=attr_dict['short_side_step_ratio_min'].default, short_side_step_ratio_max=attr_dict['short_side_step_ratio_max'].default, alpha_min=attr_dict['alpha_min'].default, alpha_max=attr_dict['alpha_max'].default):
 3    self.thickness_min = thickness_min
 4    self.thickness_max = thickness_max
 5    self.aspect_ratio_min = aspect_ratio_min
 6    self.aspect_ratio_max = aspect_ratio_max
 7    self.short_side_min = short_side_min
 8    self.short_side_min_ratio_min = short_side_min_ratio_min
 9    self.short_side_min_ratio_max = short_side_min_ratio_max
10    self.short_side_step_ratio_min = short_side_step_ratio_min
11    self.short_side_step_ratio_max = short_side_step_ratio_max
12    self.alpha_min = alpha_min
13    self.alpha_max = alpha_max

Method generated by attrs for class EllipseStreakConfigGeneratorConfig.

266class EllipseStreakConfigGenerator(
267    DistortionConfigGenerator[
268        EllipseStreakConfigGeneratorConfig,
269        distortion.EllipseStreakConfig,
270    ]
271):  # yapf: disable
272
273    def __call__(self, shape: Tuple[int, int], rng: RandomGenerator):
274        (
275            thickness,
276            aspect_ratio,
277            short_side_min,
278            short_side_step,
279            alpha,
280        ) = sample_params_for_rectangle_and_ellipse_streak(
281            level=self.level,
282            thickness_min=self.config.thickness_min,
283            thickness_max=self.config.thickness_max,
284            aspect_ratio_min=self.config.aspect_ratio_min,
285            aspect_ratio_max=self.config.aspect_ratio_max,
286            short_side_min=self.config.short_side_min,
287            short_side_min_ratio_min=self.config.short_side_min_ratio_min,
288            short_side_min_ratio_max=self.config.short_side_min_ratio_max,
289            short_side_step_ratio_min=self.config.short_side_step_ratio_min,
290            short_side_step_ratio_max=self.config.short_side_step_ratio_max,
291            alpha_min=self.config.alpha_min,
292            alpha_max=self.config.alpha_max,
293            shape=shape,
294            rng=rng,
295        )
296
297        return distortion.EllipseStreakConfig(
298            thickness=thickness,
299            aspect_ratio=aspect_ratio,
300            short_side_min=short_side_min,
301            short_side_step=short_side_step,
302            alpha=alpha,
303        )

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as::

class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.

This class can then be used as follows::

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default