Show AP positions on heatmap
This commit is contained in:
1 parent
5c98e8e4a6
commit
eccdbdcd78
1 file changed
+170
-11
+170
-11
@@ -68,12 +68,17 @@ def render_heatmap(
|
||||
- Alpha = derived from signal strength so strong zones are opaque and
|
||||
weak/absent zones fade to transparent, revealing the background.
|
||||
|
||||
If any selected BSSIDs have physical positions set in session.ap_positions,
|
||||
synthetic anchor points are injected into the interpolation so the heatmap
|
||||
peak is correctly located at the real transmitter position. AP positions
|
||||
are shown as distinct diamond icons, visually separate from measurement dots.
|
||||
|
||||
Args:
|
||||
session: The data session with measurements.
|
||||
bssids: List of BSSIDs. Multiple BSSIDs are averaged per point.
|
||||
fig/ax: Existing figure/axes (creates new if None).
|
||||
alpha: Maximum opacity of the heatmap overlay (default 0.85).
|
||||
show_points: Draw measurement dot markers.
|
||||
show_points: Draw measurement dot markers and AP position icons.
|
||||
show_colorbar: Draw the dBm color scale.
|
||||
export_path: If set, save figure to this path.
|
||||
|
||||
@@ -94,8 +99,14 @@ def render_heatmap(
|
||||
|
||||
points, values = session.get_points_and_values_multi(bssids)
|
||||
missing_points = session.get_missing_points(bssids)
|
||||
anchor_pts, anchor_vals = session.get_anchor_points(bssids)
|
||||
w, h = session.canvas_width, session.canvas_height
|
||||
|
||||
# Merge anchor points into the interpolation input when available.
|
||||
# Anchors are synthetic — they don't appear as measurement dots.
|
||||
interp_points = points + anchor_pts
|
||||
interp_values = values + anchor_vals
|
||||
|
||||
# ── Title label ───────────────────────────────────────────────────────────
|
||||
if len(bssids) == 1:
|
||||
ssid = session.get_ssid(bssids[0])
|
||||
@@ -125,15 +136,12 @@ def render_heatmap(
|
||||
heatmap_data = None
|
||||
MIN_POINTS = 4
|
||||
|
||||
if len(points) >= MIN_POINTS:
|
||||
heatmap_data = interpolate(points, values, w, h)
|
||||
grid = heatmap_data.grid_z # shape (res, res), dBm values
|
||||
if len(interp_points) >= MIN_POINTS:
|
||||
heatmap_data = interpolate(interp_points, interp_values, w, h)
|
||||
grid = heatmap_data.grid_z
|
||||
|
||||
# Build RGBA image from the interpolated grid
|
||||
rgba = _build_ekahau_rgba(grid, alpha)
|
||||
|
||||
# Dummy imshow used only to attach the colorbar scalar mappable
|
||||
# (not visible — alpha=0 on the axes imshow, real image via ax.imshow below)
|
||||
_sm = ax.imshow(
|
||||
grid,
|
||||
extent=[0, w, 0, h], origin='upper',
|
||||
@@ -141,7 +149,6 @@ def render_heatmap(
|
||||
alpha=0, zorder=0, aspect='auto'
|
||||
)
|
||||
|
||||
# The actual visible heatmap — RGBA with signal-driven alpha
|
||||
ax.imshow(
|
||||
rgba,
|
||||
extent=[0, w, 0, h], origin='upper',
|
||||
@@ -165,8 +172,7 @@ def render_heatmap(
|
||||
bbox=dict(facecolor='white', edgecolor='none', pad=1.5))
|
||||
|
||||
else:
|
||||
# Progress indicator
|
||||
collected = len(points)
|
||||
collected = len(interp_points)
|
||||
remaining = MIN_POINTS - collected
|
||||
bar = f"[{'█' * collected}{'░' * remaining}] {collected}/{MIN_POINTS}"
|
||||
msg = (f"Collecting data\n\n{bar}\n\n"
|
||||
@@ -182,6 +188,7 @@ def render_heatmap(
|
||||
# ── Measurement dots ──────────────────────────────────────────────────────
|
||||
radius = max(w, h) * 0.012
|
||||
if show_points:
|
||||
# Valid signal measurement points — filled circles
|
||||
for (px, py), dbm in zip(points, values):
|
||||
norm_val = (dbm - VMIN) / (VMAX - VMIN)
|
||||
color = SIGNAL_CMAP(norm_val)
|
||||
@@ -192,6 +199,7 @@ def render_heatmap(
|
||||
ha='center', va='bottom', fontsize=7,
|
||||
color='white', fontweight='bold', zorder=6)
|
||||
|
||||
# Out-of-range measurement points — black circles with "?"
|
||||
for (px, py) in missing_points:
|
||||
ax.add_patch(Circle((px, py), radius=radius,
|
||||
facecolor='black', edgecolor='white',
|
||||
@@ -200,6 +208,9 @@ def render_heatmap(
|
||||
ha='center', va='center', fontsize=7,
|
||||
color='white', fontweight='bold', zorder=6)
|
||||
|
||||
# AP position markers — drawn last so they sit on top of everything
|
||||
_draw_ap_markers(ax, session, bssids, radius)
|
||||
|
||||
# ── Labels & axes ─────────────────────────────────────────────────────────
|
||||
total = len(points) + len(missing_points)
|
||||
point_note = f"{total} measurement{'s' if total != 1 else ''}"
|
||||
@@ -207,6 +218,8 @@ def render_heatmap(
|
||||
point_note += f" • {len(missing_points)} out of range (●)"
|
||||
if len(bssids) > 1:
|
||||
point_note += f" • avg of {len(bssids)} BSSIDs"
|
||||
if anchor_pts:
|
||||
point_note += f" • {len(anchor_pts)} AP position{'s' if len(anchor_pts) != 1 else ''} pinned (◆)"
|
||||
if not session.floorplan_path:
|
||||
point_note += " ⚠ No floorplan — adding one increases accuracy"
|
||||
|
||||
@@ -274,7 +287,153 @@ def _build_ekahau_rgba(grid: np.ndarray, max_alpha: float) -> np.ndarray:
|
||||
return rgba
|
||||
|
||||
|
||||
# ── Grid background ───────────────────────────────────────────────────────────
|
||||
# ── AP position markers ───────────────────────────────────────────────────────
|
||||
|
||||
def _draw_ap_markers(ax: Axes, session: Session, bssids: list[str], radius: float):
|
||||
"""
|
||||
Draw a distinct diamond icon at each AP's known physical position.
|
||||
|
||||
Visual design (clearly different from measurement dots):
|
||||
- Outer diamond: white filled, black border — highly visible on any background
|
||||
- Inner WiFi arc symbol: drawn in the AP's signal color
|
||||
- SSID label below the icon
|
||||
- Small "◆" glyph instead of a dBm number so it's never confused with
|
||||
a measurement dot
|
||||
|
||||
Only BSSIDs in `bssids` that also have an entry in session.ap_positions
|
||||
are drawn.
|
||||
"""
|
||||
import matplotlib.patches as mpatches
|
||||
import matplotlib.path as mpath
|
||||
|
||||
icon_r = radius * 1.6 # diamond half-size — larger than measurement dots
|
||||
label_r = radius * 2.8 # label offset below center
|
||||
|
||||
for bssid in bssids:
|
||||
if bssid not in session.ap_positions:
|
||||
continue
|
||||
px, py = session.ap_positions[bssid]
|
||||
ssid = session.get_ssid(bssid)
|
||||
|
||||
# ── Diamond shape (rotated square) via Path ───────────────────────────
|
||||
diamond_verts = [
|
||||
(px, py - icon_r), # top
|
||||
(px + icon_r, py ), # right
|
||||
(px, py + icon_r), # bottom
|
||||
(px - icon_r, py ), # left
|
||||
(px, py - icon_r), # close
|
||||
]
|
||||
diamond_codes = [
|
||||
mpath.Path.MOVETO,
|
||||
mpath.Path.LINETO,
|
||||
mpath.Path.LINETO,
|
||||
mpath.Path.LINETO,
|
||||
mpath.Path.CLOSEPOLY,
|
||||
]
|
||||
diamond_path = mpath.Path(diamond_verts, diamond_codes)
|
||||
diamond_patch = mpatches.PathPatch(
|
||||
diamond_path,
|
||||
facecolor='white', edgecolor='#111111',
|
||||
linewidth=2.0, zorder=8, alpha=0.95
|
||||
)
|
||||
ax.add_patch(diamond_patch)
|
||||
|
||||
# ── WiFi arc symbol (three concentric arcs, bottom-left origin) ───────
|
||||
# Drawn as text using the Unicode WiFi / signal character
|
||||
ax.text(px, py, "📶",
|
||||
ha='center', va='center',
|
||||
fontsize=max(6, int(icon_r * 0.55)),
|
||||
zorder=9, alpha=0.85)
|
||||
|
||||
# ── SSID label below the diamond ──────────────────────────────────────
|
||||
ax.text(px, py + label_r, ssid,
|
||||
ha='center', va='top', fontsize=7,
|
||||
color='white', fontweight='bold', zorder=9,
|
||||
bbox=dict(boxstyle='round,pad=0.2',
|
||||
facecolor='#111111', edgecolor='none', alpha=0.7))
|
||||
|
||||
|
||||
# ── AP position markers ───────────────────────────────────────────────────────
|
||||
|
||||
def _draw_ap_markers(ax: Axes, session: Session, bssids: list[str], radius: float):
|
||||
"""
|
||||
Draw a distinct diamond ◆ icon at each AP whose physical position is known.
|
||||
|
||||
Visual design (intentionally different from measurement circles):
|
||||
- Outer diamond: white-filled rotated square, larger than measurement dots
|
||||
- Inner diamond: signal-colored fill
|
||||
- WiFi arc lines above the diamond
|
||||
- SSID label beneath
|
||||
- Thin pulse ring to make them easy to spot on a busy floorplan
|
||||
|
||||
These markers are purely informational — they are not measurement points
|
||||
and do not affect the interpolation directly (the anchor injection in
|
||||
render_heatmap() handles that separately).
|
||||
"""
|
||||
import matplotlib.patches as mpatches
|
||||
import matplotlib.transforms as mtransforms
|
||||
|
||||
for bssid in bssids:
|
||||
if bssid not in session.ap_positions:
|
||||
continue
|
||||
|
||||
px, py = session.ap_positions[bssid]
|
||||
ssid = session.get_ssid(bssid)
|
||||
r = radius * 1.6 # diamond is larger than measurement dots
|
||||
|
||||
# ── Outer pulse ring ─────────────────────────────────────────────────
|
||||
ax.add_patch(Circle((px, py), radius=r * 1.9,
|
||||
facecolor='none', edgecolor='white',
|
||||
linewidth=0.8, zorder=7, alpha=0.35,
|
||||
linestyle='--'))
|
||||
|
||||
# ── White border diamond ──────────────────────────────────────────────
|
||||
diamond_outer = mpatches.RegularPolygon(
|
||||
(px, py), numVertices=4, radius=r * 1.15,
|
||||
orientation=np.pi / 4, # rotate 45° → diamond orientation
|
||||
facecolor='white', edgecolor='white',
|
||||
linewidth=0, zorder=8, alpha=0.95)
|
||||
ax.add_patch(diamond_outer)
|
||||
|
||||
# ── Coloured inner diamond ────────────────────────────────────────────
|
||||
# Use the anchor dBm value for the color
|
||||
real_pts, real_vals = session.get_points_and_values(bssid)
|
||||
anchor_dbm = min(-25, max(real_vals) + 5) if real_vals else -35
|
||||
norm_val = np.clip((anchor_dbm - VMIN) / (VMAX - VMIN), 0.0, 1.0)
|
||||
color = SIGNAL_CMAP(norm_val)
|
||||
|
||||
diamond_inner = mpatches.RegularPolygon(
|
||||
(px, py), numVertices=4, radius=r * 0.80,
|
||||
orientation=np.pi / 4,
|
||||
facecolor=color, edgecolor='none',
|
||||
zorder=9, alpha=0.95)
|
||||
ax.add_patch(diamond_inner)
|
||||
|
||||
# ── WiFi arcs above the diamond ───────────────────────────────────────
|
||||
# Three concentric arcs drawn as partial circles
|
||||
for arc_r, arc_alpha in [(r * 0.55, 0.9), (r * 0.9, 0.65), (r * 1.25, 0.40)]:
|
||||
arc = mpatches.Arc(
|
||||
(px, py - r * 0.15), # slightly above centre
|
||||
width=arc_r * 2, height=arc_r * 2,
|
||||
angle=0, theta1=30, theta2=150, # upper semicircle arc
|
||||
color='white', linewidth=1.4,
|
||||
zorder=10, alpha=arc_alpha)
|
||||
ax.add_patch(arc)
|
||||
|
||||
# ── SSID label below the marker ───────────────────────────────────────
|
||||
ax.text(px, py + r * 2.2, ssid,
|
||||
ha='center', va='top', fontsize=7,
|
||||
color='white', fontweight='bold', zorder=10,
|
||||
bbox=dict(boxstyle='round,pad=0.3',
|
||||
facecolor='#000000', alpha=0.55,
|
||||
edgecolor='none'))
|
||||
|
||||
# ── ◆ glyph as a tiny anchor indicator ───────────────────────────────
|
||||
ax.text(px, py, '◆',
|
||||
ha='center', va='center', fontsize=6,
|
||||
color='white', zorder=11, alpha=0.7)
|
||||
|
||||
|
||||
|
||||
def _draw_grid_background(ax: Axes, w: int, h: int):
|
||||
"""Draw a subtle coordinate grid when no floorplan is loaded."""
|
||||
|
||||
Reference in new issue
Block a user