Repository navigation
Expand file tree
/
Copy pathexceptions.py
More file actions
122 lines (88 loc) · 3.9 KB
/
Copy pathexceptions.py
File metadata and controls
122 lines (88 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Defines domain exceptions that are raised by PyTransDatRO."""
from typing import Any
class PyTransDatError(Exception):
"""Base exception class for all PyTransDatRO errors."""
pass
class OutOfGridErr(PyTransDatError):
"""Signifies that the input location (N,E) is not covered by a grid
or is outside the grid's bounding envelope.
"""
def __init__(self, n: float, e: float, grid: Any) -> None:
"""Initialize OutOfGridErr with out-of-bounds coordinates and grid metadata.
:param n: Northing coordinate in meters or latitude in degrees
:type n: float
:param e: Easting coordinate in meters or longitude in degrees
:type e: float
:param grid: Grid against which values (n, e) have been tested
:type grid: Grid
"""
self.n: float = n
self.e: float = e
self.grid: Any = grid
message = (
f"({n}, {e}) location is out of the grid area defined by file {grid.source}. "
f"Location must be inside the grid defined by "
f"Min N = {grid.n_min}, Min E = {grid.e_min}, "
f"Max N = {grid.n_max}, Max E = {grid.e_max}."
)
super().__init__(message)
class OutOfGrid2DErr(OutOfGridErr):
"""Signifies that the input location is outside the 2D horizontal distortion grid."""
pass
class OutOfGrid1DErr(OutOfGridErr):
"""Signifies that the input location is outside the 1D vertical quasigeoid height grid."""
pass
class NoDataGridErr(PyTransDatError):
"""Signifies that grid shift values required for interpolation at input location (N,E)
contain No Data (NaN or 999) values, preventing computation.
"""
def __init__(self, n: float, e: float, grid: Any) -> None:
"""Initialize NoDataGridErr with location and grid metadata.
:param n: Northing coordinate in meters or latitude in degrees
:type n: float
:param e: Easting coordinate in meters or longitude in degrees
:type e: float
:param grid: Grid against which values (n, e) have been tested
:type grid: Grid
"""
self.n: float = n
self.e: float = e
self.grid: Any = grid
message = (
f"(The subgrid of size {grid.sg_size}x{grid.sg_size} nodes required "
f"for the computation of interpolated value at {n}, {e} location "
f"has No Data value(s)."
)
super().__init__(message)
class OutOfRangeIndexGridErr(PyTransDatError):
"""Signifies that the input index is out of the range of available grid indexes."""
def __init__(self, idx: int, grid: Any) -> None:
"""Initialize OutOfRangeIndexGridErr with invalid index and grid metadata.
:param idx: Linear node index queried
:type idx: int
:param grid: Grid against which index coordinates are queried
:type grid: Grid
"""
message = (
f"(Grid {grid.file_name} has index values ranging from 0 to "
f"{grid.c_count * grid.r_count - 1}. The requested index ({idx}) "
f"is out of range."
)
super().__init__(message)
class MissingGridError(FileNotFoundError, PyTransDatError):
"""Signifies that no valid grid file was found in the grids directory."""
pass
class AmbiguousGridError(ValueError, PyTransDatError):
"""Signifies that multiple grid files were found when exactly one was expected."""
pass
class InvalidCoordinateErr(ValueError, PyTransDatError):
"""Signifies that coordinate input data is non-numeric, non-finite (NaN/Inf),
or violates sexagesimal DMS bounds (minutes or seconds outside [0, 60)).
"""
pass
class WrongDimensionErr(ValueError, PyTransDatError):
"""Signifies that the coordinate tuple or sequence dimension is invalid
(e.g., fewer than 2 or more than 3 coordinate components, empty sequences,
or mismatched sequence lengths).
"""
pass