Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-12771: Support the new FitsChan ReplaceSip attribute #35

Merged
merged 5 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/attributes_fitsChan.dox
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,15 @@ If any keyword occurrs more than once, the @ref FitsChan_Nkey "Nkey" attribute v
will be smaller than the @ref FitsChan_NCard "NCard" attribute value.


@subsection FitsChan_SipReplace SipReplace

Ignore inverse SIP coefficients (replacing them with fit coefficients or an iterative inverse)? (bool)

If true then ignore SIP inverse coefficients. If false then attempt to fit
new inverse coefficients; if those cannot be determined to suitable accuracy
then use an iterative inverse. The default is false.


@subsection FitsChan_TabOK TabOK

Should the FITS "-TAB" algorithm be recognised? (bool)
Expand Down
35 changes: 19 additions & 16 deletions include/astshim/FitsChan.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ provided by @ref Channel and @ref Object
- @ref FitsChan_Iwc "Iwc": Add a Frame describing Intermediate World Coords?
- @ref FitsChan_NCard "NCard": Number of FITS header cards in a FitsChan
- @ref FitsChan_Nkey "Nkey": Number of unique keywords in a FitsChan
- @ref FitsChan_SipReplace "SipReplace": Ignore inverse SIP coefficients (replacing them with
fit coefficients or an iterative inverse)?
- @ref FitsChan_TabOK "TabOK": Should the FITS "-TAB" algorithm be recognised?
- @ref FitsChan_PolyTan "PolyTan": Use PVi_m keywords to define distorted TAN projection?
- @ref FitsChan_Warnings "Warnings": Produces warnings about selected conditions
Expand Down Expand Up @@ -555,6 +557,12 @@ class FitsChan : public Channel {
*/
int getNKey() const { return getI("NKey"); }

/**
Get @ref FitsChan_SipReplace "SipReplace": ignore inverse SIP coefficients (replacing them with
fit coefficients or an iterative inverse)?
*/
bool getSipReplace() const { return getB("SipReplace"); }

/**
Get @ref FitsChan_TabOK "TabOK": should the FITS "-TAB" algorithm be recognised?
*/
Expand Down Expand Up @@ -902,6 +910,11 @@ class FitsChan : public Channel {
assertOK();
}

/**
Set @ref FitsChan_CarLin "CarLin": ignore spherical rotations on CAR projections?
*/
void setCarLin(bool cdMatrix) { setB("CarLin", cdMatrix); }

/**
Get @ref FitsChan_CDMatrix "CDMatrix": Use CDi_j keywords to represent pixel scaling,
rotation, etc?
Expand All @@ -910,15 +923,11 @@ class FitsChan : public Channel {

/**
Set @ref FitsChan_Clean "Clean": remove cards used whilst reading even if an error occurs?

See @ref getClean for details.
*/
void setClean(bool clean) { setB("Clean", clean); }

/**
Set @ref FitsChan_DefB1950 "DefB1950": use FK4 B1950 as default equatorial coordinates?

See @ref getDefB1950 for details.
*/
void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }

Expand All @@ -931,16 +940,12 @@ class FitsChan : public Channel {
/**
Set @ref FitsChan_FitsAxisOrder "FitsAxisOrder": the order for the WCS axes in any new
FITS-WCS headers created using @ref Channel.write.

See @ref getFitsAxisOrder for details.
*/
void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }

/**
Set @ref FitsChan_FitsDigits "FitsDigits": digits of precision
for floating-point FITS values

See @ref getFitsDigits for details.
*/
void setFitsDigits(int digits) { setI("FitsDigits", digits); }

Expand All @@ -951,31 +956,29 @@ class FitsChan : public Channel {

/**
Set @ref FitsChan_Iwc "Iwc": add a Frame describing Intermediate World Coords?

See @ref getIwc for details.
*/
void setIwc(bool iwcs) { setB("Iwc", iwcs); }

/**
Set @ref FitsChan_TabOK "TabOK": should the FITS "-TAB" algorithm be recognised?
Set @ref FitsChan_SipReplace "SipReplace": ignore inverse SIP coefficients (replacing them with
fit coefficients or an iterative inverse)?
*/
void setSipReplace(bool replace) { setB("SipReplace", replace); }

See @ref getTabOK for details.
/**
Set @ref FitsChan_TabOK "TabOK": should the FITS "-TAB" algorithm be recognised?
*/
void setTabOK(int tabOK) { setI("TabOK", tabOK); }

/**
Set @ref FitsChan_PolyTan "PolyTan": use `PVi_m` keywords
to define distorted TAN projection?

See @ref getPolyTan for details.
*/
void setPolyTan(int polytan) { setI("PolyTan", polytan); }

/**
Set @ref FitsChan_Warnings "Warnings" attribute, which controls the issuing of warnings about
selected conditions when an @ref Object or keyword is read from or written to a @ref FitsChan.

See @ref getWarnings for details.
*/
void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }

Expand Down
6 changes: 3 additions & 3 deletions python/astshim/fitsChan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ PYBIND11_PLUGIN(fitsChan) {

cls.def(py::init<Stream &, std::string const &>(), "stream"_a, "options"_a = "");

cls.def_property("carLin", &FitsChan::getCarLin, &FitsChan::setCarLin);
cls.def_property("cdMatrix", &FitsChan::getCDMatrix, &FitsChan::setCDMatrix);
cls.def_property("clean", &FitsChan::getClean, &FitsChan::setClean);
cls.def_property("defB1950", &FitsChan::getDefB1950, &FitsChan::setDefB1950);
cls.def_property("encoding", &FitsChan::getEncoding, &FitsChan::setEncoding);
Expand All @@ -90,6 +92,7 @@ PYBIND11_PLUGIN(fitsChan) {
cls.def_property_readonly("nCard", &FitsChan::getNCard);
cls.def_property_readonly("nKey", &FitsChan::getNKey);
cls.def_property("iwc", &FitsChan::getIwc, &FitsChan::setIwc);
cls.def_property("sipReplace", &FitsChan::getSipReplace, &FitsChan::setSipReplace);
cls.def_property("tabOK", &FitsChan::getTabOK, &FitsChan::setTabOK);
cls.def_property("polyTan", &FitsChan::getPolyTan, &FitsChan::setPolyTan);
cls.def_property("warnings", &FitsChan::getWarnings, &FitsChan::setWarnings);
Expand All @@ -110,8 +113,6 @@ PYBIND11_PLUGIN(fitsChan) {
cls.def("getCardComm", &FitsChan::getCardComm);
cls.def("getCardName", &FitsChan::getCardName);
cls.def("getCardType", &FitsChan::getCardType);
cls.def("getCarLin", &FitsChan::getCarLin);
cls.def("getCDMatrix", &FitsChan::getCDMatrix);
cls.def("purgeWcs", &FitsChan::purgeWcs);
cls.def("putCards", &FitsChan::putCards, "cards"_a);
cls.def("putFits", &FitsChan::putFits, "card"_a, "overwrite"_a);
Expand All @@ -125,7 +126,6 @@ PYBIND11_PLUGIN(fitsChan) {
cls.def("setFitsL", &FitsChan::setFitsL, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
cls.def("setFitsS", &FitsChan::setFitsS, "name"_a, "value"_a, "comment"_a = "", "overwrite"_a = false);
cls.def("setFitsU", &FitsChan::setFitsU, "name"_a, "comment"_a = "", "overwrite"_a = false);
cls.def("setCDMatrix", &FitsChan::setCDMatrix, "cdmatrix"_a);
cls.def("showFits", &FitsChan::showFits);
cls.def("testFits", &FitsChan::testFits, "name"_a = "");
cls.def("writeFits", &FitsChan::writeFits);
Expand Down
45 changes: 45 additions & 0 deletions tests/test_fitsChan.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,51 @@ def insertPixelMapping(self, mapping, frameSet):
frameSet.addFrame(ast.FrameSet.CURRENT, iwcToSky, skyFrame)
return frameSet

def test_FitsChanAttributes(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have a docstring here saying that this tests the default values and attributes (which function like python properties, I think?).

"""Test getting and setting FitsChan attributes

Does not test the behavior of the attributes.
"""
ss = ast.StringStream("".join(self.cards))
fc = ast.FitsChan(ss)
self.assertFalse(fc.carLin)
self.assertFalse(fc.cdMatrix)
self.assertFalse(fc.clean)
self.assertFalse(fc.defB1950)
self.assertEqual(fc.encoding, "FITS-WCS")
self.assertEqual(fc.fitsAxisOrder, "<auto>")
self.assertAlmostEqual(fc.fitsTol, 0.1)
self.assertFalse(fc.iwc)
self.assertTrue(fc.sipReplace)
self.assertEqual(fc.tabOK, 0)
self.assertEqual(fc.polyTan, -1)
warningSet = set(fc.warnings.split(" "))
desiredWarningSet = set("BadKeyName BadKeyValue Tnx Zpx BadCel BadMat BadPV BadCTYPE".split(" "))
self.assertEqual(warningSet, desiredWarningSet)

fc.carLin = True
self.assertTrue(fc.carLin)
fc.cdMatrix = True
self.assertTrue(fc.cdMatrix)
fc.clean = True
self.assertTrue(fc.clean)
fc.defB1950 = True
self.assertTrue(fc.defB1950)
fc.encoding = "NATIVE"
self.assertEqual(fc.encoding, "NATIVE")
fc.fitsAxisOrder = "<copy>"
self.assertEqual(fc.fitsAxisOrder, "<copy>")
fc.fitsTol = 0.001
self.assertAlmostEqual(fc.fitsTol, 0.001)
fc.iwc = True
self.assertTrue(fc.iwc)
fc.tabOK = 1
self.assertEqual(fc.tabOK, 1)
fc.polyTan = 0
self.assertEqual(fc.polyTan, 0)
fc.warnings = "BadKeyName BadMat"
self.assertEqual(fc.warnings, "BadKeyName BadMat")

def test_FitsChanPreloaded(self):
"""Test a FitsChan that starts out loaded with data
"""
Expand Down