Skip to content

Commit 027b4d4

Browse files
committed
Expose some efficient pointing and quaternion functions to python
1 parent a8364f7 commit 027b4d4

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

core/src/G3Quat.cxx

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,42 @@ vec_abs(const G3VectorQuat &a)
292292
return out;
293293
}
294294

295+
static G3VectorDouble
296+
vec_norm(const G3VectorQuat &a)
297+
{
298+
G3VectorDouble out(a.size());
299+
for (unsigned i = 0; i < a.size(); i++)
300+
out[i] = a[i].norm();
301+
return out;
302+
}
303+
304+
static G3VectorDouble
305+
vec_vnorm(const G3VectorQuat &a)
306+
{
307+
G3VectorDouble out(a.size());
308+
for (unsigned i = 0; i < a.size(); i++)
309+
out[i] = a[i].vnorm();
310+
return out;
311+
}
312+
313+
static G3VectorDouble
314+
vec_dot3(const G3VectorQuat &a, const Quat &q)
315+
{
316+
G3VectorDouble out(a.size());
317+
for (unsigned i = 0; i < a.size(); i++)
318+
out[i] = a[i].dot3(q);
319+
return out;
320+
}
321+
322+
static G3VectorQuat
323+
vec_cross3(const G3VectorQuat &a, const Quat &q)
324+
{
325+
G3VectorQuat out(a.size());
326+
for (unsigned i = 0; i < a.size(); i++)
327+
out[i] = a[i].cross3(q);
328+
return out;
329+
}
330+
295331
static G3VectorQuat
296332
vec_neg(const G3VectorQuat &a)
297333
{
@@ -317,6 +353,46 @@ ts_abs(const G3TimestreamQuat &a)
317353
return out;
318354
}
319355

356+
static G3Timestream
357+
ts_norm(const G3TimestreamQuat &a)
358+
{
359+
G3Timestream out(a.size());
360+
out.start = a.start; out.stop = a.stop;
361+
for (unsigned i = 0; i < a.size(); i++)
362+
out[i] = a[i].norm();
363+
return out;
364+
}
365+
366+
static G3Timestream
367+
ts_vnorm(const G3TimestreamQuat &a)
368+
{
369+
G3Timestream out(a.size());
370+
out.start = a.start; out.stop = a.stop;
371+
for (unsigned i = 0; i < a.size(); i++)
372+
out[i] = a[i].vnorm();
373+
return out;
374+
}
375+
376+
static G3Timestream
377+
ts_dot3(const G3TimestreamQuat &a, const Quat &q)
378+
{
379+
G3Timestream out(a.size());
380+
out.start = a.start; out.stop = a.stop;
381+
for (unsigned i = 0; i < a.size(); i++)
382+
out[i] = a[i].dot3(q);
383+
return out;
384+
}
385+
386+
static G3TimestreamQuat
387+
ts_cross3(const G3TimestreamQuat &a, const Quat &q)
388+
{
389+
G3TimestreamQuat out(a.size());
390+
out.start = a.start; out.stop = a.stop;
391+
for (unsigned i = 0; i < a.size(); i++)
392+
out[i] = a[i].cross3(q);
393+
return out;
394+
}
395+
320396
static G3Timestream
321397
ts_real(const G3TimestreamQuat &a)
322398
{
@@ -877,7 +953,7 @@ PYBINDINGS("core", scope)
877953
.def("__str__", quat_str)
878954
.def("__repr__", quat_repr)
879955
.def("norm", &Quat::norm, "Return the Cayley norm of the quaternion")
880-
.def("vnorm", &Quat::norm, "Return the Cayley norm of the "
956+
.def("vnorm", &Quat::vnorm, "Return the Cayley norm of the "
881957
"unreal (vector) part of the quaternion")
882958
.def("abs", &Quat::abs, "Return the Euclidean norm of the quaternion")
883959
.def("dot3", &Quat::dot3, "Dot product of last three entries")
@@ -917,6 +993,10 @@ PYBINDINGS("core", scope)
917993
.def("__abs__", vec_abs)
918994
.def("__neg__", vec_neg)
919995
.def("abs", vec_abs, "Return the Euclidean norm of each quaternion")
996+
.def("norm", &vec_norm, "Return the Cayley norm of each quaternion")
997+
.def("vnorm", &vec_vnorm, "Return the Cayley norm of the unreal (vector) part of each quaternion")
998+
.def("dot3", &vec_dot3, "Dot product of last three entries of each quaternion with the input")
999+
.def("cross3", &vec_cross3, "Cross product of last three entries of each quaternion with the input")
9201000
.def_property_readonly("real", vec_real,
9211001
"Return the real (scalar) part of each quaternion")
9221002
;
@@ -946,6 +1026,10 @@ PYBINDINGS("core", scope)
9461026
.def("__abs__", ts_abs)
9471027
.def("__neg__", ts_neg)
9481028
.def("abs", ts_abs, "Return the Euclidean norm of each quaternion")
1029+
.def("norm", &ts_norm, "Return the Cayley norm of each quaternion")
1030+
.def("vnorm", &ts_vnorm, "Return the Cayley norm of the unreal (vector) part of each quaternion")
1031+
.def("dot3", &ts_dot3, "Dot product of last three entries of each quaternion with the input")
1032+
.def("cross3", &ts_cross3, "Cross product of last three entries of each quaternion with the input")
9491033
.def_property_readonly("real", ts_real,
9501034
"Return the real (scalar) part of each quaternion")
9511035
.def_readwrite("start", &G3TimestreamQuat::start,

maps/src/pointing.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ get_detector_pointing(double x_offset, double y_offset,
336336

337337
}
338338

339+
static py::tuple
340+
py_get_detector_pointing(double x_offset, double y_offset,
341+
const G3VectorQuat &trans_quat, MapCoordReference coord_sys)
342+
{
343+
std::vector<double> alpha, delta;
344+
get_detector_pointing(x_offset, y_offset, trans_quat, coord_sys, alpha, delta);
345+
return py::make_tuple(alpha, delta);
346+
}
347+
339348
std::vector<double>
340349
get_detector_rotation(double x_offset, double y_offset,
341350
const G3VectorQuat &trans_quat)
@@ -386,4 +395,14 @@ PYBINDINGS("maps", scope)
386395
"transform from local (az_0, el_0) coordinates to equatorial "
387396
"(ra_0, dec_0), accounting for rotation about the boresight by "
388397
"including the second set of points.");
398+
scope.def("get_detector_pointing", py_get_detector_pointing,
399+
py::arg("x_offset"), py::arg("y_offset"), py::arg("trans"), py::arg("coord_sys"),
400+
"Construct detector pointing vectors ``(alpha, delta)`` for the "
401+
"given pointing offsets ``(x_offset, y_offset)`` and boresight "
402+
"quaternion vector ``trans``.");
403+
scope.def("get_detector_pointing_quats", get_detector_pointing_quats,
404+
py::arg("x_offset"), py::arg("y_offset"), py::arg("trans"), py::arg("coord_sys"),
405+
"Construct the detector pointing quaternion vector for the "
406+
"given pointing offsets ``(x_offset, y_offset)`` and boresight "
407+
"quaternion vector ``trans``.");
389408
}

0 commit comments

Comments
 (0)