-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_lofar.py
159 lines (129 loc) · 4.9 KB
/
plot_lofar.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from lofarantpos.db import LofarAntennaDatabase
from lofarantpos.geo import localnorth_to_etrs
db = LofarAntennaDatabase()
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Circle
def plot_hba(station_name, ax=None, centre=None, subfield="", labels=False):
"""
Plot LOFAR HBA tiles for one station
Args:
station_name: Station name, without suffix. E.g. "CS001"
ax: existing matplotlib axes object to use
centre: etrs coordinates of origin. Default: LBA phase centre of station.
subfield: '0', '1' or ''to suffix after 'HBA' for e.g. CS002HBA1)
labels: add labels
"""
if centre is None:
centre = db.phase_centres[station_name + "LBA"]
if ax is None:
fig, ax = plt.subplots()
ax.set_aspect("equal")
etrs_to_xyz = localnorth_to_etrs(centre).T
if station_name + "HBA" + subfield not in db.hba_rotations:
plot_hba(station_name, ax=ax, centre=centre, subfield="0", labels=labels)
plot_hba(station_name, ax=ax, centre=centre, subfield="1", labels=labels)
return
etrs_delta = db.antenna_etrs(station_name + "HBA" + subfield) - centre
xys = (etrs_to_xyz @ etrs_delta.T)[:2, :].T
theta = db.hba_rotations[station_name + "HBA" + subfield]
c, s = np.cos(theta), np.sin(theta)
rot_mat = db.pqr_to_localnorth(station_name + "HBA")[:2, :2] @ np.array(
((c, s), (-s, c))
)
x_dir = rot_mat @ [5.15, 0]
y_dir = rot_mat @ [0, 5.15]
tile = np.array(
[
-0.5 * x_dir - 0.5 * y_dir,
+0.5 * x_dir - 0.5 * y_dir,
+0.5 * x_dir + 0.5 * y_dir,
-0.5 * x_dir + 0.5 * y_dir,
-0.5 * x_dir - 0.5 * y_dir,
]
)
for num, xy in enumerate(xys):
x, y = xy
ax.plot((x + tile)[:, 0], (y + tile)[:, 1], "k")
if labels:
if subfield == "1":
num += 24
ax.text(x, y, str(num))
def plot_lba(station_name, ax=None, centre=None, labels=False):
"""
Plot LOFAR LBA locations for one station
Args:
station_name: Station name, without suffix. E.g. "CS001"
ax: existing matplotlib axes object to use
centre: etrs coordinates of origin. Default: LBA phase centre of station.
labels: add labels
"""
if centre is None:
centre = db.phase_centres[station_name + "LBA"]
if ax is None:
fig, ax = plt.subplots()
ax.set_aspect("equal")
etrs_to_xyz = localnorth_to_etrs(centre).T
etrs_delta = db.antenna_etrs(station_name + "LBA") - centre
xys = (etrs_to_xyz @ etrs_delta.T)[:2, :].T
ax.plot(xys[:, 0], xys[:, 1], "ko")
if labels:
for num, xy in enumerate(xys):
x, y = xy
ax.text(x, y, str(num))
def plot_cabinet(station_name, ax=None, centre=None, labels=False):
"""
Plot LOFAR cabinet location for one station
Args:
station_name: Station name, without suffix. E.g. "CS001"
ax: existing matplotlib axes object to use
centre: etrs coordinates of origin. Default: LBA phase centre of station.
labels: add label
"""
if centre is None:
centre = db.phase_centres[station_name + "LBA"]
if ax is None:
fig, ax = plt.subplots()
ax.set_aspect("equal")
etrs_to_xyz = localnorth_to_etrs(centre).T
etrs_delta = db.cabinet_etrs[station_name] - centre
x, y, _ = etrs_to_xyz @ etrs_delta
ax.plot(x, y, "ro")
if labels:
ax.text(x, y, station_name + " cabinet")
def plot_station(station_name, ax=None, centre=None, labels=False):
"""
Plot a LOFAR station
Args:
station_name: Station name, without suffix. E.g. "CS001"
ax: existing matplotlib axes object to use
labels: add labels
"""
if centre is None:
centre = db.phase_centres[station_name + "LBA"]
if ax is None:
fig, ax = plt.subplots()
ax.set_aspect("equal")
ax.set_title("LOFAR station " + station_name)
plot_lba(station_name, ax=ax, centre=centre, labels=labels)
plot_hba(station_name, ax=ax, centre=centre, labels=labels)
plot_cabinet(station_name, ax=ax, centre=centre, labels=labels)
def plot_superterp(ax=None, labels=False, plot_circle=True):
"""
Plot the LOFAR superterp
Args:
ax: existing matplotlib axes object to use
labels: add labels
plot_circle: plot a surrounding circle
"""
if ax is None:
fig, ax = plt.subplots()
ax.set_aspect("equal")
ax.set_xlabel("Local East (m)")
ax.set_ylabel("Local North (m)")
ax.set_title("LOFAR superterp")
if plot_circle:
circle1 = ax.add_patch(Circle((0, 0), radius=185, fill=False, edgecolor="k"))
centre = db.phase_centres["CS002LBA"]
for station_name in "CS002", "CS003", "CS004", "CS005", "CS006", "CS007":
plot_station(station_name, ax=ax, centre=centre, labels=labels)