Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is part of ap_association. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22"""Defines afw schemas and conversions for use in ap_association tasks. 

23 

24Until a more finalized interface between the alert production database (APDB) can 

25be established, we put many utility functions for converting `lsst.afw.table` and 

26`lsst.afw.image` objects to a PPD. This includes both mapping schemas between 

27different catalogs and the DB. 

28""" 

29 

30__all__ = ["make_dia_object_schema", 

31 "make_dia_source_schema", 

32 "make_dia_forced_source_schema", 

33 "getCcdVisitSchemaSql"] 

34 

35from collections import OrderedDict as oDict 

36 

37import lsst.afw.table as afwTable 

38from lsst.daf.base import DateTime 

39 

40 

41def make_dia_object_schema(filter_names=None): 

42 """Define and create the minimal schema required for a DIAObject. 

43 

44 Parameters 

45 ---------- 

46 filter_names : `list` of `str` 

47 Names of the filters expect and compute means for. 

48 

49 Returns 

50 ------- 

51 schema : `lsst.afw.table.Schema` 

52 Minimal schema for DIAObjects. 

53 """ 

54 schema = afwTable.SourceTable.makeMinimalSchema() 

55 # For the MVP/S we currently only care about the position though 

56 # in the future we will add summary computations for fluxes etc. 

57 # as well as their errors. 

58 

59 # TODO: In the future we would like to store a covariance of the coordinate. 

60 # This functionality is not defined currently in the stack, so we will hold 

61 # off until it is implemented. This is to be addressed in DM-7101. 

62 

63 # Generated automatically from apdb-schema.yaml in dax_apdb/data. 

64 schema.addField('validityStart', type='L', 

65 doc='Time when validity of this diaObject starts.') 

66 schema.addField('validityEnd', type='L', 

67 doc='Time when validity of this diaObject ends.') 

68 schema.addField('raErr', type='Angle', 

69 doc='Uncertainty of ra.') 

70 schema.addField('declErr', type='Angle', 

71 doc='Uncertainty of decl.') 

72 schema.addField('ra_decl_Cov', type='F', 

73 doc='Covariance between ra and decl.') 

74 schema.addField('radecTai', type='D', 

75 doc='Time at which the object was at a position ra/decl.') 

76 schema.addField('pmRa', type='F', 

77 doc='Proper motion (ra).') 

78 schema.addField('pmRaErr', type='F', 

79 doc='Uncertainty of pmRa.') 

80 schema.addField('pmDecl', type='F', 

81 doc='Proper motion (decl).') 

82 schema.addField('pmDeclErr', type='F', 

83 doc='Uncertainty of pmDecl.') 

84 schema.addField('parallax', type='F', 

85 doc='Parallax.') 

86 schema.addField('parallaxErr', type='F', 

87 doc='Uncertainty of parallax.') 

88 schema.addField('pmRa_pmDecl_Cov', type='F', 

89 doc='Covariance of pmRa and pmDecl.') 

90 schema.addField('pmRa_parallax_Cov', type='F', 

91 doc='Covariance of pmRa and parallax.') 

92 schema.addField('pmDecl_parallax_Cov', type='F', 

93 doc='Covariance of pmDecl and parallax.') 

94 schema.addField('pmParallaxLnL', type='F', 

95 doc='Natural log of the likelihood of the linear proper motion parallax fit.') 

96 schema.addField('pmParallaxChi2', type='F', 

97 doc='Chi^2 static of the model fit.') 

98 schema.addField('pmParallaxNdata', type='I', 

99 doc='The number of data points used to fit the model.') 

100 schema.addField('uPSFluxMean', type='F', 

101 doc='Weighted mean point-source model magnitude for u filter.') 

102 schema.addField('uPSFluxMeanErr', type='F', 

103 doc='Standard error of uPSFluxMean.') 

104 schema.addField('uPSFluxSigma', type='F', 

105 doc='Standard deviation of the distribution of uPSFlux.') 

106 schema.addField('uPSFluxChi2', type='F', 

107 doc='Chi^2 statistic for the scatter of uPSFlux around uPSFluxMean.') 

108 schema.addField('uPSFluxNdata', type='I', 

109 doc='The number of data points used to compute uPSFluxChi2.') 

110 schema.addField('uFPFluxMean', type='F', 

111 doc='Weighted mean forced photometry flux for u filter.') 

112 schema.addField('uFPFluxMeanErr', type='F', 

113 doc='Standard error of uFPFluxMean.') 

114 schema.addField('uFPFluxSigma', type='F', 

115 doc='Standard deviation of the distribution of uFPFlux.') 

116 schema.addField('gPSFluxMean', type='F', 

117 doc='Weighted mean point-source model magnitude for g filter.') 

118 schema.addField('gPSFluxMeanErr', type='F', 

119 doc='Standard error of gPSFluxMean.') 

120 schema.addField('gPSFluxSigma', type='F', 

121 doc='Standard deviation of the distribution of gPSFlux.') 

122 schema.addField('gPSFluxChi2', type='F', 

123 doc='Chi^2 statistic for the scatter of gPSFlux around gPSFluxMean.') 

124 schema.addField('gPSFluxNdata', type='I', 

125 doc='The number of data points used to compute gPSFluxChi2.') 

126 schema.addField('gFPFluxMean', type='F', 

127 doc='Weighted mean forced photometry flux for g filter.') 

128 schema.addField('gFPFluxMeanErr', type='F', 

129 doc='Standard error of gFPFluxMean.') 

130 schema.addField('gFPFluxSigma', type='F', 

131 doc='Standard deviation of the distribution of gFPFlux.') 

132 schema.addField('rPSFluxMean', type='F', 

133 doc='Weighted mean point-source model magnitude for r filter.') 

134 schema.addField('rPSFluxMeanErr', type='F', 

135 doc='Standard error of rPSFluxMean.') 

136 schema.addField('rPSFluxSigma', type='F', 

137 doc='Standard deviation of the distribution of rPSFlux.') 

138 schema.addField('rPSFluxChi2', type='F', 

139 doc='Chi^2 statistic for the scatter of rPSFlux around rPSFluxMean.') 

140 schema.addField('rPSFluxNdata', type='I', 

141 doc='The number of data points used to compute rPSFluxChi2.') 

142 schema.addField('rFPFluxMean', type='F', 

143 doc='Weighted mean forced photometry flux for r filter.') 

144 schema.addField('rFPFluxMeanErr', type='F', 

145 doc='Standard error of rFPFluxMean.') 

146 schema.addField('rFPFluxSigma', type='F', 

147 doc='Standard deviation of the distribution of rFPFlux.') 

148 schema.addField('iPSFluxMean', type='F', 

149 doc='Weighted mean point-source model magnitude for i filter.') 

150 schema.addField('iPSFluxMeanErr', type='F', 

151 doc='Standard error of iPSFluxMean.') 

152 schema.addField('iPSFluxSigma', type='F', 

153 doc='Standard deviation of the distribution of iPSFlux.') 

154 schema.addField('iPSFluxChi2', type='F', 

155 doc='Chi^2 statistic for the scatter of iPSFlux around iPSFluxMean.') 

156 schema.addField('iPSFluxNdata', type='I', 

157 doc='The number of data points used to compute iPSFluxChi2.') 

158 schema.addField('iFPFluxMean', type='F', 

159 doc='Weighted mean forced photometry flux for i filter.') 

160 schema.addField('iFPFluxMeanErr', type='F', 

161 doc='Standard error of iFPFluxMean.') 

162 schema.addField('iFPFluxSigma', type='F', 

163 doc='Standard deviation of the distribution of iFPFlux.') 

164 schema.addField('zPSFluxMean', type='F', 

165 doc='Weighted mean point-source model magnitude for z filter.') 

166 schema.addField('zPSFluxMeanErr', type='F', 

167 doc='Standard error of zPSFluxMean.') 

168 schema.addField('zPSFluxSigma', type='F', 

169 doc='Standard deviation of the distribution of zPSFlux.') 

170 schema.addField('zPSFluxChi2', type='F', 

171 doc='Chi^2 statistic for the scatter of zPSFlux around zPSFluxMean.') 

172 schema.addField('zPSFluxNdata', type='I', 

173 doc='The number of data points used to compute zPSFluxChi2.') 

174 schema.addField('zFPFluxMean', type='F', 

175 doc='Weighted mean forced photometry flux for z filter.') 

176 schema.addField('zFPFluxMeanErr', type='F', 

177 doc='Standard error of zFPFluxMean.') 

178 schema.addField('zFPFluxSigma', type='F', 

179 doc='Standard deviation of the distribution of zFPFlux.') 

180 schema.addField('yPSFluxMean', type='F', 

181 doc='Weighted mean point-source model magnitude for y filter.') 

182 schema.addField('yPSFluxMeanErr', type='F', 

183 doc='Standard error of yPSFluxMean.') 

184 schema.addField('yPSFluxSigma', type='F', 

185 doc='Standard deviation of the distribution of yPSFlux.') 

186 schema.addField('yPSFluxChi2', type='F', 

187 doc='Chi^2 statistic for the scatter of yPSFlux around yPSFluxMean.') 

188 schema.addField('yPSFluxNdata', type='I', 

189 doc='The number of data points used to compute yPSFluxChi2.') 

190 schema.addField('yFPFluxMean', type='F', 

191 doc='Weighted mean forced photometry flux for y filter.') 

192 schema.addField('yFPFluxMeanErr', type='F', 

193 doc='Standard error of yFPFluxMean.') 

194 schema.addField('yFPFluxSigma', type='F', 

195 doc='Standard deviation of the distribution of yFPFlux.') 

196 # Mapping of arrays and BLOBs is not currently supported by the APDB so we 

197 # these columns out. 

198 # schema.addField('uLcPeriodic', type='ArrayF', 

199 # doc='Periodic features extracted from light-curves using generalized Lomb-Scargle ' 

200 # 'periodogram for u filter. [32 FLOAT].') 

201 # schema.addField('gLcPeriodic', type='ArrayF', 

202 # doc='Periodic features extracted from light-curves using generalized Lomb-Scargle ' 

203 # 'periodogram for g filter. [32 FLOAT].') 

204 # schema.addField('rLcPeriodic', type='ArrayF', 

205 # doc='Periodic features extracted from light-curves using generalized Lomb-Scargle ' 

206 # 'periodogram for r filter. [32 FLOAT].') 

207 # schema.addField('iLcPeriodic', type='ArrayF', 

208 # doc='Periodic features extracted from light-curves using generalized Lomb-Scargle ' 

209 # 'periodogram for i filter. [32 FLOAT].') 

210 # schema.addField('zLcPeriodic', type='ArrayF', 

211 # doc='Periodic features extracted from light-curves using generalized Lomb-Scargle ' 

212 # 'periodogram for z filter. [32 FLOAT].') 

213 # schema.addField('yLcPeriodic', type='ArrayF', 

214 # doc='Periodic features extracted from light-curves using generalized Lomb-Scargle ' 

215 # 'periodogram for y filter. [32 FLOAT].') 

216 # schema.addField('uLcNonPeriodic', type='ArrayF', 

217 # doc='Non-periodic features extracted from light-curves using generalized Lomb-Scargle ' 

218 # 'periodogram for u filter. [20 FLOAT].') 

219 # schema.addField('gLcNonPeriodic', type='ArrayF', 

220 # doc='Non-periodic features extracted from light-curves using generalized Lomb-Scargle ' 

221 # 'periodogram for g filter. [20 FLOAT].') 

222 # schema.addField('rLcNonPeriodic', type='ArrayF', 

223 # doc='Non-periodic features extracted from light-curves using generalized Lomb-Scargle ' 

224 # 'periodogram for r filter. [20 FLOAT].') 

225 # schema.addField('iLcNonPeriodic', type='ArrayF', 

226 # doc='Non-periodic features extracted from light-curves using generalized Lomb-Scargle ' 

227 # 'periodogram for i filter. [20 FLOAT].') 

228 # schema.addField('zLcNonPeriodic', type='ArrayF', 

229 # doc='Non-periodic features extracted from light-curves using generalized Lomb-Scargle ' 

230 # 'periodogram for z filter. [20 FLOAT].') 

231 # schema.addField('yLcNonPeriodic', type='ArrayF', 

232 # doc='Non-periodic features extracted from light-curves using generalized Lomb-Scargle ' 

233 # 'periodogram for y filter. [20 FLOAT].') 

234 schema.addField('nearbyObj1', type='L', 

235 doc='Id of the closest nearby object.') 

236 schema.addField('nearbyObj1Dist', type='F', 

237 doc='Distance to nearbyObj1.') 

238 schema.addField('nearbyObj1LnP', type='F', 

239 doc='Natural log of the probability that the observed diaObject is the same as the ' 

240 'nearbyObj1.') 

241 schema.addField('nearbyObj2', type='L', 

242 doc='Id of the second-closest nearby object.') 

243 schema.addField('nearbyObj2Dist', type='F', 

244 doc='Distance to nearbyObj2.') 

245 schema.addField('nearbyObj2LnP', type='F', 

246 doc='Natural log of the probability that the observed diaObject is the same as the ' 

247 'nearbyObj2.') 

248 schema.addField('nearbyObj3', type='L', 

249 doc='Id of the third-closest nearby object.') 

250 schema.addField('nearbyObj3Dist', type='F', 

251 doc='Distance to nearbyObj3.') 

252 schema.addField('nearbyObj3LnP', type='F', 

253 doc='Natural log of the probability that the observed diaObject is the same as the ' 

254 'nearbyObj3.') 

255 schema.addField('flags', type='L', 

256 doc='Flags, bitwise OR tbd.') 

257 schema.addField('pixelId', type='L', 

258 doc='HTM index.') 

259 schema.addField('lastNonForcedSource', type='L', 

260 doc='Last time when non-forced DIASource was seen for this object') 

261 schema.addField('nDiaSources', type='I', 

262 doc='Total number of DiaSources associated with this DiaObject.') 

263 schema.addField('uTOTFluxMean', type='F', 

264 doc='Weighted mean forced photometry flux for u filter.') 

265 schema.addField('uTOTFluxMeanErr', type='F', 

266 doc='Standard error of uTOTFluxMean.') 

267 schema.addField('uTOTFluxSigma', type='F', 

268 doc='Standard deviation of the distribution of uTOTFlux.') 

269 schema.addField('gTOTFluxMean', type='F', 

270 doc='Weighted mean forced photometry flux for g filter.') 

271 schema.addField('gTOTFluxMeanErr', type='F', 

272 doc='Standard error of uTOTFluxMean.') 

273 schema.addField('gTOTFluxSigma', type='F', 

274 doc='Standard deviation of the distribution of gTOTFlux.') 

275 schema.addField('rTOTFluxMean', type='F', 

276 doc='Weighted mean forced photometry flux for r filter.') 

277 schema.addField('rTOTFluxMeanErr', type='F', 

278 doc='Standard error of uTOTFluxMean.') 

279 schema.addField('rTOTFluxSigma', type='F', 

280 doc='Standard deviation of the distribution of rTOTFlux.') 

281 schema.addField('iTOTFluxMean', type='F', 

282 doc='Weighted mean forced photometry flux for i filter.') 

283 schema.addField('iTOTFluxMeanErr', type='F', 

284 doc='Standard error of uTOTFluxMean.') 

285 schema.addField('iTOTFluxSigma', type='F', 

286 doc='Standard deviation of the distribution of iTOTFlux.') 

287 schema.addField('zTOTFluxMean', type='F', 

288 doc='Weighted mean forced photometry flux for z filter.') 

289 schema.addField('zTOTFluxMeanErr', type='F', 

290 doc='Standard error of uTOTFluxMean.') 

291 schema.addField('zTOTFluxSigma', type='F', 

292 doc='Standard deviation of the distribution of zTOTFlux.') 

293 schema.addField('yTOTFluxMean', type='F', 

294 doc='Weighted mean forced photometry flux for y filter.') 

295 schema.addField('yTOTFluxMeanErr', type='F', 

296 doc='Standard error of uTOTFluxMean.') 

297 schema.addField('yTOTFluxSigma', type='F', 

298 doc='Standard deviation of the distribution of yTOTFlux.') 

299 schema.addField('uPSFluxMAD', type='F', 

300 doc='Median absolute deviation u band fluxes.') 

301 schema.addField('uPSFluxSkew', type='F', 

302 doc='Skewness of the u band fluxes.') 

303 schema.addField('uPSFluxPercentile05', type='F', 

304 doc='Value at the 5% percentile of the u band fluxes.') 

305 schema.addField('uPSFluxPercentile25', type='F', 

306 doc='Value at the 25% percentile of the u band fluxes.') 

307 schema.addField('uPSFluxPercentile50', type='F', 

308 doc='Value at the 50% percentile of the u band fluxes.') 

309 schema.addField('uPSFluxPercentile75', type='F', 

310 doc='Value at the 75% percentile of the u band fluxes.') 

311 schema.addField('uPSFluxPercentile95', type='F', 

312 doc='Value at the 95% percentile of the u band fluxes.') 

313 schema.addField('uPSFluxMin', type='F', 

314 doc='Minimum observed u band fluxes.') 

315 schema.addField('uPSFluxMax', type='F', 

316 doc='Maximum observed u band fluxes.') 

317 schema.addField('uPSFluxStetsonJ', type='F', 

318 doc='StetsonJ statistic for the u band fluxes.') 

319 schema.addField('uPSFluxLinearSlope', type='F', 

320 doc='Linear best fit slope of the u band fluxes.') 

321 schema.addField('uPSFluxLinearIntercept', type='F', 

322 doc='Linear best fit Intercept of the u band fluxes.') 

323 schema.addField('uPSFluxMaxSlope', type='F', 

324 doc='Maximum slope between u band flux observations max(delta_flux/delta_time)') 

325 schema.addField('uPSFluxErrMean', type='F', 

326 doc='Mean of the u band flux errors.') 

327 schema.addField('gPSFluxMAD', type='F', 

328 doc='Median absolute deviation g band fluxes.') 

329 schema.addField('gPSFluxSkew', type='F', 

330 doc='Skewness of the g band fluxes.') 

331 schema.addField('gPSFluxPercentile05', type='F', 

332 doc='Value at the 5% percentile of the g band fluxes.') 

333 schema.addField('gPSFluxPercentile25', type='F', 

334 doc='Value at the 25% percentile of the g band fluxes.') 

335 schema.addField('gPSFluxPercentile50', type='F', 

336 doc='Value at the 50% percentile of the g band fluxes.') 

337 schema.addField('gPSFluxPercentile75', type='F', 

338 doc='Value at the 75% percentile of the g band fluxes.') 

339 schema.addField('gPSFluxPercentile95', type='F', 

340 doc='Value at the 95% percentile of the g band fluxes.') 

341 schema.addField('gPSFluxMin', type='F', 

342 doc='Minimum observed g band fluxes.') 

343 schema.addField('gPSFluxMax', type='F', 

344 doc='Maximum observed g band fluxes.') 

345 schema.addField('gPSFluxStetsonJ', type='F', 

346 doc='StetsonJ statistic for the g band fluxes.') 

347 schema.addField('gPSFluxLinearSlope', type='F', 

348 doc='Linear best fit slope of the g band fluxes.') 

349 schema.addField('gPSFluxLinearIntercept', type='F', 

350 doc='Linear best fit Intercept of the g band fluxes.') 

351 schema.addField('gPSFluxMaxSlope', type='F', 

352 doc='Maximum slope between g band flux observations max(delta_flux/delta_time)') 

353 schema.addField('gPSFluxErrMean', type='F', 

354 doc='Mean of the g band flux errors.') 

355 schema.addField('rPSFluxMAD', type='F', 

356 doc='Median absolute deviation r band fluxes.') 

357 schema.addField('rPSFluxSkew', type='F', 

358 doc='Skewness of the r band fluxes.') 

359 schema.addField('rPSFluxPercentile05', type='F', 

360 doc='Value at the 5% percentile of the r band fluxes.') 

361 schema.addField('rPSFluxPercentile25', type='F', 

362 doc='Value at the 25% percentile of the r band fluxes.') 

363 schema.addField('rPSFluxPercentile50', type='F', 

364 doc='Value at the 50% percentile of the r band fluxes.') 

365 schema.addField('rPSFluxPercentile75', type='F', 

366 doc='Value at the 75% percentile of the r band fluxes.') 

367 schema.addField('rPSFluxPercentile95', type='F', 

368 doc='Value at the 95% percentile of the r band fluxes.') 

369 schema.addField('rPSFluxMin', type='F', 

370 doc='Minimum observed r band fluxes.') 

371 schema.addField('rPSFluxMax', type='F', 

372 doc='Maximum observed r band fluxes.') 

373 schema.addField('rPSFluxStetsonJ', type='F', 

374 doc='StetsonJ statistic for the r band fluxes.') 

375 schema.addField('rPSFluxLinearSlope', type='F', 

376 doc='Linear best fit slope of the r band fluxes.') 

377 schema.addField('rPSFluxLinearIntercept', type='F', 

378 doc='Linear best fit Intercept of the r band fluxes.') 

379 schema.addField('rPSFluxMaxSlope', type='F', 

380 doc='Maximum slope between r band flux observations max(delta_flux/delta_time)') 

381 schema.addField('rPSFluxErrMean', type='F', 

382 doc='Mean of the r band flux errors.') 

383 schema.addField('iPSFluxMAD', type='F', 

384 doc='Median absolute deviation i band fluxes.') 

385 schema.addField('iPSFluxSkew', type='F', 

386 doc='Skewness of the i band fluxes.') 

387 schema.addField('iPSFluxPercentile05', type='F', 

388 doc='Value at the 5% percentile of the i band fluxes.') 

389 schema.addField('iPSFluxPercentile25', type='F', 

390 doc='Value at the 25% percentile of the i band fluxes.') 

391 schema.addField('iPSFluxPercentile50', type='F', 

392 doc='Value at the 50% percentile of the i band fluxes.') 

393 schema.addField('iPSFluxPercentile75', type='F', 

394 doc='Value at the 75% percentile of the i band fluxes.') 

395 schema.addField('iPSFluxPercentile95', type='F', 

396 doc='Value at the 95% percentile of the i band fluxes.') 

397 schema.addField('iPSFluxMin', type='F', 

398 doc='Minimum observed i band fluxes.') 

399 schema.addField('iPSFluxMax', type='F', 

400 doc='Maximum observed i band fluxes.') 

401 schema.addField('iPSFluxStetsonJ', type='F', 

402 doc='StetsonJ statistic for the i band fluxes.') 

403 schema.addField('iPSFluxLinearSlope', type='F', 

404 doc='Linear best fit slope of the i band fluxes.') 

405 schema.addField('iPSFluxLinearIntercept', type='F', 

406 doc='Linear best fit Intercept of the i band fluxes.') 

407 schema.addField('iPSFluxMaxSlope', type='F', 

408 doc='Maximum slope between i band flux observations max(delta_flux/delta_time)') 

409 schema.addField('iPSFluxErrMean', type='F', 

410 doc='Mean of the i band flux errors.') 

411 schema.addField('zPSFluxMAD', type='F', 

412 doc='Median absolute deviation z band fluxes.') 

413 schema.addField('zPSFluxSkew', type='F', 

414 doc='Skewness of the z band fluxes.') 

415 schema.addField('zPSFluxPercentile05', type='F', 

416 doc='Value at the 5% percentile of the z band fluxes.') 

417 schema.addField('zPSFluxPercentile25', type='F', 

418 doc='Value at the 25% percentile of the z band fluxes.') 

419 schema.addField('zPSFluxPercentile50', type='F', 

420 doc='Value at the 50% percentile of the z band fluxes.') 

421 schema.addField('zPSFluxPercentile75', type='F', 

422 doc='Value at the 75% percentile of the z band fluxes.') 

423 schema.addField('zPSFluxPercentile95', type='F', 

424 doc='Value at the 95% percentile of the z band fluxes.') 

425 schema.addField('zPSFluxMin', type='F', 

426 doc='Minimum observed z band fluxes.') 

427 schema.addField('zPSFluxMax', type='F', 

428 doc='Maximum observed z band fluxes.') 

429 schema.addField('zPSFluxStetsonJ', type='F', 

430 doc='StetsonJ statistic for the z band fluxes.') 

431 schema.addField('zPSFluxLinearSlope', type='F', 

432 doc='Linear best fit slope of the z band fluxes.') 

433 schema.addField('zPSFluxLinearIntercept', type='F', 

434 doc='Linear best fit Intercept of the z band fluxes.') 

435 schema.addField('zPSFluxMaxSlope', type='F', 

436 doc='Maximum slope between z band flux observations max(delta_flux/delta_time)') 

437 schema.addField('zPSFluxErrMean', type='F', 

438 doc='Mean of the z band flux errors.') 

439 schema.addField('yPSFluxMAD', type='F', 

440 doc='Median absolute deviation y band fluxes.') 

441 schema.addField('yPSFluxSkew', type='F', 

442 doc='Skewness of the y band fluxes.') 

443 schema.addField('yPSFluxPercentile05', type='F', 

444 doc='Value at the 5% percentile of the y band fluxes.') 

445 schema.addField('yPSFluxPercentile25', type='F', 

446 doc='Value at the 25% percentile of the y band fluxes.') 

447 schema.addField('yPSFluxPercentile50', type='F', 

448 doc='Value at the 50% percentile of the y band fluxes.') 

449 schema.addField('yPSFluxPercentile75', type='F', 

450 doc='Value at the 75% percentile of the y band fluxes.') 

451 schema.addField('yPSFluxPercentile95', type='F', 

452 doc='Value at the 95% percentile of the y band fluxes.') 

453 schema.addField('yPSFluxMin', type='F', 

454 doc='Minimum observed y band fluxes.') 

455 schema.addField('yPSFluxMax', type='F', 

456 doc='Maximum observed y band fluxes.') 

457 schema.addField('yPSFluxStetsonJ', type='F', 

458 doc='StetsonJ statistic for the y band fluxes.') 

459 schema.addField('yPSFluxLinearSlope', type='F', 

460 doc='Linear best fit slope of the y band fluxes.') 

461 schema.addField('yPSFluxLinearIntercept', type='F', 

462 doc='Linear best fit Intercept of the y band fluxes.') 

463 schema.addField('yPSFluxMaxSlope', type='F', 

464 doc='Maximum slope between y band flux observations max(delta_flux/delta_time)') 

465 schema.addField('yPSFluxErrMean', type='F', 

466 doc='Mean of the y band flux errors.') 

467 

468 return schema 

469 

470 

471def make_dia_source_schema(): 

472 """ Define and create the minimal schema required for a DIASource. 

473 

474 Returns 

475 ------- 

476 schema : `lsst.afw.table.Schema` 

477 Minimal schema for DiaSources. 

478 """ 

479 

480 # Generated automatically from apdb-schema.yaml in dax_apdb/data. 

481 schema = afwTable.SourceTable.makeMinimalSchema() 

482 schema.addField('ccdVisitId', type='L', 

483 doc='Id of the ccdVisit where this diaSource was measured. Note that we are allowing a ' 

484 'diaSource to belong to multiple amplifiers, but it may not span multiple ccds.') 

485 schema.addField('diaObjectId', type='L', 

486 doc='Id of the diaObject this source was associated with, if any. If not, it is set to ' 

487 'NULL (each diaSource will be associated with either a diaObject or ssObject).') 

488 schema.addField('ssObjectId', type='L', 

489 doc='Id of the ssObject this source was associated with, if any. If not, it is set to ' 

490 'NULL (each diaSource will be associated with either a diaObject or ssObject).') 

491 schema.addField('prv_procOrder', type='I', 

492 doc='Position of this diaSource in the processing order relative to other diaSources ' 

493 'within a given diaObjectId or ssObjectId.') 

494 schema.addField('ssObjectReassocTime', type='D', 

495 doc='Time when this diaSource was reassociated from diaObject to ssObject (if such ' 

496 'reassociation happens, otherwise NULL).') 

497 schema.addField('midPointTai', type='D', 

498 doc='Effective mid-exposure time for this diaSource.') 

499 schema.addField('raErr', type='D', 

500 doc='Uncertainty of ra.') 

501 schema.addField('declErr', type='D', 

502 doc='Uncertainty of decl.') 

503 schema.addField('ra_decl_Cov', type='D', 

504 doc='Covariance between ra and decl.') 

505 schema.addField('x', type='D', 

506 doc='x position computed by a centroiding algorithm.') 

507 schema.addField('xErr', type='F', 

508 doc='Uncertainty of x.') 

509 schema.addField('y', type='D', 

510 doc='y position computed by a centroiding algorithm.') 

511 schema.addField('yErr', type='F', 

512 doc='Uncertainty of y.') 

513 schema.addField('x_y_Cov', type='D', 

514 doc='Covariance between x and y.') 

515 schema.addField('apFlux', type='D', 

516 doc='Calibrated aperture flux. Note that this actually measures the difference between ' 

517 'the template and the visit image.') 

518 schema.addField('apFluxErr', type='D', 

519 doc='Estimated uncertainty of apFlux.') 

520 schema.addField('snr', type='D', 

521 doc='The signal-to-noise ratio at which this source was detected in the difference ' 

522 'image.') 

523 schema.addField('psFlux', type='D', 

524 doc='Calibrated flux for Point Source model. Note this actually measures the flux ' 

525 'difference between the template and the visit image.') 

526 schema.addField('psFluxErr', type='D', 

527 doc='Uncertainty of psFlux.') 

528 schema.addField('psRa', type='D', 

529 doc=' RA-coordinate of centroid for point source model.') 

530 schema.addField('psRaErr', type='D', 

531 doc='Uncertainty of psRa.') 

532 schema.addField('psDecl', type='D', 

533 doc=' Decl-coordinate of centroid for point source model.') 

534 schema.addField('psDeclErr', type='D', 

535 doc='Uncertainty of psDecl.') 

536 schema.addField('psFlux_psRa_Cov', type='D', 

537 doc='Covariance between psFlux and psRa.') 

538 schema.addField('psFlux_psDecl_Cov', type='D', 

539 doc='Covariance between psFlux and psDecl.') 

540 schema.addField('psRa_psDecl_Cov', type='D', 

541 doc='Covariance between psRa and psDecl.') 

542 schema.addField('psLnL', type='D', 

543 doc='Natural log likelihood of the observed data given the Point Source model.') 

544 schema.addField('psChi2', type='D', 

545 doc='Chi^2 statistic of the model fit.') 

546 schema.addField('psNdata', type='I', 

547 doc='The number of data points (pixels) used to fit the model.') 

548 schema.addField('trailFlux', type='D', 

549 doc='Calibrated flux for a trailed source model. Note this actually measures the flux ' 

550 'difference between the template and the visit image.') 

551 schema.addField('trailFluxErr', type='D', 

552 doc='Uncertainty of trailFlux.') 

553 schema.addField('trailRa', type='D', 

554 doc=' RA-coordinate of centroid for trailed source model.') 

555 schema.addField('trailRaErr', type='D', 

556 doc='Uncertainty of trailRa.') 

557 schema.addField('trailDecl', type='D', 

558 doc=' Decl-coordinate of centroid for trailed source model.') 

559 schema.addField('trailDeclErr', type='D', 

560 doc='Uncertainty of trailDecl.') 

561 schema.addField('trailLength', type='D', 

562 doc='Maximum likelihood fit of trail length.') 

563 schema.addField('trailLengthErr', type='D', 

564 doc='Uncertainty of trailLength.') 

565 schema.addField('trailAngle', type='D', 

566 doc='Maximum likelihood fit of the angle between the meridian through the centroid and ' 

567 'the trail direction (bearing).') 

568 schema.addField('trailAngleErr', type='D', 

569 doc='Uncertainty of trailAngle.') 

570 schema.addField('trailFlux_trailRa_Cov', type='D', 

571 doc='Covariance of trailFlux and trailRa.') 

572 schema.addField('trailFlux_trailDecl_Cov', type='D', 

573 doc='Covariance of trailFlux and trailDecl.') 

574 schema.addField('trailFlux_trailLength_Cov', type='D', 

575 doc='Covariance of trailFlux and trailLength') 

576 schema.addField('trailFlux_trailAngle_Cov', type='D', 

577 doc='Covariance of trailFlux and trailAngle') 

578 schema.addField('trailRa_trailDecl_Cov', type='D', 

579 doc='Covariance of trailRa and trailDecl.') 

580 schema.addField('trailRa_trailLength_Cov', type='D', 

581 doc='Covariance of trailRa and trailLength.') 

582 schema.addField('trailRa_trailAngle_Cov', type='D', 

583 doc='Covariance of trailRa and trailAngle.') 

584 schema.addField('trailDecl_trailLength_Cov', type='D', 

585 doc='Covariance of trailDecl and trailLength.') 

586 schema.addField('trailDecl_trailAngle_Cov', type='D', 

587 doc='Covariance of trailDecl and trailAngle.') 

588 schema.addField('trailLength_trailAngle_Cov', type='D', 

589 doc='Covariance of trailLength and trailAngle') 

590 schema.addField('trailLnL', type='D', 

591 doc='Natural log likelihood of the observed data given the trailed source model.') 

592 schema.addField('trailChi2', type='D', 

593 doc='Chi^2 statistic of the model fit.') 

594 schema.addField('trailNdata', type='I', 

595 doc='The number of data points (pixels) used to fit the model.') 

596 schema.addField('dipMeanFlux', type='D', 

597 doc='Maximum likelihood value for the mean absolute flux of the two lobes for a dipole ' 

598 'model.') 

599 schema.addField('dipMeanFluxErr', type='D', 

600 doc='Uncertainty of dipMeanFlux.') 

601 schema.addField('dipFluxDiff', type='D', 

602 doc='Maximum likelihood value for the difference of absolute fluxes of the two lobes for ' 

603 'a dipole model.') 

604 schema.addField('dipFluxDiffErr', type='D', 

605 doc='Uncertainty of dipFluxDiff.') 

606 schema.addField('dipRa', type='D', 

607 doc=' RA-coordinate of centroid for dipole model.') 

608 schema.addField('dipRaErr', type='D', 

609 doc='Uncertainty of trailRa.') 

610 schema.addField('dipDecl', type='D', 

611 doc=' Decl-coordinate of centroid for dipole model.') 

612 schema.addField('dipDeclErr', type='D', 

613 doc='Uncertainty of dipDecl.') 

614 schema.addField('dipLength', type='D', 

615 doc='Maximum likelihood value for the lobe separation in dipole model.') 

616 schema.addField('dipLengthErr', type='D', 

617 doc='Uncertainty of dipLength.') 

618 schema.addField('dipAngle', type='D', 

619 doc='Maximum likelihood fit of the angle between the meridian through the centroid and ' 

620 'the dipole direction (bearing, from negative to positive lobe).') 

621 schema.addField('dipAngleErr', type='D', 

622 doc='Uncertainty of dipAngle.') 

623 schema.addField('dipMeanFlux_dipFluxDiff_Cov', type='D', 

624 doc='Covariance of dipMeanFlux and dipFluxDiff.') 

625 schema.addField('dipMeanFlux_dipRa_Cov', type='D', 

626 doc='Covariance of dipMeanFlux and dipRa.') 

627 schema.addField('dipMeanFlux_dipDecl_Cov', type='D', 

628 doc='Covariance of dipMeanFlux and dipDecl.') 

629 schema.addField('dipMeanFlux_dipLength_Cov', type='D', 

630 doc='Covariance of dipMeanFlux and dipLength.') 

631 schema.addField('dipMeanFlux_dipAngle_Cov', type='D', 

632 doc='Covariance of dipMeanFlux and dipAngle.') 

633 schema.addField('dipFluxDiff_dipRa_Cov', type='D', 

634 doc='Covariance of dipFluxDiff and dipRa.') 

635 schema.addField('dipFluxDiff_dipDecl_Cov', type='D', 

636 doc='Covariance of dipFluxDiff and dipDecl.') 

637 schema.addField('dipFluxDiff_dipLength_Cov', type='D', 

638 doc='Covariance of dipFluxDiff and dipLength.') 

639 schema.addField('dipFluxDiff_dipAngle_Cov', type='D', 

640 doc='Covariance of dipFluxDiff and dipAngle.') 

641 schema.addField('dipRa_dipDecl_Cov', type='D', 

642 doc='Covariance of dipRa and dipDecl.') 

643 schema.addField('dipRa_dipLength_Cov', type='D', 

644 doc='Covariance of dipRa and dipLength.') 

645 schema.addField('dipRa_dipAngle_Cov', type='D', 

646 doc='Covariance of dipRa and dipAngle.') 

647 schema.addField('dipDecl_dipLength_Cov', type='D', 

648 doc='Covariance of dipDecl and dipLength.') 

649 schema.addField('dipDecl_dipAngle_Cov', type='D', 

650 doc='Covariance of dipDecl and dipAngle.') 

651 schema.addField('dipLength_dipAngle_Cov', type='D', 

652 doc='Covariance of dipLength and dipAngle.') 

653 schema.addField('dipLnL', type='D', 

654 doc='Natural log likelihood of the observed data given the dipole source model.') 

655 schema.addField('dipChi2', type='D', 

656 doc='Chi^2 statistic of the model fit.') 

657 schema.addField('dipNdata', type='I', 

658 doc='The number of data points (pixels) used to fit the model.') 

659 schema.addField('totFlux', type='D', 

660 doc='Calibrated flux for Point Source model measured on the visit image centered at the ' 

661 'centroid measured on the difference image (forced photometry flux).') 

662 schema.addField('totFluxErr', type='D', 

663 doc='Estimated uncertainty of totFlux.') 

664 schema.addField('diffFlux', type='D', 

665 doc='Calibrated flux for Point Source model centered on radec but measured on the ' 

666 'difference of snaps comprising this visit.') 

667 schema.addField('diffFluxErr', type='D', 

668 doc='Estimated uncertainty of diffFlux.') 

669 schema.addField('fpBkgd', type='D', 

670 doc='Estimated sky background at the position (centroid) of the object.') 

671 schema.addField('fpBkgdErr', type='D', 

672 doc='Estimated uncertainty of fpBkgd.') 

673 schema.addField('ixx', type='D', 

674 doc='Adaptive second moment of the source intensity.') 

675 schema.addField('ixxErr', type='F', 

676 doc='Uncertainty of ixx.') 

677 schema.addField('iyy', type='D', 

678 doc='Adaptive second moment of the source intensity.') 

679 schema.addField('iyyErr', type='F', 

680 doc='Uncertainty of iyy.') 

681 schema.addField('ixy', type='D', 

682 doc='Adaptive second moment of the source intensity.') 

683 schema.addField('ixyErr', type='F', 

684 doc='Uncertainty of ixy.') 

685 schema.addField('ixx_iyy_Cov', type='D', 

686 doc='Covariance of ixx and iyy.') 

687 schema.addField('ixx_ixy_Cov', type='D', 

688 doc='Covariance of ixx and ixy.') 

689 schema.addField('iyy_ixy_Cov', type='D', 

690 doc='Covariance of iyy and ixy.') 

691 schema.addField('ixxPSF', type='D', 

692 doc='Adaptive second moment for the PSF.') 

693 schema.addField('iyyPSF', type='D', 

694 doc='Adaptive second moment for the PSF.') 

695 schema.addField('ixyPSF', type='D', 

696 doc='Adaptive second moment for the PSF.') 

697 schema.addField('extendedness', type='D', 

698 doc='A measure of extendedness, Computed using a combination of available moments and ' 

699 'model fluxes or from a likelihood ratio of point/trailed source models (exact ' 

700 'algorithm TBD). extendedness = 1 implies a high degree of confidence that the ' 

701 'source is extended. extendedness = 0 implies a high degree of confidence that the ' 

702 'source is point-like.') 

703 schema.addField('spuriousness', type='D', 

704 doc='A measure of spuriousness, computed using information from the source and image ' 

705 'characterization, as well as the information on the Telescope and Camera system ' 

706 '(e.g., ghost maps, defect maps, etc.).') 

707 schema.addField('flags', type='L', 

708 doc='Flags, bitwise OR tbd.') 

709 schema.addField('pixelId', type='L', 

710 doc='HTM index.') 

711 schema.addField("filterName", type='String', size=10, 

712 doc='String name of the filter this source was observed ' 

713 'in.') 

714 schema.addField("filterId", type='L', 

715 doc='Obs package id of the filter this source was ' 

716 'observed in.') 

717 schema.addField("isDipole", type='Flag', 

718 doc='Object determined to be a dipole.') 

719 return schema 

720 

721 

722def make_dia_forced_source_schema(): 

723 """ Define and create the minimal schema required for a DiaForcedSource. 

724 

725 Returns 

726 ------- 

727 schema : `lsst.afw.table.Schema` 

728 Minimal schema for DiaForcedSources. 

729 """ 

730 

731 # Generated automatically from apdb-schema.yaml in dax_apdb/data. 

732 schema = afwTable.SourceTable.makeMinimalSchema() 

733 schema.addField('ccdVisitId', type='L', 

734 doc='Id of the ccdVisit where this diaSource was measured. Note that we are allowing a ' 

735 'diaSource to belong to multiple amplifiers, but it may not span multiple ccds.') 

736 schema.addField('psFlux', type='D', 

737 doc='Calibrated flux for Point Source model. Note this actually measures the flux ' 

738 'difference between the template and the visit image.') 

739 schema.addField('psFluxErr', type='D', 

740 doc='Uncertainty of psFlux.') 

741 schema.addField('totFlux', type='D', 

742 doc='Calibrated flux measured in direct image.') 

743 schema.addField('totFluxErr', type='D', 

744 doc='Uncertainty of totFlux.') 

745 schema.addField('x', type='D', 

746 doc='x position at which psFlux has been measured.') 

747 schema.addField('y', type='D', 

748 doc='y position at which psFlux has been measured.') 

749 schema.addField('flags', type='L', 

750 doc='Flags from measurement on the difference image, ' 

751 'bitwise OR tbd') 

752 schema.addField('flagsDirectIm', type='L', 

753 doc='Flags from measurement on the direct image, bitwise ' 

754 'OR tbd') 

755 return schema 

756 

757 

758def getCcdVisitSchemaSql(): 

759 """Define the schema for the CcdVisit table. 

760 

761 Returns 

762 ------- 

763 ccdVisitNames : `collections.OrderedDict` 

764 Names of columns in the ccdVisit table. 

765 """ 

766 return oDict([("ccdVisitId", "INTEGER PRIMARY KEY"), 

767 ("ccdNum", "INTEGER"), 

768 ("filterName", "TEXT"), 

769 ("filterId", "INTEGER"), 

770 ("ra", "REAL"), 

771 ("decl", "REAL"), 

772 ("expTime", "REAL"), 

773 ("expMidptMJD", "REAL"), 

774 ("calibrationMean", "REAL"), 

775 ("calibrationErr", "REAL")]) 

776 

777 

778def get_ccd_visit_info_from_exposure(exposure): 

779 """ 

780 Extract info on the ccd and visit from the exposure. 

781 

782 Parameters 

783 ---------- 

784 exposure : `lsst.afw.image.Exposure` 

785 Exposure to store information from. 

786 

787 Returns 

788 ------- 

789 values : `dict` of ``values`` 

790 List values representing info taken from the exposure. 

791 """ 

792 visit_info = exposure.getInfo().getVisitInfo() 

793 date = visit_info.getDate() 

794 sphPoint = exposure.getWcs().getSkyOrigin() 

795 filter_obj = exposure.getFilter() 

796 # Values list is: 

797 # [CcdVisitId ``int``, 

798 # ccdNum ``int``, 

799 # filterName ``str``, 

800 # RA WCS center ``degrees``, 

801 # DEC WCS center ``degrees``, 

802 # exposure time ``seconds``, 

803 # dateTimeMJD ``days``, 

804 # flux zero point ``counts``, 

805 # flux zero point error ``counts``] 

806 values = {'ccdVisitId': visit_info.getExposureId(), 

807 'ccdNum': exposure.getDetector().getId(), 

808 'filterName': filter_obj.getName(), 

809 'filterId': filter_obj.getId(), 

810 'ra': sphPoint.getRa().asDegrees(), 

811 'decl': sphPoint.getDec().asDegrees(), 

812 'expTime': visit_info.getExposureTime(), 

813 'expMidptMJD': date.get(system=DateTime.MJD), 

814 'calibrationMean': exposure.getPhotoCalib().getCalibrationMean(), 

815 'calibrationErr': exposure.getPhotoCalib().getCalibrationErr(), 

816 'photoCalib': exposure.getPhotoCalib()} 

817 return values