LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Public Member Functions | Properties | List of all members
lsst.afw.table._base.Catalog Class Reference
Inheritance diagram for lsst.afw.table._base.Catalog:
lsst.utils.wrappers.TemplateMeta

Public Member Functions

def getColumnView (self)
 
def __getitem__ (self, key)
 
def __setitem__ (self, key, value)
 
def __delitem__ (self, key)
 
def append (self, record)
 
def insert (self, key, value)
 
def clear (self)
 
def addNew (self)
 
def cast (self, type_, deep=False)
 
def copy (self, deep=False)
 
def extend (self, iterable, deep=False, mapper=None)
 
def __reduce__ (self)
 
def asAstropy (self, cls=None, copy=False, unviewable="copy")
 
def __dir__ (self)
 
def __getattr__ (self, name)
 
def __str__ (self)
 
def __repr__ (self)
 
def __new__ (cls, name, bases, attrs)
 
def __call__ (cls, args, kwds)
 
def __subclasscheck__ (cls, subclass)
 
def __instancecheck__ (cls, instance)
 
def __subclasses__ (cls)
 
def register (cls, key, subclass)
 
def alias (cls, key, subclass)
 
def __iter__ (cls)
 
def __len__ (cls)
 
def __contains__ (cls, key)
 
def keys (cls)
 
def values (cls)
 
def items (cls)
 
def get (cls, key, default=None)
 

Properties

 columns = property(__getColumns, doc="a column view of the catalog")
 

Detailed Description

Definition at line 88 of file _base.py.

Member Function Documentation

◆ __call__()

def lsst.utils.wrappers.TemplateMeta.__call__ (   cls,
  args,
  kwds 
)
inherited

Definition at line 293 of file wrappers.py.

293  def __call__(cls, *args, **kwds):
294  # __call__ is invoked when someone tries to construct an instance of
295  # the abstract base class.
296  # If the ABC defines a "TEMPLATE_PARAMS" attribute, we use those strings
297  # as the kwargs we should intercept to find the right type.
298  # Generate a type mapping key from input keywords. If the type returned
299  # from the keyword lookup is a numpy dtype object, fetch the underlying
300  # type of the dtype
301  key = []
302  for p, d in zip(cls.TEMPLATE_PARAMS, cls.TEMPLATE_DEFAULTS):
303  tempKey = kwds.pop(p, d)
304  if isinstance(tempKey, np.dtype):
305  tempKey = tempKey.type
306  key.append(tempKey)
307  key = tuple(key)
308 
309  # indices are only tuples if there are multiple elements
310  clz = cls._registry.get(key[0] if len(key) == 1 else key, None)
311  if clz is None:
312  d = {k: v for k, v in zip(cls.TEMPLATE_PARAMS, key)}
313  raise TypeError("No registered subclass for {}.".format(d))
314  return clz(*args, **kwds)
315 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ __contains__()

def lsst.utils.wrappers.TemplateMeta.__contains__ (   cls,
  key 
)
inherited

Definition at line 458 of file wrappers.py.

458  def __contains__(cls, key):
459  return key in cls._registry
460 

◆ __delitem__()

def lsst.afw.table._base.Catalog.__delitem__ (   self,
  key 
)

Definition at line 147 of file _base.py.

147  def __delitem__(self, key):
148  self._columns = None
149  if isinstance(key, slice):
150  self._delslice_(key)
151  else:
152  self._delitem_(key)
153 

◆ __dir__()

def lsst.afw.table._base.Catalog.__dir__ (   self)
This custom dir is necessary due to the custom getattr below.
Without it, not all of the methods available are returned with dir.
See DM-7199.

Definition at line 327 of file _base.py.

327  def __dir__(self):
328  """
329  This custom dir is necessary due to the custom getattr below.
330  Without it, not all of the methods available are returned with dir.
331  See DM-7199.
332  """
333  def recursive_get_class_dir(cls):
334  """
335  Return a set containing the names of all methods
336  for a given class *and* all of its subclasses.
337  """
338  result = set()
339  if cls.__bases__:
340  for subcls in cls.__bases__:
341  result |= recursive_get_class_dir(subcls)
342  result |= set(cls.__dict__.keys())
343  return result
344  return sorted(set(dir(self.columns)) | set(dir(self.table)) |
345  recursive_get_class_dir(type(self)) | set(self.__dict__.keys()))
346 
daf::base::PropertySet * set
Definition: fits.cc:902
table::Key< int > type
Definition: Detector.cc:163

◆ __getattr__()

def lsst.afw.table._base.Catalog.__getattr__ (   self,
  name 
)

Definition at line 347 of file _base.py.

347  def __getattr__(self, name):
348  # Catalog forwards unknown method calls to its table and column view
349  # for convenience. (Feature requested by RHL; complaints about magic
350  # should be directed to him.)
351  if name == "_columns":
352  self._columns = None
353  return None
354  try:
355  return getattr(self.table, name)
356  except AttributeError:
357  return getattr(self.columns, name)
358 

◆ __getitem__()

def lsst.afw.table._base.Catalog.__getitem__ (   self,
  key 
)
Return the record at index key if key is an integer,
return a column if `key` is a string field name or Key,
or return a subset of the catalog if key is a slice
or boolean NumPy array.

Definition at line 100 of file _base.py.

100  def __getitem__(self, key):
101  """Return the record at index key if key is an integer,
102  return a column if `key` is a string field name or Key,
103  or return a subset of the catalog if key is a slice
104  or boolean NumPy array.
105  """
106  if type(key) is slice:
107  (start, stop, step) = (key.start, key.stop, key.step)
108  if step is None:
109  step = 1
110  if start is None:
111  start = 0
112  if stop is None:
113  stop = len(self)
114  return self.subset(start, stop, step)
115  elif isinstance(key, np.ndarray):
116  if key.dtype == bool:
117  return self.subset(key)
118  raise RuntimeError("Unsupported array type for indexing non-contiguous Catalog: %s" %
119  (key.dtype,))
120  elif isinstance(key, Key) or isinstance(key, str):
121  if not self.isContiguous():
122  if isinstance(key, str):
123  key = self.schema[key].asKey()
124  array = self._getitem_(key)
125  # This array doesn't share memory with the Catalog, so don't let it be modified by
126  # the user who thinks that the Catalog itself is being modified.
127  # Just be aware that this array can only be passed down to C++ as an ndarray::Array<T const>
128  # instead of an ordinary ndarray::Array<T>. If pybind isn't letting it down into C++,
129  # you may have left off the 'const' in the definition.
130  array.flags.writeable = False
131  return array
132  return self.columns[key]
133  else:
134  return self._getitem_(key)
135 
table::Key< int > type
Definition: Detector.cc:163

◆ __instancecheck__()

def lsst.utils.wrappers.TemplateMeta.__instancecheck__ (   cls,
  instance 
)
inherited

Definition at line 326 of file wrappers.py.

326  def __instancecheck__(cls, instance):
327  # Special method hook for the isinstance built-in: we return true for
328  # an instance of any registered type or true subclass thereof.
329  if type(instance) in cls._registry:
330  return True
331  for v in cls._registry.values():
332  if isinstance(instance, v):
333  return True
334  return False
335 
table::Key< int > type
Definition: Detector.cc:163

◆ __iter__()

def lsst.utils.wrappers.TemplateMeta.__iter__ (   cls)
inherited

Definition at line 452 of file wrappers.py.

◆ __len__()

def lsst.utils.wrappers.TemplateMeta.__len__ (   cls)
inherited

Definition at line 455 of file wrappers.py.

455  def __len__(cls):
456  return len(cls._registry)
457 

◆ __new__()

def lsst.utils.wrappers.TemplateMeta.__new__ (   cls,
  name,
  bases,
  attrs 
)
inherited

Definition at line 261 of file wrappers.py.

261  def __new__(cls, name, bases, attrs):
262  # __new__ is invoked when the abstract base class is defined (via a
263  # class statement). We save a dict of class attributes (including
264  # methods) that were defined in the class body so we can copy them
265  # to registered subclasses later.
266  # We also initialize an empty dict to store the registered subclasses.
267  attrs["_inherited"] = {k: v for k, v in attrs.items()
268  if isAttributeSafeToTransfer(k, v)}
269  # The special "TEMPLATE_PARAMS" class attribute, if defined, contains
270  # names of the template parameters, which we use to set those
271  # attributes on registered subclasses and intercept arguments to the
272  # constructor. This line removes it from the dict of things that
273  # should be inherited while setting a default of 'dtype' if it's not
274  # defined.
275  attrs["TEMPLATE_PARAMS"] = \
276  attrs["_inherited"].pop("TEMPLATE_PARAMS", ("dtype",))
277  attrs["TEMPLATE_DEFAULTS"] = \
278  attrs["_inherited"].pop("TEMPLATE_DEFAULTS",
279  (None,)*len(attrs["TEMPLATE_PARAMS"]))
280  attrs["_registry"] = dict()
281  self = type.__new__(cls, name, bases, attrs)
282 
283  if len(self.TEMPLATE_PARAMS) == 0:
284  raise ValueError(
285  "TEMPLATE_PARAMS must be a tuple with at least one element."
286  )
287  if len(self.TEMPLATE_DEFAULTS) != len(self.TEMPLATE_PARAMS):
288  raise ValueError(
289  "TEMPLATE_PARAMS and TEMPLATE_DEFAULTS must have same length."
290  )
291  return self
292 
def isAttributeSafeToTransfer(name, value)
Definition: wrappers.py:45

◆ __reduce__()

def lsst.afw.table._base.Catalog.__reduce__ (   self)

Definition at line 233 of file _base.py.

233  def __reduce__(self):
234  import lsst.afw.fits
235  return lsst.afw.fits.reduceToFits(self)
236 

◆ __repr__()

def lsst.afw.table._base.Catalog.__repr__ (   self)

Definition at line 367 of file _base.py.

367  def __repr__(self):
368  return "%s\n%s" % (type(self), self)
369 
370 
371 Catalog.register("Base", BaseCatalog)
372 
table::Key< int > type
Definition: Detector.cc:163

◆ __setitem__()

def lsst.afw.table._base.Catalog.__setitem__ (   self,
  key,
  value 
)
If ``key`` is an integer, set ``catalog[key]`` to
``value``. Otherwise select column ``key`` and set it to
``value``.

Definition at line 136 of file _base.py.

136  def __setitem__(self, key, value):
137  """If ``key`` is an integer, set ``catalog[key]`` to
138  ``value``. Otherwise select column ``key`` and set it to
139  ``value``.
140  """
141  self._columns = None
142  if isinstance(key, Key) or isinstance(key, str):
143  self.columns[key] = value
144  else:
145  return self.set(key, value)
146 

◆ __str__()

def lsst.afw.table._base.Catalog.__str__ (   self)

Definition at line 359 of file _base.py.

359  def __str__(self):
360  if self.isContiguous():
361  return str(self.asAstropy())
362  else:
363  fields = ' '.join(x.field.getName() for x in self.schema)
364  string = "Non-contiguous afw.Catalog of %d rows.\ncolumns: %s" % (len(self), fields)
365  return string
366 

◆ __subclasscheck__()

def lsst.utils.wrappers.TemplateMeta.__subclasscheck__ (   cls,
  subclass 
)
inherited

Definition at line 316 of file wrappers.py.

316  def __subclasscheck__(cls, subclass):
317  # Special method hook for the issubclass built-in: we return true for
318  # any registered type or true subclass thereof.
319  if subclass in cls._registry:
320  return True
321  for v in cls._registry.values():
322  if issubclass(subclass, v):
323  return True
324  return False
325 

◆ __subclasses__()

def lsst.utils.wrappers.TemplateMeta.__subclasses__ (   cls)
inherited
Return a tuple of all classes that inherit from this class.

Definition at line 336 of file wrappers.py.

336  def __subclasses__(cls):
337  """Return a tuple of all classes that inherit from this class.
338  """
339  # This special method isn't defined as part of the Python data model,
340  # but it exists on builtins (including ABCMeta), and it provides useful
341  # functionality.
342  return tuple(set(cls._registry.values()))
343 
daf::base::PropertySet * set
Definition: fits.cc:902

◆ addNew()

def lsst.afw.table._base.Catalog.addNew (   self)

Definition at line 166 of file _base.py.

166  def addNew(self):
167  self._columns = None
168  return self._addNew()
169 

◆ alias()

def lsst.utils.wrappers.TemplateMeta.alias (   cls,
  key,
  subclass 
)
inherited
Add an alias that allows an existing subclass to be accessed with a
different key.

Definition at line 429 of file wrappers.py.

429  def alias(cls, key, subclass):
430  """Add an alias that allows an existing subclass to be accessed with a
431  different key.
432  """
433  if key is None:
434  raise ValueError("None may not be used as a key.")
435  if key in cls._registry:
436  raise KeyError("Cannot multiply-register key {}".format(key))
437  primaryKey = tuple(getattr(subclass, p, None)
438  for p in cls.TEMPLATE_PARAMS)
439  if len(primaryKey) == 1:
440  # indices are only tuples if there are multiple elements
441  primaryKey = primaryKey[0]
442  if cls._registry.get(primaryKey, None) != subclass:
443  raise ValueError("Subclass is not registered with this base class.")
444  cls._registry[key] = subclass
445 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ append()

def lsst.afw.table._base.Catalog.append (   self,
  record 
)

Definition at line 154 of file _base.py.

154  def append(self, record):
155  self._columns = None
156  self._append(record)
157 
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33

◆ asAstropy()

def lsst.afw.table._base.Catalog.asAstropy (   self,
  cls = None,
  copy = False,
  unviewable = "copy" 
)
Return an astropy.table.Table (or subclass thereof) view into this catalog.

Parameters
----------
cls :
    Table subclass to use; `None` implies `astropy.table.Table`
    itself.  Use `astropy.table.QTable` to get Quantity columns.
copy : bool, optional
    If `True`, copy data from the LSST catalog to the astropy
    table.  Not copying is usually faster, but can keep memory
    from being freed if columns are later removed from the
    Astropy view.
unviewable : `str`, optional
    One of the following options (which is ignored if
    copy=`True` ), indicating how to handle field types (`str`
    and `Flag`) for which views cannot be constructed:
- 'copy' (default): copy only the unviewable fields.
- 'raise': raise ValueError if unviewable fields are present.
- 'skip': do not include unviewable fields in the Astropy Table.

Returns
-------
cls : `astropy.table.Table`
    Astropy view into the catalog.

Raises
------
ValueError
    Raised if the `unviewable` option is not a known value, or
    if the option is 'raise' and an uncopyable field is found.

Definition at line 237 of file _base.py.

237  def asAstropy(self, cls=None, copy=False, unviewable="copy"):
238  """Return an astropy.table.Table (or subclass thereof) view into this catalog.
239 
240  Parameters
241  ----------
242  cls :
243  Table subclass to use; `None` implies `astropy.table.Table`
244  itself. Use `astropy.table.QTable` to get Quantity columns.
245  copy : bool, optional
246  If `True`, copy data from the LSST catalog to the astropy
247  table. Not copying is usually faster, but can keep memory
248  from being freed if columns are later removed from the
249  Astropy view.
250  unviewable : `str`, optional
251  One of the following options (which is ignored if
252  copy=`True` ), indicating how to handle field types (`str`
253  and `Flag`) for which views cannot be constructed:
254  - 'copy' (default): copy only the unviewable fields.
255  - 'raise': raise ValueError if unviewable fields are present.
256  - 'skip': do not include unviewable fields in the Astropy Table.
257 
258  Returns
259  -------
260  cls : `astropy.table.Table`
261  Astropy view into the catalog.
262 
263  Raises
264  ------
265  ValueError
266  Raised if the `unviewable` option is not a known value, or
267  if the option is 'raise' and an uncopyable field is found.
268 
269  """
270  import astropy.table
271  if cls is None:
272  cls = astropy.table.Table
273  if unviewable not in ("copy", "raise", "skip"):
274  raise ValueError(
275  "'unviewable'=%r must be one of 'copy', 'raise', or 'skip'" % (unviewable,))
276  ps = self.getMetadata()
277  meta = ps.toOrderedDict() if ps is not None else None
278  columns = []
279  items = self.schema.extract("*", ordered=True)
280  for name, item in items.items():
281  key = item.key
282  unit = item.field.getUnits() or None # use None instead of "" when empty
283  if key.getTypeString() == "String":
284  if not copy:
285  if unviewable == "raise":
286  raise ValueError("Cannot extract string "
287  "unless copy=True or unviewable='copy' or 'skip'.")
288  elif unviewable == "skip":
289  continue
290  data = np.zeros(
291  len(self), dtype=np.dtype((str, key.getSize())))
292  for i, record in enumerate(self):
293  data[i] = record.get(key)
294  elif key.getTypeString() == "Flag":
295  if not copy:
296  if unviewable == "raise":
297  raise ValueError("Cannot extract packed bit columns "
298  "unless copy=True or unviewable='copy' or 'skip'.")
299  elif unviewable == "skip":
300  continue
301  data = self.columns.get_bool_array(key)
302  elif key.getTypeString() == "Angle":
303  data = self.columns.get(key)
304  unit = "radian"
305  if copy:
306  data = data.copy()
307  elif "Array" in key.getTypeString() and key.isVariableLength():
308  # Can't get columns for variable-length array fields.
309  if unviewable == "raise":
310  raise ValueError("Cannot extract variable-length array fields unless unviewable='skip'.")
311  elif unviewable == "skip" or unviewable == "copy":
312  continue
313  else:
314  data = self.columns.get(key)
315  if copy:
316  data = data.copy()
317  columns.append(
318  astropy.table.Column(
319  data,
320  name=name,
321  unit=unit,
322  description=item.field.getDoc()
323  )
324  )
325  return cls(columns, meta=meta, copy=False)
326 

◆ cast()

def lsst.afw.table._base.Catalog.cast (   self,
  type_,
  deep = False 
)
Return a copy of the catalog with the given type.

Parameters
----------
type_ :
    Type of catalog to return.
deep : `bool`, optional
    If `True`, clone the table and deep copy all records.

Returns
-------
copy :
    Copy of catalog with the requested type.

Definition at line 170 of file _base.py.

170  def cast(self, type_, deep=False):
171  """Return a copy of the catalog with the given type.
172 
173  Parameters
174  ----------
175  type_ :
176  Type of catalog to return.
177  deep : `bool`, optional
178  If `True`, clone the table and deep copy all records.
179 
180  Returns
181  -------
182  copy :
183  Copy of catalog with the requested type.
184  """
185  if deep:
186  table = self.table.clone()
187  table.preallocate(len(self))
188  else:
189  table = self.table
190  copy = type_(table)
191  copy.extend(self, deep=deep)
192  return copy
193 

◆ clear()

def lsst.afw.table._base.Catalog.clear (   self)

Definition at line 162 of file _base.py.

162  def clear(self):
163  self._columns = None
164  self._clear()
165 

◆ copy()

def lsst.afw.table._base.Catalog.copy (   self,
  deep = False 
)
Copy a catalog (default is not a deep copy).

Definition at line 194 of file _base.py.

194  def copy(self, deep=False):
195  """
196  Copy a catalog (default is not a deep copy).
197  """
198  return self.cast(type(self), deep)
199 
table::Key< int > type
Definition: Detector.cc:163

◆ extend()

def lsst.afw.table._base.Catalog.extend (   self,
  iterable,
  deep = False,
  mapper = None 
)
Append all records in the given iterable to the catalog.

Parameters
----------
iterable :
    Any Python iterable containing records.
deep : `bool`, optional
    If `True`, the records will be deep-copied; ignored if
    mapper is not `None` (that always implies `True`).
mapper : `lsst.afw.table.schemaMapper.SchemaMapper`, optional
    Used to translate records.

Definition at line 200 of file _base.py.

200  def extend(self, iterable, deep=False, mapper=None):
201  """Append all records in the given iterable to the catalog.
202 
203  Parameters
204  ----------
205  iterable :
206  Any Python iterable containing records.
207  deep : `bool`, optional
208  If `True`, the records will be deep-copied; ignored if
209  mapper is not `None` (that always implies `True`).
210  mapper : `lsst.afw.table.schemaMapper.SchemaMapper`, optional
211  Used to translate records.
212  """
213  self._columns = None
214  # We can't use isinstance here, because the SchemaMapper symbol isn't available
215  # when this code is part of a subclass of Catalog in another package.
216  if type(deep).__name__ == "SchemaMapper":
217  mapper = deep
218  deep = None
219  if isinstance(iterable, type(self)):
220  if mapper is not None:
221  self._extend(iterable, mapper)
222  else:
223  self._extend(iterable, deep)
224  else:
225  for record in iterable:
226  if mapper is not None:
227  self._append(self.table.copyRecord(record, mapper))
228  elif deep:
229  self._append(self.table.copyRecord(record))
230  else:
231  self._append(record)
232 
table::Key< int > type
Definition: Detector.cc:163

◆ get()

def lsst.utils.wrappers.TemplateMeta.get (   cls,
  key,
  default = None 
)
inherited
Return the subclass associated with the given key (including
aliases), or ``default`` if the key is not recognized.

Definition at line 477 of file wrappers.py.

477  def get(cls, key, default=None):
478  """Return the subclass associated with the given key (including
479  aliases), or ``default`` if the key is not recognized.
480  """
481  return cls._registry.get(key, default)
482 

◆ getColumnView()

def lsst.afw.table._base.Catalog.getColumnView (   self)

Definition at line 90 of file _base.py.

90  def getColumnView(self):
91  self._columns = self._getColumnView()
92  return self._columns
93 

◆ insert()

def lsst.afw.table._base.Catalog.insert (   self,
  key,
  value 
)

Definition at line 158 of file _base.py.

158  def insert(self, key, value):
159  self._columns = None
160  self._insert(key, value)
161 

◆ items()

def lsst.utils.wrappers.TemplateMeta.items (   cls)
inherited
Return an iterable of (key, subclass) pairs.

Definition at line 472 of file wrappers.py.

472  def items(cls):
473  """Return an iterable of (key, subclass) pairs.
474  """
475  return cls._registry.items()
476 
std::vector< SchemaItem< Flag > > * items

◆ keys()

def lsst.utils.wrappers.TemplateMeta.keys (   cls)
inherited
Return an iterable containing all keys (including aliases).

Definition at line 461 of file wrappers.py.

461  def keys(cls):
462  """Return an iterable containing all keys (including aliases).
463  """
464  return cls._registry.keys()
465 

◆ register()

def lsst.utils.wrappers.TemplateMeta.register (   cls,
  key,
  subclass 
)
inherited
Register a subclass of this ABC with the given key (a string,
number, type, or other hashable).

Register may only be called once for a given key or a given subclass.

Definition at line 344 of file wrappers.py.

344  def register(cls, key, subclass):
345  """Register a subclass of this ABC with the given key (a string,
346  number, type, or other hashable).
347 
348  Register may only be called once for a given key or a given subclass.
349  """
350  if key is None:
351  raise ValueError("None may not be used as a key.")
352  if subclass in cls._registry.values():
353  raise ValueError(
354  "This subclass has already registered with another key; "
355  "use alias() instead."
356  )
357  if cls._registry.setdefault(key, subclass) != subclass:
358  if len(cls.TEMPLATE_PARAMS) == 1:
359  d = {cls.TEMPLATE_PARAMS[0]: key}
360  else:
361  d = {k: v for k, v in zip(cls.TEMPLATE_PARAMS, key)}
362  raise KeyError(
363  "Another subclass is already registered with {}".format(d)
364  )
365  # If the key used to register a class matches the default key,
366  # make the static methods available through the ABC
367  if cls.TEMPLATE_DEFAULTS:
368  defaults = (cls.TEMPLATE_DEFAULTS[0] if
369  len(cls.TEMPLATE_DEFAULTS) == 1 else
370  cls.TEMPLATE_DEFAULTS)
371  if key == defaults:
372  conflictStr = ("Base class has attribute {}"
373  " which is a {} method of {}."
374  " Cannot link method to base class.")
375  # In the following if statements, the explicit lookup in
376  # __dict__ must be done, as a call to getattr returns the
377  # bound method, which no longer reports as a static or class
378  # method. The static methods must be transfered to the ABC
379  # in this unbound state, so that python will still see them
380  # as static methods and not attempt to pass self. The class
381  # methods must be transfered to the ABC as a bound method
382  # so that the correct cls be called with the class method
383  for name in subclass.__dict__:
384  if name in ("__new__", "__init_subclass__"):
385  continue
386  obj = subclass.__dict__[name]
387  # copy over the static methods
388  isBuiltin = isinstance(obj, types.BuiltinFunctionType)
389  isStatic = isinstance(obj, staticmethod)
390  if isBuiltin or isStatic:
391  if hasattr(cls, name):
392  raise AttributeError(
393  conflictStr.format(name, "static", subclass))
394  setattr(cls, name, obj)
395  # copy over the class methods
396  elif isinstance(obj, classmethod):
397  if hasattr(cls, name):
398  raise AttributeError(
399  conflictStr.format(name, "class", subclass))
400  setattr(cls, name, getattr(subclass, name))
401 
402  def setattrSafe(name, value):
403  try:
404  currentValue = getattr(subclass, name)
405  if currentValue != value:
406  msg = ("subclass already has a '{}' attribute with "
407  "value {} != {}.")
408  raise ValueError(
409  msg.format(name, currentValue, value)
410  )
411  except AttributeError:
412  setattr(subclass, name, value)
413 
414  if len(cls.TEMPLATE_PARAMS) == 1:
415  setattrSafe(cls.TEMPLATE_PARAMS[0], key)
416  elif len(cls.TEMPLATE_PARAMS) == len(key):
417  for p, k in zip(cls.TEMPLATE_PARAMS, key):
418  setattrSafe(p, k)
419  else:
420  raise ValueError(
421  "key must have {} elements (one for each of {})".format(
422  len(cls.TEMPLATE_PARAMS), cls.TEMPLATE_PARAMS
423  )
424  )
425 
426  for name, attr in cls._inherited.items():
427  setattr(subclass, name, attr)
428 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
std::vector< SchemaItem< Flag > > * items

◆ values()

def lsst.utils.wrappers.TemplateMeta.values (   cls)
inherited
Return an iterable of registered subclasses, with duplicates
corresponding to any aliases.

Definition at line 466 of file wrappers.py.

466  def values(cls):
467  """Return an iterable of registered subclasses, with duplicates
468  corresponding to any aliases.
469  """
470  return cls._registry.values()
471 

Property Documentation

◆ columns

lsst.afw.table._base.Catalog.columns = property(__getColumns, doc="a column view of the catalog")
static

Definition at line 98 of file _base.py.


The documentation for this class was generated from the following file:
  • /j/snowflake/release/lsstsw/stack/Linux64/afw/19.0.0-4-ga671dab3b+1/python/lsst/afw/table/_base.py