LSSTApplications  18.1.0
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 
34 namespace ast {
35 
39 enum class FitsKeyState {
40  ABSENT = 0,
41  NOVALUE,
42  PRESENT
43 };
44 
48 enum class CardType {
49  NOTYPE = AST__NOTYPE,
50  COMMENT = AST__COMMENT,
51  INT = AST__INT,
52  FLOAT = AST__FLOAT,
53  STRING = AST__STRING,
54  COMPLEXF = AST__COMPLEXF,
55  COMPLEXI = AST__COMPLEXI,
56  LOGICAL = AST__LOGICAL,
57  CONTINUE = AST__CONTINUE,
58  UNDEF = AST__UNDEF,
59 };
60 
67 template <typename T>
68 class FoundValue {
69 public:
76  FoundValue(bool found, T const &value) : found(found), value(value) {}
77 
79  FoundValue() : found(false), value() {}
80  bool found;
81  T value;
82 };
83 
201 class FitsChan : public Channel {
202 public:
213  explicit FitsChan(Stream &stream, std::string const &options = "");
214 
215  virtual ~FitsChan();
216 
217  FitsChan(FitsChan const &) = delete;
218  FitsChan(FitsChan &&) = default;
219  FitsChan &operator=(FitsChan const &) = delete;
220  FitsChan &operator=(FitsChan &&) = default;
221 
229  void delFits() {
230  astDelFits(getRawPtr());
231  assertOK();
232  }
233 
243  void emptyFits() {
244  astEmptyFits(getRawPtr());
245  assertOK();
246  }
247 
345  FoundValue<std::string> findFits(std::string const &name, bool inc);
346 
364  FoundValue<std::complex<double>> getFitsCF(std::string const &name = "",
365  std::complex<double> defval = {0, 0}) const;
366 
386  FoundValue<std::string> getFitsCN(std::string const &name = "", std::string defval = "") const;
387 
405  FoundValue<double> getFitsF(std::string const &name = "", double defval = 0) const;
406 
424  FoundValue<int> getFitsI(std::string const &name = "", int defval = 0) const;
425 
443  FoundValue<bool> getFitsL(std::string const &name = "", bool defval = false) const;
444 
466  FoundValue<std::string> getFitsS(std::string const &name = "", std::string defval = "") const;
467 
474  std::vector<std::string> getAllCardNames();
475 
480  std::string getAllWarnings() const { return getC("AllWarnings"); }
481 
485  int getCard() const { return getI("Card"); }
486 
490  std::string getCardComm() const { return getC("CardComm"); }
491 
495  std::string getCardName() const { return getC("CardName"); }
496 
500  CardType getCardType() const { return static_cast<CardType>(getI("CardType")); }
501 
505  bool getCarLin() const { return getB("CarLin"); }
506 
511  bool getCDMatrix() const { return getB("CDMatrix"); }
512 
516  bool getClean() const { return getB("Clean"); }
517 
521  bool getDefB1950() const { return getB("DefB1950"); }
522 
527  std::string getEncoding() const { return getC("Encoding"); }
528 
533  std::string getFitsAxisOrder() const { return getC("FitsAxisOrder"); }
534 
539  int getFitsDigits() const { return getI("FitsDigits"); }
540 
544  double getFitsTol() const { return getD("FitsTol"); }
545 
549  bool getIwc() const { return getB("Iwc"); }
550 
554  int getNCard() const { return getI("NCard"); }
555 
559  int getNKey() const { return getI("NKey"); }
560 
564  bool getSipOK() const { return getB("SipOK"); }
565 
570  bool getSipReplace() const { return getB("SipReplace"); }
571 
575  int getTabOK() const { return getI("TabOK"); }
576 
581  int getPolyTan() const { return getI("PolyTan"); }
582 
587  std::string getWarnings() const { return getC("Warnings"); }
588 
594  void purgeWcs() {
595  astPurgeWCS(getRawPtr());
596  assertOK();
597  }
598 
615  void putCards(std::string const &cards) {
616  astPutCards(getRawPtr(), cards.c_str());
617  assertOK();
618  }
619 
643  void putFits(std::string const &card, bool overwrite) {
644  astPutFits(getRawPtr(), card.c_str(), overwrite);
645  assertOK();
646  }
647 
660  void readFits() {
661  astReadFits(getRawPtr());
662  assertOK();
663  }
664 
673  void retainFits() {
674  astRetainFits(getRawPtr());
675  assertOK();
676  }
677 
695  void setFitsCF(std::string const &name, std::complex<double> value, std::string const &comment = "",
696  bool overwrite = false) {
697  // this use of reinterpret_cast is explicitly permitted, for C compatibility
698  astSetFitsCF(getRawPtr(), name.c_str(), reinterpret_cast<double(&)[2]>(value), comment.c_str(),
699  overwrite);
700  assertOK();
701  }
702 
724  void setFitsCM(std::string const &comment, bool overwrite = false) {
725  astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
726  assertOK();
727  }
728 
755  void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
756  bool overwrite = false) {
757  astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
758  assertOK();
759  }
760 
785  void setFitsF(std::string const &name, double value, std::string const &comment = "",
786  bool overwrite = false) {
787  astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
788  assertOK();
789  }
790 
815  void setFitsI(std::string const &name, int value, std::string const &comment = "",
816  bool overwrite = false) {
817  astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
818  assertOK();
819  }
820 
845  void setFitsL(std::string const &name, bool value, std::string const &comment = "",
846  bool overwrite = false) {
847  astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
848  assertOK();
849  }
850 
883  void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
884  bool overwrite = false) {
885  astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
886  assertOK();
887  }
888 
914  void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
915  astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
916  assertOK();
917  }
918 
922  void setCarLin(bool cdMatrix) { setB("CarLin", cdMatrix); }
923 
928  void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
929 
933  void setClean(bool clean) { setB("Clean", clean); }
934 
938  void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
939 
944  void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
945 
950  void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
951 
956  void setFitsDigits(int digits) { setI("FitsDigits", digits); }
957 
961  void setFitsTol(double tol) { return setD("FitsTol", tol); }
962 
966  void setIwc(bool iwcs) { setB("Iwc", iwcs); }
967 
971  void setSipOK(bool sipOK) { setB("SipOK", sipOK); }
972 
977  void setSipReplace(bool replace) { setB("SipReplace", replace); }
978 
982  void setTabOK(int tabOK) { setI("TabOK", tabOK); }
983 
988  void setPolyTan(int polytan) { setI("PolyTan", polytan); }
989 
994  void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
995 
999  void showFits() const {
1000  astShowFits(getRawPtr());
1001  assertOK();
1002  }
1003 
1019  FitsKeyState testFits(std::string const &name = "") const;
1020 
1024  void writeFits() {
1025  astWriteFits(getRawPtr());
1026  assertOK();
1027  }
1028 
1030  void clearCard() { clear("Card"); }
1031 
1035  void setCard(int ind) { setI("Card", ind); }
1036 };
1037 
1038 } // namespace ast
1039 
1040 #endif
void setFitsTol(double tol)
Set FitsTol: Tolerance used for writing a FrameSet using a foreign encoding.
Definition: FitsChan.h:961
void setIwc(bool iwcs)
Set Iwc: add a Frame describing Intermediate World Coords?
Definition: FitsChan.h:966
bool found
Was the value found?
Definition: FitsChan.h:80
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:533
complex integer
void emptyFits()
Delete all cards and associated information from a FitsChan.
Definition: FitsChan.h:243
FoundValue(bool found, T const &value)
Construct a FoundValue.
Definition: FitsChan.h:76
void setCarLin(bool cdMatrix)
Set CarLin: ignore spherical rotations on CAR projections?
Definition: FitsChan.h:922
void setDefB1950(bool defB1950)
Set DefB1950: use FK4 B1950 as default equatorial coordinates?
Definition: FitsChan.h:938
void purgeWcs()
Delete all cards in a FitsChan that relate to any of the recognised WCS encodings.
Definition: FitsChan.h:594
complex floating point
double getFitsTol() const
Get FitsTol: Tolerance used for writing a FrameSet using a foreign encoding.
Definition: FitsChan.h:544
AST wrapper classes and functions.
CardType getCardType() const
Get CardType: data type of the current FITS card.
Definition: FitsChan.h:500
void setSipReplace(bool replace)
Set SipReplace: ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative...
Definition: FitsChan.h:977
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:695
void setPolyTan(int polytan)
Set PolyTan: use PVi_m keywords to define distorted TAN projection?
Definition: FitsChan.h:988
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:490
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:914
tuple options
Definition: lsstimport.py:47
std::string getCardName() const
Get CardName: the keyword name of the current card.
Definition: FitsChan.h:495
int getNCard() const
Get NCard: the number of cards.
Definition: FitsChan.h:554
bool getCDMatrix() const
Get CDMatrix: use CDi_j keywords to represent pixel scaling, rotation, etc?
Definition: FitsChan.h:511
A specialized form of Channel which reads and writes FITS header cards.
Definition: FitsChan.h:201
void retainFits()
Keep the current card when an Object is read that uses the card.
Definition: FitsChan.h:673
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:815
void writeFits()
Write out all cards currently in the channel and clear the channel.
Definition: FitsChan.h:1024
STL class.
void setCard(int ind)
Set Card: the index of the current card, where 1 is the first card.
Definition: FitsChan.h:1035
void setFitsDigits(int digits)
Set FitsDigits: digits of precision for floating-point FITS values.
Definition: FitsChan.h:956
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:48
void setTabOK(int tabOK)
Set TabOK: should the FITS "-TAB" algorithm be recognised?
Definition: FitsChan.h:982
bool getCarLin() const
Get CarLin: ignore spherical rotations on CAR projections?
Definition: FitsChan.h:505
int getNKey() const
Get Nkey: the number of unique keywords.
Definition: FitsChan.h:559
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:516
bool getDefB1950() const
Get DefB1950: use FK4 B1950 as default equatorial coordinates?
Definition: FitsChan.h:521
void putFits(std::string const &card, bool overwrite)
Store a FITS header card in a FitsChan.
Definition: FitsChan.h:643
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:785
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:950
void delFits()
Delete the current FITS card.
Definition: FitsChan.h:229
T value
The found value; ignore if found is false.
Definition: FitsChan.h:81
bool getSipReplace() const
Get SipReplace: ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative...
Definition: FitsChan.h:570
void setWarnings(std::string const &warnings)
Set Warnings attribute, which controls the issuing of warnings about selected conditions when an Obje...
Definition: FitsChan.h:994
void setClean(bool clean)
Set Clean: remove cards used whilst reading even if an error occurs?
Definition: FitsChan.h:933
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:883
void putCards(std::string const &cards)
Replace all FITS header cards.
Definition: FitsChan.h:615
def clean(srcMatch, wcs, order=3, nsigma=3)
void setFitsCM(std::string const &comment, bool overwrite=false)
Create a new comment card, possibly overwriting the current card.
Definition: FitsChan.h:724
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:480
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:527
int getCard() const
Get Card: the index of the current card, where 1 is the first card.
Definition: FitsChan.h:485
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:587
FitsKeyState
Enums describing the presence or absence of a FITS keyword.
Definition: FitsChan.h:39
void readFits()
Read cards from the source and store them in the FitsChan.
Definition: FitsChan.h:660
int getTabOK() const
Get TabOK: should the FITS "-TAB" algorithm be recognised?
Definition: FitsChan.h:575
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:944
void showFits() const
Write all the cards in the channel to standard output.
Definition: FitsChan.h:999
void setSipOK(bool sipOK)
Set SipOK: use Spitzer Space Telescope keywords to define distortion?
Definition: FitsChan.h:971
void setCDMatrix(bool cdMatrix)
Get CDMatrix: Use CDi_j keywords to represent pixel scaling, rotation, etc?
Definition: FitsChan.h:928
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:845
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:755
FoundValue()
Default constructor: found false, value is default-constructed.
Definition: FitsChan.h:79
A value and associated validity flag.
Definition: FitsChan.h:68
void clearCard()
Rewind the card index to the beginning.
Definition: FitsChan.h:1030
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:549
bool getSipOK() const
Get SipOK: use Spitzer Space Telescope keywords to define distortion?
Definition: FitsChan.h:564
int getPolyTan() const
Get PolyTan: use PVi_m keywords to define distorted TAN projection?
Definition: FitsChan.h:581
int getFitsDigits() const
Get FitsDigits: digits of precision for floating-point FITS values.
Definition: FitsChan.h:539