LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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 147 of file _syntax.py.

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

98 
99 def BaseRecord_extract(self, *patterns, **kwds):
100  """
101  Extract a dictionary of {<name>: <field-value>} in which the field names
102  match the given shell-style glob pattern(s).
103 
104  Any number of glob patterns may be passed; the result will be the union of all
105  the result of each glob considered separately.
106 
107  Additional optional arguments may be passed as keywords:
108 
109  items ------ The result of a call to self.schema.extract(); this will be used instead
110  of doing any new matching, and allows the pattern matching to be reused
111  to extract values from multiple records. This keyword is incompatible
112  with any position arguments and the regex, sub, and ordered keyword
113  arguments.
114 
115  split ------ If True, fields with named subfields (e.g. points) will be split into
116  separate items in the dict; instead of {"point": lsst.afw.geom.Point2I(2,3)},
117  for instance, you'd get {"point.x": 2, "point.y": 3}.
118  Default is False.
119 
120  regex ------ A regular expression to be used in addition to any glob patterns passed
121  as positional arguments. Note that this will be compared with re.match,
122  not re.search.
123 
124  sub -------- A replacement string (see re.MatchObject.expand) used to set the
125  dictionary keys of any fields matched by regex.
126 
127  ordered----- If True, a collections.OrderedDict will be returned instead of a standard
128  dict, with the order corresponding to the definition order of the Schema.
129  Default is False.
130 
131  """
132  d = kwds.pop("items", None)
133  split = kwds.pop("split", False)
134  if d is None:
135  d = self.schema.extract(*patterns, **kwds).copy()
136  elif kwds:
137  raise ValueError("Unrecognized keyword arguments for extract: %s" % ", ".join(kwds.keys()))
138  for name, schemaItem in d.items(): # can't use iteritems because we might be adding/deleting elements
139  key = schemaItem.key
140  if split and key.HAS_NAMED_SUBFIELDS:
141  for subname, subkey in zip(key.subfields, key.subkeys):
142  d["%s.%s" % (name, subname)] = self.get(subkey)
143  del d[name]
144  else:
145  d[name] = self.get(schemaItem.key)
146  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  name = item.field.getName()
86  if regex is not None:
87  m = re.match(regex, name)
88  if m is not None:
89  if sub is not None:
90  name = m.expand(sub)
91  d[name] = item
92  continue # continue outer loop so we don't match the same name twice
93  for pattern in patterns:
94  if fnmatch.fnmatchcase(item.field.getName(), pattern):
95  d[name] = item
96  break # break inner loop so we don't match the same name twice
97  return d