93 if (metadata.
exists(
"RADECSYS") && !metadata.
exists(
"RADESYS")) {
95 metadata.
remove(
"RADECSYS");
99 "Encoding=FITS-WCS, IWC=1, SipReplace=0, ReportLevel=3");
100 auto const initialNames = strip ? setFromVector(channel.getAllCardNames()) :
std::set<std::string>();
103 obj = channel.read();
105 throw LSST_EXCEPT(pex::exceptions::TypeError,
"The metadata does not describe an AST object");
111 "metadata describes a " + obj->getClassName() +
", not a FrameSet");
114 auto const finalNames = setFromVector(channel.getAllCardNames());
118 std::set_difference(initialNames.begin(), initialNames.end(), finalNames.begin(), finalNames.end(),
127 for (
auto const& name : namesToStrip) {
145 if (metadata.
exists(
"RADECSYS") && !metadata.
exists(
"RADESYS")) {
147 metadata.
remove(
"RADECSYS");
151 "Encoding=FITS-WCS, IWC=1, SipReplace=0, ReportLevel=3");
152 auto const initialNames = setFromVector(channel.getAllCardNames());
156 obj = channel.read();
161 auto const finalNames = setFromVector(channel.getAllCardNames());
165 std::set_difference(initialNames.begin(), initialNames.end(), finalNames.begin(), finalNames.end(),
174 for (
auto const& name : namesToStrip) {
187 }
catch (lsst::pex::exceptions::NotFoundError& e) {
189 throw LSST_EXCEPT(lsst::pex::exceptions::TypeError,
190 e.what() +
std::string(
"; cannot read metadata as a SkyWcs"));
194 auto const initialBaseIndex = rawFrameSet->getBase();
198 if (rawFrameSet->findFrame(
ast::Frame(2,
"Domain=GRID"))) {
199 gridIndex = rawFrameSet->getCurrent();
203 auto const baseFrame = rawFrameSet->getFrame(initialBaseIndex,
false);
204 auto const baseClassName = rawFrameSet->getClassName();
205 if (baseFrame->getClassName() !=
"Frame") {
207 "The base frame is of type " + baseFrame->getClassName() +
208 "instead of Frame; cannot read metadata as a SkyWcs");
210 if (baseFrame->getNAxes() != 2) {
213 " axes instead of 2; cannot read metadata as a SkyWcs");
215 if (baseFrame->getDomain() !=
"") {
217 "The base frame has domain \"" + baseFrame->getDomain() +
218 "\" instead of blank or GRID; cannot read metadata as a SkyWcs");
222 gridIndex = initialBaseIndex;
226 if (!rawFrameSet->findFrame(
ast::Frame(2,
"Domain=IWC"))) {
227 throw LSST_EXCEPT(pex::exceptions::TypeError,
"No IWC frame found; cannot read metadata as a SkyWcs");
229 auto const iwcIndex = rawFrameSet->getCurrent();
230 auto const iwcFrame = rawFrameSet->getFrame(iwcIndex);
235 auto const stdSkyFrameTemplate =
ast::SkyFrame(
"System=ICRS");
242 if (!rawFrameSet->findFrame(stdSkyFrameTemplate)) {
244 "Could not find a SkyFrame; cannot read metadata as a SkyWcs");
246 auto initialSkyIndex = rawFrameSet->getCurrent();
252 rawFrameSet->setBase(initialSkyIndex);
253 auto stdSkyFrameSet = rawFrameSet->findFrame(stdSkyFrameTemplate);
254 if (!stdSkyFrameSet) {
256 "Bug: found a SkyFrame the first time, but not the second time");
263 rawFrameSet->addFrame(initialSkyIndex, *stdSkyFrameSet->getMapping()->simplified(),
265 auto const stdSkyIndex = rawFrameSet->getCurrent();
266 auto const stdSkyFrame = rawFrameSet->getFrame(stdSkyIndex,
false);
275 auto const gridToIwc = rawFrameSet->getMapping(gridIndex, iwcIndex)->simplified();
276 auto const pixelToIwc = pixelToGrid.then(*gridToIwc).simplified();
277 auto const iwcToStdSky = rawFrameSet->getMapping(iwcIndex, stdSkyIndex);
280 frameDict->addFrame(
"IWC", *iwcToStdSky, *stdSkyFrame);
284 auto crpixPixels = pixelToGrid.applyInverse(crpixGrid);
285 auto crvalRad = frameDict->applyForward(crpixPixels);
288 throw LSST_EXCEPT(pex::exceptions::LogicError,
"SKY frame is not a SkyFrame");
290 skyFrame->setSkyRefIs(
"Ignored");
291 skyFrame->setSkyRef(crvalRad);
297 int const numCards = fitsChan.
getNCard();
299 for (
int cardNum = 1; cardNum <= numCards; ++cardNum) {
305 case ast::CardType::FLOAT: {
306 auto foundValue = fitsChan.
getFitsF();
307 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
310 case ast::CardType::INT: {
311 auto foundValue = fitsChan.
getFitsI();
312 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
315 case ast::CardType::STRING: {
316 auto foundValue = fitsChan.
getFitsS();
317 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
320 case ast::CardType::LOGICAL: {
321 auto foundValue = fitsChan.
getFitsL();
322 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
325 case ast::CardType::UNDEF: {
326 if (cardComment.empty()) {
327 metadata->set(cardName,
nullptr);
329 metadata->set(cardName,
nullptr, cardComment);
333 case ast::CardType::CONTINUE: {
335 setMetadataFromFoundValue(*metadata, cardName, foundValue, cardComment);
338 case ast::CardType::COMMENT:
341 case ast::CardType::COMPLEXF:
342 case ast::CardType::COMPLEXI: {
345 os <<
"Card " << cardNum <<
" with name \"" << cardName <<
"\" has type "
346 <<
static_cast<int>(cardType) <<
", which is not supported by PropertyList";
349 case ast::CardType::NOTYPE: {
352 os <<
"Bug! Card " << cardNum <<
" with name \"" << cardName
353 <<
"\" has type NOTYPE, which should not be possible";