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 | Public Attributes | List of all members
lsst.afw.table.multiMatch.GroupView Class Reference
Inheritance diagram for lsst.afw.table.multiMatch.GroupView:

Public Member Functions

def build (cls, catalog, groupField="object")
 
def __init__ (self, schema, ids, groups)
 
def __len__ (self)
 
def __iter__ (self)
 
def __getitem__ (self, key)
 
def where (self, predicate)
 
def aggregate (self, function, field=None, dtype=float)
 
def apply (self, function, field=None, dtype=float)
 

Public Attributes

 schema
 
 ids
 
 groups
 
 count
 

Detailed Description

A mapping (i.e. dict-like object) that provides convenient
operations on the concatenated catalogs returned by a MultiMatch
object.

A GroupView provides access to a catalog of grouped objects, in
which the grouping is indicated by a field for which all records
in a group have the same value.  Once constructed, it allows
operations similar to those supported by SQL "GROUP BY", such as
filtering and aggregate calculation.

Parameters
----------
schema : `lsst.afw.table.Schema`
    Catalog schema to use for the grouped object catalog.
ids : `List`
    List of identifying keys for the groups in the catalog.
groups : `List`
    List of catalog subsets associated with each key in ids.

Definition at line 202 of file multiMatch.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.afw.table.multiMatch.GroupView.__init__ (   self,
  schema,
  ids,
  groups 
)

Definition at line 251 of file multiMatch.py.

251  def __init__(self, schema, ids, groups):
252  self.schema = schema
253  self.ids = ids
254  self.groups = groups
255  self.count = sum(len(cat) for cat in self.groups)
256 

Member Function Documentation

◆ __getitem__()

def lsst.afw.table.multiMatch.GroupView.__getitem__ (   self,
  key 
)

Definition at line 263 of file multiMatch.py.

263  def __getitem__(self, key):
264  index = numpy.searchsorted(self.ids, key)
265  if self.ids[index] != key:
266  raise KeyError("Group with ID {0} not found".format(key))
267  return self.groups[index]
268 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ __iter__()

def lsst.afw.table.multiMatch.GroupView.__iter__ (   self)

Definition at line 260 of file multiMatch.py.

260  def __iter__(self):
261  return iter(self.ids)
262 

◆ __len__()

def lsst.afw.table.multiMatch.GroupView.__len__ (   self)

Definition at line 257 of file multiMatch.py.

257  def __len__(self):
258  return len(self.ids)
259 

◆ aggregate()

def lsst.afw.table.multiMatch.GroupView.aggregate (   self,
  function,
  field = None,
  dtype = float 
)
Run an aggregate function on each group, returning an array with
one element for each group.

Parameters
----------
function :
    Callable object that computes the aggregate value.  If
    `field` is None, called with the entire subset catalog as an
    argument.  If `field` is not None, called with an array view
    into that field.
field : `str`, optional
    A string name or Key object that indicates a single field the aggregate
    is computed over.
dtype :
    Data type of the output array.

Returns
-------
result : Array of `dtype`
    Aggregated values for each group.

Definition at line 293 of file multiMatch.py.

293  def aggregate(self, function, field=None, dtype=float):
294  """Run an aggregate function on each group, returning an array with
295  one element for each group.
296 
297  Parameters
298  ----------
299  function :
300  Callable object that computes the aggregate value. If
301  `field` is None, called with the entire subset catalog as an
302  argument. If `field` is not None, called with an array view
303  into that field.
304  field : `str`, optional
305  A string name or Key object that indicates a single field the aggregate
306  is computed over.
307  dtype :
308  Data type of the output array.
309 
310  Returns
311  -------
312  result : Array of `dtype`
313  Aggregated values for each group.
314  """
315  result = numpy.zeros(len(self), dtype=dtype)
316  if field is not None:
317  key = self.schema.find(field).key
318 
319  def f(cat):
320  return function(cat.get(key))
321  else:
322  f = function
323  for i in range(len(self)):
324  result[i] = f(self.groups[i])
325  return result
326 

◆ apply()

def lsst.afw.table.multiMatch.GroupView.apply (   self,
  function,
  field = None,
  dtype = float 
)
Run a non-aggregate function on each group, returning an array with
one element for each record.

Parameters
----------
function :
    Callable object that computes the aggregate value.  If field is None,
    called with the entire subset catalog as an argument.  If field is not
    None, called with an array view into that field.
field : `str`
    A string name or Key object that indicates a single field the aggregate
    is computed over.
dtype :
    Data type for the output array.

Returns
-------
result : `numpy.array` of `dtype`
    Result of the function calculated on an element-by-element basis.

Definition at line 327 of file multiMatch.py.

327  def apply(self, function, field=None, dtype=float):
328  """Run a non-aggregate function on each group, returning an array with
329  one element for each record.
330 
331  Parameters
332  ----------
333  function :
334  Callable object that computes the aggregate value. If field is None,
335  called with the entire subset catalog as an argument. If field is not
336  None, called with an array view into that field.
337  field : `str`
338  A string name or Key object that indicates a single field the aggregate
339  is computed over.
340  dtype :
341  Data type for the output array.
342 
343  Returns
344  -------
345  result : `numpy.array` of `dtype`
346  Result of the function calculated on an element-by-element basis.
347  """
348  result = numpy.zeros(self.count, dtype=dtype)
349  if field is not None:
350  key = self.schema.find(field).key
351 
352  def f(cat):
353  return function(cat.get(key))
354  else:
355  f = function
356  last = 0
357  for i in range(len(self)):
358  next = last + len(self.groups[i])
359  result[last:next] = f(self.groups[i])
360  last = next
361  return result

◆ build()

def lsst.afw.table.multiMatch.GroupView.build (   cls,
  catalog,
  groupField = "object" 
)
Construct a GroupView from a concatenated catalog.

Parameters
----------
catalog : `lsst.afw.table.base.Catalog`
    Input catalog, containing records grouped by a field in
    which all records in the same group have the same value.
    Must be sorted by the group field.
groupField : `str`, optional
    Name or Key for the field that indicates groups.  Defaults
    to "object".

Returns
-------
groupCatalog : `lsst.afw.table.multiMatch.GroupView`
    Constructed GroupView from the input concatenated catalog.

Definition at line 224 of file multiMatch.py.

224  def build(cls, catalog, groupField="object"):
225  """Construct a GroupView from a concatenated catalog.
226 
227  Parameters
228  ----------
229  catalog : `lsst.afw.table.base.Catalog`
230  Input catalog, containing records grouped by a field in
231  which all records in the same group have the same value.
232  Must be sorted by the group field.
233  groupField : `str`, optional
234  Name or Key for the field that indicates groups. Defaults
235  to "object".
236 
237  Returns
238  -------
239  groupCatalog : `lsst.afw.table.multiMatch.GroupView`
240  Constructed GroupView from the input concatenated catalog.
241  """
242  groupKey = catalog.schema.find(groupField).key
243  ids, indices = numpy.unique(catalog.get(groupKey), return_index=True)
244  groups = numpy.zeros(len(ids), dtype=object)
245  ends = list(indices[1:]) + [len(catalog)]
246  for n, (i1, i2) in enumerate(zip(indices, ends)):
247  groups[n] = catalog[i1:i2]
248  assert (groups[n].get(groupKey) == ids[n]).all()
249  return cls(catalog.schema, ids, groups)
250 
daf::base::PropertyList * list
Definition: fits.cc:913
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.

◆ where()

def lsst.afw.table.multiMatch.GroupView.where (   self,
  predicate 
)
Return a new GroupView that contains only groups for which the
given predicate function returns True.

The predicate function is called once for each group, and
passed a single argument: the subset catalog for that group.

Parameters
----------
predicate :
    Function to identify which groups should be included in
    the output.

Returns
-------
outGroupView : `lsst.afw.table.multiMatch.GroupView`
    Subset GroupView containing only groups that match the
    predicate.

Definition at line 269 of file multiMatch.py.

269  def where(self, predicate):
270  """Return a new GroupView that contains only groups for which the
271  given predicate function returns True.
272 
273  The predicate function is called once for each group, and
274  passed a single argument: the subset catalog for that group.
275 
276  Parameters
277  ----------
278  predicate :
279  Function to identify which groups should be included in
280  the output.
281 
282  Returns
283  -------
284  outGroupView : `lsst.afw.table.multiMatch.GroupView`
285  Subset GroupView containing only groups that match the
286  predicate.
287  """
288  mask = numpy.zeros(len(self), dtype=bool)
289  for i in range(len(self)):
290  mask[i] = predicate(self.groups[i])
291  return type(self)(self.schema, self.ids[mask], self.groups[mask])
292 
table::Key< int > type
Definition: Detector.cc:163

Member Data Documentation

◆ count

lsst.afw.table.multiMatch.GroupView.count

Definition at line 255 of file multiMatch.py.

◆ groups

lsst.afw.table.multiMatch.GroupView.groups

Definition at line 254 of file multiMatch.py.

◆ ids

lsst.afw.table.multiMatch.GroupView.ids

Definition at line 253 of file multiMatch.py.

◆ schema

lsst.afw.table.multiMatch.GroupView.schema

Definition at line 252 of file multiMatch.py.


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