LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
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
 Construct a GroupView from a concatenated catalog. More...
 
def __init__
 
def __len__
 
def __iter__
 
def __getitem__
 
def where
 
def aggregate
 Run an aggregate function on each group, returning an array with one element for each group. More...
 
def apply
 Run a non-aggregate function on each group, returning an array with one element for each record. More...
 

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.

Definition at line 123 of file multiMatch.py.

Constructor & Destructor Documentation

def lsst.afw.table.multiMatch.GroupView.__init__ (   self,
  schema,
  ids,
  groups 
)
Direct constructor; most users should call build() instead.

This constructor takes the constituent arrays of the object directly, to allow multiple
methods for construction.

Definition at line 149 of file multiMatch.py.

150  def __init__(self, schema, ids, groups):
151  """Direct constructor; most users should call build() instead.
152 
153  This constructor takes the constituent arrays of the object directly, to allow multiple
154  methods for construction.
155  """
156  self.schema = schema
157  self.ids = ids
158  self.groups = groups
159  self.count = sum(len(cat) for cat in self.groups)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250

Member Function Documentation

def lsst.afw.table.multiMatch.GroupView.__getitem__ (   self,
  key 
)
Return the catalog subset that corresponds to an group field value

Definition at line 168 of file multiMatch.py.

169  def __getitem__(self, key):
170  """Return the catalog subset that corresponds to an group field value"""
171  index = numpy.searchsorted(self.ids, key)
172  if self.ids[index] != key:
173  raise KeyError("Group with ID {0} not found".format(key))
174  return self.groups[index]
def lsst.afw.table.multiMatch.GroupView.__iter__ (   self)
Iterate over group field values

Definition at line 164 of file multiMatch.py.

165  def __iter__(self):
166  """Iterate over group field values"""
167  return self.ids
def lsst.afw.table.multiMatch.GroupView.__len__ (   self)
Return the number of groups

Definition at line 160 of file multiMatch.py.

161  def __len__(self):
162  """Return the number of groups"""
163  return len(self.ids)
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
[in]functionCallable 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.
[in]fieldA string name or Key object that indicates a single field the aggregate is computed over.
[in]dtypeData type for the output array.

Definition at line 187 of file multiMatch.py.

188  def aggregate(self, function, field=None, dtype=float):
189  """!Run an aggregate function on each group, returning an array with one element for each group.
190 
191  @param[in] function Callable object that computes the aggregate value. If field is None,
192  called with the entire subset catalog as an argument. If field is not
193  None, called with an array view into that field.
194  @param[in] field A string name or Key object that indicates a single field the aggregate
195  is computed over.
196  @param[in] dtype Data type for the output array.
197  """
198  result = numpy.zeros(len(self), dtype=float)
199  if field is not None:
200  key = self.schema.find(field).key
201  f = lambda cat: function(cat.get(key))
202  else:
203  f = function
204  for i in xrange(len(self)):
205  result[i] = f(self.groups[i])
206  return result
def aggregate
Run an aggregate function on each group, returning an array with one element for each group...
Definition: multiMatch.py:187
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
[in]functionCallable 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.
[in]fieldA string name or Key object that indicates a single field the aggregate is computed over.
[in]dtypeData type for the output array.

Definition at line 207 of file multiMatch.py.

208  def apply(self, function, field=None, dtype=float):
209  """!Run a non-aggregate function on each group, returning an array with one element for each record.
210 
211  @param[in] function Callable object that computes the aggregate value. If field is None,
212  called with the entire subset catalog as an argument. If field is not
213  None, called with an array view into that field.
214  @param[in] field A string name or Key object that indicates a single field the aggregate
215  is computed over.
216  @param[in] dtype Data type for the output array.
217  """
218  result = numpy.zeros(self.count, dtype=float)
219  if field is not None:
220  key = self.schema.find(field).key
221  f = lambda cat: function(cat.get(key))
222  else:
223  f = function
224  last = 0
225  for i in xrange(len(self)):
226  next = last + len(self.groups[i])
227  result[last:next] = f(self.groups[i])
228  last = next
229  return result
def apply
Run a non-aggregate function on each group, returning an array with one element for each record...
Definition: multiMatch.py:207
def lsst.afw.table.multiMatch.GroupView.build (   cls,
  catalog,
  groupField = "object" 
)

Construct a GroupView from a concatenated catalog.

Parameters
[in]catalogInput 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.
[in]groupFieldName or Key for the field that indicates groups.

Definition at line 133 of file multiMatch.py.

134  def build(cls, catalog, groupField="object"):
135  """!Construct a GroupView from a concatenated catalog.
136 
137  @param[in] catalog Input catalog, containing records grouped by a field in which all records
138  in the same group have the same value. Must be sorted by the group field.
139  @param[in] groupField Name or Key for the field that indicates groups.
140  """
141  groupKey = catalog.schema.find(groupField).key
142  ids, indices = numpy.unique(catalog.get(groupKey), return_index=True)
143  groups = numpy.zeros(len(ids), dtype=object)
144  ends = list(indices[1:]) + [len(catalog)]
145  for n, (i1, i2) in enumerate(zip(indices, ends)):
146  groups[n] = catalog[i1:i2]
147  assert (groups[n].get(groupKey) == ids[n]).all()
148  return cls(catalog.schema, ids, groups)
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.
def build
Construct a GroupView from a concatenated catalog.
Definition: multiMatch.py:133
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.

Definition at line 175 of file multiMatch.py.

176  def where(self, predicate):
177  """Return a new GroupView that contains only groups for which the given predicate function
178  returns True.
179 
180  The predicate function is called once for each group, and passed a single argument: the subset
181  catalog for that group.
182  """
183  mask = numpy.zeros(len(self), dtype=bool)
184  for i in xrange(len(self)):
185  mask[i] = predicate(self.groups[i])
186  return type(self)(self.schema, self.ids[mask], self.groups[mask])

Member Data Documentation

lsst.afw.table.multiMatch.GroupView.count

Definition at line 158 of file multiMatch.py.

lsst.afw.table.multiMatch.GroupView.groups

Definition at line 157 of file multiMatch.py.

lsst.afw.table.multiMatch.GroupView.ids

Definition at line 156 of file multiMatch.py.

lsst.afw.table.multiMatch.GroupView.schema

Definition at line 155 of file multiMatch.py.


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