mirror of
https://github.com/pim-n/pg-rad
synced 2026-02-02 14:33:09 +01:00
Add test for path simplification accuracy.
This commit is contained in:
107
tests/data/coordinates.csv
Normal file
107
tests/data/coordinates.csv
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
,East,North
|
||||||
|
0,1324671.2,6187244.9
|
||||||
|
1,1324671.8,6187239.9
|
||||||
|
2,1324672.7,6187235.0
|
||||||
|
3,1324673.5,6187230.1
|
||||||
|
4,1324675.1,6187225.4
|
||||||
|
5,1324677.4,6187220.9
|
||||||
|
6,1324679.2,6187216.3
|
||||||
|
7,1324681.5,6187211.8
|
||||||
|
8,1324683.9,6187207.4
|
||||||
|
9,1324686.5,6187203.2
|
||||||
|
10,1324689.0,6187198.9
|
||||||
|
11,1324692.3,6187195.1
|
||||||
|
12,1324695.6,6187191.5
|
||||||
|
13,1324698.1,6187187.1
|
||||||
|
14,1324701.9,6187184.1
|
||||||
|
15,1324704.2,6187179.6
|
||||||
|
16,1324707.7,6187176.0
|
||||||
|
17,1324710.2,6187171.7
|
||||||
|
18,1324712.8,6187167.4
|
||||||
|
19,1324715.1,6187163.0
|
||||||
|
20,1324718.3,6187159.2
|
||||||
|
21,1324721.3,6187155.3
|
||||||
|
22,1324725.0,6187151.9
|
||||||
|
23,1324728.0,6187147.9
|
||||||
|
24,1324732.0,6187145.0
|
||||||
|
25,1324736.5,6187142.8
|
||||||
|
26,1324741.0,6187140.7
|
||||||
|
27,1324745.9,6187140.1
|
||||||
|
28,1324750.6,6187138.6
|
||||||
|
29,1324755.2,6187136.8
|
||||||
|
30,1324760.1,6187136.4
|
||||||
|
31,1324765.1,6187136.1
|
||||||
|
32,1324770.1,6187135.9
|
||||||
|
33,1324774.8,6187134.2
|
||||||
|
34,1324779.8,6187133.7
|
||||||
|
35,1324784.8,6187133.5
|
||||||
|
36,1324789.8,6187133.3
|
||||||
|
37,1324794.5,6187132.1
|
||||||
|
38,1324799.3,6187131.1
|
||||||
|
39,1324804.0,6187129.8
|
||||||
|
40,1324808.0,6187126.7
|
||||||
|
41,1324811.7,6187123.3
|
||||||
|
42,1324815.2,6187119.8
|
||||||
|
43,1324819.1,6187116.6
|
||||||
|
44,1324822.3,6187112.9
|
||||||
|
45,1324825.5,6187109.0
|
||||||
|
46,1324828.6,6187105.1
|
||||||
|
47,1324832.3,6187101.8
|
||||||
|
48,1324836.6,6187099.3
|
||||||
|
49,1324840.3,6187095.9
|
||||||
|
50,1324843.9,6187092.4
|
||||||
|
51,1324847.2,6187088.7
|
||||||
|
52,1324851.6,6187086.5
|
||||||
|
53,1324856.3,6187084.6
|
||||||
|
54,1324860.1,6187081.4
|
||||||
|
55,1324864.8,6187079.7
|
||||||
|
56,1324868.9,6187076.9
|
||||||
|
57,1324872.9,6187073.9
|
||||||
|
58,1324876.6,6187070.4
|
||||||
|
59,1324880.4,6187067.3
|
||||||
|
60,1324884.3,6187064.1
|
||||||
|
61,1324887.6,6187060.4
|
||||||
|
62,1324891.1,6187056.8
|
||||||
|
63,1324894.8,6187053.5
|
||||||
|
64,1324898.1,6187049.8
|
||||||
|
65,1324901.7,6187046.3
|
||||||
|
66,1324905.5,6187043.1
|
||||||
|
67,1324909.3,6187039.9
|
||||||
|
68,1324913.0,6187036.4
|
||||||
|
69,1324916.4,6187032.8
|
||||||
|
70,1324919.6,6187029.0
|
||||||
|
71,1324923.3,6187025.6
|
||||||
|
72,1324926.3,6187021.6
|
||||||
|
73,1324929.4,6187017.7
|
||||||
|
74,1324933.0,6187014.2
|
||||||
|
75,1324936.6,6187010.8
|
||||||
|
76,1324939.8,6187007.0
|
||||||
|
77,1324942.7,6187002.9
|
||||||
|
78,1324945.9,6186999.1
|
||||||
|
79,1324948.4,6186994.8
|
||||||
|
80,1324951.9,6186991.2
|
||||||
|
81,1324954.9,6186987.2
|
||||||
|
82,1324957.4,6186982.8
|
||||||
|
83,1324960.4,6186978.9
|
||||||
|
84,1324962.7,6186974.4
|
||||||
|
85,1324965.8,6186970.5
|
||||||
|
86,1324968.2,6186966.1
|
||||||
|
87,1324971.1,6186962.0
|
||||||
|
88,1324973.7,6186957.8
|
||||||
|
89,1324976.4,6186953.6
|
||||||
|
90,1324978.8,6186949.2
|
||||||
|
91,1324981.8,6186945.2
|
||||||
|
92,1324984.3,6186940.9
|
||||||
|
93,1324987.0,6186936.8
|
||||||
|
94,1324989.3,6186932.3
|
||||||
|
95,1324992.1,6186928.1
|
||||||
|
96,1324994.2,6186923.6
|
||||||
|
97,1324996.7,6186919.3
|
||||||
|
98,1324998.5,6186914.8
|
||||||
|
99,1325001.4,6186910.7
|
||||||
|
100,1325003.7,6186906.2
|
||||||
|
101,1325006.8,6186902.3
|
||||||
|
102,1325009.9,6186898.4
|
||||||
|
103,1325012.9,6186894.4
|
||||||
|
104,1325015.3,6186890.0
|
||||||
|
105,1325018.9,6186886.5
|
||||||
|
47
tests/test_path_functionality.py
Normal file
47
tests/test_path_functionality.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import pathlib
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pg_rad.dataloader import load_data
|
||||||
|
from pg_rad.path import Path, path_from_RT90
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def test_df():
|
||||||
|
csv_path = pathlib.Path(__file__).parent / "data/coordinates.csv"
|
||||||
|
return load_data(csv_path)
|
||||||
|
|
||||||
|
def test_piecewise_regression(test_df):
|
||||||
|
"""_Verify whether the intermediate points deviate less than 0.1 SD._"""
|
||||||
|
|
||||||
|
p_full = path_from_RT90(
|
||||||
|
test_df,
|
||||||
|
east_col="East",
|
||||||
|
north_col="North",
|
||||||
|
simplify_path=False
|
||||||
|
)
|
||||||
|
|
||||||
|
p_simpl = path_from_RT90(
|
||||||
|
test_df,
|
||||||
|
east_col="East",
|
||||||
|
north_col="North",
|
||||||
|
simplify_path=True
|
||||||
|
)
|
||||||
|
|
||||||
|
x_f = np.array(p_full.x_list)
|
||||||
|
y_f = np.array(p_full.y_list)
|
||||||
|
|
||||||
|
x_s = np.array(p_simpl.x_list)
|
||||||
|
y_s = np.array(p_simpl.y_list)
|
||||||
|
|
||||||
|
sd = np.std(y_f)
|
||||||
|
|
||||||
|
for xb, yb in zip(x_s[1:-1], y_s[1:-1]):
|
||||||
|
# find nearest original x index
|
||||||
|
idx = np.argmin(np.abs(x_f - xb))
|
||||||
|
deviation = abs(yb - y_f[idx])
|
||||||
|
|
||||||
|
assert deviation < 0.1 * sd, (
|
||||||
|
f"Breakpoint deviation too large: {deviation:.4f} "
|
||||||
|
f"(threshold {0.1 * sd:.4f}) at x={xb:.2f}"
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user