7#include <pybind11/pybind11.h>
8#include <pybind11/chrono.h>
9#include "skyobjects/skypoint.h"
11#include "cachingdms.h"
12#include "sqlstatements.cpp"
13#include "catalogobject.h"
14#include "catalogsdb.h"
17using namespace pybind11::literals;
18namespace py = pybind11;
27 PYBIND11_TYPE_CASTER(
QString, _(
"QString"));
29 bool load(handle src,
bool)
35 catch (
const py::cast_error &)
40 return !PyErr_Occurred();
43 static handle cast(
QString src, return_value_policy , handle )
54 PYBIND11_TYPE_CASTER(
QDateTime, _(
"QDateTime"));
56 bool load(handle src,
bool)
61 std::chrono::duration_cast<std::chrono::milliseconds>(
62 src.cast<std::chrono::system_clock::time_point>().time_since_epoch())
65 catch (
const py::cast_error &)
70 return !PyErr_Occurred();
73 static handle cast(
QDateTime src, return_value_policy ,
76 const handle *obj =
new py::object(py::cast(std::chrono::system_clock::time_point(
92 int getLevel()
const {
return m_mesh->
level(); };
95 int getTrixel(
double ra,
double dec,
bool convert_epoch =
false)
const
104 return m_mesh->
index(&p);
117T cast_default(
const py::object &value,
const T &default_value)
121 return py::cast<T>(value);
123 catch (
const py::cast_error &)
125 return default_value;
129PYBIND11_MODULE(pykstars, m)
131 m.doc() =
"Thin bindings for KStars to facilitate trixel indexation from python.";
133 py::class_<Indexer>(m,
"Indexer")
134 .def(py::init<int>(),
"level"_a,
135 "Initializes an `Indexer` with the given `level`.\n"
136 "If the level is greater then approx. 10 the initialization can take some "
138 .def_property(
"level", &Indexer::getLevel, &Indexer::setLevel,
139 "Sets the level of the HTMesh/SkyMesh used to index points.")
141 "get_trixel", &Indexer::getTrixel,
"ra"_a,
"dec"_a,
"convert_epoch"_a =
false,
142 "Calculates the trixel number from the right ascention and the declination.\n"
143 "The epoch of coordinates is assumed to be J2000.\n\n"
144 "If the epoch is B1950, `convert_epoch` has to be set to `True`.")
145 .def(
"__repr__", [](
const Indexer &indexer) {
146 std::ostringstream lvl;
147 lvl << indexer.getLevel();
148 return "<Indexer level=" + lvl.str() +
">";
152 using namespace CatalogsDB;
153 py::class_<DBManager>(m,
"DBManager")
154 .def(py::init([](
const std::string &filename) {
160 [](
DBManager &self,
const py::dict &cat) {
162 py::cast<int>(cat[
"id"]), py::cast<QString>(cat[
"name"]),
163 py::cast<bool>(cat[
"mut"]), py::cast<bool>(cat[
"enabled"]),
164 py::cast<double>(cat[
"precedence"]),
165 py::cast<QString>(cat[
"author"]),
166 py::cast<QString>(cat[
"source"]),
167 py::cast<QString>(cat[
"description"]),
168 py::cast<int>(cat[
"version"]), py::cast<QString>(cat[
"color"]),
169 py::cast<QString>(cat[
"license"]),
170 py::cast<QString>(cat[
"maintainer"]),
171 py::cast<QDateTime>(cat[
"timestamp"]));
175 "update_catalog_meta",
176 [](
DBManager &self,
const py::dict &cat) {
178 { py::cast<int>(cat[
"id"]), py::cast<QString>(cat[
"name"]),
179 py::cast<double>(cat[
"precedence"]),
180 py::cast<QString>(cat[
"author"]),
181 py::cast<QString>(cat[
"source"]),
182 py::cast<QString>(cat[
"description"]),
183 py::cast<bool>(cat[
"mut"]), py::cast<bool>(cat[
"enabled"]),
184 py::cast<int>(cat[
"version"]), py::cast<QString>(cat[
"color"]),
185 py::cast<QString>(cat[
"license"]),
186 py::cast<QString>(cat[
"maintainer"]),
187 py::cast<QDateTime>(cat[
"timestamp"]) });
195 .def(
"update_catalog_views", &DBManager::update_catalog_views)
196 .def(
"compile_master_catalog", &DBManager::compile_master_catalog)
197 .def(
"dump_catalog", &DBManager::dump_catalog,
"catalog_id"_a,
"file_path"_a)
198 .def(
"import_catalog", &DBManager::import_catalog,
"file_path"_a,
200 .def(
"remove_catalog", &DBManager::remove_catalog,
"catalog_id"_a);
202 py::register_exception<DatabaseError>(m,
"DatabaseError");
205 py::enum_<SkyObject::TYPE>(m,
"ObjectType",
"The types of CatalogObjects",
207 .value(
"STAR", SkyObject::STAR)
208 .value(
"CATALOG_STAR", SkyObject::CATALOG_STAR)
209 .value(
"PLANET", SkyObject::TYPE::PLANET)
210 .value(
"OPEN_CLUSTER", SkyObject::TYPE::OPEN_CLUSTER)
211 .value(
"GLOBULAR_CLUSTER", SkyObject::TYPE::GLOBULAR_CLUSTER)
212 .value(
"GASEOUS_NEBULA", SkyObject::TYPE::GASEOUS_NEBULA)
213 .value(
"PLANETARY_NEBULA", SkyObject::TYPE::PLANETARY_NEBULA)
214 .value(
"SUPERNOVA_REMNANT", SkyObject::TYPE::SUPERNOVA_REMNANT)
215 .value(
"GALAXY", SkyObject::TYPE::GALAXY)
216 .value(
"COMET", SkyObject::TYPE::COMET)
217 .value(
"ASTEROID", SkyObject::TYPE::ASTEROID)
218 .value(
"CONSTELLATION", SkyObject::TYPE::CONSTELLATION)
219 .value(
"MOON", SkyObject::TYPE::MOON)
220 .value(
"ASTERISM", SkyObject::TYPE::ASTERISM)
221 .value(
"GALAXY_CLUSTER", SkyObject::TYPE::GALAXY_CLUSTER)
222 .value(
"DARK_NEBULA", SkyObject::TYPE::DARK_NEBULA)
223 .value(
"QUASAR", SkyObject::TYPE::QUASAR)
224 .value(
"MULT_STAR", SkyObject::TYPE::MULT_STAR)
225 .value(
"RADIO_SOURCE", SkyObject::TYPE::RADIO_SOURCE)
226 .value(
"SATELLITE", SkyObject::TYPE::SATELLITE)
227 .value(
"SUPERNOVA", SkyObject::TYPE::SUPERNOVA)
228 .value(
"NUMBER_OF_KNOWN_TYPES", SkyObject::TYPE::NUMBER_OF_KNOWN_TYPES)
229 .value(
"TYPE_UNKNOWN", SkyObject::TYPE::TYPE_UNKNOWN)
234 [](
const py::dict &obj) -> py::bytes {
237 py::cast<double>(obj[
"ra"]), py::cast<double>(obj[
"dec"]),
238 py::cast<QString>(obj[
"name"]),
239 py::cast<QString>(obj[
"catalog_identifier"]))
244 Calculate the id of an object.
252 auto s = m.def_submodule(
"sqlstatements");
256 s.doc() =
"Assorted sql statements to modify the catalog database.";
258 s.def(
"insert_dso", &insert_dso,
"catalog_id"_a);
259 s.def(
"create_catalog_table", &create_catalog_table,
"catalog_id"_a);
263 s.attr(#name) = name; \
265 ATTR(create_catalog_list_table);
266 ATTR(insert_catalog);
267 ATTR(get_catalog_by_id);
268 ATTR(all_catalog_view);
269 ATTR(master_catalog);
A simple container object to hold the minimum information for a Deep Sky Object to be drawn on the sk...
Manages the catalog database and provides an interface to provide an interface to query and modify th...
const QString & db_file_name() const
std::pair< bool, QString > update_catalog_meta(const Catalog &cat)
Update the metatadata `catalog`.
std::pair< bool, QString > register_catalog(const int id, const QString &name, const bool mut, const bool enabled, const double precedence, const QString &author=cat_defaults.author, const QString &source=cat_defaults.source, const QString &description=cat_defaults.description, const int version=cat_defaults.version, const QString &color=cat_defaults.color, const QString &license=cat_defaults.license, const QString &maintainer=cat_defaults.maintainer, const QDateTime ×tamp=cat_defaults.timestamp)
Registers a new catalog in the database.
int level() const
returns the mesh level.
Provides an interface to the Hierarchical Triangular Mesh (HTM) library written by A.
static SkyMesh * Create(int level)
creates the single instance of SkyMesh.
Trixel index(const SkyPoint *p)
returns the index of the trixel containing p.
TYPE
The type classification of the SkyObject.
The sky coordinates of a point in the sky.
An angle, stored as degrees, but expressible in many ways.
Holds a collection of hardcoded sql statements.
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
QStringView level(QStringView ifopt)
const char * constData() const const
std::string toStdString() const const
qint64 currentMSecsSinceEpoch()
QDateTime fromMSecsSinceEpoch(qint64 msecs)
QString fromStdString(const std::string &str)
QByteArray toUtf8() const const