"""Download one aligned training example and save a preview from its arrays.""" import argparse from pathlib import Path import numpy as np from PIL import Image, ImageDraw from huggingface_hub import HfApi, hf_hub_download REPO = 'KAS2003/xfield-sim-core' SAMPLE = 'demo/town12_fit.npz' def main(): parser = argparse.ArgumentParser() parser.add_argument('--revision', help='Dataset revision, defaults to the current release') parser.add_argument('--output', type=Path, default=Path('xfield_example.png')) args = parser.parse_args() rev = args.revision or HfApi(token=False).dataset_info(REPO, revision='refs/heads/main', expand=['sha']).sha file = hf_hub_download(REPO, SAMPLE, repo_type='dataset', revision=rev, token=False) with np.load(file, allow_pickle=False) as z: cube, rgb, K, T = (z[n] for n in ('cube','image_rgb','K','T')) assert cube.dtype == np.complex64 and cube.shape == (512,25,64) and np.isfinite(cube).all() and np.any(cube) assert rgb.shape == (3,360,640) and rgb.dtype == np.uint8 assert K.shape == (3,3) and T.shape == (4,4) and np.isfinite(K).all() and np.isfinite(T).all() assert bool(z['dense_present']) and all(n in z.files for n in ('role','xr_gt','static_y','dense_sem','dense_height','dense_lane')) print('key', str(z['key'])) for n in ('cube','image_rgb','K','T','role','xr_gt','static_y','dense_sem','dense_height','dense_lane'): print(n, z[n].shape, z[n].dtype) power = 10*np.log10(np.maximum((np.abs(cube)**2).sum(axis=2),1e-20)) lo, hi = np.percentile(power,[5,99]) ra = (255*np.clip((power-lo)/max(hi-lo,1e-6),0,1)).astype('uint8') camera = Image.fromarray(rgb.transpose(1,2,0)) radar = Image.fromarray(ra[::-1]).resize((192,360)).convert('RGB') out = Image.new('RGB',(832,388),'white') out.paste(camera,(0,28)); out.paste(radar,(640,28)) pen=ImageDraw.Draw(out);pen.text((7,7),'Ego RGB',fill='black');pen.text((648,7),'Radar power (range / angle)',fill='black') out.save(args.output) print('revision',rev) print('preview',args.output) if __name__=='__main__': main()