Skip to content

Commit

Permalink
Merge pull request #117 from lsst/tickets/DM-13270
Browse files Browse the repository at this point in the history
DM-13270: Cleanup ccdImage and gtransfo APIs
  • Loading branch information
parejkoj committed Nov 29, 2018
2 parents d8faad8 + c207b65 commit 07af9f2
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 203 deletions.
2 changes: 1 addition & 1 deletion include/lsst/jointcal/AstrometryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AstrometryModel {
//! The transformation used to project the positions of FittedStars.
/*! This defines the coordinate system into which the Mapping of
this Ccdimage maps the pixel coordinates. */
virtual const std::shared_ptr<Gtransfo const> getSky2TP(CcdImage const &ccdImage) const = 0;
virtual const std::shared_ptr<Gtransfo const> getSkyToTangentPlane(CcdImage const &ccdImage) const = 0;

/**
* Make a SkyWcs that contains this model.
Expand Down
53 changes: 28 additions & 25 deletions include/lsst/jointcal/CcdImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,23 @@ class CcdImage {
*
* @return The common tangent point of all ccdImages (decimal degrees).
*/
Point const &getCommonTangentPoint() const { return _commonTangentPoint; }
jointcal::Point const &getCommonTangentPoint() const { return _commonTangentPoint; }

//!
Gtransfo const *getPix2CommonTangentPlane() const { return _pix2CommonTangentPlane.get(); }
std::shared_ptr<Gtransfo> const getPixelToCommonTangentPlane() const {
return _pixelToCommonTangentPlane;
}

//!
Gtransfo const *getCommonTangentPlane2TP() const { return _CTP2TP.get(); }
std::shared_ptr<Gtransfo> const getCommonTangentPlaneToTangentPlane() const {
return _commonTangentPlaneToTangentPlane;
}

//!
Gtransfo const *getTP2CommonTangentPlane() const { return _TP2CTP.get(); }
std::shared_ptr<Gtransfo> const getTangentPlaneToCommonTangentPlane() const {
return _tangentPlaneToCommonTangentPlane;
}

//!
Gtransfo const *getPix2TangentPlane() const { return _pix2TP.get(); }
std::shared_ptr<Gtransfo> const getPixelToTangentPlane() const { return _pixelToTangentPlane; }

//!
Gtransfo const *getSky2TP() const { return _sky2TP.get(); }
std::shared_ptr<Gtransfo> const getSkyToTangentPlane() const { return _skyToTangentPlane; }

//! returns ccd ID
CcdIdType getCcdId() const { return _ccdId; }
Expand All @@ -164,26 +165,27 @@ class CcdImage {
*/
lsst::afw::geom::SpherePoint getBoresightRaDec() const { return _boresightRaDec; }

//!
double getHourAngle() const { return _hourAngle; }

double getLstObs() const { return _lstObs; }

//! Parallactic angle
double getSinEta() const { return _sineta; }
double getSinEta() const { return _sinEta; }

//! Parallactic angle
double getCosEta() const { return _coseta; }
double getCosEta() const { return _cosEta; }

//! Parallactic angle
double getTanZ() const { return _tgz; }
double getTanZ() const { return _tanZ; }

//!
Point getRefractionVector() const { return Point(_tgz * _coseta, _tgz * _sineta); }
Point getRefractionVector() const { return Point(_tanZ * _cosEta, _tanZ * _sinEta); }

//! return the CcdImage filter name
std::string getFilter() const { return _filter; }

//! the wcs read in the header. NOT updated when fitting.
Gtransfo const *readWCS() const { return _readWcs.get(); }
std::shared_ptr<Gtransfo> const getReadWcs() const { return _readWcs; }

//! Frame in pixels
Frame const &getImageFrame() const { return _imageFrame; }
Expand All @@ -192,20 +194,21 @@ class CcdImage {
void loadCatalog(lsst::afw::table::SortedCatalogT<lsst::afw::table::SourceRecord> const &Cat,
std::string const &fluxField);

Frame _imageFrame; // in pixels
jointcal::Frame _imageFrame; // in pixels

MeasuredStarList _wholeCatalog; // the catalog of measured objets
MeasuredStarList _catalogForFit;

std::shared_ptr<GtransfoSkyWcs> _readWcs; // apply goes from pix to sky

// The following ones should probably be mostly removed.
std::shared_ptr<Gtransfo> _CTP2TP; // go from CommonTangentPlane to this tangent plane.
std::shared_ptr<Gtransfo> _TP2CTP; // reverse one
std::shared_ptr<Gtransfo> _pix2CommonTangentPlane; // pixels -> CTP
std::shared_ptr<Gtransfo> _pix2TP;
// go from CommonTangentPlane to this tangent plane.
std::shared_ptr<Gtransfo> _commonTangentPlaneToTangentPlane;
std::shared_ptr<Gtransfo> _tangentPlaneToCommonTangentPlane; // reverse one
std::shared_ptr<Gtransfo> _pixelToCommonTangentPlane; // pixels -> CTP
std::shared_ptr<Gtransfo> _pixelToTangentPlane;

std::shared_ptr<Gtransfo> _sky2TP;
std::shared_ptr<Gtransfo> _skyToTangentPlane;

std::string _name;
CcdIdType _ccdId;
Expand All @@ -218,13 +221,13 @@ class CcdImage {
std::shared_ptr<afw::cameraGeom::Detector> _detector;
// refraction
// eta : parallactic angle, z: zenithal angle (X = 1/cos(z))
double _sineta, _coseta, _tgz;
double _sinEta, _cosEta, _tanZ;
// Local Sidereal Time and hour angle of observation
double _lstObs, _hourAngle;

std::string _filter;

Point _commonTangentPoint;
jointcal::Point _commonTangentPoint;
};
} // namespace jointcal
} // namespace lsst
Expand Down
6 changes: 3 additions & 3 deletions include/lsst/jointcal/ConstrainedAstrometryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class ConstrainedAstrometryModel : public AstrometryModel {
* stars are reported) onto the Tangent plane (into which the pixel coordinates
* are transformed).
*/
const std::shared_ptr<Gtransfo const> getSky2TP(CcdImage const &ccdImage) const override {
return _sky2TP->getSky2TP(ccdImage);
const std::shared_ptr<Gtransfo const> getSkyToTangentPlane(CcdImage const &ccdImage) const override {
return _skyToTangentPlane->getSkyToTangentPlane(ccdImage);
}

/// @copydoc AstrometryModel::makeSkyWcs
Expand All @@ -113,7 +113,7 @@ class ConstrainedAstrometryModel : public AstrometryModel {
std::unordered_map<CcdImageKey, std::unique_ptr<TwoTransfoMapping>> _mappings;
std::map<CcdIdType, std::shared_ptr<SimpleGtransfoMapping>> _chipMap;
std::map<VisitIdType, std::shared_ptr<SimpleGtransfoMapping>> _visitMap;
const std::shared_ptr<ProjectionHandler const> _sky2TP;
const std::shared_ptr<ProjectionHandler const> _skyToTangentPlane;
bool _fittingChips, _fittingVisits;

/// @copydoc AstrometryModel::findMapping
Expand Down
69 changes: 36 additions & 33 deletions include/lsst/jointcal/Gtransfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GtransfoLin;
providing inverseTransfo is obviously a very good idea. Before
resorting to inverseTransfo, consider using
StarMatchList::inverseTransfo(). GtransfoLin::inverted() and
TanPix2RaDec::inverted() exist.
TanPixelToRaDec::inverted() exist.
The classes also provide derivation and linear approximation.
*/
Expand Down Expand Up @@ -552,7 +552,7 @@ class BaseTanWcs : public Gtransfo {
public:
using Gtransfo::apply; // to unhide apply(const Point&)

BaseTanWcs(GtransfoLin const &pix2Tan, Point const &tangentPoint,
BaseTanWcs(GtransfoLin const &pixToTan, Point const &tangentPoint,
const GtransfoPoly *corrections = nullptr);

BaseTanWcs(const BaseTanWcs &original);
Expand All @@ -579,55 +579,57 @@ class BaseTanWcs : public Gtransfo {

//! Get a transform from pixels to tangent plane (degrees)
//! This is a linear transform plus the effects of the correction
virtual GtransfoPoly getPix2TangentPlane() const = 0;
virtual GtransfoPoly getPixelToTangentPlane() const = 0;

//! Transform from pixels to tangent plane (degrees)
virtual void pix2TP(double xPixel, double yPixel, double &xTangentPlane, double &yTangentPlane) const = 0;
virtual void pixToTangentPlane(double xPixel, double yPixel, double &xTangentPlane,
double &yTangentPlane) const = 0;

~BaseTanWcs();

protected:
GtransfoLin linPix2Tan; // transform from pixels to tangent plane (degrees)
// a linear approximation centered at the pixel and sky origins
GtransfoLin linPixelToTan; // transform from pixels to tangent plane (degrees)
// a linear approximation centered at the pixel and sky origins
std::unique_ptr<GtransfoPoly> corr;
double ra0, dec0; // sky origin (radians)
double cos0, sin0; // cos(dec0), sin(dec0)
};

class TanRaDec2Pix; // the inverse of TanPix2RaDec.
class TanRaDecToPixel; // the inverse of TanPixelToRaDec.

//! the transformation that handles pix to sideral transfos (Gnomonic, possibly with polynomial distortions).
class TanPix2RaDec : public BaseTanWcs {
class TanPixelToRaDec : public BaseTanWcs {
public:
using Gtransfo::apply; // to unhide apply(const Point&)
//! pix2Tan describes the transfo from pix to tangent plane (degrees). TangentPoint in degrees.
//! pixToTan describes the transfo from pix to tangent plane (degrees). TangentPoint in degrees.
//! Corrections are applied between Lin and deprojection parts (as in Swarp).
TanPix2RaDec(GtransfoLin const &pix2Tan, Point const &tangentPoint,
const GtransfoPoly *corrections = nullptr);
TanPixelToRaDec(GtransfoLin const &pixToTan, Point const &tangentPoint,
const GtransfoPoly *corrections = nullptr);

//! the transformation from pixels to tangent plane (degrees)
GtransfoPoly getPix2TangentPlane() const;
GtransfoPoly getPixelToTangentPlane() const;

//! transforms from pixel space to tangent plane (degrees)
virtual void pix2TP(double xPixel, double yPixel, double &xTangentPlane, double &yTangentPlane) const;
virtual void pixToTangentPlane(double xPixel, double yPixel, double &xTangentPlane,
double &yTangentPlane) const;

TanPix2RaDec();
TanPixelToRaDec();

//! composition with GtransfoLin
TanPix2RaDec operator*(GtransfoLin const &right) const;
TanPixelToRaDec operator*(GtransfoLin const &right) const;

using Gtransfo::composeAndReduce; // to unhide Gtransfo::composeAndReduce(Gtransfo const &)
/// @copydoc Gtransfo::composeAndReduce
std::unique_ptr<Gtransfo> composeAndReduce(GtransfoLin const &right) const;

//! approximate inverse : it ignores corrections;
TanRaDec2Pix inverted() const;
TanRaDecToPixel inverted() const;

//! Overload the "generic routine" (available for all Gtransfo types
std::unique_ptr<Gtransfo> roughInverse(const Frame &region) const;

//! Inverse transfo: returns a TanRaDec2Pix if there are no corrections, or the iterative solver if there
//! are.
//! Inverse transfo: returns a TanRaDecToPixel if there are no corrections, or the iterative solver if
//! there are.
std::unique_ptr<Gtransfo> inverseTransfo(const double precision, const Frame &region) const;

std::unique_ptr<Gtransfo> clone() const;
Expand All @@ -639,23 +641,24 @@ class TanPix2RaDec : public BaseTanWcs {
};

//! Implements the (forward) SIP distorsion scheme
class TanSipPix2RaDec : public BaseTanWcs {
class TanSipPixelToRaDec : public BaseTanWcs {
public:
//! pix2Tan describes the transfo from pix to tangent plane (degrees). TangentPoint in degrees.
//! pixToTan describes the transfo from pix to tangent plane (degrees). TangentPoint in degrees.
//! Corrections are applied before Lin.
TanSipPix2RaDec(GtransfoLin const &pix2Tan, Point const &tangentPoint,
const GtransfoPoly *corrections = nullptr);
TanSipPixelToRaDec(GtransfoLin const &pixToTan, Point const &tangentPoint,
const GtransfoPoly *corrections = nullptr);

//! the transformation from pixels to tangent plane (degrees)
GtransfoPoly getPix2TangentPlane() const;
GtransfoPoly getPixelToTangentPlane() const;

//! transforms from pixel space to tangent plane (degrees)
virtual void pix2TP(double xPixel, double yPixel, double &xTangentPlane, double &yTangentPlane) const;
virtual void pixToTangentPlane(double xPixel, double yPixel, double &xTangentPlane,
double &yTangentPlane) const;

TanSipPix2RaDec();
TanSipPixelToRaDec();

//! Inverse transfo: returns a TanRaDec2Pix if there are no corrections, or the iterative solver if there
//! are.
//! Inverse transfo: returns a TanRaDecToPixel if there are no corrections, or the iterative solver if
//! there are.
std::unique_ptr<Gtransfo> inverseTransfo(const double precision, const Frame &region) const;

std::unique_ptr<Gtransfo> clone() const;
Expand All @@ -670,18 +673,18 @@ class TanSipPix2RaDec : public BaseTanWcs {
/*! this transfo does not implement corrections, since
they are defined the other way around (from pixels to sky),
and not invertible analytically. The inversion of tangent
point WCS (TanPix2RaDec) is obtained via inverseTransfo().
point WCS (TanPixelToRaDec) is obtained via inverseTransfo().
*/

class TanRaDec2Pix : public Gtransfo {
class TanRaDecToPixel : public Gtransfo {
public:
using Gtransfo::apply; // to unhide apply(const Point&)

//! assume degrees everywhere.
TanRaDec2Pix(GtransfoLin const &tan2Pix, Point const &tangentPoint);
TanRaDecToPixel(GtransfoLin const &tan2Pix, Point const &tangentPoint);

//!
TanRaDec2Pix();
TanRaDecToPixel();

//! The Linear part (corresponding to CD's and CRPIX's)
GtransfoLin getLinPart() const;
Expand All @@ -699,12 +702,12 @@ class TanRaDec2Pix : public Gtransfo {
void transformPosAndErrors(const FatPoint &in, FatPoint &out) const;

//! exact typed inverse:
TanPix2RaDec inverted() const;
TanPixelToRaDec inverted() const;

//! Overload the "generic routine" (available for all Gtransfo types
std::unique_ptr<Gtransfo> roughInverse(const Frame &region) const;

//! Inverse transfo: returns a TanPix2RaDec.
//! Inverse transfo: returns a TanPixelToRaDec.
std::unique_ptr<Gtransfo> inverseTransfo(const double precision, const Frame &region) const;

void dump(std::ostream &stream) const;
Expand Down
6 changes: 3 additions & 3 deletions include/lsst/jointcal/ProjectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CcdImage;
* (where they are compared to transformed measurements)
*/
struct ProjectionHandler {
virtual const std::shared_ptr<const Gtransfo> getSky2TP(const CcdImage &ccdImage) const = 0;
virtual const std::shared_ptr<const Gtransfo> getSkyToTangentPlane(const CcdImage &ccdImage) const = 0;

virtual ~ProjectionHandler(){};
};
Expand All @@ -55,7 +55,7 @@ class IdentityProjectionHandler : public ProjectionHandler {
std::shared_ptr<GtransfoIdentity> id;

public:
const std::shared_ptr<const Gtransfo> getSky2TP(const CcdImage &ccdImage) const { return id; };
const std::shared_ptr<const Gtransfo> getSkyToTangentPlane(const CcdImage &ccdImage) const { return id; };
};

/**
Expand All @@ -72,7 +72,7 @@ class OneTPPerVisitHandler : public ProjectionHandler {
public:
OneTPPerVisitHandler(const CcdImageList &ccdImageList);

const std::shared_ptr<const Gtransfo> getSky2TP(const CcdImage &ccdImage) const;
const std::shared_ptr<const Gtransfo> getSkyToTangentPlane(const CcdImage &ccdImage) const;
};
} // namespace jointcal
} // namespace lsst
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/jointcal/SimpleAstrometryMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SimplePolyMapping : public SimpleGtransfoMapping {
SimplePolyMapping(GtransfoLin const &CenterAndScale, GtransfoPoly const &gtransfo)
: SimpleGtransfoMapping(gtransfo), _centerAndScale(CenterAndScale) {
// We assume that the initialization was done properly, for example that
// gtransfo = pix2TP*CenterAndScale.inverted(), so we do not touch transfo.
// gtransfo = pixToTangentPlane*CenterAndScale.inverted(), so we do not touch transfo.
/* store the (spatial) derivative of _centerAndScale. For the extra
diagonal terms, just copied the ones in positionDerivatives */
preDer(0, 0) = _centerAndScale.coeff(1, 0, 0);
Expand Down
6 changes: 3 additions & 3 deletions include/lsst/jointcal/SimpleAstrometryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class SimpleAstrometryModel : public AstrometryModel {
/*! the mapping of sky coordinates (i.e. the coordinate system
in which fitted stars are reported) onto the Tangent plane
(into which the pixel coordinates are transformed) */
const std::shared_ptr<Gtransfo const> getSky2TP(CcdImage const &ccdImage) const override {
return _sky2TP->getSky2TP(ccdImage);
const std::shared_ptr<Gtransfo const> getSkyToTangentPlane(CcdImage const &ccdImage) const override {
return _skyToTangentPlane->getSkyToTangentPlane(ccdImage);
}

//!
Expand All @@ -95,7 +95,7 @@ class SimpleAstrometryModel : public AstrometryModel {

private:
std::unordered_map<CcdImageKey, std::unique_ptr<SimpleGtransfoMapping>> _myMap;
const std::shared_ptr<ProjectionHandler const> _sky2TP;
const std::shared_ptr<ProjectionHandler const> _skyToTangentPlane;

/// @copydoc AstrometryModel::findMapping
AstrometryMapping *findMapping(CcdImage const &ccdImage) const override;
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/jointcal/astrometryModels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void declareAstrometryModel(py::module &mod) {
cls.def("getMapping", &AstrometryModel::getMapping, py::return_value_policy::reference_internal);
cls.def("assignIndices", &AstrometryModel::assignIndices);
cls.def("offsetParams", &AstrometryModel::offsetParams);
cls.def("getSky2TP", &AstrometryModel::getSky2TP);
cls.def("getSkyToTangentPlane", &AstrometryModel::getSkyToTangentPlane);
cls.def("makeSkyWcs", &AstrometryModel::makeSkyWcs);
cls.def("getTotalParameters", &AstrometryModel::getTotalParameters);
cls.def("validate", &AstrometryModel::validate);
Expand Down
5 changes: 3 additions & 2 deletions python/lsst/jointcal/ccdImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ void declareCcdImage(py::module &mod) {
cls.def_property("commonTangentPoint", &CcdImage::getCommonTangentPoint, &CcdImage::setCommonTangentPoint,
py::return_value_policy::reference_internal);

cls.def("getSky2TP", &CcdImage::getSky2TP, py::return_value_policy::reference_internal);
cls.def("readWCS", &CcdImage::readWCS, py::return_value_policy::reference_internal);
cls.def("getSkyToTangentPlane", &CcdImage::getSkyToTangentPlane,
py::return_value_policy::reference_internal);
cls.def("getReadWcs", &CcdImage::getReadWcs, py::return_value_policy::reference_internal);
}

PYBIND11_MODULE(ccdImage, mod) { declareCcdImage(mod); }
Expand Down

0 comments on commit 07af9f2

Please sign in to comment.