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_phase.pdf field_singleleft_phase.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:
|
||||
rm -v sine_beacon.*
|
||||
|
@ -35,3 +37,9 @@ field_singlecenter_time.%: src/beacon_field.py
|
|||
$< --time $@ single-center
|
||||
field_singlecenter_phase.%: src/beacon_field.py
|
||||
$< --phase $@ single-center
|
||||
|
||||
antenna_setup_four.%: src/four_antenna_setup.py
|
||||
$< $@
|
||||
|
||||
antenna_setup_three.%: src/four_antenna_setup.py
|
||||
$< --no-extra $@
|
||||
|
|
135
figures/beacon/src/four_antenna_setup.py
Normal file → Executable file
135
figures/beacon/src/four_antenna_setup.py
Normal file → Executable file
|
@ -16,6 +16,23 @@ from itertools import combinations
|
|||
|
||||
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):
|
||||
"""
|
||||
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 ) )
|
||||
|
||||
|
||||
def phase_mod(phase, low=np.pi):
|
||||
"""
|
||||
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
|
||||
|
||||
|
||||
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):
|
||||
return combinations(antennas, 3)
|
||||
|
||||
|
||||
def antenna_baselines(antennas):
|
||||
return combinations(antennas, 2)
|
||||
|
||||
|
||||
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)
|
||||
|
@ -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}
|
||||
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
|
||||
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.annotate(ant.name, (ant.x, ant.y), ha='center', va='center',zorder=scatter_zorder)
|
||||
|
||||
|
@ -86,8 +94,9 @@ 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)
|
||||
|
||||
# Lines due to all Antennas (including extra_ant)
|
||||
if extra_ant is not None:
|
||||
line_offset = 0.08*np.array([1,1])
|
||||
for i, ant_triangle in enumerate(antenna_triangles(ants + [extra_ant])):
|
||||
for i, ant_triangle in enumerate(antenna_triangles(all_ants)):
|
||||
tmp_line_kwargs['color'] = None
|
||||
tmp_line_kwargs['linestyle'] = '--'
|
||||
tmp_line_kwargs['alpha'] = 0.4
|
||||
|
@ -114,9 +123,20 @@ def plot_four_antenna_geometry(tx, ants, extra_ant=None, ax=None, line_kwargs={}
|
|||
|
||||
return ax
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
use_phase = False
|
||||
correct_time = True
|
||||
from argparse import ArgumentParser
|
||||
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)
|
||||
|
||||
|
@ -126,42 +146,40 @@ if __name__ == "__main__":
|
|||
Antenna(name='3', x=1, y= 3, t0=10 ),
|
||||
]
|
||||
|
||||
if args.extra:
|
||||
extra_ant = Antenna(name='4', x=4, y=-1, t0=-6)
|
||||
|
||||
|
||||
if False:#correct_time: # taken from the output of this script
|
||||
"""
|
||||
Antenna Triangle(1,2,3)
|
||||
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
|
||||
all_ants = ants + [extra_ant]
|
||||
else:
|
||||
extra_ant = None
|
||||
all_ants = ants
|
||||
|
||||
ax = plot_four_antenna_geometry(tx, ants, extra_ant=extra_ant)
|
||||
|
||||
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
|
||||
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]))
|
||||
|
||||
sigma = np.zeros((3))
|
||||
|
@ -174,7 +192,7 @@ if __name__ == "__main__":
|
|||
print('j={}: {},{}'.format(j, a.name, b.name))
|
||||
|
||||
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:
|
||||
f_beacon = 50e6 # Hz
|
||||
|
@ -189,18 +207,18 @@ if __name__ == "__main__":
|
|||
print(
|
||||
"Dt'_{},{} = ".format(a.name, b.name)
|
||||
+ "{}".format(meas_Dt)
|
||||
+ " = {} - {}".format(a.t0, b.t0)
|
||||
+ " = {} - {}".format(a.t, b.t)
|
||||
)
|
||||
print(
|
||||
"Dt_{},{} = ".format(a.name, b.name)
|
||||
+ "{}".format(phys_Dt)
|
||||
+ " = {} - {}".format(distance(tx, a), distance(tx, b))
|
||||
)
|
||||
|
||||
print(
|
||||
"sigma_{},{} = ".format(a.name, b.name)
|
||||
+ "{}".format(sigma[j])
|
||||
)
|
||||
|
||||
print("sigmas:", sigma)
|
||||
if use_phase:
|
||||
print("sigmas sum:", phase_mod(np.sum(sigma)))
|
||||
|
@ -217,12 +235,9 @@ if __name__ == "__main__":
|
|||
for i in [1,2]:
|
||||
triangle[i].offsets.append(-ant_sigma[i])
|
||||
if correct_time:
|
||||
triangle[i].backup_t0 = triangle[i].t0
|
||||
triangle[i].t0 += -ant_sigma[i]
|
||||
triangle[i].backup_t.append(triangle[i].t)
|
||||
triangle[i].t += -ant_sigma[i]
|
||||
|
||||
if correct_time:
|
||||
print(ants + [extra_ant])
|
||||
for i, ant in enumerate(ants + [extra_ant]):
|
||||
for i, ant in enumerate(all_ants):
|
||||
print(i, ant.name, ant.offsets)
|
||||
|
||||
plt.show()
|
||||
|
|
Loading…
Reference in a new issue