LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Functions
lsst.afw.table._syntax Namespace Reference

Functions

def KeyBaseCov_subfields
 
def KeyBaseCov_subkeys
 
def Schema_extract
 
def BaseRecord_extract
 
def BaseColumnView_extract
 

Function Documentation

def lsst.afw.table._syntax.BaseColumnView_extract (   self,
  patterns,
  kwds 
)
Extract a dictionary of {<name>: <column-array>} in which the field names
match the given shell-style glob pattern(s).

Any number of glob patterns may be passed; the result will be the union of all
the result of each glob considered separately.

Note that extract("*", copy=True) provides an easy way to transform a row-major
ColumnView into a possibly more efficient set of contiguous NumPy arrays.

This routines unpacks Flag columns into full boolean arrays and covariances into dense
(i.e. non-triangular packed) arrays with dimension (N,M,M), where N is the number of
records and M is the dimension of the covariance matrix.  Fields with named subfields
(e.g. points) are always split into separate dictionary items, as is done in
BaseRecord.extract(..., split=True).  String fields are silently ignored.

Additional optional arguments may be passed as keywords:

  items ------ The result of a call to self.schema.extract(); this will be used instead
               of doing any new matching, and allows the pattern matching to be reused
               to extract values from multiple records.  This keyword is incompatible
               with any position arguments and the regex, sub, and ordered keyword
               arguments.

  where ------ Any expression that can be passed as indices to a NumPy array, including
               slices, boolean arrays, and index arrays, that will be used to index
               each column array.  This is applied before arrays are copied when
               copy is True, so if the indexing results in an implicit copy no
               unnecessary second copy is performed.

  copy ------- If True, the returned arrays will be contiguous copies rather than strided
               views into the catalog.  This ensures that the lifetime of the catalog is
               not tied to the lifetime of a particular catalog, and it also may improve
               the performance if the array is used repeatedly.
               Default is False.

  regex ------ A regular expression to be used in addition to any glob patterns passed
               as positional arguments.  Note that this will be compared with re.match,
               not re.search.

  sub -------- A replacement string (see re.MatchObject.expand) used to set the
               dictionary keys of any fields matched by regex.

  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
               dict, with the order corresponding to the definition order of the Schema.
               Default is False.

Definition at line 152 of file _syntax.py.

153 def BaseColumnView_extract(self, *patterns, **kwds):
154  """
155  Extract a dictionary of {<name>: <column-array>} in which the field names
156  match the given shell-style glob pattern(s).
157 
158  Any number of glob patterns may be passed; the result will be the union of all
159  the result of each glob considered separately.
160 
161  Note that extract("*", copy=True) provides an easy way to transform a row-major
162  ColumnView into a possibly more efficient set of contiguous NumPy arrays.
163 
164  This routines unpacks Flag columns into full boolean arrays and covariances into dense
165  (i.e. non-triangular packed) arrays with dimension (N,M,M), where N is the number of
166  records and M is the dimension of the covariance matrix. Fields with named subfields
167  (e.g. points) are always split into separate dictionary items, as is done in
168  BaseRecord.extract(..., split=True). String fields are silently ignored.
169 
170  Additional optional arguments may be passed as keywords:
171 
172  items ------ The result of a call to self.schema.extract(); this will be used instead
173  of doing any new matching, and allows the pattern matching to be reused
174  to extract values from multiple records. This keyword is incompatible
175  with any position arguments and the regex, sub, and ordered keyword
176  arguments.
177 
178  where ------ Any expression that can be passed as indices to a NumPy array, including
179  slices, boolean arrays, and index arrays, that will be used to index
180  each column array. This is applied before arrays are copied when
181  copy is True, so if the indexing results in an implicit copy no
182  unnecessary second copy is performed.
183 
184  copy ------- If True, the returned arrays will be contiguous copies rather than strided
185  views into the catalog. This ensures that the lifetime of the catalog is
186  not tied to the lifetime of a particular catalog, and it also may improve
187  the performance if the array is used repeatedly.
188  Default is False.
189 
190  regex ------ A regular expression to be used in addition to any glob patterns passed
191  as positional arguments. Note that this will be compared with re.match,
192  not re.search.
193 
194  sub -------- A replacement string (see re.MatchObject.expand) used to set the
195  dictionary keys of any fields matched by regex.
196 
197  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
198  dict, with the order corresponding to the definition order of the Schema.
199  Default is False.
200 
201  """
202  copy = kwds.pop("copy", False)
203  where = kwds.pop("where", None)
204  d = kwds.pop("items", None)
205  if d is None:
206  d = self.schema.extract(*patterns, **kwds).copy()
207  elif kwds:
208  raise ValueError("Unrecognized keyword arguments for extract: %s" % ", ".join(kwds.keys()))
209  def processArray(a):
210  if where is not None:
211  a = a[where]
212  if copy:
213  a = numpy.ascontiguousarray(a)
214  return a
215  for name, schemaItem in d.items(): # can't use iteritems because we might be adding/deleting elements
216  key = schemaItem.key
217  if key.HAS_NAMED_SUBFIELDS:
218  for subname, subkey in zip(key.subfields, key.subkeys):
219  d["%s.%s" % (name, subname)] = processArray(self.get(subkey))
220  del d[name]
221  elif key.getTypeString().startswith("Cov"):
222  unpacked = None
223  for idx, subkey in zip(key.subfields, key.subkeys):
224  i, j = idx
225  array = processArray(self.get(subkey))
226  if unpacked is None:
227  unpacked = numpy.zeros((array.size, key.getSize(), key.getSize()), dtype=array.dtype)
228  unpacked[:,i,j] = array
229  if i != j:
230  unpacked[:,j,i] = array
231  d[name] = unpacked
232  elif key.getTypeString() == "String":
233  del d[name]
234  else:
235  d[name] = processArray(self.get(schemaItem.key))
236  return d
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
def lsst.afw.table._syntax.BaseRecord_extract (   self,
  patterns,
  kwds 
)
Extract a dictionary of {<name>: <field-value>} in which the field names
match the given shell-style glob pattern(s).

Any number of glob patterns may be passed; the result will be the union of all
the result of each glob considered separately.

Additional optional arguments may be passed as keywords:

  items ------ The result of a call to self.schema.extract(); this will be used instead
               of doing any new matching, and allows the pattern matching to be reused
               to extract values from multiple records.  This keyword is incompatible
               with any position arguments and the regex, sub, and ordered keyword
               arguments.

  split ------ If True, fields with named subfields (e.g. points) will be split into
               separate items in the dict; instead of {"point": lsst.afw.geom.Point2I(2,3)},
               for instance, you'd get {"point.x": 2, "point.y": 3}.
               Default is False.

  regex ------ A regular expression to be used in addition to any glob patterns passed
               as positional arguments.  Note that this will be compared with re.match,
               not re.search.

  sub -------- A replacement string (see re.MatchObject.expand) used to set the
               dictionary keys of any fields matched by regex.

  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
               dict, with the order corresponding to the definition order of the Schema.
               Default is False.

Definition at line 103 of file _syntax.py.

104 def BaseRecord_extract(self, *patterns, **kwds):
105  """
106  Extract a dictionary of {<name>: <field-value>} in which the field names
107  match the given shell-style glob pattern(s).
108 
109  Any number of glob patterns may be passed; the result will be the union of all
110  the result of each glob considered separately.
111 
112  Additional optional arguments may be passed as keywords:
113 
114  items ------ The result of a call to self.schema.extract(); this will be used instead
115  of doing any new matching, and allows the pattern matching to be reused
116  to extract values from multiple records. This keyword is incompatible
117  with any position arguments and the regex, sub, and ordered keyword
118  arguments.
119 
120  split ------ If True, fields with named subfields (e.g. points) will be split into
121  separate items in the dict; instead of {"point": lsst.afw.geom.Point2I(2,3)},
122  for instance, you'd get {"point.x": 2, "point.y": 3}.
123  Default is False.
124 
125  regex ------ A regular expression to be used in addition to any glob patterns passed
126  as positional arguments. Note that this will be compared with re.match,
127  not re.search.
128 
129  sub -------- A replacement string (see re.MatchObject.expand) used to set the
130  dictionary keys of any fields matched by regex.
131 
132  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
133  dict, with the order corresponding to the definition order of the Schema.
134  Default is False.
135 
136  """
137  d = kwds.pop("items", None)
138  split = kwds.pop("split", False)
139  if d is None:
140  d = self.schema.extract(*patterns, **kwds).copy()
141  elif kwds:
142  raise ValueError("Unrecognized keyword arguments for extract: %s" % ", ".join(kwds.keys()))
143  for name, schemaItem in d.items(): # can't use iteritems because we might be adding/deleting elements
144  key = schemaItem.key
145  if split and key.HAS_NAMED_SUBFIELDS:
146  for subname, subkey in zip(key.subfields, key.subkeys):
147  d["%s.%s" % (name, subname)] = self.get(subkey)
148  del d[name]
149  else:
150  d[name] = self.get(schemaItem.key)
151  return d
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
def lsst.afw.table._syntax.KeyBaseCov_subfields (   self)
a tuple of Key subfield extraction indices (the lower-triangular elements).

Definition at line 35 of file _syntax.py.

35 
36 def KeyBaseCov_subfields(self):
37  """a tuple of Key subfield extraction indices (the lower-triangular elements)."""
38  r = []
39  for i in range(self.getSize()):
40  for j in range(i+1):
41  r.append((i,j))
42  return tuple(r)
def lsst.afw.table._syntax.KeyBaseCov_subkeys (   self)
a tuple of subelement Keys (the lower-triangular elements).

Definition at line 43 of file _syntax.py.

43 
44 def KeyBaseCov_subkeys(self):
45  """a tuple of subelement Keys (the lower-triangular elements)."""
46  r = []
47  for i in range(self.getSize()):
48  for j in range(i+1):
49  r.append(self[i,j])
50  return tuple(r)
def lsst.afw.table._syntax.Schema_extract (   self,
  patterns,
  kwds 
)
Extract a dictionary of {<name>: <schema-item>} in which the field names
match the given shell-style glob pattern(s).

Any number of glob patterns may be passed; the result will be the union of all
the result of each glob considered separately.

Additional optional arguments may be passed as keywords:

  regex ------ A regular expression to be used in addition to any glob patterns passed
               as positional arguments.  Note that this will be compared with re.match,
               not re.search.

  sub -------- A replacement string template (see re.MatchObject.expand) used to set the
               dictionary keys of any fields matched by regex.  The field name in the
               SchemaItem is not modified.

  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
               dict, with the order corresponding to the definition order of the Schema.

Definition at line 51 of file _syntax.py.

51 
52 def Schema_extract(self, *patterns, **kwds):
53  """
54  Extract a dictionary of {<name>: <schema-item>} in which the field names
55  match the given shell-style glob pattern(s).
56 
57  Any number of glob patterns may be passed; the result will be the union of all
58  the result of each glob considered separately.
59 
60  Additional optional arguments may be passed as keywords:
61 
62  regex ------ A regular expression to be used in addition to any glob patterns passed
63  as positional arguments. Note that this will be compared with re.match,
64  not re.search.
65 
66  sub -------- A replacement string template (see re.MatchObject.expand) used to set the
67  dictionary keys of any fields matched by regex. The field name in the
68  SchemaItem is not modified.
69 
70  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
71  dict, with the order corresponding to the definition order of the Schema.
72 
73  """
74  if kwds.pop("ordered", False):
75  d = collections.OrderedDict()
76  else:
77  d = dict()
78  regex = kwds.pop("regex", None)
79  sub = kwds.pop("sub", None)
80  if sub is not None and regex is None:
81  raise ValueError("'sub' keyword argument to extract is invalid without 'regex' argument")
82  if kwds:
83  raise ValueError("Unrecognized keyword arguments for extract: %s" % ", ".join(kwds.keys()))
84  for item in self:
85  trueName = item.field.getName()
86  names = [trueName]
87  for alias, target in self.getAliasMap().iteritems():
88  if trueName.startswith(target):
89  names.append(trueName.replace(target, alias, 1))
90  for name in names:
91  if regex is not None:
92  m = re.match(regex, name)
93  if m is not None:
94  if sub is not None:
95  name = m.expand(sub)
96  d[name] = item
97  continue # continue middle loop so we don't match the same name twice
98  for pattern in patterns:
99  if fnmatch.fnmatchcase(name, pattern):
100  d[name] = item
101  break # break inner loop so we don't match the same name twice
102  return d