69 void setMetadataFromFoundValue(daf::base::PropertyList& metadata,
std::string const&
name,
71 if (!foundValue.
found) {
72 throw LSST_EXCEPT(pex::exceptions::LogicError,
"Bug! FitsChan card \"" + name +
"\" not found");
74 if (comment.empty()) {
75 metadata.set(name, foundValue.
value);
77 metadata.set(name, foundValue.
value, comment);
91 excludeNames.
insert(moreNames.begin(), moreNames.end());
94 if (metadata.
exists(
"RADECSYS") && !metadata.
exists(
"RADESYS")) {
96 metadata.
remove(
"RADECSYS");
100 "Encoding=FITS-WCS, IWC=1, SipReplace=0, ReportLevel=3");
101 auto const initialNames = strip ? setFromVector(channel.getAllCardNames()) :
std::set<std::string>();
104 obj = channel.read();
112 "metadata describes a " + obj->getClassName() +
", not a FrameSet");
115 auto const finalNames = setFromVector(channel.getAllCardNames());
119 std::set_difference(initialNames.begin(), initialNames.end(), finalNames.begin(), finalNames.end(),
120 std::inserter(namesChannelStripped, namesChannelStripped.begin()));
128 for (
auto const& name : namesToStrip) {
150 auto const initialBaseIndex = rawFrameSet->getBase();
154 if (rawFrameSet->findFrame(
ast::Frame(2,
"Domain=GRID"))) {
155 gridIndex = rawFrameSet->getCurrent();
159 auto const baseFrame = rawFrameSet->getFrame(initialBaseIndex,
false);
160 auto const baseClassName = rawFrameSet->getClassName();
161 if (baseFrame->getClassName() !=
"Frame") {
163 "The base frame is of type " + baseFrame->getClassName() +
164 "instead of Frame; cannot read metadata as a SkyWcs");
166 if (baseFrame->getNAxes() != 2) {
169 " axes instead of 2; cannot read metadata as a SkyWcs");
171 if (baseFrame->getDomain() !=
"") {
173 "The base frame has domain \"" + baseFrame->getDomain() +
174 "\" instead of blank or GRID; cannot read metadata as a SkyWcs");
178 gridIndex = initialBaseIndex;
182 if (!rawFrameSet->findFrame(
ast::Frame(2,
"Domain=IWC"))) {
185 auto const iwcIndex = rawFrameSet->getCurrent();
186 auto const iwcFrame = rawFrameSet->getFrame(iwcIndex);
191 auto const stdSkyFrameTemplate =
ast::SkyFrame(
"System=ICRS");
198 if (!rawFrameSet->findFrame(stdSkyFrameTemplate)) {
200 "Could not find a SkyFrame; cannot read metadata as a SkyWcs");
202 auto initialSkyIndex = rawFrameSet->getCurrent();
208 rawFrameSet->setBase(initialSkyIndex);
209 auto stdSkyFrameSet = rawFrameSet->findFrame(stdSkyFrameTemplate);
210 if (!stdSkyFrameSet) {
212 "Bug: found a SkyFrame the first time, but not the second time");
219 rawFrameSet->addFrame(initialSkyIndex, *stdSkyFrameSet->getMapping()->simplified(),
221 auto const stdSkyIndex = rawFrameSet->getCurrent();
222 auto const stdSkyFrame = rawFrameSet->getFrame(stdSkyIndex,
false);
231 auto const gridToIwc = rawFrameSet->getMapping(gridIndex, iwcIndex)->simplified();
232 auto const pixelToIwc = pixelToGrid.then(*gridToIwc).simplified();
233 auto const iwcToStdSky = rawFrameSet->getMapping(iwcIndex, stdSkyIndex);
235 auto frameDict = std::make_shared<ast::FrameDict>(
ast::Frame(2,
"Domain=PIXELS"), *pixelToIwc, *iwcFrame);
236 frameDict->addFrame(
"IWC", *iwcToStdSky, *stdSkyFrame);
240 auto crpixPixels = pixelToGrid.applyInverse(crpixGrid);
241 auto crvalRad = frameDict->applyForward(crpixPixels);
246 skyFrame->setSkyRefIs(
"Ignored");
247 skyFrame->setSkyRef(crvalRad);
253 int const numCards = fitsChan.
getNCard();
254 auto metadata = std::make_shared<daf::base::PropertyList>();
255 for (
int cardNum = 1; cardNum <= numCards; ++cardNum) {
262 auto foundValue = fitsChan.
getFitsF();
263 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
267 auto foundValue = fitsChan.
getFitsI();
268 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
272 auto foundValue = fitsChan.
getFitsS();
273 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
277 auto foundValue = fitsChan.
getFitsL();
278 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
282 if (cardComment.empty()) {
283 metadata->set(cardName,
nullptr);
285 metadata->set(cardName,
nullptr, cardComment);
291 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
301 os <<
"Card " << cardNum <<
" with name \"" << cardName <<
"\" has type " 302 <<
static_cast<int>(cardType) <<
", which is not supported by PropertyList";
308 os <<
"Bug! Card " << cardNum <<
" with name \"" << cardName
309 <<
"\" has type NOTYPE, which should not be possible";
334 for (
auto const &fullName : allParamNames) {
335 if (excludeNames.
count(fullName) == 0) {
336 std::size_t lastPeriod = fullName.rfind(
char(
'.'));
337 auto name = (lastPeriod == std::string::npos) ? fullName : fullName.
substr(lastPeriod + 1);
340 if (name.
size() > 8) {
344 if (type ==
typeid(
bool)) {
345 fc.setFitsL(name, metadata.
get<
bool>(name));
348 }
else if (type ==
typeid(
int)) {
349 fc.setFitsI(name, metadata.
get<
int>(name));
350 }
else if (type ==
typeid(
double)) {
351 fc.setFitsF(name, metadata.
get<
double>(name));
352 }
else if (type ==
typeid(
float)) {
353 fc.setFitsF(name, static_cast<double>(metadata.
get<
float>(name)));
357 if (str.
size() <= 68) {
double getAsDouble(std::string const &name) const
FoundValue< std::string > getFitsCN(std::string const &name="", std::string defval="") const
virtual char const * what(void) const noexcept
T get(std::string const &name) const
CardType getCardType() const
std::string getCardComm() const
T make_move_iterator(T... args)
std::shared_ptr< ast::FrameDict > readLsstSkyWcs(daf::base::PropertySet &metadata, bool strip=true)
Read an LSST celestial WCS FrameDict from a FITS header.
virtual void remove(std::string const &name)
std::vector< std::string > paramNames(bool topLevelOnly=true) const
std::string getCardName() const
static int constexpr CURRENT
void set(std::string const &name, T const &value)
FoundValue< int > getFitsI(std::string const &name="", int defval=0) const
A base class for image defects.
ast::FitsChan getFitsChanFromPropertyList(daf::base::PropertySet &metadata, std::set< std::string > const &excludeNames={}, std::string options="")
Construct AST FitsChan from PropertyList.
FoundValue< std::string > getFitsS(std::string const &name="", std::string defval="") const
std::shared_ptr< daf::base::PropertyList > createTrivialWcsMetadata(std::string const &wcsName, lsst::geom::Point2I const &xy0)
static int constexpr NOFRAME
bool exists(std::string const &name) const
std::shared_ptr< daf::base::PropertyList > getPropertyListFromFitsChan(ast::FitsChan &fitsChan)
Copy values from an AST FitsChan into a PropertyList.
T dynamic_pointer_cast(T... args)
FoundValue< double > getFitsF(std::string const &name="", double defval=0) const
#define LSST_EXCEPT(type,...)
lsst::geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
std::shared_ptr< ast::FrameSet > readFitsWcs(daf::base::PropertySet &metadata, bool strip=true)
Read a FITS convention WCS FrameSet from FITS metadata.
std::string getAsString(std::string const &name) const
std::vector< std::string > getOrderedNames() const
T set_difference(T... args)
std::string const wcsNameForXY0
std::type_info const & typeOf(std::string const &name) const
FoundValue< bool > getFitsL(std::string const &name="", bool defval=false) const