LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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 
35 namespace ast {
36 
40 enum class FitsKeyState {
41  ABSENT = 0,
42  NOVALUE,
43  PRESENT
44 };
45 
49 enum 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 
68 template <typename T>
69 class FoundValue {
70 public:
77  FoundValue(bool found, T const &value) : found(found), value(value) {}
78 
80  FoundValue() : found(false), value() {}
81  bool found;
82  T value;
83 };
84 
202 class FitsChan : public Channel {
203 public:
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;
221  FitsChan &operator=(FitsChan &&) = default;
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 
365  FoundValue<std::complex<double>> getFitsCF(std::string const &name = "",
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 
475  std::vector<std::string> getAllCardNames();
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
void setFitsTol(double tol)
Set FitsTol: Tolerance used for writing a FrameSet using a foreign encoding.
Definition: FitsChan.h:962
void setIwc(bool iwcs)
Set Iwc: add a Frame describing Intermediate World Coords?
Definition: FitsChan.h:967
bool found
Was the value found?
Definition: FitsChan.h:81
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
complex integer
void emptyFits()
Delete all cards and associated information from a FitsChan.
Definition: FitsChan.h:244
FoundValue(bool found, T const &value)
Construct a FoundValue.
Definition: FitsChan.h:77
void setCarLin(bool cdMatrix)
Set CarLin: ignore spherical rotations on CAR projections?
Definition: FitsChan.h:923
void setDefB1950(bool defB1950)
Set DefB1950: use FK4 B1950 as default equatorial coordinates?
Definition: FitsChan.h:939
void purgeWcs()
Delete all cards in a FitsChan that relate to any of the recognised WCS encodings.
Definition: FitsChan.h:595
complex floating point
double getFitsTol() const
Get FitsTol: Tolerance used for writing a FrameSet using a foreign encoding.
Definition: FitsChan.h:545
AST wrapper classes and functions.
CardType getCardType() const
Get CardType: data type of the current FITS card.
Definition: FitsChan.h:501
void setSipReplace(bool replace)
Set SipReplace: ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative...
Definition: FitsChan.h:978
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 setPolyTan(int polytan)
Set PolyTan: use PVi_m keywords to define distorted TAN projection?
Definition: FitsChan.h:989
Channel provides input/output of AST objects.
Definition: Channel.h:60
std::string getCardComm() const
Get CardComm: the comment of the current card.
Definition: FitsChan.h:491
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST&#39;s state is bad.
Definition: base.cc:49
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
std::string getCardName() const
Get CardName: the keyword name of the current card.
Definition: FitsChan.h:496
int getNCard() const
Get NCard: the number of cards.
Definition: FitsChan.h:555
bool getCDMatrix() const
Get CDMatrix: use CDi_j keywords to represent pixel scaling, rotation, etc?
Definition: FitsChan.h:512
A specialized form of Channel which reads and writes FITS header cards.
Definition: FitsChan.h:202
void retainFits()
Keep the current card when an Object is read that uses the card.
Definition: FitsChan.h:674
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 writeFits()
Write out all cards currently in the channel and clear the channel.
Definition: FitsChan.h:1025
STL class.
void setCard(int ind)
Set Card: the index of the current card, where 1 is the first card.
Definition: FitsChan.h:1036
void setFitsDigits(int digits)
Set FitsDigits: digits of precision for floating-point FITS values.
Definition: FitsChan.h:957
keyword is present and has a value
card is a comment-style card with no "=" (COMMENT, HISTORY, ...)
CardType
Enums describing the FITS card type.
Definition: FitsChan.h:49
void setTabOK(int tabOK)
Set TabOK: should the FITS "-TAB" algorithm be recognised?
Definition: FitsChan.h:983
bool getCarLin() const
Get CarLin: ignore spherical rotations on CAR projections?
Definition: FitsChan.h:506
int getNKey() const
Get Nkey: the number of unique keywords.
Definition: FitsChan.h:560
keyword is present, but has no value
keyword is not present
bool getClean() const
Get Clean: remove cards used whilst reading even if an error occurs?
Definition: FitsChan.h:517
bool getDefB1950() const
Get DefB1950: use FK4 B1950 as default equatorial coordinates?
Definition: FitsChan.h:522
void putFits(std::string const &card, bool overwrite)
Store a FITS header card in a FitsChan.
Definition: FitsChan.h:644
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
T str(T... args)
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
void delFits()
Delete the current FITS card.
Definition: FitsChan.h:230
T value
The found value; ignore if found is false.
Definition: FitsChan.h:82
bool getSipReplace() const
Get SipReplace: ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative...
Definition: FitsChan.h:571
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 setClean(bool clean)
Set Clean: remove cards used whilst reading even if an error occurs?
Definition: FitsChan.h:934
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
std::string getClassName(AstObject const *rawObj)
Get the AST class name, changing CmpMap to SeriesMap or ParallelMap as appropriate.
Definition: utils.cc:37
void putCards(std::string const &cards)
Replace all FITS header cards.
Definition: FitsChan.h:616
void setFitsCM(std::string const &comment, bool overwrite=false)
Create a new comment card, possibly overwriting the current card.
Definition: FitsChan.h:725
card has no value
std::string getAllWarnings() const
Get AllWarnings: a space separated list of all the conditions names recognized by the Warnings attrib...
Definition: FitsChan.h:481
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
int getCard() const
Get Card: the index of the current card, where 1 is the first card.
Definition: FitsChan.h:486
T c_str(T... args)
std::string getWarnings() const
Get Warnings attribute, which controls the issuing of warnings about selected conditions when an Obje...
Definition: FitsChan.h:588
FitsKeyState
Enums describing the presence or absence of a FITS keyword.
Definition: FitsChan.h:40
void readFits()
Read cards from the source and store them in the FitsChan.
Definition: FitsChan.h:661
int getTabOK() const
Get TabOK: should the FITS "-TAB" algorithm be recognised?
Definition: FitsChan.h:576
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 showFits() const
Write all the cards in the channel to standard output.
Definition: FitsChan.h:1000
void setSipOK(bool sipOK)
Set SipOK: use Spitzer Space Telescope keywords to define distortion?
Definition: FitsChan.h:972
void setCDMatrix(bool cdMatrix)
Get CDMatrix: Use CDi_j keywords to represent pixel scaling, rotation, etc?
Definition: FitsChan.h:929
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 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
std::ostream * os
Definition: Schema.cc:746
FoundValue()
Default constructor: found false, value is default-constructed.
Definition: FitsChan.h:80
A value and associated validity flag.
Definition: FitsChan.h:69
void clearCard()
Rewind the card index to the beginning.
Definition: FitsChan.h:1031
card does not exist (card number invalid)
A stream for ast::Channel.
Definition: Stream.h:41
bool getIwc() const
Get Iwc: add a Frame describing Intermediate World Coords?
Definition: FitsChan.h:550
std::shared_ptr< KeyMap > getTables() const
Definition: FitsChan.h:1038
bool getSipOK() const
Get SipOK: use Spitzer Space Telescope keywords to define distortion?
Definition: FitsChan.h:565
int getPolyTan() const
Get PolyTan: use PVi_m keywords to define distorted TAN projection?
Definition: FitsChan.h:582
int getFitsDigits() const
Get FitsDigits: digits of precision for floating-point FITS values.
Definition: FitsChan.h:540
FitsChan(AstFitsChan *rawFitsChan)
Construct a FitsChan from a raw AstFitsChan.
Definition: FitsChan.h:1051