Datasets:
Download compact_uint16/read_sample.py from DaftJun/RFWM: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/datasets/DaftJun/RFWM/resolve/main/compact_uint16/read_sample.py
- Command line
-
hf download hf://datasets/DaftJun/RFWM/compact_uint16/read_sample.py
-
curl -L -o read_sample.py https://huggingface.co/datasets/DaftJun/RFWM/resolve/main/compact_uint16/read_sample.py
1.73 kB
| """Read one extracted NumPy RF episode; returned RSS values are float32 dBm.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| def load_rss(directory, frames=slice(None)): | |
| directory = Path(directory) | |
| metadata = json.loads((directory / "metadata.json").read_text()) | |
| stored = np.load(directory / metadata["training_file"], mmap_mode="r", allow_pickle=False) | |
| selected = stored[frames] | |
| quantization_file = metadata.get("quantization_file") | |
| if quantization_file: | |
| encoding = json.loads((directory / quantization_file).read_text()) | |
| if encoding["schema"] != "uint16_centi_dbm_v1" or stored.dtype != np.dtype("uint16"): | |
| raise ValueError("Unsupported RSS encoding") | |
| values = (selected.astype(np.int32) - encoding["integer_offset"]).astype(np.float32) | |
| values *= np.float32(encoding["step_db"]) | |
| values[selected == encoding["invalid_code"]] = np.nan | |
| else: | |
| if stored.dtype != np.dtype("float32"): | |
| raise ValueError("Expected direct float32 RSS") | |
| values = selected | |
| return np.ascontiguousarray(values) | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("directory", type=Path) | |
| parser.add_argument("--frame", type=int, default=0) | |
| args = parser.parse_args() | |
| rss = load_rss(args.directory, args.frame) | |
| valid = rss[np.isfinite(rss)] | |
| print(json.dumps(dict(unit="dBm", shape=list(rss.shape), dtype=str(rss.dtype), | |
| valid_voxels=int(valid.size), | |
| min_dbm=float(valid.min()) if valid.size else None, | |
| max_dbm=float(valid.max()) if valid.size else None))) | |