Skip to content

Commit

Permalink
Use SpherePoint instead of Coord or IcrsCoord
Browse files Browse the repository at this point in the history
  • Loading branch information
r-owen committed Mar 16, 2018
1 parent e85fd51 commit d9e83df
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
12 changes: 6 additions & 6 deletions include/lsst/meas/mosaic/mosaicfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace lsst {
_err = sqrt(record.get(record.getSchema().find<double>("flux").key)*1.E-08);
}
}
Source(lsst::afw::coord::IcrsCoord coord, double flux=std::numeric_limits<double>::quiet_NaN()) :
Source(lsst::afw::geom::SpherePoint coord, double flux=std::numeric_limits<double>::quiet_NaN()) :
_id(-1), _chip(UNSET), _exp(UNSET), _sky(coord),
_pixels(lsst::afw::geom::Point2D(std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN())),
Expand All @@ -71,7 +71,7 @@ namespace lsst {
IdType getId() const { return _id; }
ChipType getChip() const { return _chip; }
ExpType getExp() const { return _exp; }
lsst::afw::coord::IcrsCoord getSky() const { return _sky; }
lsst::afw::geom::SpherePoint getSky() const { return _sky; }
lsst::afw::geom::Angle getRa() const { return getSky().getLongitude(); }
lsst::afw::geom::Angle getDec() const { return getSky().getLatitude(); }
lsst::afw::geom::Point2D getPixels() const { return _pixels; }
Expand All @@ -91,7 +91,7 @@ namespace lsst {
IdType _id; // Identifier
ChipType _chip; // Chip identifier
ExpType _exp; // Exposure identifier
lsst::afw::coord::IcrsCoord _sky; // Sky coordinates
lsst::afw::geom::SpherePoint _sky; // ICRS sky coordinates
lsst::afw::geom::Point2D _pixels; // Pixel coordinates
double _flux; // Flux
double _err; // Flux Err
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace lsst {
int depth;
int axis;
lsst::afw::geom::Angle location[2];
lsst::afw::coord::IcrsCoord c;
lsst::afw::geom::SpherePoint c;
KDTree::Ptr left;
KDTree::Ptr right;
SourceSet set;
Expand All @@ -247,7 +247,7 @@ namespace lsst {
KDTree(SourceMatch const& m, int depth);

~KDTree();
ConstPtr search(lsst::afw::coord::IcrsCoord const& sky) const;
ConstPtr search(lsst::afw::geom::SpherePoint const& sky) const;
ConstPtr findSource(Source const& s) const;
void add(SourceMatch const& m);
void add(PTR(Source) s,
Expand All @@ -261,7 +261,7 @@ namespace lsst {
KDTree::Ptr findNearest(Source const& s);

double distance(Source const& s) const {
return c.angularSeparation(lsst::afw::coord::IcrsCoord(s.getRa(), s.getDec())).asDegrees();
return c.separation(lsst::afw::geom::SpherePoint(s.getRa(), s.getDec())).asDegrees();
}

private:
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/meas/mosaic/checkMosaicTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def makeDiffPosFlux(self, allMat, allSource, wcsDic, calibDic, ffpDic):
ichip = ss[j].getChip()
x, y = ss[j].getX(), ss[j].getY()
wcs = wcsDic[iexp][ichip]
ra, dec = wcs.pixelToSky(x, y).getPosition()
ra, dec = wcs.pixelToSky(x, y).getPosition(afwGeom.degrees)
dx_m.append((ra - ra_cat) * 3600)
dy_m.append((dec - dec_cat) * 3600)
mag = 2.5*math.log10(calibDic[iexp][ichip].getFluxMag0()[0]/ss[j].getFlux())
Expand All @@ -81,7 +81,7 @@ def makeDiffPosFlux(self, allMat, allSource, wcsDic, calibDic, ffpDic):
ichip = ss[j].getChip()
x, y = ss[j].getX(), ss[j].getY()
wcs = wcsDic[iexp][ichip]
ra, dec = wcs.pixelToSky(x, y).getPosition()
ra, dec = wcs.pixelToSky(x, y).getPosition(afwGeom.degrees)
ra_source.append(ra)
dec_source.append(dec)
n += 1
Expand Down Expand Up @@ -126,7 +126,7 @@ def makeDiffPosFlux(self, allMat, allSource, wcsDic, calibDic, ffpDic):
ichip = ss[j].getChip()
x, y = ss[j].getX(), ss[j].getY()
wcs = wcsDic[iexp][ichip]
ra, dec = wcs.pixelToSky(x, y).getPosition()
ra, dec = wcs.pixelToSky(x, y).getPosition(afwGeom.degrees)
ra_source.append(ra)
dec_source.append(dec)
n += 1
Expand Down Expand Up @@ -410,7 +410,7 @@ def writeCatalog(self, allSource, wcsDic, calibDic, ffpDic):
outData.id[i] = src.getId()
x, y = src.getX(), src.getY()
wcs = wcsDic[iexp][ichip]
ra, dec = wcs.pixelToSky(x, y).getPosition()
ra, dec = wcs.pixelToSky(x, y).getPosition(afwGeom.degrees)
outData.ra[i] = ra
outData.dec[i] = dec
fluxMag0 = calibDic[iexp][ichip].getFluxMag0()[0]
Expand Down
3 changes: 1 addition & 2 deletions python/lsst/meas/mosaic/mosaicfit/mosaicfit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void declareSource(py::module &mod) {

cls.def(py::init<lsst::afw::table::SourceRecord const &>(), "record"_a);
cls.def(py::init<lsst::afw::table::SimpleRecord const &, lsst::afw::geom::SkyWcs const &>());
cls.def(py::init<lsst::afw::coord::IcrsCoord, double>(), "coord"_a,
cls.def(py::init<lsst::afw::geom::SpherePoint, double>(), "coord"_a,
"flux"_a = std::numeric_limits<double>::quiet_NaN());
cls.def(py::init<typename Source::IdType, typename Source::ChipType, typename Source::ExpType, double,
double, double, double, double, double, double, double, bool>(),
Expand Down Expand Up @@ -230,7 +230,6 @@ void declareKDTree(py::module &mod) {

PYBIND11_PLUGIN(mosaicfit) {
py::module::import("lsst.afw.cameraGeom");
py::module::import("lsst.afw.coord");
py::module::import("lsst.afw.geom");
py::module::import("lsst.afw.image");
py::module::import("lsst.afw.table");
Expand Down
3 changes: 1 addition & 2 deletions python/lsst/meas/mosaic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

import lsst.afw.coord as afwCoord
import lsst.afw.geom as afwGeom
import lsst.afw.table as afwTable
import lsst.afw.image as afwImage
Expand Down Expand Up @@ -877,7 +876,7 @@ def writeCatalog(coeffSet, ffpSet, fexp, fchip, matchVec, sourceVec, outputFile)
continue
r = catalog.addNew()
r.setId(i)
r.setCoord(afwCoord.Coord(ra[i]*afwGeom.radians, dec[i]*afwGeom.radians))
r.setCoord(afwGeom.SpherePoint(ra[i], dec[i], afwGeom.radians))
r.set(magKey, float(mag[i]))
r.set(errKey, float(err[i]))
r.set(numKey, int(numbers[i]))
Expand Down
32 changes: 15 additions & 17 deletions src/mosaicfit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "boost/filesystem/path.hpp"
#include "boost/format.hpp"

#include "lsst/afw/coord/Coord.h"
#include "lsst/afw/table/Match.h"
#include "lsst/meas/mosaic/mosaicfit.h"
#include "lsst/meas/mosaic/shimCameraGeom.h"
Expand Down Expand Up @@ -401,7 +400,7 @@ void KDTree::_initializeSources(SourceSet &s, int depth) {
if (s.size() == 1) {
this->location[0] = s[0]->getRa();
this->location[1] = s[0]->getDec();
this->c = lsst::afw::coord::IcrsCoord(this->location[0], this->location[1]);
this->c = lsst::afw::geom::SpherePoint(this->location[0], this->location[1]);
this->set.push_back(s[0]);

this->left = KDTree::Ptr();
Expand All @@ -415,7 +414,7 @@ void KDTree::_initializeSources(SourceSet &s, int depth) {

this->location[0] = s[s.size() / 2]->getRa();
this->location[1] = s[s.size() / 2]->getDec();
this->c = lsst::afw::coord::IcrsCoord(this->location[0], this->location[1]);
this->c = lsst::afw::geom::SpherePoint(this->location[0], this->location[1]);

this->set.push_back(s[s.size() / 2]);

Expand Down Expand Up @@ -444,7 +443,7 @@ void KDTree::_initializeMatches(SourceMatchSet &m, int depth) {
if (m.size() == 1) {
this->location[0] = m[0].first->getRa();
this->location[1] = m[0].first->getDec();
this->c = lsst::afw::coord::IcrsCoord(this->location[0], this->location[1]);
this->c = lsst::afw::geom::SpherePoint(this->location[0], this->location[1]);

this->set.push_back(m[0].first);
this->set.push_back(m[0].second);
Expand All @@ -463,7 +462,7 @@ void KDTree::_initializeMatches(SourceMatchSet &m, int depth) {

this->location[0] = m[middle].first->getRa();
this->location[1] = m[middle].first->getDec();
this->c = lsst::afw::coord::IcrsCoord(this->location[0], this->location[1]);
this->c = lsst::afw::geom::SpherePoint(this->location[0], this->location[1]);

this->set.push_back(m[middle].first);
this->set.push_back(m[middle].second);
Expand Down Expand Up @@ -495,7 +494,7 @@ KDTree::~KDTree() {
}
}

KDTree::ConstPtr KDTree::search(lsst::afw::coord::IcrsCoord const &sky) const {
KDTree::ConstPtr KDTree::search(lsst::afw::geom::SpherePoint const &sky) const {
lsst::afw::geom::Angle ra = sky.getLongitude();
lsst::afw::geom::Angle dec = sky.getLatitude();

Expand Down Expand Up @@ -572,11 +571,11 @@ KDTree::ConstPtr KDTree::findSource(Source const &s) const {
else
val = dec;

lsst::afw::coord::IcrsCoord coord(s.getRa(), s.getDec());
lsst::afw::geom::SpherePoint coord(s.getRa(), s.getDec());
for (size_t i = 0; i < this->set.size(); i++) {
// Previous code compared x,y, but those aren't available always now so using RA,Dec.
// Is this too slow?
if (coord.angularSeparation(set[i]->getSky()).asArcseconds() < 0.01) {
if (coord.separation(set[i]->getSky()).asArcseconds() < 0.01) {
return shared_from_this();
}
}
Expand Down Expand Up @@ -620,11 +619,11 @@ KDTree::Ptr KDTree::findNearest(Source const &s) {
leaf = this->right->findNearest(s);
}
double d_leaf = leaf->distance(s);
lsst::afw::coord::IcrsCoord c;
lsst::afw::geom::SpherePoint c;
if (this->axis == 0) {
c = lsst::afw::coord::IcrsCoord(val, this->location[1]);
c = lsst::afw::geom::SpherePoint(val, this->location[1]);
} else {
c = lsst::afw::coord::IcrsCoord(this->location[0], val);
c = lsst::afw::geom::SpherePoint(this->location[0], val);
}
double d_this = this->distance(Source(c));
if (d_leaf > d_this && this->right != NULL) {
Expand All @@ -645,11 +644,11 @@ KDTree::Ptr KDTree::findNearest(Source const &s) {
leaf = this->left->findNearest(s);
}
double d_leaf = leaf->distance(s);
lsst::afw::coord::IcrsCoord c;
lsst::afw::geom::SpherePoint c;
if (this->axis == 0) {
c = lsst::afw::coord::IcrsCoord(val, this->location[1]);
c = lsst::afw::geom::SpherePoint(val, this->location[1]);
} else {
c = lsst::afw::coord::IcrsCoord(this->location[0], val);
c = lsst::afw::geom::SpherePoint(this->location[0], val);
}
double d_this = this->distance(Source(c));
if (d_leaf > d_this && this->left != NULL) {
Expand Down Expand Up @@ -741,8 +740,7 @@ SourceGroup KDTree::mergeSource(unsigned int minNumMatch) {
double dec = sd / sn;
double mag = sm / sn;
PTR(Source)
source(new Source(
lsst::afw::coord::IcrsCoord(lsst::afw::geom::Point2D(ra, dec), lsst::afw::geom::degrees), mag));
source(new Source(lsst::afw::geom::SpherePoint(ra, dec, lsst::afw::geom::degrees), mag));
this->set.insert(set.begin(), source);
sg.push_back(this->set);
}
Expand Down Expand Up @@ -2943,7 +2941,7 @@ Coeff::Ptr lsst::meas::mosaic::convertCoeff(Coeff::Ptr &coeff, PTR(lsst::afw::ca
std::shared_ptr<lsst::afw::geom::SkyWcs> lsst::meas::mosaic::wcsFromCoeff(Coeff::Ptr &coeff) {
int order = coeff->p->order;

lsst::afw::geom::PointD crval = lsst::afw::geom::Point2D(coeff->A * R2D, coeff->D * R2D);
lsst::afw::geom::SpherePoint crval(coeff->A * R2D, coeff->D * R2D, lsst::afw::geom::degrees);
lsst::afw::geom::PointD crpix = lsst::afw::geom::Point2D(-coeff->x0, -coeff->y0);

Eigen::Matrix2d cd;
Expand Down

0 comments on commit d9e83df

Please sign in to comment.