Visualise response and Planck spectrum fits

This commit is contained in:
2026-09-10 15:27:04 +01:00
parent d62864bd89
commit 192c595441
2 changed files with 110 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
#!/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}")