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