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
19 import lsst.afw.coord
as afwCoord
20 import lsst.afw.geom
as afwGeom
21 import lsst.afw.image
as afwImage
22 import lsst.afw.table
as afwTable
23 import lsst.afw.display.ds9
as ds9
24 from lsst.daf.base
import PropertySet
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
554 import lsst.afw.display.utils
as ds9Utils
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]))
599 mosWcs = afwImage.makeWcs(pos[0][1], pos[0][0], CD[0], 0, 0, CD[1])
602 title =
"%s-%d" % (title, ext)
604 if frame
is not None:
605 ds9.mtv(mosaic, frame=frame, title=title, wcs=mosWcs)
608 outFile =
"%s-mod.fits" % title
610 outFile = os.path.join(outDir, outFile)
611 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
615 mos = ds9Utils.Mosaic(gutter=4, background=0.002)
616 for i
in range(set.getNsample()):
618 if ext
is not None and s.getExtindex() != ext:
621 smos = ds9Utils.Mosaic(gutter=2, background=-0.003)
622 for func
in [s.getVig, s.getVigResi]:
625 norm = float(arr.max())
if True else s.getNorm()
628 im = afwImage.ImageF(*arr.shape)
629 im.getArray()[:] = arr
632 mos.append(smos.makeMosaic(mode=
"x"))
634 mosaic = mos.makeMosaic(title=title)
636 if frame
is not None:
637 ds9.mtv(mosaic, title=title, frame=frame+1)
640 outFile =
"%s-psfstars.fits" % title
642 outFile = os.path.join(outDir, outFile)
644 mosaic.writeFits(outFile)
651 "base_PixelFlags_flag_edge",
655 "base_PixelFlags_flag_saturatedCenter",
657 "base_PixelFlags_flag_crCenter",
658 "base_PixelFlags_flag_bad",
665 for i, k
in enumerate(flagKeys):
666 flags[1 << i] = re.sub(
r"\_flag",
"",
667 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
670 for i, k
in enumerate(flagKeys):
673 isSet = tab.get(
"deblend_nChild") > 0
678 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
685 re.sub(
"/src",
r"", fileName),
686 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
688 if guess != fileName
and os.path.exists(guess):
691 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
697 """This is the python wrapper that reads lsst tables""" 699 if prefs.getVerboseType() != prefs.QUIET:
700 print(
"----- %d input catalogues:" % prefs.getNcat())
705 fields = psfexLib.vectorField()
706 for cat
in prefs.getCatalogs():
707 field = psfexLib.Field(cat)
709 wcssList.append(wcss)
710 with pyfits.open(cat):
713 md = afwImage.readMetadata(calexpFile)
714 wcs = afwImage.makeWcs(md)
717 crval = afwCoord.makeCoord(afwCoord.ICRS, 0.0*afwGeom.degrees, 0.0*afwGeom.degrees)
718 wcs = afwImage.makeWcs(crval, afwGeom.PointD(0, 0), 1.0, 0, 0, 1.0)
720 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
722 md = afwImage.readMetadata(cat)
724 field.addExt(wcs, naxis1, naxis2, md.get(
"NAXIS2"))
726 wcss.append((wcs, naxis1, naxis2))
735 sets = psfexLib.vectorSet()
739 psfexLib.makeit(fields, sets)
741 ret = [[f.getPsfs()
for f
in fields], sets]
750 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
751 plot=dict(showFlags=
False, showRejection=
False)):
754 set = psfexLib.Set(context)
756 cmin, cmax =
None,
None 757 if set.getNcontext():
758 cmin = np.empty(set.getNcontext())
759 cmax = np.empty(set.getNcontext())
760 for i
in range(set.getNcontext()):
762 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
763 cmax[i] = cmin[i] + set.getContextScale(i)
765 cmin[i] = psfexLib.BIG
766 cmax[i] = -psfexLib.BIG
770 tab = afwTable.SourceCatalog.readFits(filename)
772 centroid = tab.getCentroidDefinition()
773 xm = tab.get(
"%s.x" % centroid)
774 ym = tab.get(
"%s.y" % centroid)
776 shape = tab.getShapeDefinition()
777 ixx = tab.get(
"%s.xx" % shape)
778 iyy = tab.get(
"%s.yy" % shape)
780 rmsSize = np.sqrt(0.5*(ixx + iyy))
781 elong = 0.5*(ixx - iyy)/(ixx + iyy)
783 flux = tab.get(prefs.getPhotfluxRkey())
784 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
792 set.setVigSize(vigw, vigh)
794 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
798 mi = afwImage.MaskedImageF(calexpFile)
799 backnoise2 = np.median(mi.getVariance().getArray())
802 edgeBit = [k
for k, v
in getFlags().items()
if v ==
"edge"][0]
804 for i, xc, yc
in zip(range(nobj), xm, ym):
806 x, y = int(xc), int(yc)
811 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
812 vignet[i] = pstamp.getImage().getArray().transpose()
819 for i, key
in enumerate(context.getName()):
820 if context.getPcflag(i):
821 contextvalp.append(pcval[pc])
825 contextvalp.append(tab.header[key[1:]])
827 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
831 contextvalp.append(tab.get(key))
833 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
835 set.setContextname(i, key)
839 flags, flux, fluxErr, rmsSize, elong, vignet,
840 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
844 if not vignet.dtype.isnative:
846 vignet = vignet.byteswap()
848 for i
in np.where(good)[0]:
849 sample = set.newSample()
850 sample.setCatindex(catindex)
851 sample.setExtindex(ext)
853 sample.setVig(vignet[i])
855 pstamp = afwImage.ImageF(*vignet[i].shape)
856 pstamp.getArray()[:] = sample.getVig()
860 sample.setNorm(float(flux[i]))
861 sample.setBacknoise2(backnoise2)
863 sample.setX(float(xm[i]))
864 sample.setY(float(ym[i]))
865 sample.setFluxrad(float(rmsSize[i]))
867 for j
in range(set.getNcontext()):
868 sample.setContext(j, float(contextvalp[j][i]))
870 set.finiSample(sample, prefs.getProfAccuracy())
873 for j
in range(set.getNcontext()):
874 cmin[j] = contextvalp[j][good].min()
875 cmax[j] = contextvalp[j][good].max()
879 for i
in range(set.getNcontext()):
880 set.setContextScale(i, cmax[i] - cmin[i])
881 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
891 def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
892 minsn = prefs.getMinsn()
893 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
894 min = prefs.getFwhmrange()[0]
895 max = prefs.getFwhmrange()[1]
897 filenames = prefs.getCatalogs()
899 ncat = len(filenames)
900 fwhmmin = np.empty(ncat)
901 fwhmmax = np.empty(ncat)
903 if not prefs.getAutoselectFlag():
904 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
905 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
906 fwhmmode = (fwhmmin + fwhmmax)/2.0
913 for i, fileName
in enumerate(filenames):
916 if prefs.getVerboseType() != prefs.QUIET:
917 print(
"Examining Catalog #%d" % (i+1))
920 tab = afwTable.SourceCatalog.readFits(fileName)
923 shape = tab.getShapeDefinition()
924 ixx = tab.get(
"%s.xx" % shape)
925 iyy = tab.get(
"%s.yy" % shape)
927 rmsSize = np.sqrt(0.5*(ixx + iyy))
928 elong = 0.5*(ixx - iyy)/(ixx + iyy)
930 flux = tab.get(prefs.getPhotfluxRkey())
931 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
935 good = np.logical_and(flux/fluxErr > minsn,
936 np.logical_not(flags & prefs.getFlagMask()))
937 good = np.logical_and(good, elong < maxelong)
939 good = np.logical_and(good, fwhm >= min)
940 good = np.logical_and(good, fwhm < max)
941 fwhms[i] = fwhm[good]
943 if prefs.getVarType() == prefs.VAR_NONE:
945 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
947 for l
in fwhms.values():
948 fwhms_all[i:len(l)] = l
951 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
954 raise RuntimeError(
"No source with appropriate FWHM found!!")
955 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
957 fwhmmin = np.zeros(ncat) + min
958 fwhmmax = np.zeros(ncat) + max
959 fwhmmode = np.zeros(ncat) + mode
961 fwhmmode = np.empty(ncat)
962 fwhmmin = np.empty(ncat)
963 fwhmmax = np.empty(ncat)
965 for i
in range(ncat):
968 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
970 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
972 raise RuntimeError(
"No source with appropriate FWHM found!!")
973 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
979 for i, fileName
in enumerate(filenames):
981 for ext
in range(next):
982 set =
read_samplesLsst(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
983 ext, next, i, context,
984 context.getPc(i)
if context.getNpc()
else None, plot=plot)
986 if fwhmmode[i] < mode:
991 if prefs.getVerboseType() != prefs.QUIET:
993 print(
"%d samples loaded." % set.getNsample())
995 raise RuntimeError(
"No appropriate source found!!")
1004 def makeit(prefs, context, saveWcs=False, plot=dict()):
1005 """This is the python wrapper for the original psfex that reads SExtractor outputs""" 1007 if prefs.getVerboseType() != prefs.QUIET:
1008 print(
"----- %d input catalogues:" % prefs.getNcat())
1013 fields = psfexLib.vectorField()
1014 for cat
in prefs.getCatalogs():
1015 field = psfexLib.Field(cat)
1017 wcssList.append(wcss)
1018 with pyfits.open(cat)
as pf:
1020 if hdu.name ==
"PRIMARY":
1022 elif hdu.name ==
"LDAC_IMHEAD":
1023 hdr = hdu.data[0][0]
1028 except AttributeError:
1031 if not md.exists(
"CRPIX1"):
1032 for k
in md.names():
1033 if re.search(
r"A$", k):
1034 md.set(k[:-1], md.get(k))
1035 wcs = afwImage.makeWcs(md)
1036 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
1037 elif hdu.name ==
"LDAC_OBJECTS":
1038 nobj = len(hdu.data)
1040 assert wcs,
"LDAC_OBJECTS comes after LDAC_IMHEAD" 1041 field.addExt(wcs, naxis1, naxis2, nobj)
1043 wcss.append((wcs, naxis1, naxis2))
1047 fields.append(field)
1049 sets = psfexLib.vectorSet()
1053 psfexLib.makeit(fields, sets)
1055 ret = [[f.getPsfs()
for f
in fields], sets]
1057 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())