LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
fitsChan.cc
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 *
4 * This product includes software developed by the
5 * LSST Project (http://www.lsst.org/).
6 * See the COPYRIGHT file
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the LSST License Statement and
19 * the GNU General Public License along with this program. If not,
20 * see <https://www.lsstcorp.org/LegalNotices/>.
21 */
22#include <complex>
23#include <memory>
24
25#include <pybind11/pybind11.h>
26#include <pybind11/complex.h>
27#include <pybind11/stl.h>
28
29#include "astshim/Channel.h"
30#include "astshim/FitsChan.h"
31
32namespace py = pybind11;
33using namespace pybind11::literals;
34
35namespace ast {
36namespace {
37
38template <typename T>
39void wrapFoundValue(py::module &mod, std::string const &suffix) {
40 py::class_<FoundValue<T>> cls(mod, ("FoundValue" + suffix).c_str());
41
42 cls.def(py::init<bool, T const &>(), "found"_a, "value"_a);
43
44 cls.def_readwrite("found", &FoundValue<T>::found);
45 cls.def_readwrite("value", &FoundValue<T>::value);
46}
47
48PYBIND11_MODULE(fitsChan, mod) {
49 py::module::import("astshim.channel");
50
51 py::enum_<FitsKeyState>(mod, "FitsKeyState")
52 .value("ABSENT", FitsKeyState::ABSENT)
53 .value("NOVALUE", FitsKeyState::NOVALUE)
54 .value("PRESENT", FitsKeyState::PRESENT)
55 .export_values();
56
57 py::enum_<CardType>(mod, "CardType")
58 .value("NOTYPE", CardType::NOTYPE)
59 .value("COMMENT", CardType::COMMENT)
60 .value("INT", CardType::INT)
61 .value("FLOAT", CardType::FLOAT)
62 .value("STRING", CardType::STRING)
63 .value("COMPLEXF", CardType::COMPLEXF)
64 .value("COMPLEXI", CardType::COMPLEXI)
65 .value("LOGICAL", CardType::LOGICAL)
66 .value("CONTINUE", CardType::CONTINUE)
67 .value("UNDEF", CardType::UNDEF)
68 .export_values();
69
70 // Wrap FoundValue struct for returning various types
71 wrapFoundValue<std::string>(mod, "S");
72 wrapFoundValue<std::complex<double>>(mod, "CF");
73 wrapFoundValue<double>(mod, "F");
74 wrapFoundValue<int>(mod, "I");
75 wrapFoundValue<bool>(mod, "L");
76
77 // Wrap FitsChan
78 py::class_<FitsChan, std::shared_ptr<FitsChan>, Channel> cls(mod, "FitsChan");
79
80 cls.def(py::init<Stream &, std::string const &>(), "stream"_a, "options"_a = "");
81
82 cls.def_property("carLin", &FitsChan::getCarLin, &FitsChan::setCarLin);
83 cls.def_property("cdMatrix", &FitsChan::getCDMatrix, &FitsChan::setCDMatrix);
84 cls.def_property("clean", &FitsChan::getClean, &FitsChan::setClean);
85 cls.def_property("defB1950", &FitsChan::getDefB1950, &FitsChan::setDefB1950);
86 cls.def_property("encoding", &FitsChan::getEncoding, &FitsChan::setEncoding);
87 cls.def_property("fitsAxisOrder", &FitsChan::getFitsAxisOrder, &FitsChan::setFitsAxisOrder);
88 cls.def_property("fitsDigits", &FitsChan::getFitsDigits, &FitsChan::setFitsDigits);
89 cls.def_property_readonly("nCard", &FitsChan::getNCard);
90 cls.def_property_readonly("nKey", &FitsChan::getNKey);
91 cls.def_property("iwc", &FitsChan::getIwc, &FitsChan::setIwc);
92 cls.def_property("sipOK", &FitsChan::getSipOK, &FitsChan::setSipOK);
93 cls.def_property("sipReplace", &FitsChan::getSipReplace, &FitsChan::setSipReplace);
94 cls.def_property("tabOK", &FitsChan::getTabOK, &FitsChan::setTabOK);
95 cls.def_property("polyTan", &FitsChan::getPolyTan, &FitsChan::setPolyTan);
96 cls.def_property("warnings", &FitsChan::getWarnings, &FitsChan::setWarnings);
97 cls.def_property("fitsTol", &FitsChan::getFitsTol, &FitsChan::setFitsTol);
98
99 cls.def("delFits", &FitsChan::delFits);
100 cls.def("emptyFits", &FitsChan::emptyFits);
101 cls.def("findFits", &FitsChan::findFits, "name"_a, "inc"_a);
102 cls.def("getFitsCF", &FitsChan::getFitsCF, "name"_a = "", "defval"_a = std::complex<double>(0, 0));
103 cls.def("getFitsCN", &FitsChan::getFitsCN, "name"_a = "", "defval"_a = "");
104 cls.def("getFitsF", &FitsChan::getFitsF, "name"_a = "", "defval"_a = 0);
105 cls.def("getFitsI", &FitsChan::getFitsI, "name"_a = "", "defval"_a = 0);
106 cls.def("getFitsL", &FitsChan::getFitsL, "name"_a = "", "defval"_a = false);
107 cls.def("getFitsS", &FitsChan::getFitsS, "name"_a = "", "defval"_a = "");
108 cls.def("getAllCardNames", &FitsChan::getAllCardNames);
109 cls.def("getAllWarnings", &FitsChan::getAllWarnings);
110 cls.def("getCard", &FitsChan::getCard);
111 cls.def("getCardComm", &FitsChan::getCardComm);
112 cls.def("getCardName", &FitsChan::getCardName);
113 cls.def("getCardType", &FitsChan::getCardType);
114 cls.def("getTables", &FitsChan::getTables);
115 cls.def("purgeWcs", &FitsChan::purgeWcs);
116 cls.def("putCards", &FitsChan::putCards, "cards"_a);
117 cls.def("putFits", &FitsChan::putFits, "card"_a, "overwrite"_a);
118 cls.def("readFits", &FitsChan::readFits);
119 cls.def("retainFits", &FitsChan::retainFits);
120 cls.def("setFitsCF", &FitsChan::setFitsCF, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
121 cls.def("setFitsCM", &FitsChan::setFitsCM, "comment"_a = "", "overwrite"_a = false);
122 cls.def("setFitsCN", &FitsChan::setFitsCN, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
123 cls.def("setFitsF", &FitsChan::setFitsF, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
124 cls.def("setFitsI", &FitsChan::setFitsI, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
125 cls.def("setFitsL", &FitsChan::setFitsL, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
126 cls.def("setFitsS", &FitsChan::setFitsS, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
127 cls.def("setFitsU", &FitsChan::setFitsU, "name"_a, "comment"_a = "", "overwrite"_a = false);
128 cls.def("showFits", &FitsChan::showFits);
129 cls.def("testFits", &FitsChan::testFits, "name"_a = "");
130 cls.def("writeFits", &FitsChan::writeFits);
131 cls.def("clearCard", &FitsChan::clearCard);
132 cls.def("setCard", &FitsChan::setCard, "i"_a);
133}
134
135} // namespace
136} // namespace ast
bool getDefB1950() const
Get DefB1950: use FK4 B1950 as default equatorial coordinates?
Definition: FitsChan.h:522
int getNKey() const
Get Nkey: the number of unique keywords.
Definition: FitsChan.h:560
bool getCDMatrix() const
Get CDMatrix: use CDi_j keywords to represent pixel scaling, rotation, etc?
Definition: FitsChan.h:512
std::shared_ptr< KeyMap > getTables() const
Definition: FitsChan.h:1038
std::string getCardComm() const
Get CardComm: the comment of the current card.
Definition: FitsChan.h:491
void setFitsF(std::string const &name, double value, std::string const &comment="", bool overwrite=false)
Create a new card of type double, possibly overwriting the current card.
Definition: FitsChan.h:786
void setIwc(bool iwcs)
Set Iwc: add a Frame describing Intermediate World Coords?
Definition: FitsChan.h:967
std::string getWarnings() const
Get Warnings attribute, which controls the issuing of warnings about selected conditions when an Obje...
Definition: FitsChan.h:588
void setFitsDigits(int digits)
Set FitsDigits: digits of precision for floating-point FITS values.
Definition: FitsChan.h:957
FitsKeyState testFits(std::string const &name="") const
Determine if a card is present, and if so, whether it has a value.
Definition: FitsChan.cc:132
std::vector< std::string > getAllCardNames()
Get the name of all cards, in order, starting from the first card.
Definition: FitsChan.cc:106
int getPolyTan() const
Get PolyTan: use PVi_m keywords to define distorted TAN projection?
Definition: FitsChan.h:582
FoundValue< std::string > findFits(std::string const &name, bool inc)
Search for a card in a FitsChan by keyword.
Definition: FitsChan.cc:124
FoundValue< std::string > getFitsS(std::string const &name="", std::string defval="") const
Get the value of a string card.
Definition: FitsChan.cc:98
void retainFits()
Keep the current card when an Object is read that uses the card.
Definition: FitsChan.h:674
std::string getEncoding() const
Get Encoding: the encoding system to use when AST Objects are stored as FITS header cards in a FitsCh...
Definition: FitsChan.h:528
void setFitsS(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Create a new card of type string, possibly overwriting the current card.
Definition: FitsChan.h:884
void setFitsI(std::string const &name, int value, std::string const &comment="", bool overwrite=false)
Create a new card of type int, possibly overwriting the current card.
Definition: FitsChan.h:816
void setCard(int ind)
Set Card: the index of the current card, where 1 is the first card.
Definition: FitsChan.h:1036
void putFits(std::string const &card, bool overwrite)
Store a FITS header card in a FitsChan.
Definition: FitsChan.h:644
FoundValue< bool > getFitsL(std::string const &name="", bool defval=false) const
Get the value of a bool card.
Definition: FitsChan.cc:91
void purgeWcs()
Delete all cards in a FitsChan that relate to any of the recognised WCS encodings.
Definition: FitsChan.h:595
std::string getFitsAxisOrder() const
Get FitsAxisOrder: the order for the WCS axes in any new FITS-WCS headers created using Channel::writ...
Definition: FitsChan.h:534
int getCard() const
Get Card: the index of the current card, where 1 is the first card.
Definition: FitsChan.h:486
void showFits() const
Write all the cards in the channel to standard output.
Definition: FitsChan.h:1000
void clearCard()
Rewind the card index to the beginning.
Definition: FitsChan.h:1031
void setCarLin(bool cdMatrix)
Set CarLin: ignore spherical rotations on CAR projections?
Definition: FitsChan.h:923
void setFitsAxisOrder(std::string const &order)
Set FitsAxisOrder: the order for the WCS axes in any new FITS-WCS headers created using Channel::writ...
Definition: FitsChan.h:951
std::string getAllWarnings() const
Get AllWarnings: a space separated list of all the conditions names recognized by the Warnings attrib...
Definition: FitsChan.h:481
void setClean(bool clean)
Set Clean: remove cards used whilst reading even if an error occurs?
Definition: FitsChan.h:934
bool getSipOK() const
Get SipOK: use Spitzer Space Telescope keywords to define distortion?
Definition: FitsChan.h:565
bool getSipReplace() const
Get SipReplace: ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative...
Definition: FitsChan.h:571
std::string getCardName() const
Get CardName: the keyword name of the current card.
Definition: FitsChan.h:496
void readFits()
Read cards from the source and store them in the FitsChan.
Definition: FitsChan.h:661
void putCards(std::string const &cards)
Replace all FITS header cards.
Definition: FitsChan.h:616
void setFitsCN(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Create a new "CONTINUE" card, possibly overwriting the current card.
Definition: FitsChan.h:756
void setPolyTan(int polytan)
Set PolyTan: use PVi_m keywords to define distorted TAN projection?
Definition: FitsChan.h:989
FoundValue< int > getFitsI(std::string const &name="", int defval=0) const
Get the value of a int card.
Definition: FitsChan.cc:84
void setFitsCM(std::string const &comment, bool overwrite=false)
Create a new comment card, possibly overwriting the current card.
Definition: FitsChan.h:725
CardType getCardType() const
Get CardType: data type of the current FITS card.
Definition: FitsChan.h:501
bool getCarLin() const
Get CarLin: ignore spherical rotations on CAR projections?
Definition: FitsChan.h:506
int getTabOK() const
Get TabOK: should the FITS "-TAB" algorithm be recognised?
Definition: FitsChan.h:576
void setFitsTol(double tol)
Set FitsTol: Tolerance used for writing a FrameSet using a foreign encoding.
Definition: FitsChan.h:962
bool getIwc() const
Get Iwc: add a Frame describing Intermediate World Coords?
Definition: FitsChan.h:550
void setWarnings(std::string const &warnings)
Set Warnings attribute, which controls the issuing of warnings about selected conditions when an Obje...
Definition: FitsChan.h:995
void writeFits()
Write out all cards currently in the channel and clear the channel.
Definition: FitsChan.h:1025
int getNCard() const
Get NCard: the number of cards.
Definition: FitsChan.h:555
int getFitsDigits() const
Get FitsDigits: digits of precision for floating-point FITS values.
Definition: FitsChan.h:540
FoundValue< std::complex< double > > getFitsCF(std::string const &name="", std::complex< double > defval={0, 0}) const
Get the value of a complex double card.
Definition: FitsChan.cc:59
void setTabOK(int tabOK)
Set TabOK: should the FITS "-TAB" algorithm be recognised?
Definition: FitsChan.h:983
FoundValue< double > getFitsF(std::string const &name="", double defval=0) const
Get the value of a double card.
Definition: FitsChan.cc:77
void setSipReplace(bool replace)
Set SipReplace: ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative...
Definition: FitsChan.h:978
void setFitsU(std::string const &name, std::string const &comment="", bool overwrite=false)
Create a new card with an undefined value, possibly overwriting the current card.
Definition: FitsChan.h:915
bool getClean() const
Get Clean: remove cards used whilst reading even if an error occurs?
Definition: FitsChan.h:517
void emptyFits()
Delete all cards and associated information from a FitsChan.
Definition: FitsChan.h:244
void setFitsL(std::string const &name, bool value, std::string const &comment="", bool overwrite=false)
Create a new card of type bool, possibly overwriting the current card.
Definition: FitsChan.h:846
void setSipOK(bool sipOK)
Set SipOK: use Spitzer Space Telescope keywords to define distortion?
Definition: FitsChan.h:972
FoundValue< std::string > getFitsCN(std::string const &name="", std::string defval="") const
Get the value of a CONTINUE card.
Definition: FitsChan.cc:69
void setEncoding(std::string const &encoding)
Set Encoding: the encoding system to use when AST Objects are stored as FITS header cards in a FitsCh...
Definition: FitsChan.h:945
void setCDMatrix(bool cdMatrix)
Get CDMatrix: Use CDi_j keywords to represent pixel scaling, rotation, etc?
Definition: FitsChan.h:929
void delFits()
Delete the current FITS card.
Definition: FitsChan.h:230
double getFitsTol() const
Get FitsTol: Tolerance used for writing a FrameSet using a foreign encoding.
Definition: FitsChan.h:545
void setFitsCF(std::string const &name, std::complex< double > value, std::string const &comment="", bool overwrite=false)
Create a new card of type std::complex<double>, possibly overwriting the current card.
Definition: FitsChan.h:696
void setDefB1950(bool defB1950)
Set DefB1950: use FK4 B1950 as default equatorial coordinates?
Definition: FitsChan.h:939
T value
The found value; ignore if found is false.
Definition: FitsChan.h:82
bool found
Was the value found?
Definition: FitsChan.h:81
AST wrapper classes and functions.
@ NOTYPE
card does not exist (card number invalid)
@ CONTINUE
CONTINUE card.
@ LOGICAL
boolean
@ COMPLEXI
complex integer
@ INT
integer
@ COMPLEXF
complex floating point
@ STRING
string
@ UNDEF
card has no value
@ COMMENT
card is a comment-style card with no "=" (COMMENT, HISTORY, ...)
@ NOVALUE
keyword is present, but has no value
@ PRESENT
keyword is present and has a value
@ ABSENT
keyword is not present
PYBIND11_MODULE(_cameraGeom, mod)
Definition: _cameraGeom.cc:38