cesm_hawc.convergence¶
Convergence diagnostics for the L2 retrieval.
The retrieval’s output dataset carries no reliable convergence flag. The
dependable source is the verbose=2 output that
scipy.optimize.least_squares prints during the retrieval: capture
stdout around the call (e.g. with contextlib.redirect_stdout) and pass
it to parse_scipy_convergence().
parse_scipy_convergence¶
def parse_scipy_convergence(captured_stdout: str) -> dictRead the convergence status from least_squares verbose output.
Parameters¶
captured_stdout(str) — Everythingscipy.optimize.least_squares(..., verbose=2)printed during one retrieval.
Returns¶
dict —
converged(bool),termination_reason("ftol","xtol","gtol","max_nfev"or"max_iter") andn_function_evaluations(int). Each value isNoneif no recognized message was found.
extract_l2_native_diagnostics¶
def extract_l2_native_diagnostics(l2_obj) -> dictRead the iteration count and final cost from an L2 dataset.
Use these as a cross-check on parse_scipy_convergence().
Parameters¶
l2_obj(xarray.Dataset or None) — The"l2"product fromsimulator.run().
Returns¶
dict —
l2_num_iterations(int) andl2_final_cost(float), eachNoneif missing or unreadable.