Download examples/read_sample.py from PATIENTHZ/low-altitude-rf-worldmodel: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/datasets/PATIENTHZ/low-altitude-rf-worldmodel/resolve/main/examples/read_sample.py
- Command line
-
hf download hf://datasets/PATIENTHZ/low-altitude-rf-worldmodel/examples/read_sample.py
-
curl -L -o read_sample.py https://huggingface.co/datasets/PATIENTHZ/low-altitude-rf-worldmodel/resolve/main/examples/read_sample.py
1.21 kB
| """Read an extracted training sample. Needs h5py, numpy and Pillow only.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import h5py | |
| import numpy as np | |
| from PIL import Image | |
| parser=argparse.ArgumentParser() | |
| parser.add_argument('sample_directory',type=Path) | |
| parser.add_argument('--frame',type=int,default=0) | |
| parser.add_argument('--height-index',type=int,default=0) | |
| args=parser.parse_args();root=args.sample_directory | |
| with h5py.File(root/'training.h5','r') as h: | |
| rss_dbm=h['rf/rss_dbm'][args.frame,args.height_index] | |
| valid=np.isfinite(rss_dbm) | |
| timestamp=float(h['state/timestamps_s'][args.frame]) | |
| height=float(h['state/height_levels_m'][args.height_index]) | |
| sync=json.loads((root/'visual/synchronization.json').read_text()) | |
| frame=sync['frames'][args.frame] | |
| assert frame['timestamp_s']==timestamp | |
| images={view:np.asarray(Image.open(root/'visual'/frame['cameras'][view]['rgb']).convert('RGB')) | |
| for view in ['bs','topdown','elevated']} | |
| print(json.dumps(dict(timestamp_s=timestamp,height_m=height,rss_shape=list(rss_dbm.shape), | |
| unit='dBm',valid_fraction=float(valid.mean()), | |
| rgb_shapes={view:list(img.shape) for view,img in images.items()}),ensure_ascii=False,indent=2)) | |