#!/usr/bin/env python """Plot the instrument's relative spectral response R(lambda) from responsivity.csv. Shows the calibrated response curve (counts per unit irradiance, normalised to a median of 1 over the fit band). The curve is defined only where the calibration is valid; outside that band responsivity.csv holds NaN and nothing is drawn. Usage: python plot_response.py [responsivity.csv] [--png fig.png] """ import argparse import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from response import load_csv p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) p.add_argument("responsivity", nargs="?", default="responsivity.csv") p.add_argument("--png", default="response.png") args = p.parse_args() wl, r = load_csv(args.responsivity) good = np.isfinite(r) lo, hi = wl[good].min(), wl[good].max() fig, ax = plt.subplots(figsize=(9, 5)) ax.plot(wl, r, lw=1.8, color="C3") ax.set_xlabel("wavelength (nm)") ax.set_ylabel("relative responsivity R(λ)\n(median 1 over the band)") ax.set_title(f"Instrument spectral response, calibrated {lo:.0f}-{hi:.0f} nm") ax.set_ylim(bottom=0) ax.grid(alpha=0.3) fig.tight_layout() fig.savefig(args.png, dpi=130) print(f"calibrated band {lo:.0f}-{hi:.0f} nm, peak R={np.nanmax(r):.2f} at " f"{wl[np.nanargmax(r)]:.0f} nm") print(f"wrote {args.png}")