MCPcopy Create free account
hub / github.com/PolymathicAI/AstroCLIP / plot_spectrum

Method plot_spectrum

astroclip/callbacks.py:62–84  ·  view source on GitHub ↗
(self, batch, output)

Source from the content-addressed store, hash-verified

60 super().__init__()
61
62 def plot_spectrum(self, batch, output):
63 sample_id = 3
64
65 bs = len(batch["spectrum"])
66 sp_rec = batch["target"][:, 1:, 2:99].reshape(bs, -1)[sample_id]
67 in_rec = batch["input"][:, 1:, 2:99].reshape(bs, -1)[sample_id]
68 out_rec = output[:, 1:, 2:99].reshape(bs, -1)[sample_id]
69
70 # plot the moving average of the spectrum
71 win = 20
72
73 sp_rec = [sp_rec[i : i + win].mean().item() for i in range(0, len(sp_rec), win)]
74 in_rec = [in_rec[i : i + win].mean().item() for i in range(0, len(in_rec), win)]
75 out_rec = [
76 out_rec[i : i + win].mean().item() for i in range(0, len(out_rec), win)
77 ]
78
79 fig = plt.figure()
80 plt.plot(sp_rec, label="original")
81 plt.plot(in_rec, label="dropped")
82 plt.plot(out_rec, label="reconstructed")
83 plt.legend()
84 return fig
85
86 def on_validation_batch_start(
87 self,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected