Channels4World / docs /library-guide.md
INL-Yonsei's picture
Clarify CLI download hint in library guide
424268b verified
|
Raw History Blame Contribute Delete
8.33 kB

Library guide

The channels4world library (1.0.0) requires Python ≥3.11, NumPy and PyArrow. Install it with pip install channels4world; its full documentation is at https://github.com/JoonkyuJang/channels4world#readme. It reads local files and never downloads them. A download into the Hugging Face cache (snapshot_download without local_dir) works too: open the snapshot folder it returns.

Partial Tiny and direct reads

Opening a root reads c4w-root.json and every table referenced by that manifest. For Tiny these include scenes, files and included records. Payloads and group metadata load later. Downloading those root tables, shared schemas, the chosen scene's group metadata and its payloads permits direct access to that explicit scene even when the other Tiny payloads are absent. Do not select an arbitrary first scene when only one known scene has been downloaded.

from pathlib import Path
import channels4world as c4w

TINY_ROOT = Path("c4w/tiny")
SCENE_ID, CARRIER_HZ, BS_ID, UE_ID = "urban_scene_019234", 3_500_000_000, 0, 14

ds = c4w.open(TINY_ROOT)
scene = ds.scene(SCENE_ID)
record = scene.frequencies[CARRIER_HZ].base_stations[BS_ID].read()
positions = scene.read_positions()
link = record.get_link(UE_ID)        # BS 0 → UE 14: 16 retained paths

A loaded record's absent UE IDs mean no retained link; missing files and unpublished components raise separate availability errors. Selecting across partially downloaded loose Tiny before group metadata is available can conservatively plan other files in a touched group. For the first scene, use the card's narrow include command and explicit scene read; direct reads do not require every scene's payload.

Root-first planning for TAR releases

Download the release catalog (c4w-root.json and c4w-root/) at the release revision. missing() can then plan from the catalog alone. For groups whose members/snapshot are absent, it lists matching component/carrier TARs and requested scene assets, plus required metadata and schemas. Once metadata is local, it maps selected records to their TARs. Because a TAR contains the group's records for one component/carrier, either route uses archives as download units. Rerun after downloading to resolve unpublished requests and confirm completeness.

import channels4world as c4w

ds = c4w.open("c4w")                 # the release root is the repository top level
selection = ds.select(
    tier="small", frequencies_hz=[3_500_000_000], components=("positions", "core"),
)
report = selection.missing()
print(report)                        # files and total bytes
if report.files:
    print(report.hf_command(revision="v1.0.0"))

report.files are paths inside the opened root. report.repo_files are the same files as repository paths (identical for the release root; prefixed with tiny/ for Tiny), and report.local_dir is the folder that corresponds to the repository's top level. hf_command(revision=...) uses both and quotes every argument. It refuses an empty plan and roots that are not published as-is, such as a subset you extracted yourself, whose loose files exist only on your disk.

For long plans, avoid putting thousands of paths on a shell command line:

from huggingface_hub import snapshot_download

if report.files:
    snapshot_download(
        repo_id="Intelligence-Networking-Lab/Channels4World", repo_type="dataset",
        revision="v1.0.0", local_dir=report.local_dir,
        allow_patterns=report.repo_files,
    )
report = selection.missing()
if report.files:
    raise RuntimeError("Files are still missing; re-plan the download.")
if report.unpublished:
    raise RuntimeError(f"Requested components are not published: {report.unpublished}")

The published catalogs at that revision are the source of truth for paths, sizes and hashes. Without the library, the increment-folder patterns in the file guide select a whole tier.

Selections combine filters. ds.profiles lists the catalog's profile names:

metro_train = ds.select(tier="medium", split="train", profile="metropolitan",
                        frequencies_hz=[7_000_000_000], components=("positions", "core"))

Share a selection as a recipe

A recipe is a small JSON file that records a selection (tier, split, profiles, scene IDs, carriers, BS IDs and components) and the release it refers to. It holds no paths or commands, so whoever replays it plans the download from their own catalog:

with open("selection.json", "w") as fh:
    fh.write(c4w.recipe.dumps(selection.to_recipe(revision="v1.0.0")))

same = c4w.open("c4w").select_recipe("selection.json")

The command line does the same. c4w recipe never overwrites a file, so choose a new name:

c4w recipe c4w --tier small --frequency 3500000000 --components positions,core \
  --revision v1.0.0 -o small-core.json
c4w missing c4w --recipe small-core.json     # prints a pinned hf download command, or a snapshot_download hint for long plans

The download helper on the project website writes the same recipes. A recipe for another release is refused, and every filter is checked against the catalog exactly as select() checks it.

The examples below continue with the Small selection from above.

Iterate, extract or cache

for scene in selection.scenes():
    positions = scene.read_positions()
    for record in scene.records():  # selected scene preserves carrier/BS/component filters
        print(record.scene_id, record.frequency_hz, record.bs_id, record.n_links)

# Use new destinations after missing()/coverage checks have passed.
c4w.extract(selection, "small-loose", verify="basic", check_space=True)
c4w.to_cache(selection, "small-npy", verify="basic", check_space=True)

Packed TARs preserve original NPZ/ZIP records. extract preserves selected member_path values and original payload bytes and writes a common loose subset root. The optional NPY cache instead stores arrays plus indexes for memory-mapped repeated access; values, IDs, dtypes and ragged associations stay the same. Geometry remains ZIP. A cache is not another scene tier.

Arrays are read-only

Arrays returned by the library are read-only views of the stored data. Arithmetic such as record.core["tau"] * 1e9 creates a new array; to modify values in place, copy first (record.copy() or np.array(...)).

Reads, file handles and disk writes

Verb Meaning Examples
read / read_* Load data into memory bs.read(), scene.read_positions()
open_* Return a handle to close scene.open_geometry() returns ZipFile
extract / extract_* Write files and return a path c4w.extract(selection, dest), scene.extract_geometry(dest)

Geometry extraction requires a destination because renderers load XML and referenced meshes from disk. Positions are arrays. No hidden temporary geometry location is assumed.

verify="basic" checks declared bytes and array structure. verify="full" adds scientific/content-proof checks for loaded components. A full core+detail read checks their association together. Extraction/cache conversion does not replace that pairwise read check. See the schema reference.

Optional transforms

import numpy as np
from channels4world import transforms as T

rms_delay_s = T.delay_spread(record)
response = T.frequency_response(
    record, np.array([-1e6, 0.0, 1e6]), delay_reference="absolute",
)

These return new writable arrays describing retained paths. Frequency inputs above are offsets from the record's carrier, not absolute frequencies. T.pad_paths(record.core, "tau") gives one row per link, (links, 16), with a mask of stored paths, and T.pad_interactions(record.detail, "interaction_vertex") one row per path, (paths, 4, 3); both match the card's padding snippet. Stored a_real + 1j*a_imag is a scalar passband coefficient excluding carrier-delay phase; tau is absolute propagation delay. Do not add antenna effects twice. The conventions reference provides the details.

Return to card · Without the library