8 import matplotlib.pyplot
as plt
18 from .
import psfexLib
24 """Split a fits header, returning (key, value)""" 26 k, v = re.search(
r"(\S+)\s*=\s*'?((?:\S+|'))", line).groups()
27 except AttributeError:
45 PURPOSE Compute the FWHM range associated to a series of FWHM measurements. 46 INPUT Pointer to an array of FWHMs, 47 maximum allowed FWHM variation, 51 OUTPUT FWHM mode, lower FWHM range, upper FWHM range 53 AUTHOR E. Bertin (IAP, Leiden observatory & ESO) 65 for i
in range(nfwhm - nw):
66 df = fwhm[i + nw] - fwhm[i]
69 fmin = (fwhm[i + nw] + fwhm[i])/2.0
74 dfmin = (maxvar + 1.0)**0.3333333
75 minout = fmin/dfmin
if dfmin > 0.0
else 0.0
79 maxout = fmin*dfmin**2
83 if plt
and plot.get(
"fwhmHistogram"):
85 plt.hist(fwhm, nfwhm//10 + 1, normed=1, facecolor=
'g', alpha=0.75)
87 plt.axvline(fmin, color=
'red')
88 [plt.axvline(_, color=
'blue')
for _
in (minout, maxout)]
92 return fmin, minout, maxout
97 def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
98 plot=dict(showFlags=
False, showRejection=
False)):
101 set = psfexLib.Set(context)
103 cmin, cmax =
None,
None 104 if set.getNcontext():
105 cmin = np.empty(set.getNcontext())
106 cmax = np.empty(set.getNcontext())
107 for i
in range(set.getNcontext()):
109 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
110 cmax[i] = cmin[i] + set.getContextScale(i)
112 cmin[i] = psfexLib.BIG
113 cmax[i] = -psfexLib.BIG
117 with pyfits.open(filename)
as cat:
120 if tab.name ==
"LDAC_IMHEAD":
128 if tab.name ==
"PRIMARY":
130 elif tab.name ==
"LDAC_IMHEAD":
137 except AttributeError:
149 elif tab.name ==
"LDAC_OBJECTS":
150 xm = tab.data[prefs.getCenterKey(0)]
151 ym = tab.data[prefs.getCenterKey(1)]
152 fluxrad = tab.data[
"FLUX_RADIUS"]
153 flux = tab.data[prefs.getPhotfluxRkey()]
154 fluxerr = tab.data[prefs.getPhotfluxerrRkey()]
155 elong = tab.data[
"ELONGATION"]
156 flags = tab.data[
"FLAGS"]
158 n = prefs.getPhotfluxNum() - 1
160 assert False,
"Code to handle e.g. FLUX_APER(3) isn't yet converted" 161 if key.naxis == 1
and n < key.naxisn[0]:
164 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
165 (prefs.getPhotfluxRkey(), filename), file=sys.stderr)
167 n = prefs.getPhotfluxerrNum() - 1
169 if key.naxis == 1
and n < key.naxisn[0]:
172 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
173 (prefs.getPhotfluxerrRkey(), filename), file=sys.stderr)
177 vignet = tab.data[
"VIGNET"]
180 vigw, vigh = vignet[0].shape
182 raise RuntimeError(
"*Error*: VIGNET should be a 2D vector; saw %s" % str(vignet[0].shape))
185 set.setVigSize(vigw, vigh)
190 for i, key
in enumerate(context.getName()):
191 if context.getPcflag(i):
192 contextvalp.append(pcval[pc])
196 contextvalp.append(tab.header[key[1:]])
198 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
202 contextvalp.append(tab.data[key])
204 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
206 set.setContextname(i, key)
210 flags, flux, fluxerr, fluxrad, elong, vignet,
211 plot=plot, title=
"%s[%d]" % (filename, ext + 1))
215 if not vignet.dtype.isnative:
217 vignet = vignet.byteswap()
219 for i
in np.where(good)[0]:
220 sample = set.newSample()
221 sample.setCatindex(catindex)
222 sample.setExtindex(ext)
224 sample.setVig(vignet[i])
226 sample.setNorm(float(flux[i]))
227 sample.setBacknoise2(backnoise2)
229 sample.setX(float(xm[i]))
230 sample.setY(float(ym[i]))
231 sample.setFluxrad(float(fluxrad[i]))
233 for j
in range(set.getNcontext()):
234 sample.setContext(j, float(contextvalp[j][i]))
236 set.finiSample(sample, prefs.getProfAccuracy())
239 for j
in range(set.getNcontext()):
240 cmin[j] = contextvalp[j][good].min()
241 cmax[j] = contextvalp[j][good].max()
245 for i
in range(set.getNcontext()):
246 set.setContextScale(i, cmax[i] - cmin[i])
247 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
258 return {1:
"flux blended",
264 64:
"memory error (deblend)",
265 128:
"memory error (extract)",
270 flags, flux, fluxerr, rmsSize, elong, vignet,
271 plot=dict(), title=
""):
272 maxbad = prefs.getBadpixNmax()
273 maxbadflag = prefs.getBadpixFlag()
274 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100.0
275 minsn = prefs.getMinsn()
277 sn = flux/np.where(fluxerr > 0, fluxerr, 1)
278 sn[fluxerr <= 0] = -psfexLib.BIG
280 plotFlags = plot.get(
"showFlags")
if plt
else False 281 plotRejection = plot.get(
"showRejection")
if plt
else False 283 bad = flags & prefs.getFlagMask() != 0
284 set.setBadFlags(int(sum(bad != 0)))
287 selectionVectors = []
288 selectionVectors.append((bad,
"flags %d" % sum(bad != 0)))
291 set.setBadSN(int(sum(dbad)))
292 bad = np.logical_or(bad, dbad)
294 selectionVectors.append((dbad,
"S/N %d" % sum(dbad)))
296 dbad = rmsSize < frmin
297 set.setBadFrmin(int(sum(dbad)))
298 bad = np.logical_or(bad, dbad)
300 selectionVectors.append((dbad,
"frmin %d" % sum(dbad)))
302 dbad = rmsSize > frmax
303 set.setBadFrmax(int(sum(dbad)))
304 bad = np.logical_or(bad, dbad)
306 selectionVectors.append((dbad,
"frmax %d" % sum(dbad)))
308 dbad = elong > maxelong
309 set.setBadElong(int(sum(dbad)))
310 bad = np.logical_or(bad, dbad)
312 selectionVectors.append((dbad,
"elong %d" % sum(dbad)))
316 nbad = np.array([(v <= -psfexLib.BIG).sum()
for v
in vignet])
318 set.setBadPix(int(sum(dbad)))
319 bad = np.logical_or(bad, dbad)
321 selectionVectors.append((dbad,
"badpix %d" % sum(dbad)))
323 good = np.logical_not(bad)
324 if plotFlags
or plotRejection:
325 imag = -2.5*np.log10(flux)
332 isSet = np.where(flags == 0x0)[0]
333 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=
"good")
337 if mask & prefs.getFlagMask():
338 isSet = np.where(np.bitwise_and(flags, mask))[0]
340 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=labels[mask])
342 for bad, label
in selectionVectors:
343 plt.plot(imag[bad], rmsSize[bad],
'o', alpha=alpha, label=label)
345 plt.plot(imag[good], rmsSize[good],
'o', color=
"black", label=
"selected")
346 [plt.axhline(_, color=
'red')
for _
in [frmin, frmax]]
347 plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
348 plt.ylim(-0.1, 2*frmax)
350 plt.xlabel(
"Instrumental Magnitude")
351 plt.ylabel(
"rmsSize")
352 plt.title(
"%s %d selected" % (title, sum(good)))
369 _dataTypes = dict(LSST=_LSST,
370 SExtractor=_SExtractor
372 _dataType = _SExtractor
376 _dataType = _dataTypes[t]
380 if _dataType == _LSST:
388 def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
389 minsn = prefs.getMinsn()
390 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
391 min = prefs.getFwhmrange()[0]
392 max = prefs.getFwhmrange()[1]
394 filenames = prefs.getCatalogs()
396 ncat = len(filenames)
397 fwhmmin = np.empty(ncat)
398 fwhmmax = np.empty(ncat)
400 if not prefs.getAutoselectFlag():
401 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
402 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
403 fwhmmode = (fwhmmin + fwhmmax)/2.0
410 for i, fileName
in enumerate(filenames):
413 if prefs.getVerboseType() != prefs.QUIET:
414 print(
"Examining Catalog #%d" % (i+1))
418 with pyfits.open(fileName)
as cat:
421 if tab.name ==
"LDAC_IMHEAD":
424 if extCtr != ext
and ext != prefs.ALL_EXTENSIONS:
429 if tab.name ==
"PRIMARY":
431 elif tab.name ==
"LDAC_IMHEAD":
436 except AttributeError:
440 if v < 1/psfexLib.BIG:
445 elif tab.name ==
"LDAC_OBJECTS":
447 rmsSize = tab.data[
"FLUX_RADIUS"]
448 fmax = tab.data[
"FLUX_MAX"]
449 flags = tab.data[
"FLAGS"]
450 elong = tab.data[
"ELONGATION"]
451 backnoise = backnoises[-1]
453 good = np.logical_and(fmax/backnoise > minsn,
454 np.logical_not(flags & prefs.getFlagMask()))
455 good = np.logical_and(good, elong < maxelong)
457 good = np.logical_and(good, fwhm >= min)
458 good = np.logical_and(good, fwhm < max)
459 fwhms[i] = fwhm[good]
461 if prefs.getVarType() == prefs.VAR_NONE:
463 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
465 for l
in fwhms.values():
466 fwhms_all[i:len(l)] = l
469 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
472 raise RuntimeError(
"No source with appropriate FWHM found!!")
473 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
475 fwhmmin = np.zeros(ncat) + min
476 fwhmmax = np.zeros(ncat) + max
477 fwhmmode = np.zeros(ncat) + mode
479 fwhmmode = np.empty(ncat)
480 fwhmmin = np.empty(ncat)
481 fwhmmax = np.empty(ncat)
483 for i
in range(ncat):
486 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
488 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
490 raise RuntimeError(
"No source with appropriate FWHM found!!")
491 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
497 for i, fileName
in enumerate(filenames):
499 if ext == prefs.ALL_EXTENSIONS:
500 extensions = list(range(len(backnoises)))
505 set =
read_samples(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
506 e, next, i, context, context.getPc(i)
if context.getNpc()
else None, plot=plot)
508 if fwhmmode[i] < mode:
513 if prefs.getVerboseType() != prefs.QUIET:
515 print(
"%d samples loaded." % set.getNsample())
517 raise RuntimeError(
"No appropriate source found!!")
526 def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
527 diagnostics=False, outDir="", frame=None, title=None):
528 """Show a PSF on ds9""" 535 wcsData = wcsData[ext]
536 wcs, naxis1, naxis2 = wcsData
538 wcs, naxis1, naxis2 =
None,
None,
None 540 naxis = [naxis1, naxis2]
544 cmin, cmax = [set.getContextOffset(i) + d*set.getContextScale(i)
for d
in (-0.5, 0.5)]
545 naxis[i] = cmax + cmin
548 if naxis[0] > naxis[1]:
549 nx, ny = int(nspot*naxis[0]/float(naxis[1]) + 0.5), nspot
551 nx, ny = nspot, int(nspot*naxis[1]/float(naxis[0]) + 0.5)
553 mos = ds9Utils.Mosaic(gutter=2, background=0.02)
555 xpos, ypos = np.linspace(0, naxis[0], nx), np.linspace(0, naxis[1], ny)
560 im = afwImage.ImageF(*psf.getLoc().shape)
561 im.getArray()[:] = psf.getLoc()
562 im /= float(im.getArray().max())
564 if trim > im.getHeight()//2:
565 trim = im.getHeight()//2
567 im = im[trim:-trim, trim:-trim]
571 mosaic = mos.makeMosaic(mode=nx)
572 if frame
is not None:
573 ds9.mtv(mosaic, frame=frame, title=title)
579 for x, y, i
in zip((xpos[0], xpos[-1]), (ypos[0], ypos[-1]), (0, mos.nImage - 1)):
580 bbox = mos.getBBox(i)
581 mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
582 mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
583 pos.append([afwGeom.PointD(mosx, mosy), wcs.pixelToSky(afwGeom.PointD(x, y))])
585 pos.append([afwGeom.PointD(0, 0), wcs.pixelToSky(afwGeom.PointD(0, 0))])
586 pos.append([afwGeom.PointD(*mosaic.getDimensions()), wcs.pixelToSky(afwGeom.PointD(naxis1, naxis2))])
590 delta = pos[1][1][i].asDegrees() - pos[0][1][i].asDegrees()
591 CD.append(delta/(pos[1][0][i] - pos[0][0][i]))
594 mosWcs = afwGeom.makeSkyWcs(crval=pos[0][0], crpix=pos[0][1], cdMatrix=CD)
597 title =
"%s-%d" % (title, ext)
599 if frame
is not None:
600 ds9.mtv(mosaic, frame=frame, title=title, wcs=mosWcs)
603 outFile =
"%s-mod.fits" % title
605 outFile = os.path.join(outDir, outFile)
606 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
610 mos = ds9Utils.Mosaic(gutter=4, background=0.002)
611 for i
in range(set.getNsample()):
613 if ext
is not None and s.getExtindex() != ext:
616 smos = ds9Utils.Mosaic(gutter=2, background=-0.003)
617 for func
in [s.getVig, s.getVigResi]:
620 norm = float(arr.max())
if True else s.getNorm()
623 im = afwImage.ImageF(*arr.shape)
624 im.getArray()[:] = arr
627 mos.append(smos.makeMosaic(mode=
"x"))
629 mosaic = mos.makeMosaic(title=title)
631 if frame
is not None:
632 ds9.mtv(mosaic, title=title, frame=frame+1)
635 outFile =
"%s-psfstars.fits" % title
637 outFile = os.path.join(outDir, outFile)
639 mosaic.writeFits(outFile)
646 "base_PixelFlags_flag_edge",
650 "base_PixelFlags_flag_saturatedCenter",
652 "base_PixelFlags_flag_crCenter",
653 "base_PixelFlags_flag_bad",
660 for i, k
in enumerate(flagKeys):
661 flags[1 << i] = re.sub(
r"\_flag",
"",
662 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
665 for i, k
in enumerate(flagKeys):
668 isSet = tab.get(
"deblend_nChild") > 0
673 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
680 re.sub(
"/src",
r"", fileName),
681 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
683 if guess != fileName
and os.path.exists(guess):
686 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
692 """This is the python wrapper that reads lsst tables""" 694 if prefs.getVerboseType() != prefs.QUIET:
695 print(
"----- %d input catalogues:" % prefs.getNcat())
700 fields = psfexLib.vectorField()
701 for cat
in prefs.getCatalogs():
702 field = psfexLib.Field(cat)
704 wcssList.append(wcss)
705 with pyfits.open(cat):
708 md = readMetadata(calexpFile)
709 wcs = afwGeom.makeSkyWcs(md)
712 cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
713 cdMatrix.shape = (2, 2)
714 wcs = afwGeom.makeSkyWcs(crpix=afwGeom.PointD(0, 0),
715 crval=afwGeom.SpherePoint(0.0, 0.0, afwGeom.degrees),
718 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
720 md = readMetadata(cat)
722 field.addExt(wcs, naxis1, naxis2, md.get(
"NAXIS2"))
724 wcss.append((wcs, naxis1, naxis2))
733 sets = psfexLib.vectorSet()
737 psfexLib.makeit(fields, sets)
739 ret = [[f.getPsfs()
for f
in fields], sets]
748 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
749 plot=dict(showFlags=
False, showRejection=
False)):
752 set = psfexLib.Set(context)
754 cmin, cmax =
None,
None 755 if set.getNcontext():
756 cmin = np.empty(set.getNcontext())
757 cmax = np.empty(set.getNcontext())
758 for i
in range(set.getNcontext()):
760 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
761 cmax[i] = cmin[i] + set.getContextScale(i)
763 cmin[i] = psfexLib.BIG
764 cmax[i] = -psfexLib.BIG
768 tab = afwTable.SourceCatalog.readFits(filename)
770 centroid = tab.getCentroidDefinition()
771 xm = tab.get(
"%s.x" % centroid)
772 ym = tab.get(
"%s.y" % centroid)
774 shape = tab.getShapeDefinition()
775 ixx = tab.get(
"%s.xx" % shape)
776 iyy = tab.get(
"%s.yy" % shape)
778 rmsSize = np.sqrt(0.5*(ixx + iyy))
779 elong = 0.5*(ixx - iyy)/(ixx + iyy)
781 flux = tab.get(prefs.getPhotfluxRkey())
782 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
790 set.setVigSize(vigw, vigh)
792 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
796 mi = afwImage.MaskedImageF(calexpFile)
797 backnoise2 = np.median(mi.getVariance().getArray())
800 edgeBit = [k
for k, v
in getFlags().items()
if v ==
"edge"][0]
802 for i, xc, yc
in zip(range(nobj), xm, ym):
804 x, y = int(xc), int(yc)
809 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
810 vignet[i] = pstamp.getImage().getArray().transpose()
817 for i, key
in enumerate(context.getName()):
818 if context.getPcflag(i):
819 contextvalp.append(pcval[pc])
823 contextvalp.append(tab.header[key[1:]])
825 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
829 contextvalp.append(tab.get(key))
831 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
833 set.setContextname(i, key)
837 flags, flux, fluxErr, rmsSize, elong, vignet,
838 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
842 if not vignet.dtype.isnative:
844 vignet = vignet.byteswap()
846 for i
in np.where(good)[0]:
847 sample = set.newSample()
848 sample.setCatindex(catindex)
849 sample.setExtindex(ext)
851 sample.setVig(vignet[i])
853 pstamp = afwImage.ImageF(*vignet[i].shape)
854 pstamp.getArray()[:] = sample.getVig()
858 sample.setNorm(float(flux[i]))
859 sample.setBacknoise2(backnoise2)
861 sample.setX(float(xm[i]))
862 sample.setY(float(ym[i]))
863 sample.setFluxrad(float(rmsSize[i]))
865 for j
in range(set.getNcontext()):
866 sample.setContext(j, float(contextvalp[j][i]))
868 set.finiSample(sample, prefs.getProfAccuracy())
871 for j
in range(set.getNcontext()):
872 cmin[j] = contextvalp[j][good].min()
873 cmax[j] = contextvalp[j][good].max()
877 for i
in range(set.getNcontext()):
878 set.setContextScale(i, cmax[i] - cmin[i])
879 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
889 def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
890 minsn = prefs.getMinsn()
891 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
892 min = prefs.getFwhmrange()[0]
893 max = prefs.getFwhmrange()[1]
895 filenames = prefs.getCatalogs()
897 ncat = len(filenames)
898 fwhmmin = np.empty(ncat)
899 fwhmmax = np.empty(ncat)
901 if not prefs.getAutoselectFlag():
902 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
903 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
904 fwhmmode = (fwhmmin + fwhmmax)/2.0
911 for i, fileName
in enumerate(filenames):
914 if prefs.getVerboseType() != prefs.QUIET:
915 print(
"Examining Catalog #%d" % (i+1))
918 tab = afwTable.SourceCatalog.readFits(fileName)
921 shape = tab.getShapeDefinition()
922 ixx = tab.get(
"%s.xx" % shape)
923 iyy = tab.get(
"%s.yy" % shape)
925 rmsSize = np.sqrt(0.5*(ixx + iyy))
926 elong = 0.5*(ixx - iyy)/(ixx + iyy)
928 flux = tab.get(prefs.getPhotfluxRkey())
929 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
933 good = np.logical_and(flux/fluxErr > minsn,
934 np.logical_not(flags & prefs.getFlagMask()))
935 good = np.logical_and(good, elong < maxelong)
937 good = np.logical_and(good, fwhm >= min)
938 good = np.logical_and(good, fwhm < max)
939 fwhms[i] = fwhm[good]
941 if prefs.getVarType() == prefs.VAR_NONE:
943 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
945 for l
in fwhms.values():
946 fwhms_all[i:len(l)] = l
949 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
952 raise RuntimeError(
"No source with appropriate FWHM found!!")
953 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
955 fwhmmin = np.zeros(ncat) + min
956 fwhmmax = np.zeros(ncat) + max
957 fwhmmode = np.zeros(ncat) + mode
959 fwhmmode = np.empty(ncat)
960 fwhmmin = np.empty(ncat)
961 fwhmmax = np.empty(ncat)
963 for i
in range(ncat):
966 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
968 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
970 raise RuntimeError(
"No source with appropriate FWHM found!!")
971 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
977 for i, fileName
in enumerate(filenames):
979 for ext
in range(next):
980 set =
read_samplesLsst(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
981 ext, next, i, context,
982 context.getPc(i)
if context.getNpc()
else None, plot=plot)
984 if fwhmmode[i] < mode:
989 if prefs.getVerboseType() != prefs.QUIET:
991 print(
"%d samples loaded." % set.getNsample())
993 raise RuntimeError(
"No appropriate source found!!")
1002 def makeit(prefs, context, saveWcs=False, plot=dict()):
1003 """This is the python wrapper for the original psfex that reads SExtractor outputs""" 1005 if prefs.getVerboseType() != prefs.QUIET:
1006 print(
"----- %d input catalogues:" % prefs.getNcat())
1011 fields = psfexLib.vectorField()
1012 for cat
in prefs.getCatalogs():
1013 field = psfexLib.Field(cat)
1015 wcssList.append(wcss)
1016 with pyfits.open(cat)
as pf:
1018 if hdu.name ==
"PRIMARY":
1020 elif hdu.name ==
"LDAC_IMHEAD":
1021 hdr = hdu.data[0][0]
1026 except AttributeError:
1029 if not md.exists(
"CRPIX1"):
1030 for k
in md.names():
1031 if re.search(
r"A$", k):
1032 md.set(k[:-1], md.get(k))
1033 wcs = afwGeom.makeSkyWcs(md)
1034 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
1035 elif hdu.name ==
"LDAC_OBJECTS":
1036 nobj = len(hdu.data)
1038 assert wcs,
"LDAC_OBJECTS comes after LDAC_IMHEAD" 1039 field.addExt(wcs, naxis1, naxis2, nobj)
1041 wcss.append((wcs, naxis1, naxis2))
1045 fields.append(field)
1047 sets = psfexLib.vectorSet()
1051 psfexLib.makeit(fields, sets)
1053 ret = [[f.getPsfs()
for f
in fields], sets]
1055 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 read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval, plot=dict(showFlags=False, showRejection=False))
def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict())
def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict())