6 from astropy.io
import fits
8 import matplotlib.pyplot
as plt
18 from .
import psfexLib
20 afwDisplay.setDefaultMaskTransparency(75)
24 """Split a FITS header, returning (key, value). 29 A string from a FITS header. 40 k, v = re.search(
r"(\S+)\s*=\s*'?((?:\S+|'))", line).groups()
41 except AttributeError:
56 """Compute the FWHM range associated to a series of FWHM measurements. 57 AUTHOR E. Bertin (IAP, Leiden observatory & ESO) 62 fwhm: iterable of `float` 63 Iterable of full width half-maxima. 65 Maximum allowed FWHM variation. 70 plot: `dict`, optional 71 Dict of plotting options. 92 for i
in range(nfwhm - nw):
93 df = fwhm[i + nw] - fwhm[i]
96 fmin = (fwhm[i + nw] + fwhm[i])/2.0
101 dfmin = (maxvar + 1.0)**0.3333333
102 minout = fmin/dfmin
if dfmin > 0.0
else 0.0
106 maxout = fmin*dfmin**2
110 if plt
and plot.get(
"fwhmHistogram"):
112 plt.hist(fwhm, nfwhm//10 + 1, normed=1, facecolor=
'g', alpha=0.75)
114 plt.axvline(fmin, color=
'red')
115 [plt.axvline(_, color=
'blue')
for _
in (minout, maxout)]
119 return fmin, minout, maxout
122 def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
123 plot=dict(showFlags=
False, showRejection=
False)):
126 set = psfexLib.Set(context)
128 cmin, cmax =
None,
None 129 if set.getNcontext():
130 cmin = np.empty(set.getNcontext())
131 cmax = np.empty(set.getNcontext())
132 for i
in range(set.getNcontext()):
134 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
135 cmax[i] = cmin[i] + set.getContextScale(i)
137 cmin[i] = psfexLib.BIG
138 cmax[i] = -psfexLib.BIG
142 with fits.open(filename)
as cat:
145 if tab.name ==
"LDAC_IMHEAD":
153 if tab.name ==
"PRIMARY":
155 elif tab.name ==
"LDAC_IMHEAD":
162 except AttributeError:
174 elif tab.name ==
"LDAC_OBJECTS":
175 xm = tab.data[prefs.getCenterKey(0)]
176 ym = tab.data[prefs.getCenterKey(1)]
177 fluxrad = tab.data[
"FLUX_RADIUS"]
178 flux = tab.data[prefs.getPhotfluxRkey()]
179 fluxerr = tab.data[prefs.getPhotfluxerrRkey()]
180 elong = tab.data[
"ELONGATION"]
181 flags = tab.data[
"FLAGS"]
183 n = prefs.getPhotfluxNum() - 1
185 assert False,
"Code to handle e.g. FLUX_APER(3) isn't yet converted" 186 if key.naxis == 1
and n < key.naxisn[0]:
189 print(
"Not enough apertures for %s in catalogue %s: using first aperture" %
190 (prefs.getPhotfluxRkey(), filename), file=sys.stderr)
192 n = prefs.getPhotfluxerrNum() - 1
194 if key.naxis == 1
and n < key.naxisn[0]:
197 print(
"Not enough apertures for %s in catalogue %s: using first aperture" %
198 (prefs.getPhotfluxerrRkey(), filename), file=sys.stderr)
202 vignet = tab.data[
"VIGNET"]
205 vigw, vigh = vignet[0].shape
207 raise RuntimeError(
"*Error*: VIGNET should be a 2D vector; saw %s" %
str(vignet[0].shape))
210 set.setVigSize(vigw, vigh)
215 for i, key
in enumerate(context.getName()):
216 if context.getPcflag(i):
217 contextvalp.append(pcval[pc])
221 contextvalp.append(tab.header[key[1:]])
223 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
227 contextvalp.append(tab.data[key])
229 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
231 set.setContextname(i, key)
235 flags, flux, fluxerr, fluxrad, elong, vignet,
236 plot=plot, title=
"%s[%d]" % (filename, ext + 1))
240 if not vignet.dtype.isnative:
242 vignet = vignet.byteswap()
244 for i
in np.where(good)[0]:
245 sample = set.newSample()
246 sample.setCatindex(catindex)
247 sample.setExtindex(ext)
249 sample.setVig(vignet[i])
251 sample.setNorm(
float(flux[i]))
252 sample.setBacknoise2(backnoise2)
254 sample.setX(
float(xm[i]))
255 sample.setY(
float(ym[i]))
256 sample.setFluxrad(
float(fluxrad[i]))
258 for j
in range(set.getNcontext()):
259 sample.setContext(j,
float(contextvalp[j][i]))
261 set.finiSample(sample, prefs.getProfAccuracy())
264 for j
in range(set.getNcontext()):
265 cmin[j] = contextvalp[j][good].
min()
266 cmax[j] = contextvalp[j][good].
max()
270 for i
in range(set.getNcontext()):
271 set.setContextScale(i, cmax[i] - cmin[i])
272 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
281 return {1:
"flux blended",
287 64:
"memory error (deblend)",
288 128:
"memory error (extract)",
293 flags, flux, fluxerr, rmsSize, elong, vignet,
294 plot=dict(), title=
""):
295 maxbad = prefs.getBadpixNmax()
296 maxbadflag = prefs.getBadpixFlag()
297 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100.0
298 minsn = prefs.getMinsn()
300 sn = flux/np.where(fluxerr > 0, fluxerr, 1)
301 sn[fluxerr <= 0] = -psfexLib.BIG
303 plotFlags = plot.get(
"showFlags")
if plt
else False 304 plotRejection = plot.get(
"showRejection")
if plt
else False 306 bad = flags & prefs.getFlagMask() != 0
307 set.setBadFlags(
int(sum(bad != 0)))
310 selectionVectors = []
311 selectionVectors.append((bad,
"flags %d" % sum(bad != 0)))
314 set.setBadSN(
int(sum(dbad)))
315 bad = np.logical_or(bad, dbad)
317 selectionVectors.append((dbad,
"S/N %d" % sum(dbad)))
319 dbad = rmsSize < frmin
320 set.setBadFrmin(
int(sum(dbad)))
321 bad = np.logical_or(bad, dbad)
323 selectionVectors.append((dbad,
"frmin %d" % sum(dbad)))
325 dbad = rmsSize > frmax
326 set.setBadFrmax(
int(sum(dbad)))
327 bad = np.logical_or(bad, dbad)
329 selectionVectors.append((dbad,
"frmax %d" % sum(dbad)))
331 dbad = elong > maxelong
332 set.setBadElong(
int(sum(dbad)))
333 bad = np.logical_or(bad, dbad)
335 selectionVectors.append((dbad,
"elong %d" % sum(dbad)))
339 nbad = np.array([(v <= -psfexLib.BIG).sum()
for v
in vignet])
341 set.setBadPix(
int(sum(dbad)))
342 bad = np.logical_or(bad, dbad)
344 selectionVectors.append((dbad,
"badpix %d" % sum(dbad)))
346 good = np.logical_not(bad)
347 if plotFlags
or plotRejection:
348 imag = -2.5*np.log10(flux)
355 isSet = np.where(flags == 0x0)[0]
356 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=
"good")
360 if mask & prefs.getFlagMask():
361 isSet = np.where(np.bitwise_and(flags, mask))[0]
363 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=labels[mask])
365 for bad, label
in selectionVectors:
366 plt.plot(imag[bad], rmsSize[bad],
'o', alpha=alpha, label=label)
368 plt.plot(imag[good], rmsSize[good],
'o', color=
"black", label=
"selected")
369 [plt.axhline(_, color=
'red')
for _
in [frmin, frmax]]
370 plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
371 plt.ylim(-0.1, 2*frmax)
373 plt.xlabel(
"Instrumental Magnitude")
374 plt.ylabel(
"rmsSize")
375 plt.title(
"%s %d selected" % (title, sum(good)))
391 _dataTypes = dict(LSST=_LSST,
392 SExtractor=_SExtractor
394 _dataType = _SExtractor
398 _dataType = _dataTypes[t]
402 if _dataType == _LSST:
408 def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
409 minsn = prefs.getMinsn()
410 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
411 min = prefs.getFwhmrange()[0]
412 max = prefs.getFwhmrange()[1]
414 filenames = prefs.getCatalogs()
416 ncat = len(filenames)
417 fwhmmin = np.empty(ncat)
418 fwhmmax = np.empty(ncat)
420 if not prefs.getAutoselectFlag():
421 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
422 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
423 fwhmmode = (fwhmmin + fwhmmax)/2.0
430 for i, fileName
in enumerate(filenames):
433 if prefs.getVerboseType() != prefs.QUIET:
434 print(
"Examining Catalog #%d" % (i+1))
438 with fits.open(fileName)
as cat:
441 if tab.name ==
"LDAC_IMHEAD":
444 if extCtr != ext
and ext != prefs.ALL_EXTENSIONS:
449 if tab.name ==
"PRIMARY":
451 elif tab.name ==
"LDAC_IMHEAD":
456 except AttributeError:
460 if v < 1/psfexLib.BIG:
465 elif tab.name ==
"LDAC_OBJECTS":
467 rmsSize = tab.data[
"FLUX_RADIUS"]
468 fmax = tab.data[
"FLUX_MAX"]
469 flags = tab.data[
"FLAGS"]
470 elong = tab.data[
"ELONGATION"]
471 backnoise = backnoises[-1]
473 good = np.logical_and(fmax/backnoise > minsn,
474 np.logical_not(flags & prefs.getFlagMask()))
475 good = np.logical_and(good, elong < maxelong)
477 good = np.logical_and(good, fwhm >= min)
478 good = np.logical_and(good, fwhm < max)
479 fwhms[i] = fwhm[good]
481 if prefs.getVarType() == prefs.VAR_NONE:
483 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
485 for l
in fwhms.values():
486 fwhms_all[i:len(l)] = l
489 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
492 raise RuntimeError(
"No source with appropriate FWHM found!!")
493 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
495 fwhmmin = np.zeros(ncat) + min
496 fwhmmax = np.zeros(ncat) + max
497 fwhmmode = np.zeros(ncat) + mode
499 fwhmmode = np.empty(ncat)
500 fwhmmin = np.empty(ncat)
501 fwhmmax = np.empty(ncat)
503 for i
in range(ncat):
506 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
508 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
510 raise RuntimeError(
"No source with appropriate FWHM found!!")
511 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
517 for i, fileName
in enumerate(filenames):
519 if ext == prefs.ALL_EXTENSIONS:
520 extensions =
list(range(len(backnoises)))
525 set =
read_samples(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
526 e, next, i, context, context.getPc(i)
if context.getNpc()
else None, plot=plot)
528 if fwhmmode[i] < mode:
533 if prefs.getVerboseType() != prefs.QUIET:
535 print(
"%d samples loaded." % set.getNsample())
537 raise RuntimeError(
"No appropriate source found!!")
544 def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
545 diagnostics=False, outDir="", frame=None, title=None):
546 """Show a PSF on display (e.g., ds9) 554 wcsData = wcsData[ext]
555 wcs, naxis1, naxis2 = wcsData
557 wcs, naxis1, naxis2 =
None,
None,
None 559 naxis = [naxis1, naxis2]
563 cmin, cmax = [set.getContextOffset(i) + d*set.getContextScale(i)
for d
in (-0.5, 0.5)]
564 naxis[i] = cmax + cmin
566 if naxis[0] > naxis[1]:
567 nx, ny =
int(nspot*naxis[0]/
float(naxis[1]) + 0.5), nspot
569 nx, ny = nspot,
int(nspot*naxis[1]/
float(naxis[0]) + 0.5)
571 mos = afwDisplay.utils.Mosaic(gutter=2, background=0.02)
573 xpos, ypos = np.linspace(0, naxis[0], nx), np.linspace(0, naxis[1], ny)
578 im = afwImage.ImageF(*psf.getLoc().shape)
579 im.getArray()[:] = psf.getLoc()
582 if trim > im.getHeight()//2:
583 trim = im.getHeight()//2
585 im = im[trim:-trim, trim:-trim]
589 mosaic = mos.makeMosaic(mode=nx)
590 if frame
is not None:
591 afwDisplay.Display(frame=frame).
mtv(mosaic, title=title)
597 for x, y, i
in zip((xpos[0], xpos[-1]), (ypos[0], ypos[-1]), (0, mos.nImage - 1)):
598 bbox = mos.getBBox(i)
599 mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
600 mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
608 delta = pos[1][1][i].asDegrees() - pos[0][1][i].asDegrees()
609 CD.append(delta/(pos[1][0][i] - pos[0][0][i]))
615 title =
"%s-%d" % (title, ext)
617 if frame
is not None:
618 afwDisplay.Display(frame=frame).
mtv(mosaic, title=title, wcs=mosWcs)
621 outFile =
"%s-mod.fits" % title
623 outFile = os.path.join(outDir, outFile)
624 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
626 mos = afwDisplay.utils.Mosaic(gutter=4, background=0.002)
627 for i
in range(set.getNsample()):
629 if ext
is not None and s.getExtindex() != ext:
632 smos = afwDisplay.utils.Mosaic(gutter=2, background=-0.003)
633 for func
in [s.getVig, s.getVigResi]:
636 norm =
float(arr.max())
if True else s.getNorm()
639 im = afwImage.ImageF(*arr.shape)
640 im.getArray()[:] = arr
643 mos.append(smos.makeMosaic(mode=
"x"))
645 mosaic = mos.makeMosaic(title=title)
647 if frame
is not None:
648 afwDisplay.Display(frame=frame + 1).
mtv(mosaic, title=title)
651 outFile =
"%s-psfstars.fits" % title
653 outFile = os.path.join(outDir, outFile)
655 mosaic.writeFits(outFile)
660 "base_PixelFlags_flag_edge",
664 "base_PixelFlags_flag_saturatedCenter",
666 "base_PixelFlags_flag_crCenter",
667 "base_PixelFlags_flag_bad",
674 for i, k
in enumerate(flagKeys):
675 flags[1 << i] = re.sub(
r"\_flag",
"",
676 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
679 for i, k
in enumerate(flagKeys):
682 isSet = tab.get(
"deblend_nChild") > 0
687 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
694 re.sub(
"/src",
r"", fileName),
695 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
697 if guess != fileName
and os.path.exists(guess):
700 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
704 """This is the python wrapper that reads lsst tables 707 if prefs.getVerboseType() != prefs.QUIET:
708 print(
"----- %d input catalogues:" % prefs.getNcat())
713 fields = psfexLib.vectorField()
714 for cat
in prefs.getCatalogs():
715 field = psfexLib.Field(cat)
717 wcssList.append(wcss)
725 cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
726 cdMatrix.shape = (2, 2)
731 naxis1, naxis2 = md.getScalar(
"NAXIS1"), md.getScalar(
"NAXIS2")
735 field.addExt(wcs, naxis1, naxis2, md.getScalar(
"NAXIS2"))
737 wcss.append((wcs, naxis1, naxis2))
746 sets = psfexLib.vectorSet()
750 psfexLib.makeit(fields, sets)
752 ret = [[f.getPsfs()
for f
in fields], sets]
759 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval, nobj,
760 plot=dict(showFlags=
False, showRejection=
False)):
763 set = psfexLib.Set(context)
765 cmin, cmax =
None,
None 766 if set.getNcontext():
767 cmin = np.empty(set.getNcontext())
768 cmax = np.empty(set.getNcontext())
769 for i
in range(set.getNcontext()):
771 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
772 cmax[i] = cmin[i] + set.getContextScale(i)
774 cmin[i] = psfexLib.BIG
775 cmax[i] = -psfexLib.BIG
779 tab = afwTable.SourceCatalog.readFits(filename)
781 centroid = tab.getCentroidDefinition()
782 xm = tab.get(
"%s.x" % centroid)
783 ym = tab.get(
"%s.y" % centroid)
785 shape = tab.getShapeDefinition()
786 ixx = tab.get(
"%s.xx" % shape)
787 iyy = tab.get(
"%s.yy" % shape)
789 rmsSize = np.sqrt(0.5*(ixx + iyy))
790 elong = 0.5*(ixx - iyy)/(ixx + iyy)
792 flux = tab.get(prefs.getPhotfluxRkey())
793 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
801 set.setVigSize(vigw, vigh)
803 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
807 mi = afwImage.MaskedImageF(calexpFile)
808 backnoise2 = np.median(mi.getVariance().getArray())
811 edgeBit = [k
for k, v
in getFlags().
items()
if v ==
"edge"][0]
813 for i, xc, yc
in zip(range(nobj), xm, ym):
820 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
821 vignet[i] = pstamp.getImage().getArray().transpose()
828 for i, key
in enumerate(context.getName()):
829 if context.getPcflag(i):
830 contextvalp.append(pcval[pc])
834 contextvalp.append(tab.header[key[1:]])
836 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
840 contextvalp.append(tab.get(key))
842 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
844 set.setContextname(i, key)
848 flags, flux, fluxErr, rmsSize, elong, vignet,
849 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
853 if not vignet.dtype.isnative:
855 vignet = vignet.byteswap()
857 for i
in np.where(good)[0]:
858 sample = set.newSample()
859 sample.setCatindex(catindex)
860 sample.setExtindex(ext)
862 sample.setVig(vignet[i])
864 pstamp = afwImage.ImageF(*vignet[i].shape)
865 pstamp.getArray()[:] = sample.getVig()
866 afwDisplay.Display().
mtv(pstamp)
868 sample.setNorm(
float(flux[i]))
869 sample.setBacknoise2(backnoise2)
871 sample.setX(
float(xm[i]))
872 sample.setY(
float(ym[i]))
873 sample.setFluxrad(
float(rmsSize[i]))
875 for j
in range(set.getNcontext()):
876 sample.setContext(j,
float(contextvalp[j][i]))
878 set.finiSample(sample, prefs.getProfAccuracy())
881 for j
in range(set.getNcontext()):
882 cmin[j] = contextvalp[j][good].
min()
883 cmax[j] = contextvalp[j][good].
max()
887 for i
in range(set.getNcontext()):
888 set.setContextScale(i, cmax[i] - cmin[i])
889 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
897 def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
898 minsn = prefs.getMinsn()
899 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
900 min = prefs.getFwhmrange()[0]
901 max = prefs.getFwhmrange()[1]
903 filenames = prefs.getCatalogs()
905 ncat = len(filenames)
906 fwhmmin = np.empty(ncat)
907 fwhmmax = np.empty(ncat)
909 if not prefs.getAutoselectFlag():
910 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
911 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
912 fwhmmode = (fwhmmin + fwhmmax)/2.0
919 for i, fileName
in enumerate(filenames):
922 if prefs.getVerboseType() != prefs.QUIET:
923 print(
"Examining Catalog #%d" % (i+1))
926 tab = afwTable.SourceCatalog.readFits(fileName)
929 shape = tab.getShapeDefinition()
930 ixx = tab.get(
"%s.xx" % shape)
931 iyy = tab.get(
"%s.yy" % shape)
933 rmsSize = np.sqrt(0.5*(ixx + iyy))
934 elong = 0.5*(ixx - iyy)/(ixx + iyy)
936 flux = tab.get(prefs.getPhotfluxRkey())
937 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
941 good = np.logical_and(flux/fluxErr > minsn,
942 np.logical_not(flags & prefs.getFlagMask()))
943 good = np.logical_and(good, elong < maxelong)
945 good = np.logical_and(good, fwhm >= min)
946 good = np.logical_and(good, fwhm < max)
947 fwhms[i] = fwhm[good]
949 if prefs.getVarType() == prefs.VAR_NONE:
951 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
953 for l
in fwhms.values():
954 fwhms_all[i:len(l)] = l
957 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
960 raise RuntimeError(
"No source with appropriate FWHM found!!")
961 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
963 fwhmmin = np.zeros(ncat) + min
964 fwhmmax = np.zeros(ncat) + max
965 fwhmmode = np.zeros(ncat) + mode
967 fwhmmode = np.empty(ncat)
968 fwhmmin = np.empty(ncat)
969 fwhmmax = np.empty(ncat)
971 for i
in range(ncat):
974 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
976 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
978 raise RuntimeError(
"No source with appropriate FWHM found!!")
979 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
985 for i, fileName
in enumerate(filenames):
987 for ext
in range(next):
988 set =
read_samplesLsst(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
989 ext, next, i, context,
990 context.getPc(i)
if context.getNpc()
else None, nobj, plot=plot)
992 if fwhmmode[i] < mode:
997 if prefs.getVerboseType() != prefs.QUIET:
999 print(
"%d samples loaded." % set.getNsample())
1001 raise RuntimeError(
"No appropriate source found!!")
1008 def makeit(prefs, context, saveWcs=False, plot=dict()):
1009 """This is the python wrapper for the original psfex that reads SExtractor outputs 1012 if prefs.getVerboseType() != prefs.QUIET:
1013 print(
"----- %d input catalogues:" % prefs.getNcat())
1018 fields = psfexLib.vectorField()
1019 for cat
in prefs.getCatalogs():
1020 field = psfexLib.Field(cat)
1022 wcssList.append(wcss)
1023 with fits.open(cat)
as pf:
1025 if hdu.name ==
"PRIMARY":
1027 elif hdu.name ==
"LDAC_IMHEAD":
1028 hdr = hdu.data[0][0]
1033 except AttributeError:
1036 if not md.exists(
"CRPIX1"):
1037 for k
in md.names():
1038 if re.search(
r"A$", k):
1039 md.set(k[:-1], md.getScalar(k))
1041 naxis1, naxis2 = md.getScalar(
"NAXIS1"), md.getScalar(
"NAXIS2")
1042 elif hdu.name ==
"LDAC_OBJECTS":
1043 nobj = len(hdu.data)
1045 assert wcs,
"LDAC_OBJECTS comes after LDAC_IMHEAD" 1046 field.addExt(wcs, naxis1, naxis2, nobj)
1048 wcss.append((wcs, naxis1, naxis2))
1052 fields.append(field)
1054 sets = psfexLib.vectorSet()
1058 psfexLib.makeit(fields, sets)
1060 ret = [[f.getPsfs()
for f
in fields], sets]
1062 ret.append(wcssList)
def getLsstFlags(tab=None)
def select_candidates(set, prefs, frmin, frmax, flags, flux, fluxerr, rmsSize, elong, vignet, plot=dict(), title="")
def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval, plot=dict(showFlags=False, showRejection=False))
def makeit(prefs, context, saveWcs=False, plot=dict())
def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5, diagnostics=False, outDir="", frame=None, title=None)
def makeitLsst(prefs, context, saveWcs=False, plot=dict())
def guessCalexp(fileName)
def compute_fwhmrange(fwhm, maxvar, minin, maxin, plot=dict(fwhmHistogram=False))
def mtv(data, frame=None, title="", wcs=None, args, kwargs)
Point in an unspecified spherical coordinate system.
std::shared_ptr< SkyWcs > makeSkyWcs(TransformPoint2ToPoint2 const &pixelsToFieldAngle, lsst::geom::Angle const &orientation, bool flipX, lsst::geom::SpherePoint const &boresight, std::string const &projection="TAN")
Construct a FITS SkyWcs from camera geometry.
def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict())
Class for storing generic metadata.
def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval, nobj, plot=dict(showFlags=False, showRejection=False))
std::vector< SchemaItem< Flag > > * items
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
daf::base::PropertyList * list
def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict())