Skip to content

Commit c174824

Browse files
committed
refactor to group common code and fix click choice errors
1 parent 096f0bc commit c174824

File tree

1 file changed

+21
-41
lines changed

1 file changed

+21
-41
lines changed

orthority/enums.py

+21-41
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
from rasterio.enums import Resampling
2222

2323

24-
class CameraType(str, Enum):
24+
class _StrChoiceEnum(str, Enum):
25+
"""String value enumeration class that can be used with a ``click.Choice()`` parameter type."""
26+
27+
def __repr__(self):
28+
return self._value_
29+
30+
def __str__(self):
31+
return self._value_
32+
33+
34+
class CameraType(_StrChoiceEnum):
2535
"""Camera model types."""
2636

2737
pinhole = 'pinhole'
@@ -31,18 +41,18 @@ class CameraType(str, Enum):
3141
"""
3242
Brown-Conrady frame camera model.
3343
34-
Compatible with `OpenDroneMap / OpenSfM
35-
<https://opensfm.org/docs/geometry.html#camera-models>`__ ``perspective``, ``simple_radial``,
36-
``radial`` and ``brown`` model parameters, and the 4- and 5-coefficient versions of the
44+
Compatible with `OpenDroneMap / OpenSfM
45+
<https://opensfm.org/docs/geometry.html#camera-models>`__ ``perspective``, ``simple_radial``,
46+
``radial`` and ``brown`` model parameters, and the 4- and 5-coefficient versions of the
3747
`OpenCV general model <https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html>`__."""
3848

3949
fisheye = 'fisheye'
4050
"""
4151
Fisheye frame camera model.
4252
43-
Compatible with `OpenDroneMap / OpenSfM
44-
<https://opensfm.org/docs/geometry.html#fisheye-camera>`__ ``fisheye``, and `OpenCV
45-
<https://docs.opencv.org/4.x/db/d58/group__calib3d__fisheye.html>`__ fisheye model
53+
Compatible with `OpenDroneMap / OpenSfM
54+
<https://opensfm.org/docs/geometry.html#fisheye-camera>`__ ``fisheye``, and `OpenCV
55+
<https://docs.opencv.org/4.x/db/d58/group__calib3d__fisheye.html>`__ fisheye model
4656
parameters."""
4757

4858
opencv = 'opencv'
@@ -53,12 +63,6 @@ class CameraType(str, Enum):
5363
rpc = 'rpc'
5464
"""RPC camera model."""
5565

56-
def __repr__(self):
57-
return self._name_
58-
59-
def __str__(self):
60-
return self._name_
61-
6266
@classmethod
6367
def from_odm(cls, cam_type: str):
6468
"""Convert from OpenDroneMap / OpenSfM projection type."""
@@ -70,7 +74,7 @@ def from_odm(cls, cam_type: str):
7074
return cls(cam_type)
7175

7276

73-
class Interp(str, Enum):
77+
class Interp(_StrChoiceEnum):
7478
"""Interpolation types."""
7579

7680
nearest = 'nearest'
@@ -84,12 +88,6 @@ class Interp(str, Enum):
8488
lanczos = 'lanczos'
8589
"""Lanczos windowed sinc interpolation."""
8690

87-
def __repr__(self):
88-
return self._name_
89-
90-
def __str__(self):
91-
return self._name_
92-
9391
def to_cv(self) -> int:
9492
"""Convert to OpenCV interpolation type."""
9593
name_to_cv = dict(
@@ -106,7 +104,7 @@ def to_rio(self) -> Resampling:
106104
return Resampling[self._name_]
107105

108106

109-
class Compress(str, Enum):
107+
class Compress(_StrChoiceEnum):
110108
"""Compression types."""
111109

112110
jpeg = 'jpeg'
@@ -116,12 +114,6 @@ class Compress(str, Enum):
116114
lzw = 'lzw'
117115
"""LZW compression."""
118116

119-
def __repr__(self):
120-
return self._name_
121-
122-
def __str__(self):
123-
return self._name_
124-
125117

126118
class CsvFormat(Enum):
127119
"""Type of the position and orientation values in a CSV exterior parameter file."""
@@ -146,31 +138,19 @@ def is_opk(self) -> bool:
146138
return self is CsvFormat.xyz_opk or self is CsvFormat.lla_opk
147139

148140

149-
class RpcRefine(str, Enum):
141+
class RpcRefine(_StrChoiceEnum):
150142
"""RPC refinement method."""
151143

152144
shift = 'shift'
153145
"""Pixel coordinate translation."""
154146
shift_drift = 'shift-drift'
155147
"""Pixel coordinate scale and translation."""
156148

157-
def __repr__(self):
158-
return self._name_
159149

160-
def __str__(self):
161-
return self._name_
162-
163-
164-
class Driver(str, Enum):
150+
class Driver(_StrChoiceEnum):
165151
"""Raster format drivers."""
166152

167153
gtiff = 'gtiff'
168154
"""GeoTIFF."""
169155
cog = 'cog'
170156
"""Cloud Optimised GeoTIFF."""
171-
172-
def __repr__(self):
173-
return self._name_
174-
175-
def __str__(self):
176-
return self._name_

0 commit comments

Comments
 (0)