389 plot=dict(showFlags=
False, showRejection=
False)):
392 set = psfexLib.Set(context)
394 cmin, cmax =
None,
None
395 if set.getNcontext():
396 cmin = np.empty(set.getNcontext())
397 cmax = np.empty(set.getNcontext())
398 for i
in range(set.getNcontext()):
400 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
401 cmax[i] = cmin[i] + set.getContextScale(i)
403 cmin[i] = psfexLib.BIG
404 cmax[i] = -psfexLib.BIG
408 tab = afwTable.SourceCatalog.readFits(filename)
410 centroid = tab.getCentroidDefinition()
411 xm = tab.get(
"%s.x" % centroid)
412 ym = tab.get(
"%s.y" % centroid)
414 shape = tab.getShapeDefinition()
415 ixx = tab.get(
"%s.xx" % shape)
416 iyy = tab.get(
"%s.yy" % shape)
418 rmsSize = np.sqrt(0.5*(ixx + iyy))
419 elong = 0.5*(ixx - iyy)/(ixx + iyy)
421 flux = tab.get(prefs.getPhotfluxRkey())
422 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
430 set.setVigSize(vigw, vigh)
432 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
436 mi = afwImage.MaskedImageF(calexpFile)
437 backnoise2 = np.median(mi.getVariance().getArray())
440 edgeBit = [k
for k, v
in getFlags().
items()
if v ==
"edge"][0]
442 for i, xc, yc
in zip(range(nobj), xm, ym):
444 x, y = int(xc), int(yc)
449 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
450 vignet[i] = pstamp.getImage().getArray().transpose()
457 for i, key
in enumerate(context.getName()):
458 if context.getPcflag(i):
459 contextvalp.append(pcval[pc])
463 contextvalp.append(tab.header[key[1:]])
465 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
469 contextvalp.append(tab.get(key))
471 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
473 set.setContextname(i, key)
477 flags, flux, fluxErr, rmsSize, elong, vignet,
478 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
482 if not vignet.dtype.isnative:
485 vignet = vignet.byteswap()
487 for i
in np.where(good)[0]:
488 sample = set.newSample()
489 sample.setCatindex(catindex)
490 sample.setExtindex(ext)
492 sample.setVig(vignet[i])
493 sample.setNorm(float(flux[i]))
494 sample.setBacknoise2(backnoise2)
496 sample.setX(float(xm[i]))
497 sample.setY(float(ym[i]))
498 sample.setFluxrad(float(rmsSize[i]))
500 for j
in range(set.getNcontext()):
501 sample.setContext(j, float(contextvalp[j][i]))
503 set.finiSample(sample, prefs.getProfAccuracy())
506 for j
in range(set.getNcontext()):
507 cmin[j] = contextvalp[j][good].
min()
508 cmax[j] = contextvalp[j][good].
max()
512 for i
in range(set.getNcontext()):
513 set.setContextScale(i, cmax[i] - cmin[i])
514 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
std::vector< SchemaItem< Flag > > * items
def select_candidates(set, prefs, frmin, frmax, flags, flux, fluxerr, rmsSize, elong, vignet, plot=dict(), title="")