23 Special Python syntactic sugar for Catalogs and Records.
25 This module is imported by tableLib.py, and should not need to be imported by any other module.
26 I've moved the code out of the .i file here to avoid recompiling when only pure-Python code is
37 Extract a dictionary of {<name>: <schema-item>} in which the field names
38 match the given shell-style glob pattern(s).
40 Any number of glob patterns may be passed; the result will be the union of all
41 the result of each glob considered separately.
43 Additional optional arguments may be passed as keywords:
45 regex ------ A regular expression to be used in addition to any glob patterns passed
46 as positional arguments. Note that this will be compared with re.match,
49 sub -------- A replacement string template (see re.MatchObject.expand) used to set the
50 dictionary keys of any fields matched by regex. The field name in the
51 SchemaItem is not modified.
53 ordered----- If True, a collections.OrderedDict will be returned instead of a standard
54 dict, with the order corresponding to the definition order of the Schema.
57 if kwds.pop(
"ordered",
False):
58 d = collections.OrderedDict()
61 regex = kwds.pop(
"regex",
None)
62 sub = kwds.pop(
"sub",
None)
63 if sub
is not None and regex
is None:
64 raise ValueError(
"'sub' keyword argument to extract is invalid without 'regex' argument")
66 raise ValueError(
"Unrecognized keyword arguments for extract: %s" %
", ".join(kwds.keys()))
68 trueName = item.field.getName()
70 for alias, target
in self.getAliasMap().iteritems():
71 if trueName.startswith(target):
72 names.append(trueName.replace(target, alias, 1))
75 m = re.match(regex, name)
81 for pattern
in patterns:
82 if fnmatch.fnmatchcase(name, pattern):
89 Extract a dictionary of {<name>: <field-value>} in which the field names
90 match the given shell-style glob pattern(s).
92 Any number of glob patterns may be passed; the result will be the union of all
93 the result of each glob considered separately.
95 Additional optional arguments may be passed as keywords:
97 items ------ The result of a call to self.schema.extract(); this will be used instead
98 of doing any new matching, and allows the pattern matching to be reused
99 to extract values from multiple records. This keyword is incompatible
100 with any position arguments and the regex, sub, and ordered keyword
103 split ------ If True, fields with named subfields (e.g. points) will be split into
104 separate items in the dict; instead of {"point": lsst.afw.geom.Point2I(2,3)},
105 for instance, you'd get {"point.x": 2, "point.y": 3}.
108 regex ------ A regular expression to be used in addition to any glob patterns passed
109 as positional arguments. Note that this will be compared with re.match,
112 sub -------- A replacement string (see re.MatchObject.expand) used to set the
113 dictionary keys of any fields matched by regex.
115 ordered----- If True, a collections.OrderedDict will be returned instead of a standard
116 dict, with the order corresponding to the definition order of the Schema.
120 d = kwds.pop(
"items",
None)
121 split = kwds.pop(
"split",
False)
123 d = self.schema.extract(*patterns, **kwds).
copy()
125 raise ValueError(
"Unrecognized keyword arguments for extract: %s" %
", ".join(kwds.keys()))
126 for name, schemaItem
in d.items():
128 if split
and key.HAS_NAMED_SUBFIELDS:
129 for subname, subkey
in zip(key.subfields, key.subkeys):
130 d[
"%s.%s" % (name, subname)] = self.get(subkey)
133 d[name] = self.get(schemaItem.key)
138 Extract a dictionary of {<name>: <column-array>} in which the field names
139 match the given shell-style glob pattern(s).
141 Any number of glob patterns may be passed; the result will be the union of all
142 the result of each glob considered separately.
144 Note that extract("*", copy=True) provides an easy way to transform a row-major
145 ColumnView into a possibly more efficient set of contiguous NumPy arrays.
147 This routines unpacks Flag columns into full boolean arrays and covariances into dense
148 (i.e. non-triangular packed) arrays with dimension (N,M,M), where N is the number of
149 records and M is the dimension of the covariance matrix. Fields with named subfields
150 (e.g. points) are always split into separate dictionary items, as is done in
151 BaseRecord.extract(..., split=True). String fields are silently ignored.
153 Additional optional arguments may be passed as keywords:
155 items ------ The result of a call to self.schema.extract(); this will be used instead
156 of doing any new matching, and allows the pattern matching to be reused
157 to extract values from multiple records. This keyword is incompatible
158 with any position arguments and the regex, sub, and ordered keyword
161 where ------ Any expression that can be passed as indices to a NumPy array, including
162 slices, boolean arrays, and index arrays, that will be used to index
163 each column array. This is applied before arrays are copied when
164 copy is True, so if the indexing results in an implicit copy no
165 unnecessary second copy is performed.
167 copy ------- If True, the returned arrays will be contiguous copies rather than strided
168 views into the catalog. This ensures that the lifetime of the catalog is
169 not tied to the lifetime of a particular catalog, and it also may improve
170 the performance if the array is used repeatedly.
173 regex ------ A regular expression to be used in addition to any glob patterns passed
174 as positional arguments. Note that this will be compared with re.match,
177 sub -------- A replacement string (see re.MatchObject.expand) used to set the
178 dictionary keys of any fields matched by regex.
180 ordered----- If True, a collections.OrderedDict will be returned instead of a standard
181 dict, with the order corresponding to the definition order of the Schema.
185 copy = kwds.pop(
"copy",
False)
186 where = kwds.pop(
"where",
None)
187 d = kwds.pop(
"items",
None)
189 d = self.schema.extract(*patterns, **kwds).
copy()
191 raise ValueError(
"Unrecognized keyword arguments for extract: %s" %
", ".join(kwds.keys()))
193 if where
is not None:
196 a = numpy.ascontiguousarray(a)
198 for name, schemaItem
in d.items():
200 if key.getTypeString() ==
"String":
203 d[name] = processArray(self.get(schemaItem.key))
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
def BaseColumnView_extract