22 #ifndef AFW_TABLE_PYTHON_CATALOG_H_INCLUDED 23 #define AFW_TABLE_PYTHON_CATALOG_H_INCLUDED 25 #include "pybind11/pybind11.h" 36 template <
typename Record>
40 template <
typename T,
typename Record>
45 ndarray::Array<typename Field<T>::Value, 1, 1> out = ndarray::allocate(catalog.
size());
46 auto outIter = out.begin();
47 auto inIter = catalog.
begin();
48 for (; inIter != catalog.
end(); ++inIter, ++outIter) {
49 *outIter = inIter->get(key);
56 template <
typename Record>
61 ndarray::Array<double, 1, 1> out = ndarray::allocate(catalog.
size());
62 auto outIter = out.begin();
63 auto inIter = catalog.
begin();
64 for (; inIter != catalog.
end(); ++inIter, ++outIter) {
65 *outIter = inIter->get(key).asRadians();
79 template <
typename T,
typename Record>
82 using namespace pybind11::literals;
87 cls.def(
"isSorted", (
bool (Catalog::*)(
Key<T> const &)
const) & Catalog::isSorted);
88 cls.def(
"sort", (
void (Catalog::*)(
Key<T> const &)) & Catalog::sort);
90 auto iter =
self.find(value, key);
91 if (iter ==
self.
end()) {
96 cls.def(
"upper_bound", [](Catalog &
self, Value
const &value,
Key<T> const &key) ->
std::ptrdiff_t {
97 return self.upper_bound(value, key) -
self.begin();
99 cls.def(
"lower_bound", [](Catalog &
self, Value
const &value,
Key<T> const &key) ->
std::ptrdiff_t {
100 return self.lower_bound(value, key) -
self.begin();
102 cls.def(
"equal_range", [](Catalog &
self, Value
const &value,
Key<T> const &key) {
103 auto p =
self.equal_range(value, key);
104 return py::slice(p.first -
self.begin(), p.second -
self.begin(), 1);
106 cls.def(
"between", [](Catalog &
self, Value
const &lower, Value
const &upper,
Key<T> const &key) {
109 return py::slice(a, b, 1);
128 template <
typename Record>
131 using namespace pybind11::literals;
134 using Table =
typename Record::Table;
138 fullName =
"_" + name +
"CatalogBase";
140 fullName = name +
"Catalog";
147 cls.def(py::init<Schema const &>(),
"schema"_a);
149 cls.def(py::init<Catalog const &>(),
"other"_a);
152 cls.def_static(
"readFits", (
Catalog(*)(
std::string const &,
int,
int)) & Catalog::readFits,
"filename"_a,
159 cls.def(
"getTable", &Catalog::getTable);
160 cls.def_property_readonly(
"table", &Catalog::getTable);
161 cls.def(
"getSchema", &Catalog::getSchema);
162 cls.def_property_readonly(
"schema", &Catalog::getSchema);
163 cls.def(
"capacity", &Catalog::capacity);
164 cls.def(
"__len__", &Catalog::size);
165 cls.def(
"resize", &Catalog::resize);
172 self.insert(
self.
end(), other.begin(), other.end(), deep);
175 self.insert(mapper,
self.
end(), other.begin(), other.end());
181 cls.def(
"_delslice_", [](
Catalog &
self, py::slice
const &s) {
182 Py_ssize_t start = 0, stop = 0,
step = 0, length = 0;
183 if (PySlice_GetIndicesEx(
185 #
if PY_MAJOR_VERSION < 3 || (PY_MINOR_VERSION == 3 && PY_MINOR_VERSION < 2)
189 self.size(), &start, &stop, &
step, &length) != 0) {
190 throw py::error_already_set();
193 throw py::index_error(
"Slice step must not exactly 1");
195 self.erase(
self.begin() + start,
self.begin() + stop);
202 cls.def(
"isContiguous", &Catalog::isContiguous);
205 "filename"_a,
"mode"_a =
"w",
"flags"_a = 0);
208 "manager"_a,
"mode"_a =
"w",
"flags"_a = 0);
209 cls.def(
"reserve", &Catalog::reserve);
210 cls.def(
"subset", (
Catalog(
Catalog::*)(ndarray::Array<bool const, 1>
const &)
const) & Catalog::subset);
214 declareCatalogOverloads<std::int32_t>(
cls);
215 declareCatalogOverloads<std::int64_t>(
cls);
216 declareCatalogOverloads<float>(
cls);
217 declareCatalogOverloads<double>(
cls);
218 declareCatalogOverloads<lsst::geom::Angle>(
cls);
231 #endif // !LSST_AFW_TABLE_PYTHON_CATALOG_H_INCLUDED
A custom container class for records, based on std::vector.
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
A mapping between the keys of two Schemas, used to copy data between them.
ndarray::Array< typename Field< T >::Value const, 1, 1 > _getArrayFromCatalog(CatalogT< Record > const &catalog, Key< T > const &key)
Extract a column from a potentially non-contiguous Catalog.
pybind11::class_< CatalogT< Record >, std::shared_ptr< CatalogT< Record > >> PyCatalog
ItemVariant const * other
A base class for image defects.
Lifetime-management for memory that goes into FITS memory files.
iterator end()
Iterator access.
void declareCatalogOverloads(PyCatalog< Record > &cls)
Declare field-type-specific overloaded catalog member functions for one field type.
A class used as a handle to a particular field in a table.
T Value
the type returned by BaseRecord::get
PyCatalog< Record > declareCatalog(pybind11::module &mod, std::string const &name, bool isBase=false)
Wrap an instantiation of lsst::afw::table::CatalogT<Record>.
Key specialization for Flag.
size_type size() const
Return the number of elements in the catalog.
iterator begin()
Iterator access.
const int DEFAULT_HDU
Specify that the default HDU should be read.
daf::base::PropertySet * set