2 from __future__
import absolute_import, division, print_function
3 from builtins
import zip
4 from builtins
import input
5 from builtins
import str
6 from builtins
import range
7 from builtins
import object
15 import matplotlib.pyplot
as plt
25 from .
import psfexLib
31 """Split a fits header, returning (key, value)""" 33 k, v = re.search(
r"(\S+)\s*=\s*'?((?:\S+|'))", line).groups()
34 except AttributeError:
52 PURPOSE Compute the FWHM range associated to a series of FWHM measurements. 53 INPUT Pointer to an array of FWHMs, 54 maximum allowed FWHM variation, 58 OUTPUT FWHM mode, lower FWHM range, upper FWHM range 60 AUTHOR E. Bertin (IAP, Leiden observatory & ESO) 72 for i
in range(nfwhm - nw):
73 df = fwhm[i + nw] - fwhm[i]
76 fmin = (fwhm[i + nw] + fwhm[i])/2.0
81 dfmin = (maxvar + 1.0)**0.3333333
82 minout = fmin/dfmin
if dfmin > 0.0
else 0.0
86 maxout = fmin*dfmin**2
90 if plt
and plot.get(
"fwhmHistogram"):
92 plt.hist(fwhm, nfwhm//10 + 1, normed=1, facecolor=
'g', alpha=0.75)
94 plt.axvline(fmin, color=
'red')
95 [plt.axvline(_, color=
'blue')
for _
in (minout, maxout)]
99 return fmin, minout, maxout
104 def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
105 plot=dict(showFlags=
False, showRejection=
False)):
108 set = psfexLib.Set(context)
110 cmin, cmax =
None,
None 111 if set.getNcontext():
112 cmin = np.empty(set.getNcontext())
113 cmax = np.empty(set.getNcontext())
114 for i
in range(set.getNcontext()):
116 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
117 cmax[i] = cmin[i] + set.getContextScale(i)
119 cmin[i] = psfexLib.BIG
120 cmax[i] = -psfexLib.BIG
124 with pyfits.open(filename)
as cat:
127 if tab.name ==
"LDAC_IMHEAD":
135 if tab.name ==
"PRIMARY":
137 elif tab.name ==
"LDAC_IMHEAD":
144 except AttributeError:
156 elif tab.name ==
"LDAC_OBJECTS":
157 xm = tab.data[prefs.getCenterKey(0)]
158 ym = tab.data[prefs.getCenterKey(1)]
159 fluxrad = tab.data[
"FLUX_RADIUS"]
160 flux = tab.data[prefs.getPhotfluxRkey()]
161 fluxerr = tab.data[prefs.getPhotfluxerrRkey()]
162 elong = tab.data[
"ELONGATION"]
163 flags = tab.data[
"FLAGS"]
165 n = prefs.getPhotfluxNum() - 1
167 assert False,
"Code to handle e.g. FLUX_APER(3) isn't yet converted" 168 if key.naxis == 1
and n < key.naxisn[0]:
171 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
172 (prefs.getPhotfluxRkey(), filename), file=sys.stderr)
174 n = prefs.getPhotfluxerrNum() - 1
176 if key.naxis == 1
and n < key.naxisn[0]:
179 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
180 (prefs.getPhotfluxerrRkey(), filename), file=sys.stderr)
184 vignet = tab.data[
"VIGNET"]
187 vigw, vigh = vignet[0].shape
189 raise RuntimeError(
"*Error*: VIGNET should be a 2D vector; saw %s" % str(vignet[0].shape))
192 set.setVigSize(vigw, vigh)
197 for i, key
in enumerate(context.getName()):
198 if context.getPcflag(i):
199 contextvalp.append(pcval[pc])
203 contextvalp.append(tab.header[key[1:]])
205 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
209 contextvalp.append(tab.data[key])
211 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
213 set.setContextname(i, key)
217 flags, flux, fluxerr, fluxrad, elong, vignet,
218 plot=plot, title=
"%s[%d]" % (filename, ext + 1))
222 if not vignet.dtype.isnative:
224 vignet = vignet.byteswap()
226 for i
in np.where(good)[0]:
227 sample = set.newSample()
228 sample.setCatindex(catindex)
229 sample.setExtindex(ext)
231 sample.setVig(vignet[i])
233 sample.setNorm(float(flux[i]))
234 sample.setBacknoise2(backnoise2)
236 sample.setX(float(xm[i]))
237 sample.setY(float(ym[i]))
238 sample.setFluxrad(float(fluxrad[i]))
240 for j
in range(set.getNcontext()):
241 sample.setContext(j, float(contextvalp[j][i]))
243 set.finiSample(sample, prefs.getProfAccuracy())
246 for j
in range(set.getNcontext()):
247 cmin[j] = contextvalp[j][good].min()
248 cmax[j] = contextvalp[j][good].max()
252 for i
in range(set.getNcontext()):
253 set.setContextScale(i, cmax[i] - cmin[i])
254 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
265 return {1:
"flux blended",
271 64:
"memory error (deblend)",
272 128:
"memory error (extract)",
277 flags, flux, fluxerr, rmsSize, elong, vignet,
278 plot=dict(), title=
""):
279 maxbad = prefs.getBadpixNmax()
280 maxbadflag = prefs.getBadpixFlag()
281 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100.0
282 minsn = prefs.getMinsn()
284 sn = flux/np.where(fluxerr > 0, fluxerr, 1)
285 sn[fluxerr <= 0] = -psfexLib.BIG
287 plotFlags = plot.get(
"showFlags")
if plt
else False 288 plotRejection = plot.get(
"showRejection")
if plt
else False 290 bad = flags & prefs.getFlagMask() != 0
291 set.setBadFlags(int(sum(bad != 0)))
294 selectionVectors = []
295 selectionVectors.append((bad,
"flags %d" % sum(bad != 0)))
298 set.setBadSN(int(sum(dbad)))
299 bad = np.logical_or(bad, dbad)
301 selectionVectors.append((dbad,
"S/N %d" % sum(dbad)))
303 dbad = rmsSize < frmin
304 set.setBadFrmin(int(sum(dbad)))
305 bad = np.logical_or(bad, dbad)
307 selectionVectors.append((dbad,
"frmin %d" % sum(dbad)))
309 dbad = rmsSize > frmax
310 set.setBadFrmax(int(sum(dbad)))
311 bad = np.logical_or(bad, dbad)
313 selectionVectors.append((dbad,
"frmax %d" % sum(dbad)))
315 dbad = elong > maxelong
316 set.setBadElong(int(sum(dbad)))
317 bad = np.logical_or(bad, dbad)
319 selectionVectors.append((dbad,
"elong %d" % sum(dbad)))
323 nbad = np.array([(v <= -psfexLib.BIG).sum()
for v
in vignet])
325 set.setBadPix(int(sum(dbad)))
326 bad = np.logical_or(bad, dbad)
328 selectionVectors.append((dbad,
"badpix %d" % sum(dbad)))
330 good = np.logical_not(bad)
331 if plotFlags
or plotRejection:
332 imag = -2.5*np.log10(flux)
339 isSet = np.where(flags == 0x0)[0]
340 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=
"good")
344 if mask & prefs.getFlagMask():
345 isSet = np.where(np.bitwise_and(flags, mask))[0]
347 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=labels[mask])
349 for bad, label
in selectionVectors:
350 plt.plot(imag[bad], rmsSize[bad],
'o', alpha=alpha, label=label)
352 plt.plot(imag[good], rmsSize[good],
'o', color=
"black", label=
"selected")
353 [plt.axhline(_, color=
'red')
for _
in [frmin, frmax]]
354 plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
355 plt.ylim(-0.1, 2*frmax)
357 plt.xlabel(
"Instrumental Magnitude")
358 plt.ylabel(
"rmsSize")
359 plt.title(
"%s %d selected" % (title, sum(good)))
376 _dataTypes = dict(LSST=_LSST,
377 SExtractor=_SExtractor
379 _dataType = _SExtractor
383 _dataType = _dataTypes[t]
387 if _dataType == _LSST:
395 def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
396 minsn = prefs.getMinsn()
397 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
398 min = prefs.getFwhmrange()[0]
399 max = prefs.getFwhmrange()[1]
401 filenames = prefs.getCatalogs()
403 ncat = len(filenames)
404 fwhmmin = np.empty(ncat)
405 fwhmmax = np.empty(ncat)
407 if not prefs.getAutoselectFlag():
408 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
409 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
410 fwhmmode = (fwhmmin + fwhmmax)/2.0
417 for i, fileName
in enumerate(filenames):
420 if prefs.getVerboseType() != prefs.QUIET:
421 print(
"Examining Catalog #%d" % (i+1))
425 with pyfits.open(fileName)
as cat:
428 if tab.name ==
"LDAC_IMHEAD":
431 if extCtr != ext
and ext != prefs.ALL_EXTENSIONS:
436 if tab.name ==
"PRIMARY":
438 elif tab.name ==
"LDAC_IMHEAD":
443 except AttributeError:
447 if v < 1/psfexLib.BIG:
452 elif tab.name ==
"LDAC_OBJECTS":
454 rmsSize = tab.data[
"FLUX_RADIUS"]
455 fmax = tab.data[
"FLUX_MAX"]
456 flags = tab.data[
"FLAGS"]
457 elong = tab.data[
"ELONGATION"]
458 backnoise = backnoises[-1]
460 good = np.logical_and(fmax/backnoise > minsn,
461 np.logical_not(flags & prefs.getFlagMask()))
462 good = np.logical_and(good, elong < maxelong)
464 good = np.logical_and(good, fwhm >= min)
465 good = np.logical_and(good, fwhm < max)
466 fwhms[i] = fwhm[good]
468 if prefs.getVarType() == prefs.VAR_NONE:
470 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
472 for l
in fwhms.values():
473 fwhms_all[i:len(l)] = l
476 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
479 raise RuntimeError(
"No source with appropriate FWHM found!!")
480 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
482 fwhmmin = np.zeros(ncat) + min
483 fwhmmax = np.zeros(ncat) + max
484 fwhmmode = np.zeros(ncat) + mode
486 fwhmmode = np.empty(ncat)
487 fwhmmin = np.empty(ncat)
488 fwhmmax = np.empty(ncat)
490 for i
in range(ncat):
493 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
495 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
497 raise RuntimeError(
"No source with appropriate FWHM found!!")
498 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
504 for i, fileName
in enumerate(filenames):
506 if ext == prefs.ALL_EXTENSIONS:
507 extensions = list(range(len(backnoises)))
512 set =
read_samples(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
513 e, next, i, context, context.getPc(i)
if context.getNpc()
else None, plot=plot)
515 if fwhmmode[i] < mode:
520 if prefs.getVerboseType() != prefs.QUIET:
522 print(
"%d samples loaded." % set.getNsample())
524 raise RuntimeError(
"No appropriate source found!!")
533 def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
534 diagnostics=False, outDir="", frame=None, title=None):
535 """Show a PSF on ds9""" 542 wcsData = wcsData[ext]
543 wcs, naxis1, naxis2 = wcsData
545 wcs, naxis1, naxis2 =
None,
None,
None 547 naxis = [naxis1, naxis2]
551 cmin, cmax = [set.getContextOffset(i) + d*set.getContextScale(i)
for d
in (-0.5, 0.5)]
552 naxis[i] = cmax + cmin
555 if naxis[0] > naxis[1]:
556 nx, ny = int(nspot*naxis[0]/float(naxis[1]) + 0.5), nspot
558 nx, ny = nspot, int(nspot*naxis[1]/float(naxis[0]) + 0.5)
560 mos = ds9Utils.Mosaic(gutter=2, background=0.02)
562 xpos, ypos = np.linspace(0, naxis[0], nx), np.linspace(0, naxis[1], ny)
567 im = afwImage.ImageF(*psf.getLoc().shape)
568 im.getArray()[:] = psf.getLoc()
569 im /= float(im.getArray().max())
571 if trim > im.getHeight()//2:
572 trim = im.getHeight()//2
574 im = im[trim:-trim, trim:-trim]
578 mosaic = mos.makeMosaic(mode=nx)
579 if frame
is not None:
580 ds9.mtv(mosaic, frame=frame, title=title)
586 for x, y, i
in zip((xpos[0], xpos[-1]), (ypos[0], ypos[-1]), (0, mos.nImage - 1)):
587 bbox = mos.getBBox(i)
588 mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
589 mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
590 pos.append([afwGeom.PointD(mosx, mosy), wcs.pixelToSky(afwGeom.PointD(x, y))])
592 pos.append([afwGeom.PointD(0, 0), wcs.pixelToSky(afwGeom.PointD(0, 0))])
593 pos.append([afwGeom.PointD(*mosaic.getDimensions()), wcs.pixelToSky(afwGeom.PointD(naxis1, naxis2))])
597 delta = pos[1][1][i].asDegrees() - pos[0][1][i].asDegrees()
598 CD.append(delta/(pos[1][0][i] - pos[0][0][i]))
601 mosWcs = afwGeom.makeSkyWcs(crval=pos[0][0], crpix=pos[0][1], cdMatrix=CD)
604 title =
"%s-%d" % (title, ext)
606 if frame
is not None:
607 ds9.mtv(mosaic, frame=frame, title=title, wcs=mosWcs)
610 outFile =
"%s-mod.fits" % title
612 outFile = os.path.join(outDir, outFile)
613 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
617 mos = ds9Utils.Mosaic(gutter=4, background=0.002)
618 for i
in range(set.getNsample()):
620 if ext
is not None and s.getExtindex() != ext:
623 smos = ds9Utils.Mosaic(gutter=2, background=-0.003)
624 for func
in [s.getVig, s.getVigResi]:
627 norm = float(arr.max())
if True else s.getNorm()
630 im = afwImage.ImageF(*arr.shape)
631 im.getArray()[:] = arr
634 mos.append(smos.makeMosaic(mode=
"x"))
636 mosaic = mos.makeMosaic(title=title)
638 if frame
is not None:
639 ds9.mtv(mosaic, title=title, frame=frame+1)
642 outFile =
"%s-psfstars.fits" % title
644 outFile = os.path.join(outDir, outFile)
646 mosaic.writeFits(outFile)
653 "base_PixelFlags_flag_edge",
657 "base_PixelFlags_flag_saturatedCenter",
659 "base_PixelFlags_flag_crCenter",
660 "base_PixelFlags_flag_bad",
667 for i, k
in enumerate(flagKeys):
668 flags[1 << i] = re.sub(
r"\_flag",
"",
669 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
672 for i, k
in enumerate(flagKeys):
675 isSet = tab.get(
"deblend_nChild") > 0
680 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
687 re.sub(
"/src",
r"", fileName),
688 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
690 if guess != fileName
and os.path.exists(guess):
693 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
699 """This is the python wrapper that reads lsst tables""" 701 if prefs.getVerboseType() != prefs.QUIET:
702 print(
"----- %d input catalogues:" % prefs.getNcat())
707 fields = psfexLib.vectorField()
708 for cat
in prefs.getCatalogs():
709 field = psfexLib.Field(cat)
711 wcssList.append(wcss)
712 with pyfits.open(cat):
715 md = readMetadata(calexpFile)
716 wcs = afwGeom.makeSkyWcs(md)
719 cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
720 cdMatrix.shape = (2, 2)
721 wcs = afwGeom.makeSkyWcs(crpix=afwGeom.PointD(0, 0),
722 crval=afwGeom.SpherePoint(0.0, 0.0, afwGeom.degrees),
725 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
727 md = readMetadata(cat)
729 field.addExt(wcs, naxis1, naxis2, md.get(
"NAXIS2"))
731 wcss.append((wcs, naxis1, naxis2))
740 sets = psfexLib.vectorSet()
744 psfexLib.makeit(fields, sets)
746 ret = [[f.getPsfs()
for f
in fields], sets]
755 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
756 plot=dict(showFlags=
False, showRejection=
False)):
759 set = psfexLib.Set(context)
761 cmin, cmax =
None,
None 762 if set.getNcontext():
763 cmin = np.empty(set.getNcontext())
764 cmax = np.empty(set.getNcontext())
765 for i
in range(set.getNcontext()):
767 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
768 cmax[i] = cmin[i] + set.getContextScale(i)
770 cmin[i] = psfexLib.BIG
771 cmax[i] = -psfexLib.BIG
775 tab = afwTable.SourceCatalog.readFits(filename)
777 centroid = tab.getCentroidDefinition()
778 xm = tab.get(
"%s.x" % centroid)
779 ym = tab.get(
"%s.y" % centroid)
781 shape = tab.getShapeDefinition()
782 ixx = tab.get(
"%s.xx" % shape)
783 iyy = tab.get(
"%s.yy" % shape)
785 rmsSize = np.sqrt(0.5*(ixx + iyy))
786 elong = 0.5*(ixx - iyy)/(ixx + iyy)
788 flux = tab.get(prefs.getPhotfluxRkey())
789 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
797 set.setVigSize(vigw, vigh)
799 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
803 mi = afwImage.MaskedImageF(calexpFile)
804 backnoise2 = np.median(mi.getVariance().getArray())
807 edgeBit = [k
for k, v
in getFlags().items()
if v ==
"edge"][0]
809 for i, xc, yc
in zip(range(nobj), xm, ym):
811 x, y = int(xc), int(yc)
816 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
817 vignet[i] = pstamp.getImage().getArray().transpose()
824 for i, key
in enumerate(context.getName()):
825 if context.getPcflag(i):
826 contextvalp.append(pcval[pc])
830 contextvalp.append(tab.header[key[1:]])
832 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
836 contextvalp.append(tab.get(key))
838 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
840 set.setContextname(i, key)
844 flags, flux, fluxErr, rmsSize, elong, vignet,
845 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
849 if not vignet.dtype.isnative:
851 vignet = vignet.byteswap()
853 for i
in np.where(good)[0]:
854 sample = set.newSample()
855 sample.setCatindex(catindex)
856 sample.setExtindex(ext)
858 sample.setVig(vignet[i])
860 pstamp = afwImage.ImageF(*vignet[i].shape)
861 pstamp.getArray()[:] = sample.getVig()
865 sample.setNorm(float(flux[i]))
866 sample.setBacknoise2(backnoise2)
868 sample.setX(float(xm[i]))
869 sample.setY(float(ym[i]))
870 sample.setFluxrad(float(rmsSize[i]))
872 for j
in range(set.getNcontext()):
873 sample.setContext(j, float(contextvalp[j][i]))
875 set.finiSample(sample, prefs.getProfAccuracy())
878 for j
in range(set.getNcontext()):
879 cmin[j] = contextvalp[j][good].min()
880 cmax[j] = contextvalp[j][good].max()
884 for i
in range(set.getNcontext()):
885 set.setContextScale(i, cmax[i] - cmin[i])
886 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
896 def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
897 minsn = prefs.getMinsn()
898 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
899 min = prefs.getFwhmrange()[0]
900 max = prefs.getFwhmrange()[1]
902 filenames = prefs.getCatalogs()
904 ncat = len(filenames)
905 fwhmmin = np.empty(ncat)
906 fwhmmax = np.empty(ncat)
908 if not prefs.getAutoselectFlag():
909 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
910 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
911 fwhmmode = (fwhmmin + fwhmmax)/2.0
918 for i, fileName
in enumerate(filenames):
921 if prefs.getVerboseType() != prefs.QUIET:
922 print(
"Examining Catalog #%d" % (i+1))
925 tab = afwTable.SourceCatalog.readFits(fileName)
928 shape = tab.getShapeDefinition()
929 ixx = tab.get(
"%s.xx" % shape)
930 iyy = tab.get(
"%s.yy" % shape)
932 rmsSize = np.sqrt(0.5*(ixx + iyy))
933 elong = 0.5*(ixx - iyy)/(ixx + iyy)
935 flux = tab.get(prefs.getPhotfluxRkey())
936 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
940 good = np.logical_and(flux/fluxErr > minsn,
941 np.logical_not(flags & prefs.getFlagMask()))
942 good = np.logical_and(good, elong < maxelong)
944 good = np.logical_and(good, fwhm >= min)
945 good = np.logical_and(good, fwhm < max)
946 fwhms[i] = fwhm[good]
948 if prefs.getVarType() == prefs.VAR_NONE:
950 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
952 for l
in fwhms.values():
953 fwhms_all[i:len(l)] = l
956 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
959 raise RuntimeError(
"No source with appropriate FWHM found!!")
960 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
962 fwhmmin = np.zeros(ncat) + min
963 fwhmmax = np.zeros(ncat) + max
964 fwhmmode = np.zeros(ncat) + mode
966 fwhmmode = np.empty(ncat)
967 fwhmmin = np.empty(ncat)
968 fwhmmax = np.empty(ncat)
970 for i
in range(ncat):
973 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
975 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
977 raise RuntimeError(
"No source with appropriate FWHM found!!")
978 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
984 for i, fileName
in enumerate(filenames):
986 for ext
in range(next):
987 set =
read_samplesLsst(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
988 ext, next, i, context,
989 context.getPc(i)
if context.getNpc()
else None, plot=plot)
991 if fwhmmode[i] < mode:
996 if prefs.getVerboseType() != prefs.QUIET:
998 print(
"%d samples loaded." % set.getNsample())
1000 raise RuntimeError(
"No appropriate source found!!")
1009 def makeit(prefs, context, saveWcs=False, plot=dict()):
1010 """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 pyfits.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.get(k))
1040 wcs = afwGeom.makeSkyWcs(md)
1041 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"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 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())