{ "cells": [ { "cell_type": "markdown", "id": "cell-00", "metadata": {}, "source": [ "# Read one scene without the library\n", "\n", "The same link as the [library tutorial](https://huggingface.co/datasets/Intelligence-Networking-Lab/Channels4World/blob/main/docs/tutorial-library.md), **BS 0 → UE 14 of\n", "`urban_scene_019234` at 3.5 GHz**, read with NumPy and the standard library from Tiny's loose\n", "files: about 15 MB. Archives from larger tiers hold the same files; see\n", "[without the library](https://huggingface.co/datasets/Intelligence-Networking-Lab/Channels4World/blob/main/docs/without-library.md) for TAR access.\n", "\n", "Install with `pip install numpy huggingface_hub matplotlib`." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-01", "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "import json\n", "import zipfile\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from huggingface_hub import snapshot_download\n", "from matplotlib.collections import PolyCollection" ] }, { "cell_type": "markdown", "id": "cell-02", "metadata": {}, "source": [ "## 1. Choose the link\n", "\n", "The same identifiers as the library tutorial. A UE ID is a row of `ue_positions`, and the BS\n", "ID is both a row of `bs_positions` and the number in the record's file name." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-03", "metadata": {}, "outputs": [], "source": [ "REPO, REVISION = \"Intelligence-Networking-Lab/Channels4World\", \"v1.0.0\"\n", "SCENE_ID, GROUP = \"urban_scene_019234\", \"test-urban-g00000\" # GROUP: from the tiny_scenes catalog\n", "CARRIER_HZ, BS_ID, UE_ID = 3_500_000_000, 0, 14\n", "OTHER_HZ = 7_000_000_000\n", "DATA = Path(\"c4w\")" ] }, { "cell_type": "markdown", "id": "cell-04", "metadata": {}, "source": [ "## 2. Download the scene's files\n", "\n", "NumPy needs only the record files: positions, geometry, and BS 0's core and detail at both\n", "carriers." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-05", "metadata": {}, "outputs": [], "source": [ "scene_dir = DATA / \"tiny\" / \"records\" / f\"scene={SCENE_ID}\"\n", "remote = f\"tiny/records/scene={SCENE_ID}\"\n", "snapshot_download(REPO, repo_type=\"dataset\", revision=REVISION, local_dir=DATA, allow_patterns=[\n", " f\"{remote}/positions.npz\", f\"{remote}/geometry.zip\", f\"{remote}/band_hz=*/component=*/bs{BS_ID:05d}.npz\"])\n", "\n", "def record_path(carrier_hz, component):\n", " return scene_dir / f\"band_hz={carrier_hz}\" / f\"component={component}\" / f\"bs{BS_ID:05d}.npz\"\n", "\n", "print(sorted(p.relative_to(scene_dir).as_posix() for p in scene_dir.rglob(\"*\") if p.is_file()))" ] }, { "cell_type": "markdown", "id": "cell-06", "metadata": {}, "source": [ "## 3. The hierarchy on disk\n", "\n", "Each scene folder holds `positions.npz` and `geometry.zip`, shared by both carriers, and one\n", "file per carrier, component and BS: `band_hz=/component=/bs.npz`.\n", "Every NPZ carries its identity in a JSON `__meta__` entry:" ] }, { "cell_type": "code", "execution_count": null, "id": "cell-07", "metadata": {}, "outputs": [], "source": [ "with np.load(record_path(CARRIER_HZ, \"core\"), allow_pickle=False) as npz:\n", " meta = json.loads(npz[\"__meta__\"].item())\n", "print(json.dumps(meta[\"identity\"], indent=1))\n", "print(meta[\"dimensions\"]) # retained links and paths in this record" ] }, { "cell_type": "markdown", "id": "cell-08", "metadata": {}, "source": [ "## 4. Geometry and positions\n", "\n", "Geometry, positions and interaction points share one frame: scene metres, z up." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-09", "metadata": {}, "outputs": [], "source": [ "with np.load(scene_dir / \"positions.npz\", allow_pickle=False) as positions:\n", " bs_positions, ue_positions = positions[\"bs_positions\"], positions[\"ue_positions\"]\n", "bs_xyz, ue_xyz = bs_positions[BS_ID], ue_positions[UE_ID]\n", "print(bs_positions.shape, ue_positions.shape)\n", "print(\"BS\", bs_xyz, \"UE\", ue_xyz, f\"distance {np.linalg.norm(ue_xyz - bs_xyz):.1f} m\")\n", "\n", "def top_view(read, names):\n", " \"\"\"Building triangles projected onto the ground (x, y), from OBJ meshes.\"\"\"\n", " triangles = []\n", " for name in names:\n", " verts, faces = [], []\n", " for line in read(name).decode().splitlines():\n", " if line.startswith(\"v \"):\n", " verts.append([float(v) for v in line.split()[1:4]])\n", " elif line.startswith(\"f \"):\n", " idx = [int(t.split(\"/\")[0]) for t in line.split()[1:]]\n", " faces += [[idx[0], idx[k], idx[k + 1]] for k in range(1, len(idx) - 1)]\n", " v = np.array(verts)\n", " triangles += [v[[i - 1 for i in f], :2] for f in faces] # OBJ indices start at 1\n", " return triangles\n", "\n", "with zipfile.ZipFile(scene_dir / \"geometry.zip\") as geometry:\n", " print(\"entry point:\", json.loads(geometry.read(\"scene.json\"))[\"entrypoint\"])\n", " meshes = [n for n in geometry.namelist() if n.endswith(\".obj\") and \"ground\" not in n]\n", " triangles = top_view(geometry.read, meshes)\n", "print(len(meshes), \"building meshes\")" ] }, { "cell_type": "code", "execution_count": null, "id": "cell-10", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(6, 6))\n", "ax.add_collection(PolyCollection(triangles, facecolor=\"#c3cbc2\", edgecolor=\"none\"))\n", "ax.scatter(ue_positions[:, 0], ue_positions[:, 1], s=0.2, color=\"#4d9688\", label=f\"{len(ue_positions):,} UEs\")\n", "ax.scatter(bs_positions[:, 0], bs_positions[:, 1], marker=\"^\", s=30, color=\"k\", label=f\"{len(bs_positions)} BSs\")\n", "ax.plot(*zip(bs_xyz[:2], ue_xyz[:2]), color=\"#e2733d\", lw=2, label=f\"BS {BS_ID} → UE {UE_ID}\")\n", "ax.set(xlim=(-250, 250), ylim=(-250, 250), aspect=\"equal\", xlabel=\"x (m)\", ylabel=\"y (m)\", title=SCENE_ID)\n", "ax.legend(loc=\"upper right\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "cell-11", "metadata": {}, "source": [ "## 5. Find the link\n", "\n", "`link_ue_index` lists the UEs this BS reaches, in ascending order; the link's row is where\n", "`UE_ID` sits in that list. Link `row` owns paths `link_path_offsets[row]` to\n", "`link_path_offsets[row + 1]`. A UE that is not listed has no retained link to this BS (not a\n", "zero-valued channel)." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-12", "metadata": {}, "outputs": [], "source": [ "def load(carrier_hz, component):\n", " with np.load(record_path(carrier_hz, component), allow_pickle=False) as npz:\n", " return {name: npz[name] for name in npz.files if name != \"__meta__\"}\n", "\n", "def link_of(core, detail, ue_id):\n", " ue_ids = core[\"link_ue_index\"]\n", " row = int(np.searchsorted(ue_ids, ue_id))\n", " if row == ue_ids.size or ue_ids[row] != ue_id:\n", " return None # no retained link to this UE\n", " p0, p1 = map(int, core[\"link_path_offsets\"][row:row + 2])\n", " link_core = {k: v[p0:p1] for k, v in core.items() if k not in (\"link_ue_index\", \"link_path_offsets\")}\n", " i0, i1 = map(int, detail[\"path_interaction_offsets\"][[p0, p1]])\n", " link_detail = {k: detail[k][i0:i1] for k in (\"interaction_rank\", \"interaction_type\", \"interaction_vertex\")}\n", " link_detail[\"path_interaction_offsets\"] = detail[\"path_interaction_offsets\"][p0:p1 + 1] - i0\n", " return row, link_core, link_detail\n", "\n", "core, detail = load(CARRIER_HZ, \"core\"), load(CARRIER_HZ, \"detail\")\n", "row, link_core, link_detail = link_of(core, detail, UE_ID)\n", "print(f\"UE {UE_ID}: link row {row} of {core['link_ue_index'].size}, {link_core['tau'].size} paths\")" ] }, { "cell_type": "markdown", "id": "cell-13", "metadata": {}, "source": [ "## 6. What each path stores\n", "\n", "The same arrays as in the library tutorial: the complex coefficient `a_real + 1j*a_imag`\n", "(passband, without the carrier-delay phase, antennas included), the delay `tau` in seconds,\n", "departure and arrival angles in radians and, in detail, each interaction's type and location\n", "in order. Paths are stored strongest first, at most 16 per link above −150 dB." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-14", "metadata": {}, "outputs": [], "source": [ "NAMES = {1: \"specular reflection\", 2: \"diffuse reflection\", 4: \"refraction\", 8: \"diffraction\"}\n", "\n", "def describe(core, detail):\n", " \"\"\"One line per retained path, strongest first.\"\"\"\n", " re, im = core[\"a_real\"].astype(np.float64), core[\"a_imag\"].astype(np.float64)\n", " power_db = 10 * np.log10(re**2 + im**2)\n", " off = detail[\"path_interaction_offsets\"]\n", " for p in range(len(core[\"tau\"])):\n", " kinds = [NAMES.get(int(t), str(t)) for t in detail[\"interaction_type\"][off[p]:off[p + 1]]]\n", " print(f\"rank {int(core['path_rank'][p]):2d} {core['tau'][p] * 1e9:8.2f} ns {power_db[p]:7.2f} dB \"\n", " f\"AoD az {np.degrees(core['phi_t'][p]):6.1f}° AoA az {np.degrees(core['phi_r'][p]):6.1f}° \"\n", " f\"{' → '.join(kinds) or 'line of sight'}\")\n", "\n", "describe(link_core, link_detail)" ] }, { "cell_type": "markdown", "id": "cell-15", "metadata": {}, "source": [ "## 7. A power–delay profile\n", "\n", "Placing each path by delay and power gives the link's power–delay profile: a path-based view\n", "of the stored channel, not a sampled impulse response." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-16", "metadata": {}, "outputs": [], "source": [ "def stems(ax, tau, a_real, a_imag, label, marker, color):\n", " power_db = 10 * np.log10(a_real.astype(np.float64)**2 + a_imag.astype(np.float64)**2)\n", " ax.vlines(tau * 1e9, -150, power_db, color=color, lw=1.2)\n", " ax.scatter(tau * 1e9, power_db, marker=marker, color=color, zorder=3, label=label)\n", "\n", "fig, ax = plt.subplots(figsize=(7, 3))\n", "stems(ax, link_core[\"tau\"], link_core[\"a_real\"], link_core[\"a_imag\"], \"3.5 GHz\", \"o\", \"#e2733d\")\n", "ax.set(xlabel=\"delay (ns)\", ylabel=\"path power (dB)\", ylim=(-150, None),\n", " title=f\"{SCENE_ID} · BS {BS_ID} → UE {UE_ID}\")\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "cell-17", "metadata": {}, "source": [ "## 8. The same link at 7 GHz" ] }, { "cell_type": "code", "execution_count": null, "id": "cell-18", "metadata": {}, "outputs": [], "source": [ "other = link_of(load(OTHER_HZ, \"core\"), load(OTHER_HZ, \"detail\"), UE_ID)\n", "fig, ax = plt.subplots(figsize=(7, 3))\n", "stems(ax, link_core[\"tau\"], link_core[\"a_real\"], link_core[\"a_imag\"], \"3.5 GHz\", \"o\", \"#e2733d\")\n", "if other is None:\n", " print(\"UE\", UE_ID, \"has no retained link at 7 GHz\")\n", "else:\n", " _, core7, _ = other\n", " stems(ax, core7[\"tau\"], core7[\"a_real\"], core7[\"a_imag\"], \"7 GHz\", \"s\", \"#4d9688\")\n", " for c, label in ((link_core, \"3.5 GHz\"), (core7, \"7 GHz\")):\n", " power = np.sum(c[\"a_real\"].astype(np.float64) ** 2 + c[\"a_imag\"].astype(np.float64) ** 2)\n", " print(f\"{label}: {c['tau'].size} paths, link power {10 * np.log10(power):.2f} dB\")\n", "ax.set(xlabel=\"delay (ns)\", ylabel=\"path power (dB)\", ylim=(-150, None))\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "cell-19", "metadata": {}, "source": [ "Ranks order the paths within one record, so the same rank at 3.5 and 7 GHz need not be\n", "the same route. Compare delays, interaction sequences or interaction points instead.\n", "\n", "## Next\n", "\n", "- [Without the library](https://huggingface.co/datasets/Intelligence-Networking-Lab/Channels4World/blob/main/docs/without-library.md): TAR archives, catalogs and byte-range reads.\n", "- [Schema reference](https://huggingface.co/datasets/Intelligence-Networking-Lab/Channels4World/blob/main/docs/schema-reference.md): every array, its dtype and its meaning." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }