lsst.afw
g3a5ebb7d8a+28b83bf6a5
Toggle main menu visibility
Loading...
Searching...
No Matches
include
lsst
afw
table
python
sortedCatalog.h
Go to the documentation of this file.
1
#ifndef AFW_TABLE_PYBIND11_SORTEDCATALOG_H_INCLUDED
2
#define AFW_TABLE_PYBIND11_SORTEDCATALOG_H_INCLUDED
3
/*
4
* This file is part of afw.
5
*
6
* Developed for the LSST Data Management System.
7
* This product includes software developed by the LSST Project
8
* (https://www.lsst.org).
9
* See the COPYRIGHT file at the top-level directory of this distribution
10
* for details of code ownership.
11
*
12
* This program is free software: you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation, either version 3 of the License, or
15
* (at your option) any later version.
16
*
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program. If not, see <https://www.gnu.org/licenses/>.
24
*/
25
26
#include "pybind11/pybind11.h"
27
28
#include "
lsst/cpputils/python.h
"
29
30
#include "
lsst/afw/table/SortedCatalog.h
"
31
#include "
lsst/afw/table/python/catalog.h
"
32
33
namespace
lsst
{
34
namespace
afw
{
35
namespace
table
{
36
namespace
python
{
37
38
template
<
typename
Record>
39
using
PySortedCatalog
= pybind11::classh<SortedCatalogT<Record>,
CatalogT<Record>
>;
40
55
template
<
typename
Record>
56
PySortedCatalog<Record>
declareSortedCatalog
(
cpputils::python::WrapperCollection
&wrappers,
57
std::string
const
&name,
bool
isBase =
false
) {
58
namespace
py
=
pybind11
;
59
using namespace
pybind11::literals;
60
61
using
Catalog
=
SortedCatalogT<Record>
;
62
using
Table =
typename
Record::Table;
63
64
auto
clsBase =
declareCatalog<Record>
(wrappers, name,
true
);
65
66
std::string
fullName;
67
if
(isBase) {
68
fullName =
"_"
+ name +
"SortedCatalogBase"
;
69
}
else
{
70
fullName = name +
"Catalog"
;
71
}
72
73
// We need py::dynamic_attr() in the class definition to support our Python-side caching
74
// of the associated ColumnView.
75
return
wrappers.
wrapType
(
76
PySortedCatalog<Record>
(wrappers.
module
, fullName.
c_str
(), py::dynamic_attr()),
77
[clsBase](
auto
&mod,
auto
&cls) {
78
/* Constructors */
79
cls.def(pybind11::init<Schema const &>());
80
cls.def(pybind11::init<std::shared_ptr<Table> const &>(),
81
"table"
_a = std::shared_ptr<Table>());
82
cls.def(pybind11::init<Catalog const &>());
83
84
/* Overridden and Variant Methods */
85
cls.def_static(
"readFits"
, (Catalog(*)(std::string const &, int, int)) & Catalog::readFits,
86
"filename"
_a,
"hdu"
_a = fits::DEFAULT_HDU,
"flags"
_a = 0);
87
cls.def_static(
"readFits"
, (Catalog(*)(fits::MemFileManager &, int, int)) & Catalog::readFits,
88
"manager"
_a,
"hdu"
_a = fits::DEFAULT_HDU,
"flags"
_a = 0);
89
// readFits taking Fits objects not wrapped, because Fits objects are not wrapped.
90
91
cls.def(
"subset"
,
92
(Catalog(Catalog::*)(ndarray::Array<bool const, 1> const &) const) & Catalog::subset);
93
cls.def(
"subset"
,
94
(Catalog(Catalog::*)(std::ptrdiff_t, std::ptrdiff_t, std::ptrdiff_t) const) &
95
Catalog::subset);
96
97
// The following three methods shadow those in the base class in C++ (unlike the base class
98
// versions, they do not require a key argument because we assume it's the ID key). In
99
// Python, we make that appear as though the key argument is available but has a default
100
// value. If that key is not None, we delegate to the base class.
101
cls.def(
"isSorted"
,
102
[clsBase](py::object const &self, py::object key) -> py::object {
103
if (key.is(py::none())) {
104
key = self.attr(
"table"
).attr(
"getIdKey"
)();
105
}
106
return clsBase.attr(
"isSorted"
)(self, key);
107
},
108
"key"
_a = py::none());
109
cls.def(
"sort"
,
110
[clsBase](py::object
const
&self, py::object key) -> py::object {
111
if
(key.is(py::none())) {
112
key = self.attr(
"table"
).attr(
"getIdKey"
)();
113
}
114
return
clsBase.attr(
"sort"
)(self, key);
115
},
116
"key"
_a = py::none());
117
cls.def(
"find"
,
118
[clsBase](py::object
const
&self, py::object
const
&value,
119
py::object key) -> py::object {
120
if
(key.is(py::none())) {
121
key = self.attr(
"table"
).attr(
"getIdKey"
)();
122
}
123
return
clsBase.attr(
"find"
)(self, value, key);
124
},
125
"value"
_a,
"key"
_a = py::none());
126
127
});
128
}
129
130
}
// namespace python
131
}
// namespace table
132
}
// namespace afw
133
}
// namespace lsst
134
135
#endif
// !AFW_TABLE_PYBIND11_CATALOG_H_INCLUDED
std::string
std::string::c_str
T c_str(T... args)
lsst::afw::table._base.Catalog
Definition
_base.py:73
lsst::afw::table::CatalogT
A custom container class for records, based on std::vector.
Definition
Catalog.h:98
lsst::afw::table::SortedCatalogT
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition
SortedCatalog.h:42
lsst::cpputils::python::WrapperCollection
lsst::cpputils::python::WrapperCollection::wrapType
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
lsst::cpputils::python::WrapperCollection::module
pybind11::module module
lsst::afw::table::python
Definition
catalog.h:36
lsst::afw::table::python::declareCatalog
PyCatalog< Record > declareCatalog(cpputils::python::WrapperCollection &wrappers, std::string const &name, bool isBase=false)
Wrap an instantiation of lsst::afw::table::CatalogT<Record>.
Definition
catalog.h:276
lsst::afw::table::python::declareSortedCatalog
PySortedCatalog< Record > declareSortedCatalog(cpputils::python::WrapperCollection &wrappers, std::string const &name, bool isBase=false)
Wrap an instantiation of lsst::afw::table::SortedCatalogT<Record>.
Definition
sortedCatalog.h:56
lsst::afw::table::python::PySortedCatalog
pybind11::classh< SortedCatalogT< Record >, CatalogT< Record > > PySortedCatalog
Definition
sortedCatalog.h:39
lsst::afw::table
Definition
table.dox:3
lsst::afw
Definition
imageAlgorithm.dox:1
lsst
catalog.h
python.h
SortedCatalog.h
pybind11
Generated on
for lsst.afw by
1.17.0