|
1 | 1 | from io import TextIOWrapper |
2 | 2 | from time import sleep |
3 | | -from pathlib import Path |
4 | 3 | from math import tan, atan, degrees |
| 4 | +from re import compile |
5 | 5 |
|
6 | 6 | from click_extra import echo |
7 | 7 | from geocompy.data import Angle, Coordinate |
|
12 | 12 | from ..utils import echo_green |
13 | 13 |
|
14 | 14 |
|
| 15 | +_LINE = compile(r"^\d+(?:\.\d+)?(?:,\-?\d+\.\d+){2}$") |
| 16 | + |
| 17 | + |
15 | 18 | def run_measure( |
16 | 19 | tps: GeoCom, |
17 | 20 | output: TextIOWrapper | None = None, |
@@ -42,11 +45,13 @@ def run_measure( |
42 | 45 | if fullangles.params is None: |
43 | 46 | continue |
44 | 47 |
|
| 48 | + az = fullangles.params[0] |
45 | 49 | cross = fullangles.params[4] |
46 | 50 | length = fullangles.params[5] |
47 | 51 |
|
48 | 52 | echo( |
49 | | - f"{a % 360:d},{cross.asunit('deg') * 3600:.2f}," |
| 53 | + f"{az.asunit('deg'):.4f}," |
| 54 | + f"{cross.asunit('deg') * 3600:.2f}," |
50 | 55 | f"{length.asunit('deg') * 3600:.2f}", |
51 | 56 | output |
52 | 57 | ) |
@@ -75,51 +80,75 @@ def main_measure( |
75 | 80 |
|
76 | 81 |
|
77 | 82 | def main_merge( |
78 | | - inputs: list[Path], |
79 | | - output: Path |
| 83 | + inputs: list[TextIOWrapper], |
| 84 | + output: TextIOWrapper |
80 | 85 | ) -> None: |
81 | | - with output.open("wt", encoding="utf8") as outfile: |
82 | | - echo("hz_deg,cross_sec,length_sec", outfile) |
83 | | - for item in inputs: |
84 | | - with item.open("rt", encoding="utf8") as infile: |
85 | | - next(infile) |
86 | | - echo(infile.read(), outfile, False) |
| 86 | + echo("hz_deg,cross_sec,length_sec", output) |
| 87 | + for item in inputs: |
| 88 | + for line in item: |
| 89 | + if not _LINE.match(line.strip()): |
| 90 | + continue |
| 91 | + |
| 92 | + echo(line, output, False) |
87 | 93 |
|
88 | 94 | echo_green(f"Merged measurements from {len(inputs)} files.") |
89 | 95 |
|
90 | 96 |
|
91 | 97 | def main_calc( |
92 | | - input: Path |
| 98 | + input: TextIOWrapper, |
| 99 | + output: TextIOWrapper | None = None |
93 | 100 | ) -> None: |
94 | 101 | points: list[Coordinate] = [] |
95 | | - with input.open("rt", encoding="utf8") as file: |
96 | | - next(file) |
97 | | - for line in file: |
98 | | - fields = line.strip().split(",") |
99 | | - azimut = Angle(float(fields[0]), 'deg') |
100 | | - cross = Angle(float(fields[1]) / 3600, 'deg') |
101 | | - length = Angle(float(fields[2]) / 3600, 'deg') |
102 | | - |
103 | | - coord = Coordinate(tan(cross), tan(length), 1) |
104 | | - bearing, inclination, s = coord.to_polar() |
105 | | - |
106 | | - points.append( |
107 | | - Coordinate.from_polar( |
108 | | - (bearing + azimut).normalized(), |
109 | | - inclination, |
110 | | - s |
111 | | - ) |
| 102 | + |
| 103 | + for line in input: |
| 104 | + if not _LINE.match(line.strip()): |
| 105 | + continue |
| 106 | + |
| 107 | + fields = line.strip().split(",") |
| 108 | + azimut = Angle(float(fields[0]), 'deg') |
| 109 | + cross = Angle(float(fields[1]) / 3600, 'deg') |
| 110 | + length = Angle(float(fields[2]) / 3600, 'deg') |
| 111 | + |
| 112 | + coord = Coordinate(tan(cross), tan(length), 1) |
| 113 | + bearing, inclination, s = coord.to_polar() |
| 114 | + |
| 115 | + points.append( |
| 116 | + Coordinate.from_polar( |
| 117 | + (bearing + azimut).normalized(), |
| 118 | + inclination, |
| 119 | + s |
112 | 120 | ) |
| 121 | + ) |
113 | 122 |
|
114 | 123 | x, x_dev = adjust_uniform_single([p.x for p in points]) |
115 | 124 | y, y_dev = adjust_uniform_single([p.y for p in points]) |
116 | 125 |
|
| 126 | + inc_x = degrees(atan(x)) * 3600 |
| 127 | + inc_y = degrees(atan(y)) * 3600 |
| 128 | + inc_x_dev = degrees(atan(x_dev)) * 3600 |
| 129 | + inc_y_dev = degrees(atan(y_dev)) * 3600 |
| 130 | + |
117 | 131 | direction, inc, _ = Coordinate(x, y, 1).to_polar() |
118 | 132 |
|
| 133 | + if output is None: |
| 134 | + echo(f"""Axis aligned: |
| 135 | + inclination X: {inc_x:.1f}" +/- {inc_x_dev:.1f}" |
| 136 | + inclination Y: {inc_y:.1f}" +/- {inc_y_dev:.1f}" |
| 137 | +Polar: |
| 138 | + direction: {direction.asunit('deg'):.4f}° |
| 139 | + inclination: {inc.asunit('deg') * 3600:.1f}\"""" |
| 140 | + ) |
| 141 | + return |
| 142 | + |
| 143 | + echo( |
| 144 | + "inc_x_sec,inc_x_dev_sec,inc_y_sec,inc_y_dev_sec,dir_deg,inc_sec", |
| 145 | + output |
| 146 | + ) |
| 147 | + |
119 | 148 | echo( |
120 | | - f"""Direction: {direction.to_dms()} |
121 | | -Inclination: {inc.asunit('deg') * 3600:.1f} seconds |
122 | | -Deviation easting: {degrees(atan(x_dev)) * 3600:.1f} seconds |
123 | | -Deviation northing: {degrees(atan(y_dev)) * 3600:.1f} seconds |
124 | | - """ |
| 149 | + ( |
| 150 | + f"{inc_x:.1f},{inc_x_dev:.1f},{inc_y:.1f},{inc_y_dev:.1f}," |
| 151 | + f"{direction.asunit('deg'):.4f},{inc.asunit('deg') * 3600:.1f}" |
| 152 | + ), |
| 153 | + output |
125 | 154 | ) |
0 commit comments