-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
101 lines (75 loc) · 3.06 KB
/
test.py
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
# Test code for position estimation. To run, you'll need the following
# Python packages:
# utm, numdifftools (available through pip)
# numpy, scipy, matplotlib
from qraat.srv import util, signal, position
import numpy as np
import matplotlib.pyplot as pp
cal_id = 3 # Calibration ID, specifies steering vectors to use.
dep_id = 105 # Deployment ID, specifies a transmitter.
# siteID -> UTM position, known positions of sites for source
# localization. The real component is northing, the imaginary
# component is easting.
sites = {2 : (4261604.51+574239.47j), # site2
3 : (4261569.32+575013.86j), # site10
4 : (4260706.17+573882.15j), # site13
5 : (4260749.75+575321.92j), # site20
6 : (4260856.82+574794.06j), # site21
8 : (4261100.56+574000.17j) # site39
}
# UTM position, initial guess of position.
center = (4260500+574500j)
zone = (10, 'S') # UTM zone.
# Read steering vectors from file.
db_con = util.get_db('writer')
sv = signal.SteeringVectors(db_con, cal_id)
def real_data():
# Read signal data, about an hour's worth.
sv = signal.SteeringVectors.read(cal_id, 'sample/sv')
sig = signal.Signal.read(sites.keys(), 'sample/sig')
t_step=120
t_win=60
pos = position.WindowedPositionEstimator(sig, sites, center, sv,
t_step, t_win, method=signal.Signal.Bartlet)
cov = position.WindowedCovarianceEstimator(pos, sites, max_resamples=100)
position.InsertPositionsCovariances(db_con, dep_id, cal_id, zone, pos, cov)
def read_db():
t_start = 1407452400
t_end = 1407455880
pos = position.ReadPositions(db_con, dep_id, t_start, t_end)
conf = position.ReadConfidenceRegions(db_con, dep_id, t_start, t_end, 0.95)
bearings = position.ReadAllBearings(db_con, dep_id, t_start, t_end)
def sim_data():
# Simpulate signal given known position p.
p = center + complex(650,0)
include = [2,4,6,8]
sig_n = 0.002 # noise
rho = signal.scale_tx_coeff(p, 1, sites, include)
sv_splines = signal.compute_bearing_splines(sv)
sig = signal.Simulator(p, sites, sv_splines, rho, sig_n, 10, include)
(sig_n, sig_t) = sig.estimate_var()
pos = position.PositionEstimator(sig, sites, center,
sv, method=signal.Signal.Bartlet)
pos.plot('fella.png', 999, sites, center, p)
level=0.95
E = position.BootstrapCovariance(pos, sites).conf(level)
E.display(p)
#E.plot('conf.png', p)
#position.BootstrapCovariance2(pos, sites).conf(level).display(p)
#position.Covariance(pos, sites, p_known=p).conf(level).display(p)
def bm():
p = center + complex(650,0)
include = [2,4,6,8]
sig_n = 0.002 # noise
rho = signal.scale_tx_coeff(p, 1, sites, include)
sv_splines = signal.compute_bearing_splines(sv)
for i in range(100):
sig = signal.Simulator(p, sites, sv_splines, rho, sig_n, 10, include)
pos = position.PositionEstimator(sig, sites, center,
sv, method=signal.Signal.Bartlet)
cov = position.BootstrapCovariance(pos, sites)
# Testing, testing ....
bm()
#sim_data()
#real_data()
#read_db()