from __future__ import annotations
import time
import numpy as np
from rustmatrix import Scatterer
from rustmatrix import orientation as rs_orient
from rustmatrix import radar
from rustmatrix.tmatrix_aux import geom_horiz_back, wl_W
from rustmatrix.refractive import mi
def main() -> None:
D_eq_mm = 0.5
ice_m = mi(wl_W, 0.9) print(f"λ = {wl_W} mm (W-band), m_ice(0.9 g/cm³) = {ice_m}")
base_kwargs = dict(
radius=D_eq_mm / 2.0,
wavelength=wl_W,
m=ice_m,
axis_ratio=0.5, ddelt=1e-4,
ndgs=2,
)
pdf = rs_orient.gaussian_pdf(std=20.0, mean=90.0)
schemes = [
("orient_single",
rs_orient.orient_single,
{"or_pdf": pdf}),
("orient_averaged_fixed (n_alpha=6, n_beta=12)",
rs_orient.orient_averaged_fixed,
{"or_pdf": pdf, "n_alpha": 6, "n_beta": 12}),
("orient_averaged_adaptive",
rs_orient.orient_averaged_adaptive,
{"or_pdf": pdf}),
]
print(f"{'scheme':<50} {'Z_dr [dB]':>12} {'time [s]':>10}")
print("-" * 74)
for label, orient, extra in schemes:
s = Scatterer(**base_kwargs, **extra)
s.orient = orient
s.set_geometry(geom_horiz_back)
t0 = time.perf_counter()
zdr = radar.Zdr(s)
elapsed = time.perf_counter() - t0
print(f"{label:<50} {10 * np.log10(zdr):>+12.4f} {elapsed:>10.3f}")
print()
print("Takeaway: the 'fixed' scheme is ~100× faster than 'adaptive'")
print("and matches it to within a few hundredths of a dB in Z_dr for")
print("smooth PDFs — pick 'fixed' for PSD-integrated work.")
if __name__ == "__main__":
main()