LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst.pipe.tasks.objectMasks.ObjectMaskCatalog Class Reference

Public Member Functions

def __init__ (self)
 
def __len__ (self)
 
def __iter__ (self)
 
def __getitem__ (self, i)
 
def __setitem__ (self, i, v)
 
def readFits (cls, fileName, hdu=0, flags=0)
 

Static Public Member Functions

def read (fileName)
 

Public Attributes

 table
 
 addNew
 

Detailed Description

Class to support bright object masks

N.b. I/O is done by providing a readFits method which fools the butler.

Definition at line 31 of file objectMasks.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.__init__ (   self)

Definition at line 37 of file objectMasks.py.

37  def __init__(self):
38  schema = afwTable.SimpleTable.makeMinimalSchema()
39  schema.addField("type", str, "type of region (e.g. box, circle)", size=10)
40  schema.addField("radius", "Angle", "radius of mask (if type == circle")
41  schema.addField("height", "Angle", "height of mask (if type == box)")
42  schema.addField("width", "Angle", "width of mask (if type == box)")
43  schema.addField("angle", "Angle", "rotation of mask (if type == box)")
44  schema.addField("mag", float, "object's magnitude")
45 
46  self._catalog = afwTable.SimpleCatalog(schema)
47  self._catalog.table.setMetadata(dafBase.PropertyList())
48 
49  self.table = self._catalog.table
50  self.addNew = self._catalog.addNew
51 
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: SortedCatalog.h:42
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68

Member Function Documentation

◆ __getitem__()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.__getitem__ (   self,
  i 
)

Definition at line 58 of file objectMasks.py.

58  def __getitem__(self, i):
59  return self._catalog.__getitem__(i)
60 

◆ __iter__()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.__iter__ (   self)

Definition at line 55 of file objectMasks.py.

55  def __iter__(self):
56  return iter(self._catalog)
57 

◆ __len__()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.__len__ (   self)

Definition at line 52 of file objectMasks.py.

52  def __len__(self):
53  return len(self._catalog)
54 

◆ __setitem__()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.__setitem__ (   self,
  i,
  v 
)

Definition at line 61 of file objectMasks.py.

61  def __setitem__(self, i, v):
62  return self._catalog.__setitem__(i, v)
63 

◆ read()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.read (   fileName)
static
Read a ds9 region file, returning a ObjectMaskCatalog object

The files should be structured as follows:

# Description of catalogue as a comment
# CATALOG: catalog-id-string
# TRACT: 0
# PATCH: 5,4
# FILTER: HSC-I

wcs; fk5

circle(RA, DEC, RADIUS)           # ID: 1, mag: 12.34
box(RA, DEC, XSIZE, YSIZE, THETA) # ID: 2, mag: 23.45
...

The ", mag: XX.YY" is optional

The commented lines must be present, with the relevant fields such as
tract patch and filter filled in. The coordinate system must be listed
as above. Each patch is specified as a box or circle, with RA, DEC,
and dimensions specified in decimal degrees (with or without an
explicit "d").

Only (axis-aligned) boxes and circles are currently supported as
region definitions.

Definition at line 92 of file objectMasks.py.

92  def read(fileName):
93  """Read a ds9 region file, returning a ObjectMaskCatalog object
94 
95  The files should be structured as follows:
96 
97  # Description of catalogue as a comment
98  # CATALOG: catalog-id-string
99  # TRACT: 0
100  # PATCH: 5,4
101  # FILTER: HSC-I
102 
103  wcs; fk5
104 
105  circle(RA, DEC, RADIUS) # ID: 1, mag: 12.34
106  box(RA, DEC, XSIZE, YSIZE, THETA) # ID: 2, mag: 23.45
107  ...
108 
109  The ", mag: XX.YY" is optional
110 
111  The commented lines must be present, with the relevant fields such as
112  tract patch and filter filled in. The coordinate system must be listed
113  as above. Each patch is specified as a box or circle, with RA, DEC,
114  and dimensions specified in decimal degrees (with or without an
115  explicit "d").
116 
117  Only (axis-aligned) boxes and circles are currently supported as
118  region definitions.
119  """
120 
121  log = logging.getLogger("lsst.ObjectMaskCatalog")
122 
123  brightObjects = ObjectMaskCatalog()
124  checkedWcsIsFk5 = False
125  NaN = float("NaN")*geom.degrees
126 
127  nFormatError = 0 # number of format errors seen
128  with open(fileName) as fd:
129  for lineNo, line in enumerate(fd.readlines(), 1):
130  line = line.rstrip()
131 
132  if re.search(r"^\s*#", line):
133  #
134  # Parse any line of the form "# key : value" and put them into the metadata.
135  #
136  # The medatdata values must be defined as outlined in the above docstring
137  #
138  # The value of these three keys will be checked,
139  # so get them right!
140  #
141  mat = re.search(r"^\s*#\s*([a-zA-Z][a-zA-Z0-9_]+)\s*:\s*(.*)", line)
142  if mat:
143  key, value = mat.group(1).lower(), mat.group(2)
144  if key == "tract":
145  value = int(value)
146 
147  brightObjects.table.getMetadata().set(key, value)
148 
149  line = re.sub(r"^\s*#.*", "", line)
150  if not line:
151  continue
152 
153  if re.search(r"^\s*wcs\s*;\s*fk5\s*$", line, re.IGNORECASE):
154  checkedWcsIsFk5 = True
155  continue
156 
157  # This regular expression parses the regions file for each region to be masked,
158  # with the format as specified in the above docstring.
159  mat = re.search(r"^\s*(box|circle)"
160  r"(?:\s+|\s*\‍(\s*)" # open paren or space
161  r"([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)([d]*)" # ra + units
162  r"(?:\s+|\s*,\s*)" # sep
163  r"([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)([d]*)" # dec + units
164  r"(?:\s+|\s*,\s*)" # sep
165  r"([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)([d]*)" # param1 + units
166  r"(?:" # start optional 1
167  r"(?:\s+|\s*,\s*)" # sep
168  r"([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)([d]*)" # param2 + units
169  r"(?:" # start optional 2
170  r"(?:\s+|\s*,\s*)" # sep
171  r"([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)([d]*)" # param3 + units
172  ")?" # end optional 2
173  ")?" # end optional 1
174  r"(?:\s*|\s*\‍)\s*)" # close paren or space
175  r"#\s*ID:[\w\s]*(\d+)" # start comment, ID
176  r"(?:\s*,?\s*mag:\s*([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?))?"
177  r"\s*$", line)
178  if mat:
179  _type, ra, raUnit, dec, decUnit, \
180  param1, param1Unit, param2, param2Unit, param3, param3Unit, \
181  _id, mag = mat.groups()
182 
183  _id = int(_id)
184  if mag is None:
185  mag = NaN
186  else:
187  mag = float(mag)
188 
189  ra = convertToAngle(ra, raUnit, "ra", fileName, lineNo)
190  dec = convertToAngle(dec, decUnit, "dec", fileName, lineNo)
191 
192  radius = NaN
193  width = NaN
194  height = NaN
195  angle = 0.0*geom.degrees
196 
197  if _type == "box":
198  width = convertToAngle(param1, param1Unit, "width", fileName, lineNo)
199  height = convertToAngle(param2, param2Unit, "height", fileName, lineNo)
200  if param3 is not None:
201  angle = convertToAngle(param3, param3Unit, "angle", fileName, lineNo)
202 
203  if angle != 0.0:
204  log.warning("Rotated boxes are not supported: \"%s\" at %s:%d",
205  line, fileName, lineNo)
206  nFormatError += 1
207  elif _type == "circle":
208  radius = convertToAngle(param1, param1Unit, "radius", fileName, lineNo)
209 
210  if not (param2 is None and param3 is None):
211  log.warning("Extra parameters for circle: \"%s\" at %s:%d",
212  line, fileName, lineNo)
213  nFormatError += 1
214 
215  rec = brightObjects.addNew()
216  # N.b. rec["coord"] = Coord is not supported, so we have to use the setter
217  rec["type"] = _type
218  rec["id"] = _id
219  rec["mag"] = mag
220  rec.setCoord(geom.SpherePoint(ra, dec))
221 
222  rec["angle"] = angle
223  rec["height"] = height
224  rec["width"] = width
225  rec["radius"] = radius
226  else:
227  log.warning("Unexpected line \"%s\" at %s:%d", line, fileName, lineNo)
228  nFormatError += 1
229 
230  if nFormatError > 0:
231  raise RuntimeError("Saw %d formatting errors in %s" % (nFormatError, fileName))
232 
233  if not checkedWcsIsFk5:
234  raise RuntimeError("Expected to see a line specifying an fk5 wcs in %s" % fileName)
235 
236  # This makes the deep copy contiguous in memory so that a ColumnView can be exposed to Numpy
237  brightObjects._catalog = brightObjects._catalog.copy(True)
238 
239  return brightObjects
240 
241 
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
daf::base::PropertySet * set
Definition: fits.cc:912
def convertToAngle(var, varUnit, what, fileName, lineNo)
Definition: objectMasks.py:242
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override
Definition: warpExposure.cc:0

◆ readFits()

def lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.readFits (   cls,
  fileName,
  hdu = 0,
  flags = 0 
)
FitsCatalogStorage facade for `read`.

This method is intended for use by the Gen2 Butler only.

Parameters
----------
fileName : `str`
    Name of the file to read.
hdu : `int`
    Provided for compatibility with the "FitsCatalogStorage" read API
    defined in `lsst.daf.persistence`, and ignored here.
flags : `int`
    Provided for compatibility with the "FitsCatalogStorage" read API
    defined in `lsst.daf.persistence`, and ignored here.

Notes
-----
Having a `readFits` method makes the `ObjectCatalogMask` class
duck-type compatible with `lsst.afw.table` catalogs, to the extent
needed to support reading by the Gen2 Butler with no specialized code
in `lsst.daf.persistence`. The on-disk type should actually be an
ASCII ds9 region file, typically with a ".reg" suffix.

Definition at line 65 of file objectMasks.py.

65  def readFits(cls, fileName, hdu=0, flags=0):
66  """FitsCatalogStorage facade for `read`.
67 
68  This method is intended for use by the Gen2 Butler only.
69 
70  Parameters
71  ----------
72  fileName : `str`
73  Name of the file to read.
74  hdu : `int`
75  Provided for compatibility with the "FitsCatalogStorage" read API
76  defined in `lsst.daf.persistence`, and ignored here.
77  flags : `int`
78  Provided for compatibility with the "FitsCatalogStorage" read API
79  defined in `lsst.daf.persistence`, and ignored here.
80 
81  Notes
82  -----
83  Having a `readFits` method makes the `ObjectCatalogMask` class
84  duck-type compatible with `lsst.afw.table` catalogs, to the extent
85  needed to support reading by the Gen2 Butler with no specialized code
86  in `lsst.daf.persistence`. The on-disk type should actually be an
87  ASCII ds9 region file, typically with a ".reg" suffix.
88  """
89  return cls.read(fileName)
90 

Member Data Documentation

◆ addNew

lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.addNew

Definition at line 50 of file objectMasks.py.

◆ table

lsst.pipe.tasks.objectMasks.ObjectMaskCatalog.table

Definition at line 49 of file objectMasks.py.


The documentation for this class was generated from the following file: