6 from astropy.io
import fits
8 import matplotlib.pyplot
as plt
19 from .
import psfexLib
21 afwDisplay.setDefaultMaskTransparency(75)
25 """Split a FITS header, returning (key, value). 30 A string from a FITS header. 41 k, v = re.search(
r"(\S+)\s*=\s*'?((?:\S+|'))", line).groups()
42 except AttributeError:
57 """Compute the FWHM range associated to a series of FWHM measurements. 58 AUTHOR E. Bertin (IAP, Leiden observatory & ESO) 63 fwhm: iterable of `float` 64 Iterable of full width half-maxima. 66 Maximum allowed FWHM variation. 71 plot: `dict`, optional 72 Dict of plotting options. 93 for i
in range(nfwhm - nw):
94 df = fwhm[i + nw] - fwhm[i]
97 fmin = (fwhm[i + nw] + fwhm[i])/2.0
102 dfmin = (maxvar + 1.0)**0.3333333
103 minout = fmin/dfmin
if dfmin > 0.0
else 0.0
107 maxout = fmin*dfmin**2
111 if plt
and plot.get(
"fwhmHistogram"):
113 plt.hist(fwhm, nfwhm//10 + 1, normed=1, facecolor=
'g', alpha=0.75)
115 plt.axvline(fmin, color=
'red')
116 [plt.axvline(_, color=
'blue')
for _
in (minout, maxout)]
120 return fmin, minout, maxout
123 def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
124 plot=dict(showFlags=
False, showRejection=
False)):
127 set = psfexLib.Set(context)
129 cmin, cmax =
None,
None 130 if set.getNcontext():
131 cmin = np.empty(set.getNcontext())
132 cmax = np.empty(set.getNcontext())
133 for i
in range(set.getNcontext()):
135 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
136 cmax[i] = cmin[i] + set.getContextScale(i)
138 cmin[i] = psfexLib.BIG
139 cmax[i] = -psfexLib.BIG
143 with fits.open(filename)
as cat:
146 if tab.name ==
"LDAC_IMHEAD":
154 if tab.name ==
"PRIMARY":
156 elif tab.name ==
"LDAC_IMHEAD":
163 except AttributeError:
175 elif tab.name ==
"LDAC_OBJECTS":
176 xm = tab.data[prefs.getCenterKey(0)]
177 ym = tab.data[prefs.getCenterKey(1)]
178 fluxrad = tab.data[
"FLUX_RADIUS"]
179 flux = tab.data[prefs.getPhotfluxRkey()]
180 fluxerr = tab.data[prefs.getPhotfluxerrRkey()]
181 elong = tab.data[
"ELONGATION"]
182 flags = tab.data[
"FLAGS"]
184 n = prefs.getPhotfluxNum() - 1
186 raise RuntimeError(
"Code to handle e.g. FLUX_APER(3) isn't yet converted")
187 if key.naxis == 1
and n < key.naxisn[0]:
190 print(
"Not enough apertures for %s in catalogue %s: using first aperture" %
191 (prefs.getPhotfluxRkey(), filename), file=sys.stderr)
193 n = prefs.getPhotfluxerrNum() - 1
195 raise RuntimeError(
"Code for getPhotfluxerrNum is broken")
196 if key.naxis == 1
and n < key.naxisn[0]:
199 print(
"Not enough apertures for %s in catalogue %s: using first aperture" %
200 (prefs.getPhotfluxerrRkey(), filename), file=sys.stderr)
204 vignet = tab.data[
"VIGNET"]
207 vigw, vigh = vignet[0].shape
209 raise RuntimeError(
"*Error*: VIGNET should be a 2D vector; saw %s" % str(vignet[0].shape))
212 set.setVigSize(vigw, vigh)
217 for i, key
in enumerate(context.getName()):
218 if context.getPcflag(i):
219 contextvalp.append(pcval[pc])
223 contextvalp.append(tab.header[key[1:]])
225 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
229 contextvalp.append(tab.data[key])
231 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
233 set.setContextname(i, key)
237 flags, flux, fluxerr, fluxrad, elong, vignet,
238 plot=plot, title=
"%s[%d]" % (filename, ext + 1))
242 if not vignet.dtype.isnative:
245 vignet = vignet.byteswap()
247 for i
in np.where(good)[0]:
248 sample = set.newSample()
249 sample.setCatindex(catindex)
250 sample.setExtindex(ext)
252 sample.setVig(vignet[i])
254 sample.setNorm(float(flux[i]))
255 sample.setBacknoise2(backnoise2)
257 sample.setX(float(xm[i]))
258 sample.setY(float(ym[i]))
259 sample.setFluxrad(float(fluxrad[i]))
261 for j
in range(set.getNcontext()):
262 sample.setContext(j, float(contextvalp[j][i]))
264 set.finiSample(sample, prefs.getProfAccuracy())
267 for j
in range(set.getNcontext()):
268 cmin[j] = contextvalp[j][good].
min()
269 cmax[j] = contextvalp[j][good].
max()
273 for i
in range(set.getNcontext()):
274 set.setContextScale(i, cmax[i] - cmin[i])
275 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
284 return {1:
"flux blended",
290 64:
"memory error (deblend)",
291 128:
"memory error (extract)",
296 flags, flux, fluxerr, rmsSize, elong, vignet,
297 plot=dict(), title=
""):
298 maxbad = prefs.getBadpixNmax()
299 maxbadflag = prefs.getBadpixFlag()
300 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100.0
301 minsn = prefs.getMinsn()
303 sn = flux/np.where(fluxerr > 0, fluxerr, 1)
304 sn[fluxerr <= 0] = -psfexLib.BIG
306 plotFlags = plot.get(
"showFlags")
if plt
else False 307 plotRejection = plot.get(
"showRejection")
if plt
else False 309 bad = flags & prefs.getFlagMask() != 0
310 set.setBadFlags(int(sum(bad != 0)))
313 selectionVectors = []
314 selectionVectors.append((bad,
"flags %d" % sum(bad != 0)))
317 set.setBadSN(int(sum(dbad)))
318 bad = np.logical_or(bad, dbad)
320 selectionVectors.append((dbad,
"S/N %d" % sum(dbad)))
322 dbad = rmsSize < frmin
323 set.setBadFrmin(int(sum(dbad)))
324 bad = np.logical_or(bad, dbad)
326 selectionVectors.append((dbad,
"frmin %d" % sum(dbad)))
328 dbad = rmsSize > frmax
329 set.setBadFrmax(int(sum(dbad)))
330 bad = np.logical_or(bad, dbad)
332 selectionVectors.append((dbad,
"frmax %d" % sum(dbad)))
334 dbad = elong > maxelong
335 set.setBadElong(int(sum(dbad)))
336 bad = np.logical_or(bad, dbad)
338 selectionVectors.append((dbad,
"elong %d" % sum(dbad)))
342 nbad = np.array([(v <= -psfexLib.BIG).sum()
for v
in vignet])
344 set.setBadPix(int(sum(dbad)))
345 bad = np.logical_or(bad, dbad)
347 selectionVectors.append((dbad,
"badpix %d" % sum(dbad)))
349 good = np.logical_not(bad)
350 if plotFlags
or plotRejection:
351 imag = -2.5*np.log10(flux)
358 isSet = np.where(flags == 0x0)[0]
359 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=
"good")
363 if mask & prefs.getFlagMask():
364 isSet = np.where(np.bitwise_and(flags, mask))[0]
366 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=labels[mask])
368 for bad, label
in selectionVectors:
369 plt.plot(imag[bad], rmsSize[bad],
'o', alpha=alpha, label=label)
371 plt.plot(imag[good], rmsSize[good],
'o', color=
"black", label=
"selected")
372 [plt.axhline(_, color=
'red')
for _
in [frmin, frmax]]
373 plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
374 plt.ylim(-0.1, 2*frmax)
376 plt.xlabel(
"Instrumental Magnitude")
377 plt.ylabel(
"rmsSize")
378 plt.title(
"%s %d selected" % (title, sum(good)))
394 _dataTypes = dict(LSST=_LSST,
395 SExtractor=_SExtractor
397 _dataType = _SExtractor
401 _dataType = _dataTypes[t]
405 if _dataType == _LSST:
411 def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
412 minsn = prefs.getMinsn()
413 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
414 min = prefs.getFwhmrange()[0]
415 max = prefs.getFwhmrange()[1]
417 filenames = prefs.getCatalogs()
419 ncat = len(filenames)
420 fwhmmin = np.empty(ncat)
421 fwhmmax = np.empty(ncat)
423 if not prefs.getAutoselectFlag():
424 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
425 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
426 fwhmmode = (fwhmmin + fwhmmax)/2.0
433 for i, fileName
in enumerate(filenames):
436 if prefs.getVerboseType() != prefs.QUIET:
437 print(
"Examining Catalog #%d" % (i+1))
441 with fits.open(fileName)
as cat:
444 if tab.name ==
"LDAC_IMHEAD":
447 if extCtr != ext
and ext != prefs.ALL_EXTENSIONS:
452 if tab.name ==
"PRIMARY":
454 elif tab.name ==
"LDAC_IMHEAD":
459 except AttributeError:
463 if v < 1/psfexLib.BIG:
468 elif tab.name ==
"LDAC_OBJECTS":
470 rmsSize = tab.data[
"FLUX_RADIUS"]
471 fmax = tab.data[
"FLUX_MAX"]
472 flags = tab.data[
"FLAGS"]
473 elong = tab.data[
"ELONGATION"]
474 backnoise = backnoises[-1]
476 good = np.logical_and(fmax/backnoise > minsn,
477 np.logical_not(flags & prefs.getFlagMask()))
478 good = np.logical_and(good, elong < maxelong)
480 good = np.logical_and(good, fwhm >= min)
481 good = np.logical_and(good, fwhm < max)
482 fwhms[i] = fwhm[good]
484 if prefs.getVarType() == prefs.VAR_NONE:
486 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
488 for l
in fwhms.values():
489 fwhms_all[i:len(l)] = l
492 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
495 raise RuntimeError(
"No source with appropriate FWHM found!!")
496 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
498 fwhmmin = np.zeros(ncat) + min
499 fwhmmax = np.zeros(ncat) + max
500 fwhmmode = np.zeros(ncat) + mode
502 fwhmmode = np.empty(ncat)
503 fwhmmin = np.empty(ncat)
504 fwhmmax = np.empty(ncat)
506 for i
in range(ncat):
509 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
511 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
513 raise RuntimeError(
"No source with appropriate FWHM found!!")
514 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
520 for i, fileName
in enumerate(filenames):
522 if ext == prefs.ALL_EXTENSIONS:
523 extensions =
list(range(len(backnoises)))
528 set =
read_samples(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
529 e, next, i, context, context.getPc(i)
if context.getNpc()
else None, plot=plot)
531 if fwhmmode[i] < mode:
536 if prefs.getVerboseType() != prefs.QUIET:
538 print(
"%d samples loaded." % set.getNsample())
540 raise RuntimeError(
"No appropriate source found!!")
547 def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
548 diagnostics=False, outDir="", frame=None, title=None):
549 """Show a PSF on display (e.g., ds9) 557 wcsData = wcsData[ext]
558 wcs, naxis1, naxis2 = wcsData
560 wcs, naxis1, naxis2 =
None,
None,
None 562 naxis = [naxis1, naxis2]
566 cmin, cmax = [set.getContextOffset(i) + d*set.getContextScale(i)
for d
in (-0.5, 0.5)]
567 naxis[i] = cmax + cmin
569 if naxis[0] > naxis[1]:
570 nx, ny = int(nspot*naxis[0]/float(naxis[1]) + 0.5), nspot
572 nx, ny = nspot, int(nspot*naxis[1]/float(naxis[0]) + 0.5)
574 mos = afwDisplay.utils.Mosaic(gutter=2, background=0.02)
576 xpos, ypos = np.linspace(0, naxis[0], nx), np.linspace(0, naxis[1], ny)
581 im = afwImage.ImageF(*psf.getLoc().shape)
582 im.getArray()[:] = psf.getLoc()
583 im /= float(im.getArray().
max())
585 if trim > im.getHeight()//2:
586 trim = im.getHeight()//2
588 im = im[trim:-trim, trim:-trim]
592 mosaic = mos.makeMosaic(mode=nx)
593 if frame
is not None:
594 afwDisplay.Display(frame=frame).
mtv(mosaic, title=title)
600 for x, y, i
in zip((xpos[0], xpos[-1]), (ypos[0], ypos[-1]), (0, mos.nImage - 1)):
601 bbox = mos.getBBox(i)
602 mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
603 mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
611 delta = pos[1][1][i].asDegrees() - pos[0][1][i].asDegrees()
612 CD.append(delta/(pos[1][0][i] - pos[0][0][i]))
618 title =
"%s-%d" % (title, ext)
620 if frame
is not None:
621 afwDisplay.Display(frame=frame).
mtv(mosaic, title=title, wcs=mosWcs)
624 outFile =
"%s-mod.fits" % title
626 outFile = os.path.join(outDir, outFile)
627 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
629 mos = afwDisplay.utils.Mosaic(gutter=4, background=0.002)
630 for i
in range(set.getNsample()):
632 if ext
is not None and s.getExtindex() != ext:
635 smos = afwDisplay.utils.Mosaic(gutter=2, background=-0.003)
636 for func
in [s.getVig, s.getVigResi]:
639 norm = float(arr.max())
if True else s.getNorm()
642 im = afwImage.ImageF(*arr.shape)
643 im.getArray()[:] = arr
646 mos.append(smos.makeMosaic(mode=
"x"))
648 mosaic = mos.makeMosaic(title=title)
650 if frame
is not None:
651 afwDisplay.Display(frame=frame + 1).
mtv(mosaic, title=title)
654 outFile =
"%s-psfstars.fits" % title
656 outFile = os.path.join(outDir, outFile)
658 mosaic.writeFits(outFile)
663 "base_PixelFlags_flag_edge",
667 "base_PixelFlags_flag_saturatedCenter",
669 "base_PixelFlags_flag_crCenter",
670 "base_PixelFlags_flag_bad",
677 for i, k
in enumerate(flagKeys):
678 flags[1 << i] = re.sub(
r"\_flag",
"",
679 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
682 for i, k
in enumerate(flagKeys):
685 isSet = tab.get(
"deblend_nChild") > 0
690 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
697 re.sub(
"/src",
r"", fileName),
698 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
700 if guess != fileName
and os.path.exists(guess):
703 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
707 """This is the python wrapper that reads lsst tables 710 if prefs.getVerboseType() != prefs.QUIET:
711 print(
"----- %d input catalogues:" % prefs.getNcat())
716 fields = psfexLib.vectorField()
717 for cat
in prefs.getCatalogs():
718 field = psfexLib.Field(cat)
720 wcssList.append(wcss)
729 cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
730 cdMatrix.shape = (2, 2)
735 naxis1, naxis2 = md.getScalar(
"NAXIS1"), md.getScalar(
"NAXIS2")
739 field.addExt(wcs, naxis1, naxis2, md.getScalar(
"NAXIS2"))
741 wcss.append((wcs, naxis1, naxis2))
750 sets = psfexLib.vectorSet()
754 psfexLib.makeit(fields, sets)
756 ret = [[f.getPsfs()
for f
in fields], sets]
763 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval, nobj,
764 plot=dict(showFlags=
False, showRejection=
False)):
767 set = psfexLib.Set(context)
769 cmin, cmax =
None,
None 770 if set.getNcontext():
771 cmin = np.empty(set.getNcontext())
772 cmax = np.empty(set.getNcontext())
773 for i
in range(set.getNcontext()):
775 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
776 cmax[i] = cmin[i] + set.getContextScale(i)
778 cmin[i] = psfexLib.BIG
779 cmax[i] = -psfexLib.BIG
783 tab = afwTable.SourceCatalog.readFits(filename)
785 centroid = tab.getCentroidDefinition()
786 xm = tab.get(
"%s.x" % centroid)
787 ym = tab.get(
"%s.y" % centroid)
789 shape = tab.getShapeDefinition()
790 ixx = tab.get(
"%s.xx" % shape)
791 iyy = tab.get(
"%s.yy" % shape)
793 rmsSize = np.sqrt(0.5*(ixx + iyy))
794 elong = 0.5*(ixx - iyy)/(ixx + iyy)
796 flux = tab.get(prefs.getPhotfluxRkey())
797 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
805 set.setVigSize(vigw, vigh)
807 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
811 mi = afwImage.MaskedImageF(calexpFile)
812 backnoise2 = np.median(mi.getVariance().getArray())
815 edgeBit = [k
for k, v
in getFlags().
items()
if v ==
"edge"][0]
817 for i, xc, yc
in zip(range(nobj), xm, ym):
819 x, y = int(xc), int(yc)
824 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
825 vignet[i] = pstamp.getImage().getArray().transpose()
832 for i, key
in enumerate(context.getName()):
833 if context.getPcflag(i):
834 contextvalp.append(pcval[pc])
838 contextvalp.append(tab.header[key[1:]])
840 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
844 contextvalp.append(tab.get(key))
846 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
848 set.setContextname(i, key)
852 flags, flux, fluxErr, rmsSize, elong, vignet,
853 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
857 if not vignet.dtype.isnative:
860 vignet = vignet.byteswap()
862 for i
in np.where(good)[0]:
863 sample = set.newSample()
864 sample.setCatindex(catindex)
865 sample.setExtindex(ext)
867 sample.setVig(vignet[i])
869 pstamp = afwImage.ImageF(*vignet[i].shape)
870 pstamp.getArray()[:] = sample.getVig()
871 afwDisplay.Display().
mtv(pstamp)
873 sample.setNorm(float(flux[i]))
874 sample.setBacknoise2(backnoise2)
876 sample.setX(float(xm[i]))
877 sample.setY(float(ym[i]))
878 sample.setFluxrad(float(rmsSize[i]))
880 for j
in range(set.getNcontext()):
881 sample.setContext(j, float(contextvalp[j][i]))
883 set.finiSample(sample, prefs.getProfAccuracy())
886 for j
in range(set.getNcontext()):
887 cmin[j] = contextvalp[j][good].
min()
888 cmax[j] = contextvalp[j][good].
max()
892 for i
in range(set.getNcontext()):
893 set.setContextScale(i, cmax[i] - cmin[i])
894 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
902 def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
903 minsn = prefs.getMinsn()
904 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
905 min = prefs.getFwhmrange()[0]
906 max = prefs.getFwhmrange()[1]
908 filenames = prefs.getCatalogs()
910 ncat = len(filenames)
911 fwhmmin = np.empty(ncat)
912 fwhmmax = np.empty(ncat)
914 if not prefs.getAutoselectFlag():
915 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
916 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
917 fwhmmode = (fwhmmin + fwhmmax)/2.0
924 for i, fileName
in enumerate(filenames):
927 if prefs.getVerboseType() != prefs.QUIET:
928 print(
"Examining Catalog #%d" % (i+1))
931 tab = afwTable.SourceCatalog.readFits(fileName)
934 shape = tab.getShapeDefinition()
935 ixx = tab.get(
"%s.xx" % shape)
936 iyy = tab.get(
"%s.yy" % shape)
938 rmsSize = np.sqrt(0.5*(ixx + iyy))
939 elong = 0.5*(ixx - iyy)/(ixx + iyy)
941 flux = tab.get(prefs.getPhotfluxRkey())
942 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
946 good = np.logical_and(flux/fluxErr > minsn,
947 np.logical_not(flags & prefs.getFlagMask()))
948 good = np.logical_and(good, elong < maxelong)
950 good = np.logical_and(good, fwhm >= min)
951 good = np.logical_and(good, fwhm < max)
952 fwhms[i] = fwhm[good]
954 if prefs.getVarType() == prefs.VAR_NONE:
956 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
958 for l
in fwhms.values():
959 fwhms_all[i:len(l)] = l
962 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
965 raise RuntimeError(
"No source with appropriate FWHM found!!")
966 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
968 fwhmmin = np.zeros(ncat) + min
969 fwhmmax = np.zeros(ncat) + max
970 fwhmmode = np.zeros(ncat) + mode
972 fwhmmode = np.empty(ncat)
973 fwhmmin = np.empty(ncat)
974 fwhmmax = np.empty(ncat)
976 for i
in range(ncat):
979 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
981 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
983 raise RuntimeError(
"No source with appropriate FWHM found!!")
984 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
990 for i, fileName
in enumerate(filenames):
992 for ext
in range(next):
993 set =
read_samplesLsst(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
994 ext, next, i, context,
995 context.getPc(i)
if context.getNpc()
else None, nobj, plot=plot)
997 if fwhmmode[i] < mode:
1002 if prefs.getVerboseType() != prefs.QUIET:
1003 if set.getNsample():
1004 print(
"%d samples loaded." % set.getNsample())
1006 raise RuntimeError(
"No appropriate source found!!")
1013 def makeit(prefs, context, saveWcs=False, plot=dict()):
1014 """This is the python wrapper for the original psfex that reads SExtractor 1017 if prefs.getVerboseType() != prefs.QUIET:
1018 print(
"----- %d input catalogues:" % prefs.getNcat())
1023 fields = psfexLib.vectorField()
1024 for cat
in prefs.getCatalogs():
1025 field = psfexLib.Field(cat)
1027 wcssList.append(wcss)
1028 with fits.open(cat)
as pf:
1030 if hdu.name ==
"PRIMARY":
1032 elif hdu.name ==
"LDAC_IMHEAD":
1033 hdr = hdu.data[0][0]
1038 except AttributeError:
1041 if not md.exists(
"CRPIX1"):
1042 for k
in md.names():
1043 if re.search(
r"A$", k):
1044 md.set(k[:-1], md.getScalar(k))
1046 naxis1, naxis2 = md.getScalar(
"NAXIS1"), md.getScalar(
"NAXIS2")
1047 elif hdu.name ==
"LDAC_OBJECTS":
1048 nobj = len(hdu.data)
1050 assert wcs,
"LDAC_OBJECTS comes after LDAC_IMHEAD" 1051 field.addExt(wcs, naxis1, naxis2, nobj)
1053 wcss.append((wcs, naxis1, naxis2))
1057 fields.append(field)
1059 sets = psfexLib.vectorSet()
1063 psfexLib.makeit(fields, sets)
1065 ret = [[f.getPsfs()
for f
in fields], sets]
1067 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))
std::vector< SchemaItem< Flag > > * items
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))
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())