# Last edited on 2025-08-17 13:25:37 by stolfi def plot_mask_spectrum\ ( page, vset, mask, bands, illum_tb, wlen_tb, \ savg, P, rdev ): # Writes a file suitable for plotting given the results {savg,P,rdev} # from the analysis for page {page}, analysis set {vset}, mask name {mask}, # and a list of {nb} spectral bands with names {bands[0..nb-1]}. # # The file has {nb} lines with format # # "{bands[ib]} {illum[ib]} {wlen[ib]} {savg[ib]} {P[ib,0]} {tdev[ib]}" # # where # # {illum[ib] = illum_tb[bands[ib]]}, # {wlen[ib] = wlen_tb[bands[ib]]}, # {tdev[ib] = sqrt(SUM(P[ib,ie]^2 : ie\in 1..ne-1) + rdev[ib]^2) # # The column {tdev[ib]} is the deviation of the spectra on band {ib} # that is not accounted by the principal component {P[ib,0]}. # # Then calls the script {plot_mask_spectrum.sh} to create a plot of that # spectrum as a ".png" file. # nb, ne = numpy.shape(P) assert numpy.shape(bands) == (nb,), "bad {bands}" assert numpy.shape(savg) == (nb,), "bad {savg}" assert numpy.shape(rdev) == (nb,), "bad {rdev}" ddir = f"pages/{page}/vsets/{vset}/masks" bash(f"mkdir -p {edir}") dfile = f"{ddir}/{mask}-plot.txt" with open(dfile, "w") as wr: for ib in range(nb): sum2_P = 0; for ke in range(1,ne): sum2_P += P[ib,ke]**2 tdev = sqrt(sum2_P + rdev[ib]**2) wr.write("%-15s" % bands[ib]) illum = illum_tb[bands[ib]] wr.write(f" {illum:d}") wlen = wlen_tb[bands[ib]] wr.write(" %7.1f" % wlen) wr.write(" %7.4f" % savg[ib]) wr.write(" %+7.4f" % P[ib,0]) wr.write(" %7.4f" % tdev) wr.write("\n") wr.close() bash(f"plot_mask_spectrum.sh {page} {vset} {mask}") return # ----------------------------------------------------------------------