LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Functions
lsst.afw.table._syntax Namespace Reference

Functions

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 136 of file _syntax.py.

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

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

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