LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
lsst.afw.table._baseColumnView._BaseColumnViewBase Class Reference

Public Member Functions

 getBits (self, keys=None)
 
 __getitem__ (self, key)
 
 __setitem__ (self, key, value)
 
 get_bool_array (self, key)
 
 extract (self, *patterns, **kwds)
 

Static Public Attributes

 get = __getitem__
 
 set = __setitem__
 

Detailed Description

Definition at line 37 of file _baseColumnView.py.

Member Function Documentation

◆ __getitem__()

lsst.afw.table._baseColumnView._BaseColumnViewBase.__getitem__ ( self,
key )
Get a column view; key may be a key object or the name of a field.

Definition at line 64 of file _baseColumnView.py.

64 def __getitem__(self, key):
65 """Get a column view; key may be a key object or the name of a field.
66 """
67 if isinstance(key, str):
68 keyobj = self.schema.find(key).key
69 else:
70 keyobj = key
71 return self._basicget(keyobj)
72

◆ __setitem__()

lsst.afw.table._baseColumnView._BaseColumnViewBase.__setitem__ ( self,
key,
value )
Set a full column to an array or scalar; key may be a key object or
the name of a field.

Definition at line 75 of file _baseColumnView.py.

75 def __setitem__(self, key, value):
76 """Set a full column to an array or scalar; key may be a key object or
77 the name of a field.
78 """
79 self.get(key)[:] = value
80

◆ extract()

lsst.afw.table._baseColumnView._BaseColumnViewBase.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 (including none); 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.

String fields are silently ignored.  Support for `Flag` columns is
deprecated; at present they are copied into full boolean arrays, but
after v26 they will be silently ignored as well.

Parameters
----------
patterns : Array of `str`
    List of glob patterns to use to select field names.
kwds : `dict`
    Dictionary of additional keyword arguments.  May contain:

    ``items`` : `list`
        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`` : array index expression
        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`` : `bool`
        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`` : `str` or `re` pattern
        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`` : `str`
        A replacement string (see re.MatchObject.expand) used to set
        the dictionary keys of any fields matched by regex.
    ``ordered`` : `bool`
        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.

Returns
-------
d : `dict`
    Dictionary of extracted name-column array sets.

Raises
------
ValueError
    Raised if a list of ``items`` is supplied with additional keywords.

Definition at line 115 of file _baseColumnView.py.

115 def extract(self, *patterns, **kwds):
116 """Extract a dictionary of {<name>: <column-array>} in which the field
117 names match the given shell-style glob pattern(s).
118
119 Any number of glob patterns may be passed (including none); the result
120 will be the union of all the result of each glob considered separately.
121
122 Note that extract("*", copy=True) provides an easy way to transform a
123 row-major ColumnView into a possibly more efficient set of contiguous
124 NumPy arrays.
125
126 String fields are silently ignored. Support for `Flag` columns is
127 deprecated; at present they are copied into full boolean arrays, but
128 after v26 they will be silently ignored as well.
129
130 Parameters
131 ----------
132 patterns : Array of `str`
133 List of glob patterns to use to select field names.
134 kwds : `dict`
135 Dictionary of additional keyword arguments. May contain:
136
137 ``items`` : `list`
138 The result of a call to self.schema.extract(); this will be
139 used instead of doing any new matching, and allows the pattern
140 matching to be reused to extract values from multiple records.
141 This keyword is incompatible with any position arguments and
142 the regex, sub, and ordered keyword arguments.
143 ``where`` : array index expression
144 Any expression that can be passed as indices to a NumPy array,
145 including slices, boolean arrays, and index arrays, that will
146 be used to index each column array. This is applied before
147 arrays are copied when copy is True, so if the indexing results
148 in an implicit copy no unnecessary second copy is performed.
149 ``copy`` : `bool`
150 If True, the returned arrays will be contiguous copies rather
151 than strided views into the catalog. This ensures that the
152 lifetime of the catalog is not tied to the lifetime of a
153 particular catalog, and it also may improve the performance if
154 the array is used repeatedly. Default is False.
155 ``regex`` : `str` or `re` pattern
156 A regular expression to be used in addition to any glob
157 patterns passed as positional arguments. Note that this will
158 be compared with re.match, not re.search.
159 ``sub`` : `str`
160 A replacement string (see re.MatchObject.expand) used to set
161 the dictionary keys of any fields matched by regex.
162 ``ordered`` : `bool`
163 If True, a collections.OrderedDict will be returned instead of
164 a standard dict, with the order corresponding to the definition
165 order of the Schema. Default is False.
166
167 Returns
168 -------
169 d : `dict`
170 Dictionary of extracted name-column array sets.
171
172 Raises
173 ------
174 ValueError
175 Raised if a list of ``items`` is supplied with additional keywords.
176 """
177 # TODO: on DM-32980, adjust docs above to reflect reference to
178 # "after v26."
179 copy = kwds.pop("copy", False)
180 where = kwds.pop("where", None)
181 d = kwds.pop("items", None)
182 # If ``items`` is given as a kwd, an extraction has already been
183 # performed and there shouldn't be any additional keywords. Otherwise
184 # call schema.extract to load the dictionary.
185 if d is None:
186 d = self.schema.extract(*patterns, **kwds).copy()
187 elif kwds:
188 raise ValueError(
189 "kwd 'items' was specified, which is not compatible with additional keywords")
190
191 def processArray(a):
192 if where is not None:
193 a = a[where]
194 if copy:
195 a = np.ascontiguousarray(a)
196 return a
197
198 # must use list because we might be adding/deleting elements
199 for name, schemaItem in list(d.items()):
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

◆ get_bool_array()

lsst.afw.table._baseColumnView._BaseColumnViewBase.get_bool_array ( self,
key )
Get the value of a flag column as a boolean array; key must be a
key object or the name of a field.

Parameters
----------
key : `lsst.afw.table.KeyFlag`
    Flag column to search for.

Returns
-------
value : `list` of `bool`
    Array of booleans corresponding to the flag.

Raises
------
TypeError
    Raised if the key is not a KeyFlag.

Definition at line 92 of file _baseColumnView.py.

92 def get_bool_array(self, key):
93 """Get the value of a flag column as a boolean array; key must be a
94 key object or the name of a field.
95
96 Parameters
97 ----------
98 key : `lsst.afw.table.KeyFlag`
99 Flag column to search for.
100
101 Returns
102 -------
103 value : `list` of `bool`
104 Array of booleans corresponding to the flag.
105
106 Raises
107 ------
108 TypeError
109 Raised if the key is not a KeyFlag.
110 """
111 if isinstance(key, KeyFlag):
112 return self[key]
113 raise TypeError("key={} not an lsst.afw.table.KeyFlag".format(key))
114

◆ getBits()

lsst.afw.table._baseColumnView._BaseColumnViewBase.getBits ( self,
keys = None )
Get the bits associated with the specified keys.

Parameters
----------
key : `str`
    Key to retrieve. Unlike the C++ version, each key may be a
    field name or a key, and if keys is `None` then all bits
    are returned.

Returns
-------
bits : `int`
     Integer array of the requested bitmask.

Definition at line 39 of file _baseColumnView.py.

39 def getBits(self, keys=None):
40 """Get the bits associated with the specified keys.
41
42 Parameters
43 ----------
44 key : `str`
45 Key to retrieve. Unlike the C++ version, each key may be a
46 field name or a key, and if keys is `None` then all bits
47 are returned.
48
49 Returns
50 -------
51 bits : `int`
52 Integer array of the requested bitmask.
53 """
54 if keys is None:
55 return self.getAllBits()
56 arg = []
57 for k in keys:
58 if isinstance(k, str):
59 arg.append(self.schema.find(k).key)
60 else:
61 arg.append(k)
62 return self._getBits(arg)
63

Member Data Documentation

◆ get

lsst.afw.table._baseColumnView._BaseColumnViewBase.get = __getitem__
static

Definition at line 73 of file _baseColumnView.py.

◆ set

lsst.afw.table._baseColumnView._BaseColumnViewBase.set = __setitem__
static

Definition at line 81 of file _baseColumnView.py.


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