A 1D convolutional neural network that predicts galaxy redshifts from
high-resolution JWST/NIRSpec spectra, with calibrated uncertainty estimates.
The model is roughly calibrated (calibration std 1.16 against a target of 1.0)
but has a substantial outlier population: about one in five galaxies is
predicted badly, typically through a catastrophic line misidentification. Treat
the predicted σ as meaningful — high-σ predictions are the unreliable ones.
1import numpy as np
2from zestimatr import download_pretrained, load_model, predict
3
4ckpt = download_pretrained() # pulls best_zhead_hires.pth from this repo
5zhead, norm_params = load_model(ckpt)
6
7# flux: (N, L) array; wavelength in microns. Resampled to the 2500-pt grid.
8out = predict(flux, zhead, norm_params, wavelength=wavelength)
9print(out["z_pred"], out["z_uncertainty"])
1import numpy as np
2from huggingface_hub import hf_hub_download
3from zestimatr import download_pretrained, load_model, predict
4
5zhead, norm_params = load_model(download_pretrained())
6
7path = hf_hub_download("aryana-haghjoo/zestimatr-jades-dr4",
8 "eval_DR4.npz", repo_type="dataset")
9d = np.load(path, allow_pickle=True)
10
11out = predict(d["flux_high"][:5], zhead, norm_params,
12 wavelength=d["wavelength_high"])
13for zp, zs, zt in zip(out["z_pred"], out["z_uncertainty"], d["z"][:5]):
14 print(f"z_pred={zp:.3f} +/- {zs:.3f} (true {zt:.3f})")