mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m.internship-documentation.git
synced 2024-11-22 15:03:35 +01:00
use makefile to create 4antenna_setup
This commit is contained in:
parent
5147ddfa1c
commit
5c706a8d4a
2 changed files with 101 additions and 78 deletions
|
@ -7,7 +7,9 @@ dist: \
|
||||||
field_singleleft_time.pdf field_singleleft_time.png \
|
field_singleleft_time.pdf field_singleleft_time.png \
|
||||||
field_singleleft_phase.pdf field_singleleft_phase.png \
|
field_singleleft_phase.pdf field_singleleft_phase.png \
|
||||||
field_singlecenter_time.pdf field_singlecenter_time.png \
|
field_singlecenter_time.pdf field_singlecenter_time.png \
|
||||||
field_singlecenter_phase.pdf field_singlecenter_phase.png
|
field_singlecenter_phase.pdf field_singlecenter_phase.png \
|
||||||
|
antenna_setup_four.pdf antenna_setup_four.png \
|
||||||
|
antenna_setup_three.pdf antenna_setup_three.png
|
||||||
|
|
||||||
dist-clean:
|
dist-clean:
|
||||||
rm -v sine_beacon.*
|
rm -v sine_beacon.*
|
||||||
|
@ -35,3 +37,9 @@ field_singlecenter_time.%: src/beacon_field.py
|
||||||
$< --time $@ single-center
|
$< --time $@ single-center
|
||||||
field_singlecenter_phase.%: src/beacon_field.py
|
field_singlecenter_phase.%: src/beacon_field.py
|
||||||
$< --phase $@ single-center
|
$< --phase $@ single-center
|
||||||
|
|
||||||
|
antenna_setup_four.%: src/four_antenna_setup.py
|
||||||
|
$< $@
|
||||||
|
|
||||||
|
antenna_setup_three.%: src/four_antenna_setup.py
|
||||||
|
$< --no-extra $@
|
||||||
|
|
169
figures/beacon/src/four_antenna_setup.py
Normal file → Executable file
169
figures/beacon/src/four_antenna_setup.py
Normal file → Executable file
|
@ -16,6 +16,23 @@ from itertools import combinations
|
||||||
|
|
||||||
c_light = 3e8 # m/s
|
c_light = 3e8 # m/s
|
||||||
|
|
||||||
|
class Antenna:
|
||||||
|
"""
|
||||||
|
Simple Antenna class
|
||||||
|
"""
|
||||||
|
def __init__(self,x=0,y=0,z=0,t0=0,name=""):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.z = z
|
||||||
|
self.t = t0
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
cls = self.__class__.__name__
|
||||||
|
|
||||||
|
return f'{cls}(x={self.x!r},y={self.y!r},z={self.z!r},t0={self.t!r},name={self.name!r})'
|
||||||
|
|
||||||
|
|
||||||
def distance(x1, x2):
|
def distance(x1, x2):
|
||||||
"""
|
"""
|
||||||
Calculate the Euclidean distance between two locations x1 and x2
|
Calculate the Euclidean distance between two locations x1 and x2
|
||||||
|
@ -29,6 +46,7 @@ def distance(x1, x2):
|
||||||
|
|
||||||
return np.sqrt( np.sum( (x1-x2)**2 ) )
|
return np.sqrt( np.sum( (x1-x2)**2 ) )
|
||||||
|
|
||||||
|
|
||||||
def phase_mod(phase, low=np.pi):
|
def phase_mod(phase, low=np.pi):
|
||||||
"""
|
"""
|
||||||
Modulo phase such that it falls within the
|
Modulo phase such that it falls within the
|
||||||
|
@ -37,30 +55,14 @@ def phase_mod(phase, low=np.pi):
|
||||||
return (phase + low) % (2*np.pi) - low
|
return (phase + low) % (2*np.pi) - low
|
||||||
|
|
||||||
|
|
||||||
class Antenna:
|
|
||||||
"""
|
|
||||||
Simple Antenna class
|
|
||||||
"""
|
|
||||||
def __init__(self,x=0,y=0,z=0,t0=0,name=""):
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.z = z
|
|
||||||
self.t0 = t0
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
self.offsets = []
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
cls = self.__class__.__name__
|
|
||||||
|
|
||||||
return f'{cls}(x={self.x!r},y={self.y!r},z={self.z!r},t0={self.t0!r},name={self.name!r})'
|
|
||||||
|
|
||||||
def antenna_triangles(antennas):
|
def antenna_triangles(antennas):
|
||||||
return combinations(antennas, 3)
|
return combinations(antennas, 3)
|
||||||
|
|
||||||
|
|
||||||
def antenna_baselines(antennas):
|
def antenna_baselines(antennas):
|
||||||
return combinations(antennas, 2)
|
return combinations(antennas, 2)
|
||||||
|
|
||||||
|
|
||||||
def plot_four_antenna_geometry(tx, ants, extra_ant=None, ax=None, line_kwargs={}, scatter_kwargs={}, scatter_zorder=5):
|
def plot_four_antenna_geometry(tx, ants, extra_ant=None, ax=None, line_kwargs={}, scatter_kwargs={}, scatter_zorder=5):
|
||||||
|
|
||||||
default_line_kwargs = dict( color='grey', lw=3, alpha=0.7)
|
default_line_kwargs = dict( color='grey', lw=3, alpha=0.7)
|
||||||
|
@ -75,8 +77,14 @@ def plot_four_antenna_geometry(tx, ants, extra_ant=None, ax=None, line_kwargs={}
|
||||||
line_kwargs = {**default_line_kwargs, **line_kwargs}
|
line_kwargs = {**default_line_kwargs, **line_kwargs}
|
||||||
scatter_kwargs = {**default_scatter_kwargs, **scatter_kwargs}
|
scatter_kwargs = {**default_scatter_kwargs, **scatter_kwargs}
|
||||||
|
|
||||||
|
if extra_ant is not None:
|
||||||
|
all_ants = ants + [extra_ant]
|
||||||
|
else:
|
||||||
|
all_ants = ants
|
||||||
|
|
||||||
|
|
||||||
# Plot Antennas + Tx
|
# Plot Antennas + Tx
|
||||||
for i, ant in enumerate([tx] + ants + [extra_ant]):
|
for i, ant in enumerate([tx] + all_ants):
|
||||||
ax.scatter(ant.x, ant.y, zorder=scatter_zorder, **scatter_kwargs)
|
ax.scatter(ant.x, ant.y, zorder=scatter_zorder, **scatter_kwargs)
|
||||||
ax.annotate(ant.name, (ant.x, ant.y), ha='center', va='center',zorder=scatter_zorder)
|
ax.annotate(ant.name, (ant.x, ant.y), ha='center', va='center',zorder=scatter_zorder)
|
||||||
|
|
||||||
|
@ -86,20 +94,21 @@ def plot_four_antenna_geometry(tx, ants, extra_ant=None, ax=None, line_kwargs={}
|
||||||
ax.plot([tx.x, ant.x], [tx.y, ant.y], **tmp_line_kwargs)
|
ax.plot([tx.x, ant.x], [tx.y, ant.y], **tmp_line_kwargs)
|
||||||
|
|
||||||
# Lines due to all Antennas (including extra_ant)
|
# Lines due to all Antennas (including extra_ant)
|
||||||
line_offset = 0.08*np.array([1,1])
|
if extra_ant is not None:
|
||||||
for i, ant_triangle in enumerate(antenna_triangles(ants + [extra_ant])):
|
line_offset = 0.08*np.array([1,1])
|
||||||
tmp_line_kwargs['color'] = None
|
for i, ant_triangle in enumerate(antenna_triangles(all_ants)):
|
||||||
tmp_line_kwargs['linestyle'] = '--'
|
tmp_line_kwargs['color'] = None
|
||||||
tmp_line_kwargs['alpha'] = 0.4
|
tmp_line_kwargs['linestyle'] = '--'
|
||||||
for j, ant in enumerate(antenna_baselines(ant_triangle)):
|
tmp_line_kwargs['alpha'] = 0.4
|
||||||
a, b = ant[0], ant[1]
|
for j, ant in enumerate(antenna_baselines(ant_triangle)):
|
||||||
if j == 1: # fix ordering
|
a, b = ant[0], ant[1]
|
||||||
a, b == b, a
|
if j == 1: # fix ordering
|
||||||
|
a, b == b, a
|
||||||
|
|
||||||
dx, dy = (i-1)*line_offset
|
dx, dy = (i-1)*line_offset
|
||||||
|
|
||||||
l = ax.plot([ a.x+dx, b.x+dx], [a.y+dy, b.y+dy], **tmp_line_kwargs)
|
l = ax.plot([ a.x+dx, b.x+dx], [a.y+dy, b.y+dy], **tmp_line_kwargs)
|
||||||
line_kwargs['color'] = l[0].get_color()
|
line_kwargs['color'] = l[0].get_color()
|
||||||
|
|
||||||
# Lines internal to ants triangle
|
# Lines internal to ants triangle
|
||||||
tmp_line_kwargs = line_kwargs
|
tmp_line_kwargs = line_kwargs
|
||||||
|
@ -114,9 +123,20 @@ def plot_four_antenna_geometry(tx, ants, extra_ant=None, ax=None, line_kwargs={}
|
||||||
|
|
||||||
return ax
|
return ax
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
use_phase = False
|
from argparse import ArgumentParser
|
||||||
correct_time = True
|
import os.path as path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
parser = ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("fname", metavar="path/to/figure[/]", nargs="?", help="Location for generated figure, will append __file__ if a directory. If not supplied, figure is shown.")
|
||||||
|
parser.add_argument("--no-extra", dest='extra', action='store_false', help='Disable the extra (fourth) antenna')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.fname is not None and path.isdir(args.fname):
|
||||||
|
args.fname = path.join(args.fname, path.splitext(path.basename(__file__))[0] + ".pdf")
|
||||||
|
|
||||||
tx = Antenna(name="T", x=-8, y=2, t0=0)
|
tx = Antenna(name="T", x=-8, y=2, t0=0)
|
||||||
|
|
||||||
|
@ -126,42 +146,40 @@ if __name__ == "__main__":
|
||||||
Antenna(name='3', x=1, y= 3, t0=10 ),
|
Antenna(name='3', x=1, y= 3, t0=10 ),
|
||||||
]
|
]
|
||||||
|
|
||||||
extra_ant = Antenna(name='4', x=4, y=-1, t0=-6)
|
if args.extra:
|
||||||
|
extra_ant = Antenna(name='4', x=4, y=-1, t0=-6)
|
||||||
|
all_ants = ants + [extra_ant]
|
||||||
if False:#correct_time: # taken from the output of this script
|
else:
|
||||||
"""
|
extra_ant = None
|
||||||
Antenna Triangle(1,2,3)
|
all_ants = ants
|
||||||
j=0: 1,2
|
|
||||||
j=1: 3,1
|
|
||||||
j=2: 2,3
|
|
||||||
sigmas: [-2.99999999 9. -6.00000001]
|
|
||||||
sigmas sum: -8.881784197001252e-16
|
|
||||||
(Antenna(x=0,y=0,z=0,t0=1,name='1'), Antenna(x=2,y=-3,z=0,t0=4,name='2'), Antenna(x=1,y=3,z=0,t0=10,name='3')) : [0. 2.99999999 9. ]
|
|
||||||
Antenna Triangle(1,2,4)
|
|
||||||
sigmas: [-2.99999999 -7.00000001 10. ]
|
|
||||||
sigmas sum: 0.0
|
|
||||||
(Antenna(x=0,y=0,z=0,t0=1,name='1'), Antenna(x=2,y=-3,z=0,t0=4,name='2'), Antenna(x=4,y=-1,z=0,t0=-6,name='4')) : [ 0. 2.99999999 -7.00000001]
|
|
||||||
Antenna Triangle(1,3,4)
|
|
||||||
sigmas: [-9. -7.00000001 16.00000001]
|
|
||||||
sigmas sum: 0.0
|
|
||||||
(Antenna(x=0,y=0,z=0,t0=1,name='1'), Antenna(x=1,y=3,z=0,t0=10,name='3'), Antenna(x=4,y=-1,z=0,t0=-6,name='4')) : [ 0. 9. -7.00000001]
|
|
||||||
Antenna Triangle(2,3,4)
|
|
||||||
sigmas: [ -6.00000001 -10. 16.00000001]
|
|
||||||
sigmas sum: 0.0
|
|
||||||
(Antenna(x=2,y=-3,z=0,t0=4,name='2'), Antenna(x=1,y=3,z=0,t0=10,name='3'), Antenna(x=4,y=-1,z=0,t0=-6,name='4')) : [ 0. 6.00000001 -10.
|
|
||||||
"""
|
|
||||||
print("Running with pre-corrected times")
|
|
||||||
ants[1].t0 -= 2.99999999
|
|
||||||
ants[2].t0 -= 9
|
|
||||||
extra_ant.t0 -= -7
|
|
||||||
|
|
||||||
ax = plot_four_antenna_geometry(tx, ants, extra_ant=extra_ant)
|
ax = plot_four_antenna_geometry(tx, ants, extra_ant=extra_ant)
|
||||||
|
|
||||||
fig = ax.get_figure()
|
fig = ax.get_figure()
|
||||||
|
|
||||||
|
if args.fname is not None:
|
||||||
|
plt.savefig(args.fname)
|
||||||
|
else:
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
if True:
|
||||||
|
sys.exit(0)
|
||||||
|
########################
|
||||||
### Lol, show my calculations are right
|
### Lol, show my calculations are right
|
||||||
for i, triangle in enumerate(antenna_triangles(ants + [extra_ant])):
|
|
||||||
|
use_phase = False
|
||||||
|
correct_time = True
|
||||||
|
|
||||||
|
if args.extra:
|
||||||
|
all_ants = ants + [extra_ant]
|
||||||
|
else:
|
||||||
|
all_ants = ants
|
||||||
|
|
||||||
|
for ant in enumerate(all_ants):
|
||||||
|
ant.offsets = []
|
||||||
|
ant.backup_t = []
|
||||||
|
|
||||||
|
for i, triangle in enumerate(antenna_triangles(all_ants)):
|
||||||
print("Antenna Triangle({},{},{})".format(*[ant.name for ant in triangle]))
|
print("Antenna Triangle({},{},{})".format(*[ant.name for ant in triangle]))
|
||||||
|
|
||||||
sigma = np.zeros((3))
|
sigma = np.zeros((3))
|
||||||
|
@ -169,12 +187,12 @@ if __name__ == "__main__":
|
||||||
a, b = ant_pair[0], ant_pair[1]
|
a, b = ant_pair[0], ant_pair[1]
|
||||||
if j == 1: # fix ordering
|
if j == 1: # fix ordering
|
||||||
a, b = b, a
|
a, b = b, a
|
||||||
|
|
||||||
if i == 0: # print sigma pairing for first triangle
|
if i == 0: # print sigma pairing for first triangle
|
||||||
print('j={}: {},{}'.format(j, a.name, b.name))
|
print('j={}: {},{}'.format(j, a.name, b.name))
|
||||||
|
|
||||||
phys_Dt = (distance(tx, a) - distance(tx, b))/c_light
|
phys_Dt = (distance(tx, a) - distance(tx, b))/c_light
|
||||||
meas_Dt = a.t0 - b.t0
|
meas_Dt = a.t - b.t
|
||||||
|
|
||||||
if use_phase:
|
if use_phase:
|
||||||
f_beacon = 50e6 # Hz
|
f_beacon = 50e6 # Hz
|
||||||
|
@ -182,25 +200,25 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
phys_Dt = to_phase(phys_Dt)
|
phys_Dt = to_phase(phys_Dt)
|
||||||
meas_Dt = to_phase(meas_Dt)
|
meas_Dt = to_phase(meas_Dt)
|
||||||
|
|
||||||
sigma[j] = meas_Dt - phys_Dt
|
sigma[j] = meas_Dt - phys_Dt
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
print(
|
print(
|
||||||
"Dt'_{},{} = ".format(a.name, b.name)
|
"Dt'_{},{} = ".format(a.name, b.name)
|
||||||
+ "{}".format(meas_Dt)
|
+ "{}".format(meas_Dt)
|
||||||
+ " = {} - {}".format(a.t0, b.t0)
|
+ " = {} - {}".format(a.t, b.t)
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
"Dt_{},{} = ".format(a.name, b.name)
|
"Dt_{},{} = ".format(a.name, b.name)
|
||||||
+ "{}".format(phys_Dt)
|
+ "{}".format(phys_Dt)
|
||||||
+ " = {} - {}".format(distance(tx, a), distance(tx, b))
|
+ " = {} - {}".format(distance(tx, a), distance(tx, b))
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"sigma_{},{} = ".format(a.name, b.name)
|
"sigma_{},{} = ".format(a.name, b.name)
|
||||||
+ "{}".format(sigma[j])
|
+ "{}".format(sigma[j])
|
||||||
)
|
)
|
||||||
|
|
||||||
print("sigmas:", sigma)
|
print("sigmas:", sigma)
|
||||||
if use_phase:
|
if use_phase:
|
||||||
print("sigmas sum:", phase_mod(np.sum(sigma)))
|
print("sigmas sum:", phase_mod(np.sum(sigma)))
|
||||||
|
@ -217,12 +235,9 @@ if __name__ == "__main__":
|
||||||
for i in [1,2]:
|
for i in [1,2]:
|
||||||
triangle[i].offsets.append(-ant_sigma[i])
|
triangle[i].offsets.append(-ant_sigma[i])
|
||||||
if correct_time:
|
if correct_time:
|
||||||
triangle[i].backup_t0 = triangle[i].t0
|
triangle[i].backup_t.append(triangle[i].t)
|
||||||
triangle[i].t0 += -ant_sigma[i]
|
triangle[i].t += -ant_sigma[i]
|
||||||
|
|
||||||
if correct_time:
|
if correct_time:
|
||||||
print(ants + [extra_ant])
|
for i, ant in enumerate(all_ants):
|
||||||
for i, ant in enumerate(ants + [extra_ant]):
|
|
||||||
print(i, ant.name, ant.offsets)
|
print(i, ant.name, ant.offsets)
|
||||||
|
|
||||||
plt.show()
|
|
||||||
|
|
Loading…
Reference in a new issue