LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
FitsChan.h
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * Copyright 2017 AURA/LSST.
4 *
5 * This product includes software developed by the
6 * LSST Project (http://www.lsst.org/).
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#ifndef ASTSHIM_FITSCHAN_H
23#define ASTSHIM_FITSCHAN_H
24
25#include <complex>
26#include <string>
27#include <vector>
28
29#include "astshim/base.h"
30#include "astshim/Object.h"
31#include "astshim/Stream.h"
32#include "astshim/Channel.h"
33#include "astshim/KeyMap.h"
34
35namespace ast {
36
40enum class FitsKeyState {
41 ABSENT = 0,
42 NOVALUE,
43 PRESENT
44};
45
49enum class CardType {
50 NOTYPE = AST__NOTYPE,
51 COMMENT = AST__COMMENT,
52 INT = AST__INT,
53 FLOAT = AST__FLOAT,
54 STRING = AST__STRING,
55 COMPLEXF = AST__COMPLEXF,
56 COMPLEXI = AST__COMPLEXI,
57 LOGICAL = AST__LOGICAL,
58 CONTINUE = AST__CONTINUE,
59 UNDEF = AST__UNDEF,
60};
61
68template <typename T>
70public:
77 FoundValue(bool found, T const &value) : found(found), value(value) {}
78
80 FoundValue() : found(false), value() {}
81 bool found;
83};
84
202class FitsChan : public Channel {
203public:
214 explicit FitsChan(Stream &stream, std::string const &options = "");
215
216 virtual ~FitsChan();
217
218 FitsChan(FitsChan const &) = delete;
219 FitsChan(FitsChan &&) = default;
220 FitsChan &operator=(FitsChan const &) = delete;
222
230 void delFits() {
231 astDelFits(getRawPtr());
232 assertOK();
233 }
234
244 void emptyFits() {
245 astEmptyFits(getRawPtr());
246 assertOK();
247 }
248
346 FoundValue<std::string> findFits(std::string const &name, bool inc);
347
366 std::complex<double> defval = {0, 0}) const;
367
387 FoundValue<std::string> getFitsCN(std::string const &name = "", std::string defval = "") const;
388
406 FoundValue<double> getFitsF(std::string const &name = "", double defval = 0) const;
407
425 FoundValue<int> getFitsI(std::string const &name = "", int defval = 0) const;
426
444 FoundValue<bool> getFitsL(std::string const &name = "", bool defval = false) const;
445
467 FoundValue<std::string> getFitsS(std::string const &name = "", std::string defval = "") const;
468
476
481 std::string getAllWarnings() const { return getC("AllWarnings"); }
482
486 int getCard() const { return getI("Card"); }
487
491 std::string getCardComm() const { return getC("CardComm"); }
492
496 std::string getCardName() const { return getC("CardName"); }
497
501 CardType getCardType() const { return static_cast<CardType>(getI("CardType")); }
502
506 bool getCarLin() const { return getB("CarLin"); }
507
512 bool getCDMatrix() const { return getB("CDMatrix"); }
513
517 bool getClean() const { return getB("Clean"); }
518
522 bool getDefB1950() const { return getB("DefB1950"); }
523
528 std::string getEncoding() const { return getC("Encoding"); }
529
534 std::string getFitsAxisOrder() const { return getC("FitsAxisOrder"); }
535
540 int getFitsDigits() const { return getI("FitsDigits"); }
541
545 double getFitsTol() const { return getD("FitsTol"); }
546
550 bool getIwc() const { return getB("Iwc"); }
551
555 int getNCard() const { return getI("NCard"); }
556
560 int getNKey() const { return getI("NKey"); }
561
565 bool getSipOK() const { return getB("SipOK"); }
566
571 bool getSipReplace() const { return getB("SipReplace"); }
572
576 int getTabOK() const { return getI("TabOK"); }
577
582 int getPolyTan() const { return getI("PolyTan"); }
583
588 std::string getWarnings() const { return getC("Warnings"); }
589
595 void purgeWcs() {
596 astPurgeWCS(getRawPtr());
597 assertOK();
598 }
599
616 void putCards(std::string const &cards) {
617 astPutCards(getRawPtr(), cards.c_str());
618 assertOK();
619 }
620
644 void putFits(std::string const &card, bool overwrite) {
645 astPutFits(getRawPtr(), card.c_str(), overwrite);
646 assertOK();
647 }
648
661 void readFits() {
662 astReadFits(getRawPtr());
663 assertOK();
664 }
665
674 void retainFits() {
675 astRetainFits(getRawPtr());
676 assertOK();
677 }
678
696 void setFitsCF(std::string const &name, std::complex<double> value, std::string const &comment = "",
697 bool overwrite = false) {
698 // this use of reinterpret_cast is explicitly permitted, for C compatibility
699 astSetFitsCF(getRawPtr(), name.c_str(), reinterpret_cast<double(&)[2]>(value), comment.c_str(),
700 overwrite);
701 assertOK();
702 }
703
725 void setFitsCM(std::string const &comment, bool overwrite = false) {
726 astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
727 assertOK();
728 }
729
756 void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
757 bool overwrite = false) {
758 astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
759 assertOK();
760 }
761
786 void setFitsF(std::string const &name, double value, std::string const &comment = "",
787 bool overwrite = false) {
788 astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
789 assertOK();
790 }
791
816 void setFitsI(std::string const &name, int value, std::string const &comment = "",
817 bool overwrite = false) {
818 astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
819 assertOK();
820 }
821
846 void setFitsL(std::string const &name, bool value, std::string const &comment = "",
847 bool overwrite = false) {
848 astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
849 assertOK();
850 }
851
884 void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
885 bool overwrite = false) {
886 astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
887 assertOK();
888 }
889
915 void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
916 astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
917 assertOK();
918 }
919
923 void setCarLin(bool cdMatrix) { setB("CarLin", cdMatrix); }
924
929 void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
930
934 void setClean(bool clean) { setB("Clean", clean); }
935
939 void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
940
945 void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
946
951 void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
952
957 void setFitsDigits(int digits) { setI("FitsDigits", digits); }
958
962 void setFitsTol(double tol) { return setD("FitsTol", tol); }
963
967 void setIwc(bool iwcs) { setB("Iwc", iwcs); }
968
972 void setSipOK(bool sipOK) { setB("SipOK", sipOK); }
973
978 void setSipReplace(bool replace) { setB("SipReplace", replace); }
979
983 void setTabOK(int tabOK) { setI("TabOK", tabOK); }
984
989 void setPolyTan(int polytan) { setI("PolyTan", polytan); }
990
995 void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
996
1000 void showFits() const {
1001 astShowFits(getRawPtr());
1002 assertOK();
1003 }
1004
1020 FitsKeyState testFits(std::string const &name = "") const;
1021
1025 void writeFits() {
1026 astWriteFits(getRawPtr());
1027 assertOK();
1028 }
1029
1031 void clearCard() { clear("Card"); }
1032
1036 void setCard(int ind) { setI("Card", ind); }
1037
1039 auto *rawKeyMap = reinterpret_cast<AstObject *>(astGetTables(getRawPtr()));
1040 assertOK(rawKeyMap);
1041 if (!rawKeyMap) {
1042 throw std::runtime_error("getTables failed (returned a null keymap)");
1043 }
1044 return Object::fromAstObject<KeyMap>(rawKeyMap, true);
1045 }
1046
1047
1051 explicit FitsChan(AstFitsChan *rawFitsChan) : Channel(reinterpret_cast<AstChannel *>(rawFitsChan)) {
1052 if (!astIsAFitsChan(getRawPtr())) {
1054 os << "this is a " << getClassName() << ", which is not a FitsChan";
1055 throw std::invalid_argument(os.str());
1056 }
1057 assertOK();
1058 }
1059};
1060
1061} // namespace ast
1062
1063#endif
std::ostream * os
Definition Schema.cc:557
T c_str(T... args)
Channel provides input/output of AST objects.
Definition Channel.h:60
A specialized form of Channel which reads and writes FITS header cards.
Definition FitsChan.h:202
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
FitsChan(FitsChan const &)=delete
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
FitsChan & operator=(FitsChan &&)=default
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
FitsChan(FitsChan &&)=default
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
virtual ~FitsChan()
Definition FitsChan.cc:51
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
FitsChan(Stream &stream, std::string const &options="")
Construct a channel that uses a provided Stream.
Definition FitsChan.cc:44
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
FitsChan & operator=(FitsChan const &)=delete
FitsChan(AstFitsChan *rawFitsChan)
Construct a FitsChan from a raw AstFitsChan.
Definition FitsChan.h:1051
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
A value and associated validity flag.
Definition FitsChan.h:69
FoundValue()
Default constructor: found false, value is default-constructed.
Definition FitsChan.h:80
T value
The found value; ignore if found is false.
Definition FitsChan.h:82
FoundValue(bool found, T const &value)
Construct a FoundValue.
Definition FitsChan.h:77
bool found
Was the value found?
Definition FitsChan.h:81
void setD(std::string const &attrib, double value)
Set the value of an attribute as a double.
Definition Object.h:472
double getD(std::string const &attrib) const
Get the value of an attribute as a double.
Definition Object.h:374
std::string const getC(std::string const &attrib) const
Get the value of an attribute as a string.
Definition Object.h:361
std::string getClassName() const
Get Class: the name of the class (e.g.
Definition Object.h:139
void setI(std::string const &attrib, int value)
Set the value of an attribute as an int.
Definition Object.h:496
bool getB(std::string const &attrib) const
Get the value of an attribute as a bool.
Definition Object.h:348
void clear(std::string const &attrib)
Clear the values of a specified set of attributes for an Object.
Definition Object.h:119
int getI(std::string const &attrib) const
Get the value of an attribute as an int.
Definition Object.cc:178
void setC(std::string const &attrib, std::string const &value)
Set the value of an attribute as a string.
Definition Object.h:460
void setB(std::string const &attrib, bool value)
Set the value of an attribute as a bool.
Definition Object.h:448
AstObject const * getRawPtr() const
Get the raw AST pointer.
Definition Object.h:292
A stream for ast::Channel.
Definition Stream.h:41
AST wrapper classes and functions.
CardType
Enums describing the FITS card type.
Definition FitsChan.h:49
@ 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, ...)
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST's state is bad.
Definition base.cc:49
FitsKeyState
Enums describing the presence or absence of a FITS keyword.
Definition FitsChan.h:40
@ NOVALUE
keyword is present, but has no value
@ PRESENT
keyword is present and has a value
@ ABSENT
keyword is not present
table::Key< int > order