337.1 / 777.4 nm photometer

Physicist verification companion · source release r4 · mathematical checks and unresolved limits

Review index · Download raw source

reference/cloud/extract_ghm_bracket.py

1"""Extract a private local337nm bracket from the externally obtained GHMNetCDF.2No download and no redistribution of the source table. Requires numpy+h5py.3"""4from pathlib import Path5import argparse,sys,json,hashlib6import numpy as np7p=argparse.ArgumentParser();p.add_argument("--source",required=True);p.add_argument("--out");p.add_argument("--verify-npz");p.add_argument("--reader-path");a=p.parse_args()8if a.reader_path:sys.path.insert(0,a.reader_path)9import h5py10with h5py.File(a.source,"r")as f:11    wav=f["wav"][:].astype(float);ids=[int(np.flatnonzero(wav<=337.1)[-1]),int(np.flatnonzero(wav>=337.1)[0])]12    data={"wavelength_nm":wav[ids],"theta_deg":f["theta"][:].astype(float),"reff_um":f["reff"][:].astype(float),13          "phase":f["phase"][:,ids,:,:],"ssa":f["ssa"][:,ids],"ext_km_inverse":f["ext"][:,ids]}14checks={}15if a.verify_npz:16    with np.load(a.verify_npz)as z:checks={k:bool(np.array_equal(v,z[k]))for k,v in data.items()}17    if not all(checks.values()):raise ValueError("Local bracket does not exactly match original table extraction")18if a.out:np.savez_compressed(a.out,**data)19print(json.dumps({"source_sha256":hashlib.sha256(Path(a.source).read_bytes()).hexdigest(),"bracket_nm":data["wavelength_nm"].tolist(),"verification":checks,"raw_output_written":bool(a.out)}))20