Coverage for python/lsst/afw/table/base/baseContinued.py : 92%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# # LSST Data Management System # Copyright 2017 LSST/AURA. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
class BaseRecord:
"""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.
Parameters ----------
items : `dict` 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 : `bool` If True, fields with named subfields (e.g. points) will be split into separate items in the dict; instead of {"point": lsst.geom.Point2I(2,3)}, for instance, you'd get {"point.x": 2, "point.y": 3}. Default is False.
regex : `str` or `re` pattern object 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`. """ elif kwds: raise ValueError( "Unrecognized keyword arguments for extract: %s" % ", ".join(kwds.keys())) # must use list because we might be adding/deleting elements for subname, subkey in zip(key.subfields, key.subkeys): d["%s.%s" % (name, subname)] = self.get(subkey) del d[name] else:
"""Return the record at index key if key is an integer, return a column if key is a string field name or Key, or return a subset of the catalog if key is a slice or boolean NumPy array. """ raise RuntimeError("Unsupported array type for indexing non-contiguous Catalog: %s" % (key.dtype,)) # This array doesn't share memory with the Catalog, so don't let it be modified by # the user who thinks that the Catalog itself is being modified. # Just be aware that this array can only be passed down to C++ as an ndarray::Array<T const> # instead of an ordinary ndarray::Array<T>. If pybind isn't letting it down into C++, # you may have left off the 'const' in the definition. else:
""" If ``key`` is an integer, set ``catalog[key]`` to ``value``. Otherwise select column ``key`` and set it to ``value``. """ else:
else:
self._columns = None self._insert(key, value)
self._columns = None self._clear()
"""Return a copy of the catalog with the given type, optionally cloning the table and deep-copying all records if deep==True. """ else:
""" Copy a catalog (default is not a deep copy). """
"""Append all records in the given iterable to the catalog.
Arguments: iterable ------ any Python iterable containing records deep ---------- if True, the records will be deep-copied; ignored if mapper is not None (that always implies True). mapper -------- a SchemaMapper object used to translate records """ # We can't use isinstance here, because the SchemaMapper symbol isn't available # when this code is part of a subclass of Catalog in another package. else: else: else:
"""!Return an astropy.table.Table (or subclass thereof) view into this catalog.
@param[in] cls Table subclass to use; None implies astropy.table.Table itself. Use astropy.table.QTable to get Quantity columns.
@param[in] copy Whether to copy data from the LSST catalog to the astropy table. Not copying is usually faster, but can keep memory from being freed if columns are later removed from the Astropy view.
@param[in] unviewable One of the following options, indicating how to handle field types (string and Flag) for which views cannot be constructed: - 'copy' (default): copy only the unviewable fields. - 'raise': raise ValueError if unviewable fields are present. - 'skip': do not include unviewable fields in the Astropy Table. This option is ignored if copy=True. """ raise ValueError( "'unviewable'=%r must be one of 'copy', 'raise', or 'skip'" % (unviewable,)) raise ValueError("Cannot extract string " "unless copy=True or unviewable='copy' or 'skip'.") len(self), dtype=np.dtype((str, key.getSize()))) "unless copy=True or unviewable='copy' or 'skip'.") # Can't get columns for variable-length array fields. else: astropy.table.Column( data, name=name, unit=unit, description=item.field.getDoc() ) )
""" This custom dir is necessary due to the custom getattr below. Without it, not all of the methods available are returned with dir. See DM-7199 """ """ Return a set containing the names of all methods for a given class *and* all of its subclasses. """ recursive_get_class_dir(type(self)) | set(self.__dict__.keys()))
# Catalog forwards unknown method calls to its table and column view # for convenience. (Feature requested by RHL; complaints about magic # should be directed to him.)
else:
|