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
286 if (isBase) {
287 fullName = "_" + name + "CatalogBase";
288 } else {
289 fullName = name + "Catalog";
290 }
291
292
293
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",
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 }
338 if (step != 1) {
339 throw py::index_error("Slice step must not exactly 1");
340 }
341 self.erase(self.begin() + start, self.begin() + stop);
342 });
344
345 cls.def("set", &Catalog::set);
346 cls.def("_getitem_", [](Catalog &self, int 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(
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) &
384 Catalog::writeFits,
385 "filename"_a, "mode"_a = "w", "flags"_a = 0);
386 cls.def("writeFits",
387 (void (Catalog::*)(fits::MemFileManager &, std::string const &, int) const) &
388 Catalog::writeFits,
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
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...
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
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 declareCatalogArrayOverloads(PyCatalog< Record > &cls)
Declare field-type-specific overloaded catalog member functions for one array-valued field type.
void _setFlagColumnToScalar(CatalogT< Record > &catalog, Key< Flag > const &key, bool value)
pybind11::class_< CatalogT< Record >, std::shared_ptr< CatalogT< Record > > > PyCatalog
void declareCatalogOverloads(PyCatalog< Record > &cls)
Declare field-type-specific overloaded catalog member functions for one field type.
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
Compute a C++ index from a Python index (negative values count from the end) and range-check.