142 """Return True and print a message if the raw chi2 increases
147 diff = np.diff(chi2Data.raw)
148 ratio = diff/chi2Data.raw[:-1]
149 if np.any(ratio > threshold):
150 increased = np.where(ratio > threshold)[0]
151 print(f
"{title} has increasing {label} chi2:")
152 for x
in zip(chi2Data.raw[increased], chi2Data.raw[increased + 1],
153 ratio[increased], diff[increased]):
154 print(f
"{x[0]:.6} -> {x[1]:.6} (ratio: {x[2]:.6}, diff: {x[3]:.6})")
159 """Return the values extracted from the chi2 statements in the logfile.
168 for line
in opened_log:
172 for line
in opened_log:
178 if match
is not None:
179 kind.append(match.group(
"kind"))
180 chi2.append(match.group(
"chi2"))
181 ndof.append(match.group(
"ndof"))
182 reduced.append(match.group(
"reduced_chi2"))
188 return Chi2Data(kind, np.array(chi2, dtype=np.float64),
189 np.array(ndof, dtype=int), np.array(reduced, dtype=np.float64))
191 def _plot(self, astrometry, photometry, title):
192 """Generate plots of chi2 values.
196 astrometry : `Chi2Data` or None
197 The as-read astrometry data, or None if there is none to plot.
198 photometry : `Chi2Data` or None
199 The as-read photometry data, or None if there is none to plot.
201 Title for the whole plot.
203 palette = itertools.cycle(sns.color_palette())
206 ax0, ax1 = self.
fig.
subplots(ncols=2, gridspec_kw={
"wspace": 0.05})
210 if max(
getattr(astrometry,
"raw", [0])) > 100
or max(
getattr(photometry,
"raw", [0])) > 100:
211 ax0.set_yscale(
"log")
212 ax1.yaxis.set_label_position(
"right")
213 ax1.yaxis.tick_right()
215 if astrometry
is not None:
216 patch1, patch2 = self.
_plot_axes(ax0, ax1, astrometry, palette, label=
"astrometry")
218 if photometry
is not None:
219 patch3, patch4 = self.
_plot_axes(ax0, ax1, photometry, palette, label=
"photometry")
223 handles, labels = ax0.get_legend_handles_labels()
224 ax1.legend(handles, labels)
227 """Make the chi2 and degrees of freedom subplots."""
228 xrange = np.arange(0,
len(chi2Data.raw), dtype=float)
231 ax0.axhline(1, color=
'grey', ls=
'--')
233 ax0.axvline(chi2Data.init_count-0.5, color=
'grey', lw=0.9)
234 color =
next(palette)
235 patch1 = ax0.plot(xrange[:chi2Data.init_count], chi2Data.raw[:chi2Data.init_count],
'*', ms=10,
236 label=f
"{label} pre-init", color=color)
237 patch2 = ax0.plot(xrange[chi2Data.init_count:], chi2Data.raw[chi2Data.init_count:],
'o', ms=10,
238 label=f
"{label} post-init", color=color)
239 patch1 = ax0.plot(xrange[:chi2Data.init_count], chi2Data.reduced[:chi2Data.init_count],
'*',
240 markerfacecolor=
"none", ms=10, color=color)
241 patch2 = ax0.plot(xrange[chi2Data.init_count:], chi2Data.reduced[chi2Data.init_count:],
'o',
242 markerfacecolor=
"none", ms=10, label=f
"{label} reduced", color=color)
244 ax0.set_xlabel(
"Iteration #", fontsize=20)
245 ax0.set_ylabel(
r"$\chi ^2$", fontsize=20)
248 ax1.axvline(chi2Data.init_count-0.5, color=
'grey', lw=0.9)
249 ax1.plot(xrange[:chi2Data.init_count], chi2Data.ndof[:chi2Data.init_count],
'*', ms=10,
250 label=
"pre-init", color=color)
251 ax1.plot(xrange[chi2Data.init_count:], chi2Data.ndof[chi2Data.init_count:],
'o', ms=10,
252 label=
"post-init", color=color)
254 ax1.set_xlabel(
"Iteration #", fontsize=20)
255 ax1.set_ylabel(
"# degrees of freedom", fontsize=20)
257 return patch1[0], patch2[0]