6 from astropy.io
import fits
8 import matplotlib.pyplot
as plt
18 from .
import psfexLib
24 """Split a FITS header, returning (key, value). 29 A string from a FITS header. 40 k, v = re.search(
r"(\S+)\s*=\s*'?((?:\S+|'))", line).groups()
41 except AttributeError:
58 """Compute the FWHM range associated to a series of FWHM measurements. 59 AUTHOR E. Bertin (IAP, Leiden observatory & ESO) 64 fwhm: iterable of `float` 65 Iterable of full width half-maxima. 67 Maximum allowed FWHM variation. 72 plot: `dict`, optional 73 Dict of plotting options. 94 for i
in range(nfwhm - nw):
95 df = fwhm[i + nw] - fwhm[i]
98 fmin = (fwhm[i + nw] + fwhm[i])/2.0
103 dfmin = (maxvar + 1.0)**0.3333333
104 minout = fmin/dfmin
if dfmin > 0.0
else 0.0
108 maxout = fmin*dfmin**2
112 if plt
and plot.get(
"fwhmHistogram"):
114 plt.hist(fwhm, nfwhm//10 + 1, normed=1, facecolor=
'g', alpha=0.75)
116 plt.axvline(fmin, color=
'red')
117 [plt.axvline(_, color=
'blue')
for _
in (minout, maxout)]
121 return fmin, minout, maxout
126 def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
127 plot=dict(showFlags=
False, showRejection=
False)):
130 set = psfexLib.Set(context)
132 cmin, cmax =
None,
None 133 if set.getNcontext():
134 cmin = np.empty(set.getNcontext())
135 cmax = np.empty(set.getNcontext())
136 for i
in range(set.getNcontext()):
138 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
139 cmax[i] = cmin[i] + set.getContextScale(i)
141 cmin[i] = psfexLib.BIG
142 cmax[i] = -psfexLib.BIG
146 with fits.open(filename)
as cat:
149 if tab.name ==
"LDAC_IMHEAD":
157 if tab.name ==
"PRIMARY":
159 elif tab.name ==
"LDAC_IMHEAD":
166 except AttributeError:
178 elif tab.name ==
"LDAC_OBJECTS":
179 xm = tab.data[prefs.getCenterKey(0)]
180 ym = tab.data[prefs.getCenterKey(1)]
181 fluxrad = tab.data[
"FLUX_RADIUS"]
182 flux = tab.data[prefs.getPhotfluxRkey()]
183 fluxerr = tab.data[prefs.getPhotfluxerrRkey()]
184 elong = tab.data[
"ELONGATION"]
185 flags = tab.data[
"FLAGS"]
187 n = prefs.getPhotfluxNum() - 1
189 assert False,
"Code to handle e.g. FLUX_APER(3) isn't yet converted" 190 if key.naxis == 1
and n < key.naxisn[0]:
193 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
194 (prefs.getPhotfluxRkey(), filename), file=sys.stderr)
196 n = prefs.getPhotfluxerrNum() - 1
198 if key.naxis == 1
and n < key.naxisn[0]:
201 print(
"Not enough apertures for %s in catalogue %s: using first aperture" % \
202 (prefs.getPhotfluxerrRkey(), filename), file=sys.stderr)
206 vignet = tab.data[
"VIGNET"]
209 vigw, vigh = vignet[0].shape
211 raise RuntimeError(
"*Error*: VIGNET should be a 2D vector; saw %s" %
str(vignet[0].shape))
214 set.setVigSize(vigw, vigh)
219 for i, key
in enumerate(context.getName()):
220 if context.getPcflag(i):
221 contextvalp.append(pcval[pc])
225 contextvalp.append(tab.header[key[1:]])
227 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
231 contextvalp.append(tab.data[key])
233 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
235 set.setContextname(i, key)
239 flags, flux, fluxerr, fluxrad, elong, vignet,
240 plot=plot, title=
"%s[%d]" % (filename, ext + 1))
244 if not vignet.dtype.isnative:
246 vignet = vignet.byteswap()
248 for i
in np.where(good)[0]:
249 sample = set.newSample()
250 sample.setCatindex(catindex)
251 sample.setExtindex(ext)
253 sample.setVig(vignet[i])
255 sample.setNorm(
float(flux[i]))
256 sample.setBacknoise2(backnoise2)
258 sample.setX(
float(xm[i]))
259 sample.setY(
float(ym[i]))
260 sample.setFluxrad(
float(fluxrad[i]))
262 for j
in range(set.getNcontext()):
263 sample.setContext(j,
float(contextvalp[j][i]))
265 set.finiSample(sample, prefs.getProfAccuracy())
268 for j
in range(set.getNcontext()):
269 cmin[j] = contextvalp[j][good].
min()
270 cmax[j] = contextvalp[j][good].
max()
274 for i
in range(set.getNcontext()):
275 set.setContextScale(i, cmax[i] - cmin[i])
276 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
287 return {1:
"flux blended",
293 64:
"memory error (deblend)",
294 128:
"memory error (extract)",
299 flags, flux, fluxerr, rmsSize, elong, vignet,
300 plot=dict(), title=
""):
301 maxbad = prefs.getBadpixNmax()
302 maxbadflag = prefs.getBadpixFlag()
303 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100.0
304 minsn = prefs.getMinsn()
306 sn = flux/np.where(fluxerr > 0, fluxerr, 1)
307 sn[fluxerr <= 0] = -psfexLib.BIG
309 plotFlags = plot.get(
"showFlags")
if plt
else False 310 plotRejection = plot.get(
"showRejection")
if plt
else False 312 bad = flags & prefs.getFlagMask() != 0
313 set.setBadFlags(
int(sum(bad != 0)))
316 selectionVectors = []
317 selectionVectors.append((bad,
"flags %d" % sum(bad != 0)))
320 set.setBadSN(
int(sum(dbad)))
321 bad = np.logical_or(bad, dbad)
323 selectionVectors.append((dbad,
"S/N %d" % sum(dbad)))
325 dbad = rmsSize < frmin
326 set.setBadFrmin(
int(sum(dbad)))
327 bad = np.logical_or(bad, dbad)
329 selectionVectors.append((dbad,
"frmin %d" % sum(dbad)))
331 dbad = rmsSize > frmax
332 set.setBadFrmax(
int(sum(dbad)))
333 bad = np.logical_or(bad, dbad)
335 selectionVectors.append((dbad,
"frmax %d" % sum(dbad)))
337 dbad = elong > maxelong
338 set.setBadElong(
int(sum(dbad)))
339 bad = np.logical_or(bad, dbad)
341 selectionVectors.append((dbad,
"elong %d" % sum(dbad)))
345 nbad = np.array([(v <= -psfexLib.BIG).sum()
for v
in vignet])
347 set.setBadPix(
int(sum(dbad)))
348 bad = np.logical_or(bad, dbad)
350 selectionVectors.append((dbad,
"badpix %d" % sum(dbad)))
352 good = np.logical_not(bad)
353 if plotFlags
or plotRejection:
354 imag = -2.5*np.log10(flux)
361 isSet = np.where(flags == 0x0)[0]
362 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=
"good")
366 if mask & prefs.getFlagMask():
367 isSet = np.where(np.bitwise_and(flags, mask))[0]
369 plt.plot(imag[isSet], rmsSize[isSet],
'o', alpha=alpha, label=labels[mask])
371 for bad, label
in selectionVectors:
372 plt.plot(imag[bad], rmsSize[bad],
'o', alpha=alpha, label=label)
374 plt.plot(imag[good], rmsSize[good],
'o', color=
"black", label=
"selected")
375 [plt.axhline(_, color=
'red')
for _
in [frmin, frmax]]
376 plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
377 plt.ylim(-0.1, 2*frmax)
379 plt.xlabel(
"Instrumental Magnitude")
380 plt.ylabel(
"rmsSize")
381 plt.title(
"%s %d selected" % (title, sum(good)))
398 _dataTypes = dict(LSST=_LSST,
399 SExtractor=_SExtractor
401 _dataType = _SExtractor
405 _dataType = _dataTypes[t]
409 if _dataType == _LSST:
417 def load_samples(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
418 minsn = prefs.getMinsn()
419 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
420 min = prefs.getFwhmrange()[0]
421 max = prefs.getFwhmrange()[1]
423 filenames = prefs.getCatalogs()
425 ncat = len(filenames)
426 fwhmmin = np.empty(ncat)
427 fwhmmax = np.empty(ncat)
429 if not prefs.getAutoselectFlag():
430 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
431 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
432 fwhmmode = (fwhmmin + fwhmmax)/2.0
439 for i, fileName
in enumerate(filenames):
442 if prefs.getVerboseType() != prefs.QUIET:
443 print(
"Examining Catalog #%d" % (i+1))
447 with fits.open(fileName)
as cat:
450 if tab.name ==
"LDAC_IMHEAD":
453 if extCtr != ext
and ext != prefs.ALL_EXTENSIONS:
458 if tab.name ==
"PRIMARY":
460 elif tab.name ==
"LDAC_IMHEAD":
465 except AttributeError:
469 if v < 1/psfexLib.BIG:
474 elif tab.name ==
"LDAC_OBJECTS":
476 rmsSize = tab.data[
"FLUX_RADIUS"]
477 fmax = tab.data[
"FLUX_MAX"]
478 flags = tab.data[
"FLAGS"]
479 elong = tab.data[
"ELONGATION"]
480 backnoise = backnoises[-1]
482 good = np.logical_and(fmax/backnoise > minsn,
483 np.logical_not(flags & prefs.getFlagMask()))
484 good = np.logical_and(good, elong < maxelong)
486 good = np.logical_and(good, fwhm >= min)
487 good = np.logical_and(good, fwhm < max)
488 fwhms[i] = fwhm[good]
490 if prefs.getVarType() == prefs.VAR_NONE:
492 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
494 for l
in fwhms.values():
495 fwhms_all[i:len(l)] = l
498 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
501 raise RuntimeError(
"No source with appropriate FWHM found!!")
502 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
504 fwhmmin = np.zeros(ncat) + min
505 fwhmmax = np.zeros(ncat) + max
506 fwhmmode = np.zeros(ncat) + mode
508 fwhmmode = np.empty(ncat)
509 fwhmmin = np.empty(ncat)
510 fwhmmax = np.empty(ncat)
512 for i
in range(ncat):
515 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
517 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
519 raise RuntimeError(
"No source with appropriate FWHM found!!")
520 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
526 for i, fileName
in enumerate(filenames):
528 if ext == prefs.ALL_EXTENSIONS:
529 extensions =
list(range(len(backnoises)))
534 set =
read_samples(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
535 e, next, i, context, context.getPc(i)
if context.getNpc()
else None, plot=plot)
537 if fwhmmode[i] < mode:
542 if prefs.getVerboseType() != prefs.QUIET:
544 print(
"%d samples loaded." % set.getNsample())
546 raise RuntimeError(
"No appropriate source found!!")
555 def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
556 diagnostics=False, outDir="", frame=None, title=None):
565 wcsData = wcsData[ext]
566 wcs, naxis1, naxis2 = wcsData
568 wcs, naxis1, naxis2 =
None,
None,
None 570 naxis = [naxis1, naxis2]
574 cmin, cmax = [set.getContextOffset(i) + d*set.getContextScale(i)
for d
in (-0.5, 0.5)]
575 naxis[i] = cmax + cmin
578 if naxis[0] > naxis[1]:
579 nx, ny =
int(nspot*naxis[0]/
float(naxis[1]) + 0.5), nspot
581 nx, ny = nspot,
int(nspot*naxis[1]/
float(naxis[0]) + 0.5)
583 mos = ds9Utils.Mosaic(gutter=2, background=0.02)
585 xpos, ypos = np.linspace(0, naxis[0], nx), np.linspace(0, naxis[1], ny)
590 im = afwImage.ImageF(*psf.getLoc().shape)
591 im.getArray()[:] = psf.getLoc()
594 if trim > im.getHeight()//2:
595 trim = im.getHeight()//2
597 im = im[trim:-trim, trim:-trim]
601 mosaic = mos.makeMosaic(mode=nx)
602 if frame
is not None:
603 ds9.mtv(mosaic, frame=frame, title=title)
609 for x, y, i
in zip((xpos[0], xpos[-1]), (ypos[0], ypos[-1]), (0, mos.nImage - 1)):
610 bbox = mos.getBBox(i)
611 mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
612 mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
620 delta = pos[1][1][i].asDegrees() - pos[0][1][i].asDegrees()
621 CD.append(delta/(pos[1][0][i] - pos[0][0][i]))
627 title =
"%s-%d" % (title, ext)
629 if frame
is not None:
630 ds9.mtv(mosaic, frame=frame, title=title, wcs=mosWcs)
633 outFile =
"%s-mod.fits" % title
635 outFile = os.path.join(outDir, outFile)
636 mosaic.writeFits(outFile, mosWcs.getFitsMetadata())
640 mos = ds9Utils.Mosaic(gutter=4, background=0.002)
641 for i
in range(set.getNsample()):
643 if ext
is not None and s.getExtindex() != ext:
646 smos = ds9Utils.Mosaic(gutter=2, background=-0.003)
647 for func
in [s.getVig, s.getVigResi]:
650 norm =
float(arr.max())
if True else s.getNorm()
653 im = afwImage.ImageF(*arr.shape)
654 im.getArray()[:] = arr
657 mos.append(smos.makeMosaic(mode=
"x"))
659 mosaic = mos.makeMosaic(title=title)
661 if frame
is not None:
662 ds9.mtv(mosaic, title=title, frame=frame+1)
665 outFile =
"%s-psfstars.fits" % title
667 outFile = os.path.join(outDir, outFile)
669 mosaic.writeFits(outFile)
676 "base_PixelFlags_flag_edge",
680 "base_PixelFlags_flag_saturatedCenter",
682 "base_PixelFlags_flag_crCenter",
683 "base_PixelFlags_flag_bad",
690 for i, k
in enumerate(flagKeys):
691 flags[1 << i] = re.sub(
r"\_flag",
"",
692 re.sub(
r"^base\_",
"", re.sub(
r"^base\_PixelFlags\_flag\_",
"", k)))
695 for i, k
in enumerate(flagKeys):
698 isSet = tab.get(
"deblend_nChild") > 0
703 flags = np.bitwise_or(flags, np.where(isSet, 1 << i, 0))
710 re.sub(
"/src",
r"", fileName),
711 re.sub(
"(SRC([^.]+))",
r"CORR\2-exp", fileName),
713 if guess != fileName
and os.path.exists(guess):
716 raise RuntimeError(
"Unable to find a calexp to go with %s" % fileName)
722 """This is the python wrapper that reads lsst tables 725 if prefs.getVerboseType() != prefs.QUIET:
726 print(
"----- %d input catalogues:" % prefs.getNcat())
731 fields = psfexLib.vectorField()
732 for cat
in prefs.getCatalogs():
733 field = psfexLib.Field(cat)
735 wcssList.append(wcss)
743 cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
744 cdMatrix.shape = (2, 2)
749 naxis1, naxis2 = md.getScalar(
"NAXIS1"), md.getScalar(
"NAXIS2")
753 field.addExt(wcs, naxis1, naxis2, md.getScalar(
"NAXIS2"))
755 wcss.append((wcs, naxis1, naxis2))
764 sets = psfexLib.vectorSet()
768 psfexLib.makeit(fields, sets)
770 ret = [[f.getPsfs()
for f
in fields], sets]
779 def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, context, pcval,
780 plot=dict(showFlags=
False, showRejection=
False)):
783 set = psfexLib.Set(context)
785 cmin, cmax =
None,
None 786 if set.getNcontext():
787 cmin = np.empty(set.getNcontext())
788 cmax = np.empty(set.getNcontext())
789 for i
in range(set.getNcontext()):
791 cmin[i] = set.getContextOffset(i) - set.getContextScale(i)/2.0
792 cmax[i] = cmin[i] + set.getContextScale(i)
794 cmin[i] = psfexLib.BIG
795 cmax[i] = -psfexLib.BIG
799 tab = afwTable.SourceCatalog.readFits(filename)
801 centroid = tab.getCentroidDefinition()
802 xm = tab.get(
"%s.x" % centroid)
803 ym = tab.get(
"%s.y" % centroid)
805 shape = tab.getShapeDefinition()
806 ixx = tab.get(
"%s.xx" % shape)
807 iyy = tab.get(
"%s.yy" % shape)
809 rmsSize = np.sqrt(0.5*(ixx + iyy))
810 elong = 0.5*(ixx - iyy)/(ixx + iyy)
812 flux = tab.get(prefs.getPhotfluxRkey())
813 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
821 set.setVigSize(vigw, vigh)
823 vignet = np.empty(nobj*vigw*vigh,
"float32").reshape(nobj, vigw, vigh)
827 mi = afwImage.MaskedImageF(calexpFile)
828 backnoise2 = np.median(mi.getVariance().getArray())
831 edgeBit = [k
for k, v
in getFlags().
items()
if v ==
"edge"][0]
833 for i, xc, yc
in zip(range(nobj), xm, ym):
840 pstamp = mi[x - vigw//2:x + vigw//2 + 1, y - vigh//2:y + vigh//2 + 1]
841 vignet[i] = pstamp.getImage().getArray().transpose()
848 for i, key
in enumerate(context.getName()):
849 if context.getPcflag(i):
850 contextvalp.append(pcval[pc])
854 contextvalp.append(tab.header[key[1:]])
856 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
860 contextvalp.append(tab.get(key))
862 raise RuntimeError(
"*Error*: %s parameter not found in the header of %s" %
864 set.setContextname(i, key)
868 flags, flux, fluxErr, rmsSize, elong, vignet,
869 plot=plot, title=
"%s[%d]" % (filename, ext + 1)
if next > 1
else filename)
873 if not vignet.dtype.isnative:
875 vignet = vignet.byteswap()
877 for i
in np.where(good)[0]:
878 sample = set.newSample()
879 sample.setCatindex(catindex)
880 sample.setExtindex(ext)
882 sample.setVig(vignet[i])
884 pstamp = afwImage.ImageF(*vignet[i].shape)
885 pstamp.getArray()[:] = sample.getVig()
889 sample.setNorm(
float(flux[i]))
890 sample.setBacknoise2(backnoise2)
892 sample.setX(
float(xm[i]))
893 sample.setY(
float(ym[i]))
894 sample.setFluxrad(
float(rmsSize[i]))
896 for j
in range(set.getNcontext()):
897 sample.setContext(j,
float(contextvalp[j][i]))
899 set.finiSample(sample, prefs.getProfAccuracy())
902 for j
in range(set.getNcontext()):
903 cmin[j] = contextvalp[j][good].
min()
904 cmax[j] = contextvalp[j][good].
max()
908 for i
in range(set.getNcontext()):
909 set.setContextScale(i, cmax[i] - cmin[i])
910 set.setContextOffset(i, (cmin[i] + cmax[i])/2.0)
920 def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict()):
921 minsn = prefs.getMinsn()
922 maxelong = (prefs.getMaxellip() + 1.0)/(1.0 - prefs.getMaxellip())
if prefs.getMaxellip() < 1.0
else 100
923 min = prefs.getFwhmrange()[0]
924 max = prefs.getFwhmrange()[1]
926 filenames = prefs.getCatalogs()
928 ncat = len(filenames)
929 fwhmmin = np.empty(ncat)
930 fwhmmax = np.empty(ncat)
932 if not prefs.getAutoselectFlag():
933 fwhmmin = np.zeros(ncat) + prefs.getFwhmrange()[0]
934 fwhmmax = np.zeros(ncat) + prefs.getFwhmrange()[1]
935 fwhmmode = (fwhmmin + fwhmmax)/2.0
942 for i, fileName
in enumerate(filenames):
945 if prefs.getVerboseType() != prefs.QUIET:
946 print(
"Examining Catalog #%d" % (i+1))
949 tab = afwTable.SourceCatalog.readFits(fileName)
952 shape = tab.getShapeDefinition()
953 ixx = tab.get(
"%s.xx" % shape)
954 iyy = tab.get(
"%s.yy" % shape)
956 rmsSize = np.sqrt(0.5*(ixx + iyy))
957 elong = 0.5*(ixx - iyy)/(ixx + iyy)
959 flux = tab.get(prefs.getPhotfluxRkey())
960 fluxErr = tab.get(prefs.getPhotfluxerrRkey())
964 good = np.logical_and(flux/fluxErr > minsn,
965 np.logical_not(flags & prefs.getFlagMask()))
966 good = np.logical_and(good, elong < maxelong)
968 good = np.logical_and(good, fwhm >= min)
969 good = np.logical_and(good, fwhm < max)
970 fwhms[i] = fwhm[good]
972 if prefs.getVarType() == prefs.VAR_NONE:
974 fwhms_all = np.empty(sum([len(l)
for l
in fwhms.values()]))
976 for l
in fwhms.values():
977 fwhms_all[i:len(l)] = l
980 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1],
983 raise RuntimeError(
"No source with appropriate FWHM found!!")
984 mode = min = max = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
986 fwhmmin = np.zeros(ncat) + min
987 fwhmmax = np.zeros(ncat) + max
988 fwhmmode = np.zeros(ncat) + mode
990 fwhmmode = np.empty(ncat)
991 fwhmmin = np.empty(ncat)
992 fwhmmax = np.empty(ncat)
994 for i
in range(ncat):
997 fwhmmode[i], fwhmmin[i], fwhmmax[i] = \
999 prefs.getFwhmrange()[0], prefs.getFwhmrange()[1], plot=plot)
1001 raise RuntimeError(
"No source with appropriate FWHM found!!")
1002 fwhmmode[i] = fwhmmin[i] = fwhmmax[i] = 2.35/(1.0 - 1.0/psfexLib.cvar.INTERPFAC)
1008 for i, fileName
in enumerate(filenames):
1010 for ext
in range(next):
1011 set =
read_samplesLsst(prefs, set, fileName, fwhmmin[i]/2.0, fwhmmax[i]/2.0,
1012 ext, next, i, context,
1013 context.getPc(i)
if context.getNpc()
else None, plot=plot)
1015 if fwhmmode[i] < mode:
1020 if prefs.getVerboseType() != prefs.QUIET:
1021 if set.getNsample():
1022 print(
"%d samples loaded." % set.getNsample())
1024 raise RuntimeError(
"No appropriate source found!!")
1033 def makeit(prefs, context, saveWcs=False, plot=dict()):
1034 """This is the python wrapper for the original psfex that reads SExtractor outputs 1037 if prefs.getVerboseType() != prefs.QUIET:
1038 print(
"----- %d input catalogues:" % prefs.getNcat())
1043 fields = psfexLib.vectorField()
1044 for cat
in prefs.getCatalogs():
1045 field = psfexLib.Field(cat)
1047 wcssList.append(wcss)
1048 with fits.open(cat)
as pf:
1050 if hdu.name ==
"PRIMARY":
1052 elif hdu.name ==
"LDAC_IMHEAD":
1053 hdr = hdu.data[0][0]
1058 except AttributeError:
1061 if not md.exists(
"CRPIX1"):
1062 for k
in md.names():
1063 if re.search(
r"A$", k):
1064 md.set(k[:-1], md.getScalar(k))
1066 naxis1, naxis2 = md.getScalar(
"NAXIS1"), md.getScalar(
"NAXIS2")
1067 elif hdu.name ==
"LDAC_OBJECTS":
1068 nobj = len(hdu.data)
1070 assert wcs,
"LDAC_OBJECTS comes after LDAC_IMHEAD" 1071 field.addExt(wcs, naxis1, naxis2, nobj)
1073 wcss.append((wcs, naxis1, naxis2))
1077 fields.append(field)
1079 sets = psfexLib.vectorSet()
1083 psfexLib.makeit(fields, sets)
1085 ret = [[f.getPsfs()
for f
in fields], sets]
1087 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))
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.
std::vector< SchemaItem< Flag > > * items
daf::base::PropertyList * list
def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1, plot=dict())