lsst.meas.extensions.psfex  16.0-10-gc1446dd+17
utils.py
Go to the documentation of this file.
1 import re
2 import numpy as np
3 from astropy.io import fits
4 import lsst.afw.image as afwImage
5 import lsst.afw.display.ds9 as ds9
6 import lsst.meas.extensions.psfex as psfex
7 
8 
9 def readSExtractor(filename):
10  with fits.open(filename) as pf:
11  for hdu in pf:
12  if hdu.name == "PRIMARY":
13  pass
14  elif hdu.name == "LDAC_IMHEAD":
15  hdr = hdu.data[0][0] # the fits header from the original fits image
16  print(hdr[3])
17  elif hdu.name == "LDAC_OBJECTS":
18  print("%d objects" % (len(hdu.data)))
19  # Find the VIGNET column
20  ttype = [k for k, v in hdu.header.items() if v == "VIGNET"]
21  if not ttype:
22  raise RuntimeError("Unable to find a VIGNET column")
23  vignetCol = int(re.search(r"^TTYPE(\d+)$", ttype[0]).group(1)) - 1
24 
25  for row in range(len(hdu.data)):
26  pixelData = hdu.data[row][vignetCol]
27  bad = np.where(pixelData < -1e29)
28  sat = np.where(pixelData > 99e3)
29  pixelData[bad] = 0.0
30  mi = afwImage.MaskedImageF(*hdu.data[row][vignetCol].shape)
31  im = mi.getImage()
32  im.getArray()[:] = pixelData
33  msk = mi.getMask().getArray()
34  msk[bad] = afwImage.MaskU.getPlaneBitMask("BAD")
35  msk[sat] = afwImage.MaskU.getPlaneBitMask("SAT")
36  ds9.mtv(mi, title=row)
37  input("Next ")
38 
39 
40 def readPrefs(filename, md=None):
41  return psfex.Prefs(filename, md)
def readSExtractor(filename)
Definition: utils.py:9
def readPrefs(filename, md=None)
Definition: utils.py:40
table::Key< table::Array< int > > group
Definition: PsfexPsf.cc:359