97 def __init__(self, config, name, schema, metadata, logName=None):
98 super().
__init__(config, name, schema, metadata, logName=logName)
101 name +
"_centroid_x", type=
"D", doc=
"Trail centroid X coordinate.", units=
"pixel")
103 name +
"_centroid_y", type=
"D", doc=
"Trail centroid Y coordinate.", units=
"pixel")
104 self.
keyX0 = schema.addField(name +
"_x0", type=
"D", doc=
"Trail head X coordinate.", units=
"pixel")
105 self.
keyY0 = schema.addField(name +
"_y0", type=
"D", doc=
"Trail head Y coordinate.", units=
"pixel")
106 self.
keyX1 = schema.addField(name +
"_x1", type=
"D", doc=
"Trail tail X coordinate.", units=
"pixel")
107 self.
keyY1 = schema.addField(name +
"_y1", type=
"D", doc=
"Trail tail Y coordinate.", units=
"pixel")
108 self.
keyLength = schema.addField(name +
"_length", type=
"D", doc=
"Length of trail.", units=
"pixel")
109 self.
keyTheta = schema.addField(name +
"_angle", type=
"D", doc=
"Angle of trail from +x-axis.")
110 self.
keyFlux = schema.addField(name +
"_flux", type=
"D", doc=
"Trailed source flux.", units=
"count")
111 self.
keyRChiSq = schema.addField(name +
"_rChiSq", type=
"D", doc=
"Reduced chi-squared of fit")
114 self.
FAILURE = flagDefs.addFailureFlag(
"No trailed-sources measured")
115 self.
NON_CONVERGE = flagDefs.add(
"flag_nonConvergence",
"Optimizer did not converge")
116 self.
NO_NAIVE = flagDefs.add(
"flag_noNaive",
"Naive measurement contains NaNs")
122 """Run the Veres trailed source measurement plugin.
126 measRecord : `lsst.afw.table.SourceRecord`
127 Record describing the object being measured.
128 exposure : `lsst.afw.image.Exposure`
129 Pixel data to be measured.
133 lsst.meas.base.SingleFramePlugin.measure
139 flux = measRecord.get(
"ext_trailedSources_Naive_flux")
140 length = measRecord.get(
"ext_trailedSources_Naive_length")
141 theta = measRecord.get(
"ext_trailedSources_Naive_angle")
142 if not np.isfinite(flux)
or not np.isfinite(length)
or not np.isfinite(theta):
150 cutout = getMeasurementCutout(measRecord, exposure)
153 model = VeresModel(cutout)
156 params = np.array([xc, yc, flux, length, theta])
157 results = sciOpt.minimize(
158 model, params, method=self.config.optimizerMethod, jac=model.gradient)
161 if not results.success:
167 xc_fit, yc_fit, flux_fit, length_fit, theta_fit = results.x
169 x0_fit = xc_fit - a * np.cos(theta_fit)
170 y0_fit = yc_fit - a * np.sin(theta_fit)
171 x1_fit = xc_fit + a * np.cos(theta_fit)
172 y1_fit = yc_fit + a * np.sin(theta_fit)
173 rChiSq = results.fun / (cutout.image.array.size - 6)
176 measRecord.set(self.
keyXC, xc_fit)
177 measRecord.set(self.
keyYC, yc_fit)
178 measRecord.set(self.
keyX0, x0_fit)
179 measRecord.set(self.
keyY0, y0_fit)
180 measRecord.set(self.
keyX1, x1_fit)
181 measRecord.set(self.
keyY1, y1_fit)
182 measRecord.set(self.
keyFlux, flux_fit)
183 measRecord.set(self.
keyLength, length_fit)
184 measRecord.set(self.
keyTheta, theta_fit)