Channels4World / docs /without-library.md
INL-Yonsei's picture
1.0.0 release
50464c0
|
Raw History Blame Contribute Delete
13.7 kB

Using Channels4World without the library

Channel arrays and positions are ordinary NPZ files (numpy.load); geometry is an ordinary ZIP (zipfile.ZipFile). Start with the one-scene Tiny download on the card; plain NumPy needs only its record files, the last three patterns. The extra Tiny root, schemas and group metadata are needed for channels4world library navigation and verification.

Commands use the release tag v1.0.0. The examples use the same scene, carrier and BS as the card.

Archive conventions

You can treat a download as a collection of archives; folder names are only needed for choosing what to download. Everything else is in two naming patterns:

Item Pattern Example
Group <split>-<profile code>-g<NNNNN>, exactly 25 scenes of one split and profile test-urban-g00000
Channel archive <group>-<band>-<core|detail>.tar test-urban-g00000-3.5ghz-core.tar
Scene-asset archive <group>-<positions|geometry>.tar test-urban-g00000-positions.tar
File inside an archive records/scene=<id>/band_hz=<Hz>/component=<core|detail>/bs<NNNNN>.npz records/scene=urban_scene_019234/band_hz=3500000000/component=core/bs00000.npz
Scene asset inside an archive records/scene=<id>/positions.npz, records/scene=<id>/geometry.zip

The profile code is urban, metro or suburban; the catalogs spell metro as metropolitan. Archive file names are unique, so {p.name: p for p in Path(release_dir).rglob("*.tar")} finds everything regardless of folders. To use a channel record, open the positions archive of the same group (<group>-positions.tar) and take the same scene's positions.npz. Inside a record, link_ue_index holds UE IDs (rows of ue_positions), and link i owns paths link_path_offsets[i]:link_path_offsets[i+1].

A standalone reader

read_archives.py (about 100 lines, NumPy only) does exactly this for one release folder:

python read_archives.py c4w --band 3.5ghz --limit 5
python read_archives.py c4w --scenes urban_scene_019234      # filter records afterwards

It stops reading once it has printed --limit records (--limit 0 reads every record). It searches only c4w/payload/, stops if the same archive file name appears twice (for example, two downloads mixed in one folder), and lists any group whose positions archive is missing instead of failing halfway through. Copy and adapt it freely.

Read one Tiny scene

Use exactly the same TINY_ROOT, SCENE_ID, CARRIER_HZ, BS_ID and UE_ID as the card's NumPy example. Do not independently choose the first catalog row and the first lexically sorted directory: those orders can differ.

from pathlib import Path
import numpy as np

TINY_ROOT = Path("c4w/tiny")
SCENE_ID, CARRIER_HZ, BS_ID, UE_ID = "urban_scene_019234", 3_500_000_000, 0, 14
scene_dir = TINY_ROOT / "records" / f"scene={SCENE_ID}"
core_path = (scene_dir / f"band_hz={CARRIER_HZ}" / "component=core"
             / f"bs{BS_ID:05d}.npz")

with np.load(core_path, allow_pickle=False) as core, np.load(
    scene_dir / "positions.npz", allow_pickle=False
) as positions:
    ue_ids = core["link_ue_index"]
    link_row = int(np.searchsorted(ue_ids, UE_ID))
    assert link_row < ue_ids.size and ue_ids[link_row] == UE_ID, "No retained link to this UE."
    start, stop = map(int, core["link_path_offsets"][link_row:link_row + 2])
    gain = core["a_real"][start:stop] + 1j * core["a_imag"][start:stop]
    print(core["tau"][start:stop], gain)
    print(np.linalg.norm(
        positions["ue_positions"][UE_ID] - positions["bs_positions"][BS_ID]
    ))

UE_ID indexes a position row; link_row indexes the retained-link table. Preserve that association when filtering. An unlisted UE in this loaded record has no retained link to this BS. This says nothing about payloads not downloaded or components not published.

For geometry, use ZIP tools, not NumPy:

import json
import zipfile

with zipfile.ZipFile(scene_dir / "geometry.zip") as archive:
    descriptor = json.loads(archive.read("scene.json"))
    print(descriptor["entrypoint"], archive.namelist())

The entrypoint is a Mitsuba XML referencing OBJ meshes. Keep relative paths together if later extracting the geometry for a renderer. This example only inspects it.

Download a tier's archives

Increment folders are numbered in tier order, so a tier is one pattern per component: Small is inc1-*, Medium inc[1-2]-*, Large inc[1-3]-*, Full inc*. A split or profile narrows it by file name. For example, Medium test-split core at 3.5 GHz with positions:

hf download Intelligence-Networking-Lab/Channels4World --repo-type dataset \
  --revision v1.0.0 --local-dir c4w \
  --include 'payload/3.5ghz/core/inc[1-2]-*/test-*' \
  --include 'payload/scene/positions/inc[1-2]-*/test-*'

In these patterns * also matches /. Detail uses payload/<3.5ghz|7ghz>/detail/... and is hosted for Small and Medium only, so the Large and Full patterns return Medium's detail. Positions and geometry archives are carrier-independent. The release root sits at the top of the repository, so these paths are also the local paths under c4w/.

Select with 🤗 Datasets

The catalogs load as ordinary tables, so standard tools can choose what to download:

from datasets import load_dataset
from huggingface_hub import snapshot_download

REPO, REV = "Intelligence-Networking-Lab/Channels4World", "v1.0.0"
scenes = load_dataset(REPO, "scenes", split="catalog", revision=REV)
files = load_dataset(REPO, "files", split="catalog", revision=REV)
groups = set(scenes.filter(lambda r: r["split"] == "test")["group"])
paths = [r["path"] for r in files
         if r["group"] in groups and r["kind"] == "payload" and r["component"] in ("positions", "core")
         and r["frequency_hz"] in (None, 3_500_000_000)]
assert paths, "No matching published payloads."
snapshot_download(REPO, repo_type="dataset", revision=REV, local_dir="c4w", allow_patterns=paths)

Use the catalog's actual profile values if narrowing further. The archives themselves also load with load_dataset("webdataset", ...); the HF guide pairs remote and local inputs and explains their decoded representation.

Arbitrary scenes: download the containing archives, then filter

Archives hold whole groups, so a list of scenes means two steps: download the archives that contain those scenes (from the catalogs), then filter records to those scenes when reading. The catalogs are two small Parquet files at the release root:

import pyarrow.parquet as pq
from huggingface_hub import hf_hub_download, snapshot_download

REPO, REV = "Intelligence-Networking-Lab/Channels4World", "v1.0.0"
for table in ("c4w-root/scenes.parquet", "c4w-root/files.parquet"):
    hf_hub_download(REPO, table, repo_type="dataset", revision=REV, local_dir="c4w")

wanted_scenes = {"urban_scene_019234"}                     # your scene list
scenes = pq.read_table("c4w/c4w-root/scenes.parquet").to_pylist()
files = pq.read_table("c4w/c4w-root/files.parquet").to_pylist()
groups = {s["group"] for s in scenes if s["scene_id"] in wanted_scenes}
archives = [f["path"] for f in files
            if f["kind"] == "payload" and f["group"] in groups
            and (f["component"], f["frequency_hz"]) in {("core", 3_500_000_000), ("positions", None)}]
snapshot_download(REPO, repo_type="dataset", revision=REV, local_dir="c4w", allow_patterns=archives)

Then read only those scenes: python read_archives.py c4w --scenes urban_scene_019234. The download includes the other scenes of the same groups; filtering skips them without reading their bytes. This works for any folder layout, because the catalog lists each archive's actual path.

Find the byte location of one record

With PyArrow available, the scene table identifies the group for an explicit scene; the members table maps a member path to its archive and byte location:

from pathlib import Path
import pyarrow.parquet as pq

RELEASE_ROOT = Path("c4w")             # the release root is the repository top level
scenes = pq.read_table(RELEASE_ROOT / "c4w-root/scenes.parquet").to_pylist()
scene_row = next(row for row in scenes if row["scene_id"] == SCENE_ID)
GROUP_ID = scene_row["group"]
# Download this group's members.parquet (and other needed metadata) first.
members = pq.read_table(
    RELEASE_ROOT / "groups" / GROUP_ID / "catalog/members.parquet"
).to_pylist()
core_member = (f"records/scene={SCENE_ID}/band_hz={CARRIER_HZ}/component=core/"
               f"bs{BS_ID:05d}.npz")
positions_member = f"records/scene={SCENE_ID}/positions.npz"
core_row = next(row for row in members if row["member_path"] == core_member)
pos_row = next(row for row in members if row["member_path"] == positions_member)
print(core_row["object_path"], pos_row["object_path"])

Retrieve the group metadata, schemas and archives at the same revision as the catalogs (tag v1.0.0). A TAR is the transfer unit and can contain many scenes, so one chosen record can require more bytes than that record's own payload size. Root files.parquet lists archive byte counts/hashes; members.parquet lists member byte counts/hashes. Scene-only payload size excludes root/schema/group metadata. data_offset and member_bytes locate the member's bytes inside the uncompressed TAR, so a byte-range read can fetch one record without the rest of the archive.

The published files.parquet is the authority for paths, sizes and hashes; reuse it for generated commands and size displays rather than keeping a second hand-written list.

Read one TAR member directly

After downloading the archives identified above, ordinary Python can read a single NPZ member without extracting the whole TAR:

import hashlib
import io
import tarfile
import numpy as np

def read_npz_member(archive_path, row):
    with tarfile.open(archive_path, "r:") as archive:
        member = archive.getmember(row["member_path"])
        if not member.isfile():
            raise ValueError("Expected a regular NPZ member.")
        with archive.extractfile(member) as stream:
            body = stream.read()
    if len(body) != row["member_bytes"]:
        raise ValueError("Member byte count mismatch.")
    if hashlib.sha256(body).hexdigest() != row["member_sha256"]:
        raise ValueError("Member hash mismatch.")
    with np.load(io.BytesIO(body), allow_pickle=False) as npz:
        return {name: npz[name] for name in npz.files if name != "__meta__"}

core = read_npz_member(RELEASE_ROOT / core_row["object_path"], core_row)
positions = read_npz_member(RELEASE_ROOT / pos_row["object_path"], pos_row)
i = int(np.searchsorted(core["link_ue_index"], UE_ID))
assert i < core["link_ue_index"].size and core["link_ue_index"][i] == UE_ID
lo, hi = map(int, core["link_path_offsets"][i:i + 2])
print(core["tau"][lo:hi], core["a_real"][lo:hi] + 1j * core["a_imag"][lo:hi])
print(np.linalg.norm(positions["ue_positions"][UE_ID] - positions["bs_positions"][BS_ID]))

The shared scene/carrier/BS/UE constants and UE-position join match the card. Check the NPZ __meta__ identity and dependencies when assembling data yourself; matching array lengths alone do not establish a core/detail association. The schema explains identities, hashes and path-axis alignment.

Or extract TARs to Tiny-like loose payloads

Prerequisite for this extraction example: Python with tarfile.data_filter, provided in 3.11.4+, including 3.12+. This does not raise the library's Python ≥3.11 requirement. It applies only to this standard-library extraction code.

from pathlib import Path
import tarfile

if not hasattr(tarfile, "data_filter"):
    raise RuntimeError("Use Python 3.11.4+ with tarfile.data_filter (including 3.12+).")
out = Path("unpacked")
out.mkdir(exist_ok=False)  # use a new destination
archives = {core_row["object_path"], pos_row["object_path"]}
for object_path in sorted(archives):
    with tarfile.open(RELEASE_ROOT / object_path, "r:") as archive:
        archive.extractall(out, filter="data")

A member records/scene=S/.../bs00000.npz becomes unpacked/records/scene=S/.../bs00000.npz: the archive's own folders are not part of the member name. The extracted folder has Tiny's layout, so the same inspection works on it:

import numpy as np

scene_dir = out / "records" / f"scene={SCENE_ID}"
core = np.load(scene_dir / f"band_hz={CARRIER_HZ}" / "component=core" / f"bs{BS_ID:05d}.npz")
positions = np.load(scene_dir / "positions.npz")
ue_ids = core["link_ue_index"]                    # retained UE IDs
row = int(np.searchsorted(ue_ids, UE_ID))         # this UE's link row
start, stop = core["link_path_offsets"][row:row + 2]
print(core["tau"][start:stop])
print(np.linalg.norm(positions["ue_positions"][UE_ID] - positions["bs_positions"][BS_ID]))

An archive holds a whole group of scenes, so extraction writes more scenes than the one you inspect.

Archive location, internal member path and extraction destinations

Ordinary TAR extraction writes payloads only. The library's c4w.extract(selection, dest) writes those selected member paths and unchanged payload bytes, preserves original group metadata/schemas, and creates a subset root and scene/file/record tables. Tiny uses that same loose subset representation. Simply copying a larger release manifest beside an extracted subset does not build a valid subset root.

Return to card · Schema · Library guide