Wrap an instantiation of lsst::afw::table::CatalogT<Record>.
In addition to calling this method you must call addCatalogMethods on the class object in Python.
277 {
279 using namespace pybind11::literals;
280
282 using Table = typename Record::Table;
283 using ColumnView = typename Record::ColumnView;
284
287 fullName =
"_" + name +
"CatalogBase";
288 } else {
290 }
291
292
293
295 PyCatalog<Record>(wrappers.module, fullName.
c_str(), py::dynamic_attr()),
296 [](auto &mod, auto &cls) {
297
298 cls.def(py::init<Schema const &>(), "schema"_a);
299 cls.def(py::init<std::shared_ptr<Table> const &>(), "table"_a);
300 cls.def(py::init<Catalog const &>(), "other"_a);
301
302
303 cls.def_static("readFits", (Catalog(*)(std::string const &, int, int)) & Catalog::readFits,
304 "filename"_a, "hdu"_a = fits::DEFAULT_HDU, "flags"_a = 0);
305 cls.def_static("readFits", (Catalog(*)(fits::MemFileManager &, int, int)) & Catalog::readFits,
306 "manager"_a, "hdu"_a = fits::DEFAULT_HDU, "flags"_a = 0);
307
308
309
310 cls.def("getTable", &Catalog::getTable);
311 cls.def_property_readonly("table", &Catalog::getTable);
312 cls.def("getSchema", &Catalog::getSchema);
313 cls.def_property_readonly("schema", &Catalog::getSchema);
314 cls.def("capacity", &Catalog::capacity);
315 cls.def("__len__", &Catalog::size);
316 cls.def("resize", &Catalog::resize);
317
318
319
320 cls.def("_getColumnView", &Catalog::getColumnView);
321 cls.def("_addNew", &Catalog::addNew);
322 cls.def("_extend", [](Catalog &self, Catalog const &other, bool deep) {
323 self.insert(self.end(), other.begin(), other.end(), deep);
324 });
325 cls.def(
"_extend", [](Catalog &self, Catalog
const &other, SchemaMapper
const &
mapper) {
326 self.insert(
mapper, self.end(), other.begin(), other.end());
327 });
328 cls.def("_append",
331 self.erase(self.begin() + cpputils::python::cppIndex(self.size(), i));
332 });
333 cls.def("_delslice_", [](Catalog &self, py::slice const &s) {
334 Py_ssize_t start = 0, stop = 0,
step = 0,
length = 0;
335 if (PySlice_GetIndicesEx(s.ptr(), self.size(), &start, &stop, &
step, &length) != 0) {
336 throw py::error_already_set();
337 }
339 throw py::index_error("Slice step must not exactly 1");
340 }
341 self.erase(self.begin() + start, self.begin() + stop);
342 });
343 cls.def("_clear", &Catalog::clear);
344
345 cls.def("set", &Catalog::set);
346 cls.def("_getitem_", [](Catalog &self, int i) {
347 return self.get(cpputils::python::cppIndex(self.size(), i));
348 });
349 cls.def("__iter__", [](Catalog & self) {
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376 return py::make_iterator(
377 PyCatalogIndexIterator<Record>(&self, 0),
378 PyCatalogIndexIterator<Record>(&self, self.size())
379 );
380 }, py::keep_alive<0, 1>());
381 cls.def("isContiguous", &Catalog::isContiguous);
382 cls.def("writeFits",
383 (
void (Catalog::*)(
std::string const &,
std::string const &,
int) const) &
385 "filename"_a, "mode"_a = "w", "flags"_a = 0);
386 cls.def("writeFits",
387 (
void (Catalog::*)(fits::MemFileManager &,
std::string const &,
int) const) &
389 "manager"_a, "mode"_a = "w", "flags"_a = 0);
390 cls.def("reserve", &Catalog::reserve);
391 cls.def("subset",
392 (Catalog(Catalog::*)(
ndarray::Array<bool const, 1> const &) const) & Catalog::subset);
393 cls.def("subset",
394 (Catalog(Catalog::*)(
std::ptrdiff_t,
std::ptrdiff_t,
std::ptrdiff_t) const) &
395 Catalog::subset);
396
397 declareCatalogOverloads<std::int32_t>(cls);
398 declareCatalogOverloads<std::int64_t>(cls);
399 declareCatalogOverloads<float>(cls);
400 declareCatalogOverloads<double>(cls);
401 declareCatalogOverloads<lsst::geom::Angle>(cls);
402 declareCatalogArrayOverloads<std::uint8_t>(cls);
403 declareCatalogArrayOverloads<std::uint16_t>(cls);
404 declareCatalogArrayOverloads<int>(cls);
405 declareCatalogArrayOverloads<float>(cls);
406 declareCatalogArrayOverloads<double>(cls);
407
408 cls.def("_get_column_from_key",
409 [](Catalog const &self, Key<Flag> const &key, pybind11::object py_column_view) {
410
411
412
413
414
415
416 return pybind11::make_tuple(
418 py_column_view
419 );
420 });
421 cls.def(
422 "_set_flag",
423 [](Catalog &self, Key<Flag> const & key, ndarray::Array<bool const, 1> const & array) {
425 }
426 );
427 cls.def(
428 "_set_flag",
429 [](Catalog &self, Key<Flag> const & key, bool value) {
431 }
432 );
433
434 });
435}
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
void _setFlagColumnToArray(CatalogT< Record > &catalog, Key< Flag > const &key, ndarray::Array< bool const, 1 > const &array)
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.
void _setFlagColumnToScalar(CatalogT< Record > &catalog, Key< Flag > const &key, bool value)
writeFits(filename, stamps, metadata, type_name, write_mask, write_variance, write_archive=False)