GroupView¶
-
class
lsst.afw.table.
GroupView
(schema, ids, groups)¶ Bases:
collections.abc.Mapping
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.
- schema
Methods Summary
aggregate
(function[, field, dtype])Run an aggregate function on each group, returning an array with one element for each group.
apply
(function[, field, dtype])Run a non-aggregate function on each group, returning an array with one element for each record.
build
(catalog[, groupField])Construct a GroupView from a concatenated catalog.
get
(k[,d])items
()keys
()values
()where
(predicate)Return a new GroupView that contains only groups for which the given predicate function returns True.
Methods Documentation
-
aggregate
(function, field=None, dtype=<class '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. Iffield
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
- resultArray of
dtype
Aggregated values for each group.
- resultArray of
-
apply
(function, field=None, dtype=<class '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
ofdtype
Result of the function calculated on an element-by-element basis.
- result
-
classmethod
build
(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”.
- catalog
- Returns
- groupCatalog
lsst.afw.table.GroupView
Constructed GroupView from the input concatenated catalog.
- groupCatalog
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
values
() → an object providing a view on D's values¶
-
where
(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.GroupView
Subset GroupView containing only groups that match the predicate.
- outGroupView