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
26 from .
import psfexLib
32 """Split a fits header, returning (key, value)""" 34 k, v = re.search(
r"(\S+)\s*=\s*'?((?:\S+|'))", line).groups()
35 except AttributeError:
53 PURPOSE Compute the FWHM range associated to a series of FWHM measurements. 54 INPUT Pointer to an array of FWHMs, 55 maximum allowed FWHM variation, 59 OUTPUT FWHM mode, lower FWHM range, upper FWHM range 61 AUTHOR E. Bertin (IAP, Leiden observatory & ESO) 73 for i
in range(nfwhm - nw):
74 df = fwhm[i + nw] - fwhm[i]
77 fmin = (fwhm[i + nw] + fwhm[i])/2.0
82 dfmin = (maxvar + 1.0)**0.3333333
83 minout = fmin/dfmin
if dfmin > 0.0
else 0.0
87 maxout = fmin*dfmin**2
91 if plt
and plot.get(
"fwhmHistogram"):
93 plt.hist(fwhm, nfwhm//10 + 1, normed=1, facecolor=
'g', alpha=0.75)
95 plt.axvline(fmin, color=
'red')
96 [plt.axvline(_, color=
'blue')
for _
in (minout, maxout)]
100 return fmin, minout, maxout
105 def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
106 plot=dict(showFlags=
False, showRejection=
False)):
109 set = psfexLib.Set(context)
111 cmin, cmax =
None,
None 112 if set.getNcontext():
113 cmin = np.empty(set.getNcontext())
114 cmax = np.empty(set.getNcontext())
115 for i
in range(set.getNcontext()):
117 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
118 cmax[i] = cmin[i] + set.getContextScale(i)
120 cmin[i] = psfexLib.BIG
121 cmax[i] = -psfexLib.BIG
125 with pyfits.open(filename)
as cat:
128 if tab.name ==
"LDAC_IMHEAD":
136 if tab.name ==
"PRIMARY":
138 elif tab.name ==
"LDAC_IMHEAD":
145 except AttributeError:
157 elif tab.name ==
"LDAC_OBJECTS":
158 xm = tab.data[prefs.getCenterKey(0)]
159 ym = tab.data[prefs.getCenterKey(1)]
160 fluxrad = tab.data[
"FLUX_RADIUS"]
161 flux = tab.data[prefs.getPhotfluxRkey()]
162 fluxerr = tab.data[prefs.getPhotfluxerrRkey()]
163 elong = tab.data[
"ELONGATION"]
164 flags = tab.data[
"FLAGS"]
166 n = prefs.getPhotfluxNum() - 1
168 assert False,
"Code to handle e.g. FLUX_APER(3) isn't yet converted" 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.getPhotfluxRkey(), filename), file=sys.stderr)
175 n = prefs.getPhotfluxerrNum() - 1
177 if key.naxis == 1
and n < key.naxisn[0]:
180 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
181 (prefs.getPhotfluxerrRkey(), filename), file=sys.stderr)
185 vignet = tab.data[
"VIGNET"]
188 vigw, vigh = vignet[0].shape
190 raise RuntimeError(
"*Error*: VIGNET should be a 2D vector; saw %s" % str(vignet[0].shape))
193 set.setVigSize(vigw, vigh)
198 for i, key
in enumerate(context.getName()):
199 if context.getPcflag(i):
200 contextvalp.append(pcval[pc])
204 contextvalp.append(tab.header[key[1:]])
206 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
210 contextvalp.append(tab.data[key])
212 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
214 set.setContextname(i, key)
218 flags, flux, fluxerr, fluxrad, elong, vignet,
219 plot=plot, title=
"%s[%d]" % (filename, ext + 1))
223 if not vignet.dtype.isnative:
225 vignet = vignet.byteswap()
227 for i
in np.where(good)[0]:
228 sample = set.newSample()
229 sample.setCatindex(catindex)
230 sample.setExtindex(ext)
232 sample.setVig(vignet[i])
234 sample.setNorm(float(flux[i]))
235 sample.setBacknoise2(backnoise2)
237 sample.setX(float(xm[i]))
238 sample.setY(float(ym[i]))
239 sample.setFluxrad(float(fluxrad[i]))
241 for j
in range(set.getNcontext()):
242 sample.setContext(j, float(contextvalp[j][i]))
244 set.finiSample(sample, prefs.getProfAccuracy())
247 for j
in range(set.getNcontext()):
248 cmin[j] = contextvalp[j][good].min()
249 cmax[j] = contextvalp[j][good].max()
253 for i
in range(set.getNcontext()):
254 set.setContextScale(i, cmax[i] - cmin[i])
255 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
266 return {1:
"flux blended",
272 64:
"memory error (deblend)",
273 128:
"memory error (extract)",
278 flags, flux, fluxerr, rmsSize, elong, vignet,
279 plot=dict(), title=
""):
280 maxbad = prefs.getBadpixNmax()
281 maxbadflag = prefs.getBadpixFlag()
282 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100.0
283 minsn = prefs.getMinsn()
285 sn = flux/np.where(fluxerr > 0, fluxerr, 1)
286 sn[fluxerr <= 0] = -psfexLib.BIG
288 plotFlags = plot.get(
"showFlags")
if plt
else False 289 plotRejection = plot.get(
"showRejection")
if plt
else False 291 bad = flags & prefs.getFlagMask() != 0
292 set.setBadFlags(int(sum(bad != 0)))
295 selectionVectors = []
296 selectionVectors.append((bad,
"flags %d" % sum(bad != 0)))
299 set.setBadSN(int(sum(dbad)))
300 bad = np.logical_or(bad, dbad)
302 selectionVectors.append((dbad,
"S/N %d" % sum(dbad)))
304 dbad = rmsSize < frmin
305 set.setBadFrmin(int(sum(dbad)))
306 bad = np.logical_or(bad, dbad)
308 selectionVectors.append((dbad,
"frmin %d" % sum(dbad)))
310 dbad = rmsSize > frmax
311 set.setBadFrmax(int(sum(dbad)))
312 bad = np.logical_or(bad, dbad)
314 selectionVectors.append((dbad,
"frmax %d" % sum(dbad)))
316 dbad = elong > maxelong
317 set.setBadElong(int(sum(dbad)))
318 bad = np.logical_or(bad, dbad)
320 selectionVectors.append((dbad,
"elong %d" % sum(dbad)))
324 nbad = np.array([(v <= -psfexLib.BIG).sum()
for v
in vignet])
326 set.setBadPix(int(sum(dbad)))
327 bad = np.logical_or(bad, dbad)
329 selectionVectors.append((dbad,
"badpix %d" % sum(dbad)))
331 good = np.logical_not(bad)
332 if plotFlags
or plotRejection:
333 imag = -2.5*np.log10(flux)
340 isSet = np.where(flags == 0x0)[0]
341 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=
"good")
345 if mask & prefs.getFlagMask():
346 isSet = np.where(np.bitwise_and(flags, mask))[0]
348 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=labels[mask])
350 for bad, label
in selectionVectors:
351 plt.plot(imag[bad], rmsSize[bad],
'o', alpha=alpha, label=label)
353 plt.plot(imag[good], rmsSize[good],
'o', color=
"black", label=
"selected")
354 [plt.axhline(_, color=
'red')
for _
in [frmin, frmax]]
355 plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
356 plt.ylim(-0.1, 2*frmax)
358 plt.xlabel(
"Instrumental Magnitude")
359 plt.ylabel(
"rmsSize")
360 plt.title(
"%s %d selected" % (title, sum(good)))
377 _dataTypes = dict(LSST=_LSST,
378 SExtractor=_SExtractor
380 _dataType = _SExtractor
384 _dataType = _dataTypes[t]
388 if _dataType == _LSST:
396 def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
397 minsn = prefs.getMinsn()
398 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
399 min = prefs.getFwhmrange()[0]
400 max = prefs.getFwhmrange()[1]
402 filenames = prefs.getCatalogs()
404 ncat = len(filenames)
405 fwhmmin = np.empty(ncat)
406 fwhmmax = np.empty(ncat)
408 if not prefs.getAutoselectFlag():
409 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
410 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
411 fwhmmode = (fwhmmin + fwhmmax)/2.0
418 for i, fileName
in enumerate(filenames):
421 if prefs.getVerboseType() != prefs.QUIET:
422 print(
"Examining Catalog #%d" % (i+1))
426 with pyfits.open(fileName)
as cat:
429 if tab.name ==
"LDAC_IMHEAD":
432 if extCtr != ext
and ext != prefs.ALL_EXTENSIONS:
437 if tab.name ==
"PRIMARY":
439 elif tab.name ==
"LDAC_IMHEAD":
444 except AttributeError:
448 if v < 1/psfexLib.BIG:
453 elif tab.name ==
"LDAC_OBJECTS":
455 rmsSize = tab.data[
"FLUX_RADIUS"]
456 fmax = tab.data[
"FLUX_MAX"]
457 flags = tab.data[
"FLAGS"]
458 elong = tab.data[
"ELONGATION"]
459 backnoise = backnoises[-1]
461 good = np.logical_and(fmax/backnoise > minsn,
462 np.logical_not(flags & prefs.getFlagMask()))
463 good = np.logical_and(good, elong < maxelong)
465 good = np.logical_and(good, fwhm >= min)
466 good = np.logical_and(good, fwhm < max)
467 fwhms[i] = fwhm[good]
469 if prefs.getVarType() == prefs.VAR_NONE:
471 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
473 for l
in fwhms.values():
474 fwhms_all[i:len(l)] = l
477 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
480 raise RuntimeError(
"No source with appropriate FWHM found!!")
481 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
483 fwhmmin = np.zeros(ncat) + min
484 fwhmmax = np.zeros(ncat) + max
485 fwhmmode = np.zeros(ncat) + mode
487 fwhmmode = np.empty(ncat)
488 fwhmmin = np.empty(ncat)
489 fwhmmax = np.empty(ncat)
491 for i
in range(ncat):
494 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
496 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
498 raise RuntimeError(
"No source with appropriate FWHM found!!")
499 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
505 for i, fileName
in enumerate(filenames):
507 if ext == prefs.ALL_EXTENSIONS:
508 extensions = list(range(len(backnoises)))
513 set =
read_samples(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
514 e, next, i, context, context.getPc(i)
if context.getNpc()
else None, plot=plot)
516 if fwhmmode[i] < mode:
521 if prefs.getVerboseType() != prefs.QUIET:
523 print(
"%d samples loaded." % set.getNsample())
525 raise RuntimeError(
"No appropriate source found!!")
534 def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
535 diagnostics=False, outDir="", frame=None, title=None):
536 """Show a PSF on ds9""" 543 wcsData = wcsData[ext]
544 wcs, naxis1, naxis2 = wcsData
546 wcs, naxis1, naxis2 =
None,
None,
None 548 naxis = [naxis1, naxis2]
552 cmin, cmax = [set.getContextOffset(i) + d*set.getContextScale(i)
for d
in (-0.5, 0.5)]
553 naxis[i] = cmax + cmin
556 if naxis[0] > naxis[1]:
557 nx, ny = int(nspot*naxis[0]/float(naxis[1]) + 0.5), nspot
559 nx, ny = nspot, int(nspot*naxis[1]/float(naxis[0]) + 0.5)
561 mos = ds9Utils.Mosaic(gutter=2, background=0.02)
563 xpos, ypos = np.linspace(0, naxis[0], nx), np.linspace(0, naxis[1], ny)
568 im = afwImage.ImageF(*psf.getLoc().shape)
569 im.getArray()[:] = psf.getLoc()
570 im /= float(im.getArray().max())
572 if trim > im.getHeight()//2:
573 trim = im.getHeight()//2
575 im = im[trim:-trim, trim:-trim]
579 mosaic = mos.makeMosaic(mode=nx)
580 if frame
is not None:
581 ds9.mtv(mosaic, frame=frame, title=title)
587 for x, y, i
in zip((xpos[0], xpos[-1]), (ypos[0], ypos[-1]), (0, mos.nImage - 1)):
588 bbox = mos.getBBox(i)
589 mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
590 mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
591 pos.append([afwGeom.PointD(mosx, mosy), wcs.pixelToSky(afwGeom.PointD(x, y))])
593 pos.append([afwGeom.PointD(0, 0), wcs.pixelToSky(afwGeom.PointD(0, 0))])
594 pos.append([afwGeom.PointD(*mosaic.getDimensions()), wcs.pixelToSky(afwGeom.PointD(naxis1, naxis2))])
598 delta = pos[1][1][i].asDegrees() - pos[0][1][i].asDegrees()
599 CD.append(delta/(pos[1][0][i] - pos[0][0][i]))
602 mosWcs = afwGeom.makeSkyWcs(crval=pos[0][0], crpix=pos[0][1], cdMatrix=CD)
605 title =
"%s-%d" % (title, ext)
607 if frame
is not None:
608 ds9.mtv(mosaic, frame=frame, title=title, wcs=mosWcs)
611 outFile =
"%s-mod.fits" % title
613 outFile = os.path.join(outDir, outFile)
614 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
618 mos = ds9Utils.Mosaic(gutter=4, background=0.002)
619 for i
in range(set.getNsample()):
621 if ext
is not None and s.getExtindex() != ext:
624 smos = ds9Utils.Mosaic(gutter=2, background=-0.003)
625 for func
in [s.getVig, s.getVigResi]:
628 norm = float(arr.max())
if True else s.getNorm()
631 im = afwImage.ImageF(*arr.shape)
632 im.getArray()[:] = arr
635 mos.append(smos.makeMosaic(mode=
"x"))
637 mosaic = mos.makeMosaic(title=title)
639 if frame
is not None:
640 ds9.mtv(mosaic, title=title, frame=frame+1)
643 outFile =
"%s-psfstars.fits" % title
645 outFile = os.path.join(outDir, outFile)
647 mosaic.writeFits(outFile)
654 "base_PixelFlags_flag_edge",
658 "base_PixelFlags_flag_saturatedCenter",
660 "base_PixelFlags_flag_crCenter",
661 "base_PixelFlags_flag_bad",
668 for i, k
in enumerate(flagKeys):
669 flags[1 << i] = re.sub(
r"\_flag",
"",
670 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
673 for i, k
in enumerate(flagKeys):
676 isSet = tab.get(
"deblend_nChild") > 0
681 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
688 re.sub(
"/src",
r"", fileName),
689 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
691 if guess != fileName
and os.path.exists(guess):
694 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
700 """This is the python wrapper that reads lsst tables""" 702 if prefs.getVerboseType() != prefs.QUIET:
703 print(
"----- %d input catalogues:" % prefs.getNcat())
708 fields = psfexLib.vectorField()
709 for cat
in prefs.getCatalogs():
710 field = psfexLib.Field(cat)
712 wcssList.append(wcss)
713 with pyfits.open(cat):
716 md = readMetadata(calexpFile)
717 wcs = afwGeom.makeSkyWcs(md)
720 cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
721 cdMatrix.shape = (2, 2)
722 wcs = afwGeom.makeSkyWcs(crpix=afwGeom.PointD(0, 0),
723 crval=
IcrsCoord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees),
726 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
728 md = readMetadata(cat)
730 field.addExt(wcs, naxis1, naxis2, md.get(
"NAXIS2"))
732 wcss.append((wcs, naxis1, naxis2))
741 sets = psfexLib.vectorSet()
745 psfexLib.makeit(fields, sets)
747 ret = [[f.getPsfs()
for f
in fields], sets]
756 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
757 plot=dict(showFlags=
False, showRejection=
False)):
760 set = psfexLib.Set(context)
762 cmin, cmax =
None,
None 763 if set.getNcontext():
764 cmin = np.empty(set.getNcontext())
765 cmax = np.empty(set.getNcontext())
766 for i
in range(set.getNcontext()):
768 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
769 cmax[i] = cmin[i] + set.getContextScale(i)
771 cmin[i] = psfexLib.BIG
772 cmax[i] = -psfexLib.BIG
776 tab = afwTable.SourceCatalog.readFits(filename)
778 centroid = tab.getCentroidDefinition()
779 xm = tab.get(
"%s.x" % centroid)
780 ym = tab.get(
"%s.y" % centroid)
782 shape = tab.getShapeDefinition()
783 ixx = tab.get(
"%s.xx" % shape)
784 iyy = tab.get(
"%s.yy" % shape)
786 rmsSize = np.sqrt(0.5*(ixx + iyy))
787 elong = 0.5*(ixx - iyy)/(ixx + iyy)
789 flux = tab.get(prefs.getPhotfluxRkey())
790 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
798 set.setVigSize(vigw, vigh)
800 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
804 mi = afwImage.MaskedImageF(calexpFile)
805 backnoise2 = np.median(mi.getVariance().getArray())
808 edgeBit = [k
for k, v
in getFlags().items()
if v ==
"edge"][0]
810 for i, xc, yc
in zip(range(nobj), xm, ym):
812 x, y = int(xc), int(yc)
817 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
818 vignet[i] = pstamp.getImage().getArray().transpose()
825 for i, key
in enumerate(context.getName()):
826 if context.getPcflag(i):
827 contextvalp.append(pcval[pc])
831 contextvalp.append(tab.header[key[1:]])
833 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
837 contextvalp.append(tab.get(key))
839 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
841 set.setContextname(i, key)
845 flags, flux, fluxErr, rmsSize, elong, vignet,
846 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
850 if not vignet.dtype.isnative:
852 vignet = vignet.byteswap()
854 for i
in np.where(good)[0]:
855 sample = set.newSample()
856 sample.setCatindex(catindex)
857 sample.setExtindex(ext)
859 sample.setVig(vignet[i])
861 pstamp = afwImage.ImageF(*vignet[i].shape)
862 pstamp.getArray()[:] = sample.getVig()
866 sample.setNorm(float(flux[i]))
867 sample.setBacknoise2(backnoise2)
869 sample.setX(float(xm[i]))
870 sample.setY(float(ym[i]))
871 sample.setFluxrad(float(rmsSize[i]))
873 for j
in range(set.getNcontext()):
874 sample.setContext(j, float(contextvalp[j][i]))
876 set.finiSample(sample, prefs.getProfAccuracy())
879 for j
in range(set.getNcontext()):
880 cmin[j] = contextvalp[j][good].min()
881 cmax[j] = contextvalp[j][good].max()
885 for i
in range(set.getNcontext()):
886 set.setContextScale(i, cmax[i] - cmin[i])
887 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, 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!!")
1010 def makeit(prefs, context, saveWcs=False, plot=dict()):
1011 """This is the python wrapper for the original psfex that reads SExtractor outputs""" 1013 if prefs.getVerboseType() != prefs.QUIET:
1014 print(
"----- %d input catalogues:" % prefs.getNcat())
1019 fields = psfexLib.vectorField()
1020 for cat
in prefs.getCatalogs():
1021 field = psfexLib.Field(cat)
1023 wcssList.append(wcss)
1024 with pyfits.open(cat)
as pf:
1026 if hdu.name ==
"PRIMARY":
1028 elif hdu.name ==
"LDAC_IMHEAD":
1029 hdr = hdu.data[0][0]
1034 except AttributeError:
1037 if not md.exists(
"CRPIX1"):
1038 for k
in md.names():
1039 if re.search(
r"A$", k):
1040 md.set(k[:-1], md.get(k))
1041 wcs = afwGeom.makeSkyWcs(md)
1042 naxis1, naxis2 = md.get(
"NAXIS1"), md.get(
"NAXIS2")
1043 elif hdu.name ==
"LDAC_OBJECTS":
1044 nobj = len(hdu.data)
1046 assert wcs,
"LDAC_OBJECTS comes after LDAC_IMHEAD" 1047 field.addExt(wcs, naxis1, naxis2, nobj)
1049 wcss.append((wcs, naxis1, naxis2))
1053 fields.append(field)
1055 sets = psfexLib.vectorSet()
1059 psfexLib.makeit(fields, sets)
1061 ret = [[f.getPsfs()
for f
in fields], sets]
1063 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())