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-4639: modernize afw code and reduce doxygen errors #75

Merged
merged 1 commit into from
Apr 28, 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
2 changes: 1 addition & 1 deletion include/lsst/meas/algorithms/ExposurePatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ExposurePatch {
afw::image::Wcs const& standardWcs ///< WCS for that other exposure
) : _exp(exp) {
afw::image::Wcs const& expWcs = *exp->getWcs();
afw::coord::Coord::ConstPtr sky = standardWcs.pixelToSky(standardCenter);
std::shared_ptr<afw::coord::Coord const> sky = standardWcs.pixelToSky(standardCenter);
const_cast<CONST_PTR(afw::detection::Footprint)&>(_foot) = standardFoot.transform(standardWcs, expWcs,
exp->getBBox());
const_cast<afw::geom::Point2D&>(_center) = expWcs.skyToPixel(*sky);
Expand Down
4 changes: 2 additions & 2 deletions include/lsst/meas/algorithms/SpatialModelPsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace meas {
namespace algorithms {

template<typename PixelT>
std::pair<lsst::afw::math::LinearCombinationKernel::Ptr, std::vector<double> >
std::pair<std::shared_ptr<lsst::afw::math::LinearCombinationKernel>, std::vector<double> >
createKernelFromPsfCandidates(lsst::afw::math::SpatialCellSet const& psfCells,
lsst::afw::geom::Extent2I const& dims,
lsst::afw::geom::Point2I const& xy0,
Expand Down Expand Up @@ -88,7 +88,7 @@ fitKernelParamsToImage(lsst::afw::math::LinearCombinationKernel const& kernel,
Image const& image, lsst::afw::geom::Point2D const& pos);

template<typename Image>
std::pair<lsst::afw::math::Kernel::Ptr, std::pair<double, double> >
std::pair<std::shared_ptr<lsst::afw::math::Kernel>, std::pair<double, double> >
fitKernelToImage(lsst::afw::math::LinearCombinationKernel const& kernel,
Image const& image, lsst::afw::geom::Point2D const& pos);

Expand Down
2 changes: 1 addition & 1 deletion src/CR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ findCosmicRays(MaskedImageT &mimage, ///< Image to search
*
* Realise PSF at center of image
*/
lsst::afw::math::Kernel::ConstPtr kernel = psf.getLocalKernel();
std::shared_ptr<lsst::afw::math::Kernel const> kernel = psf.getLocalKernel();

Choose a reason for hiding this comment

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

auto?

if (!kernel) {
throw LSST_EXCEPT(pexExcept::NotFoundError, "Psf is unable to return a kernel");
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImagePca.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void PsfImagePca<ImageT>::analyze()
// Use the median of the edge pixels

// If ImageT is a MaskedImage, unpack the Image
typename afw::image::GetImage<ImageT>::type::Ptr eImageIm =
std::shared_ptr<typename afw::image::GetImage<ImageT>::type> eImageIm =

Choose a reason for hiding this comment

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

auto?

afw::image::GetImage<ImageT>::getImage(eImage);

int const nEdge = width*height - (width - 2*_border)*(height - 2*_border);
Expand Down
4 changes: 2 additions & 2 deletions src/Interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2043,8 +2043,8 @@ static void do_defects(std::vector<Defect::Ptr> const & badList, // list of bad

namespace {
template<typename T>
struct Sort_ByX0 : public std::binary_function<typename T::Ptr const, typename T::Ptr const, bool> {
bool operator() (typename T::Ptr const a, typename T::Ptr const b) const {
struct Sort_ByX0 : public std::binary_function<std::shared_ptr<T> const, std::shared_ptr<T> const, bool> {
bool operator() (std::shared_ptr<T> const a, std::shared_ptr<T> const b) const {

Choose a reason for hiding this comment

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

Do these really need to be owning pointers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe not, but converting shared pointers to unique pointers, raw pointers, and/or references is definitely outside the scope of the ticket. For one thing, it would require some more careful thought and testing than the simple syntax replacement I've done here.

return a->getX0() < b->getX0();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/PsfAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ double PsfAttributes::computeGaussianWidth(PsfAttributes::Method how) const {
*/
afwImage::MaskedImage<double> mi = afwImage::MaskedImage<double>(_psfImage);
typedef afwImage::Exposure<double> Exposure;
Exposure::Ptr exposure = makeExposure(mi);
std::shared_ptr<Exposure> exposure = makeExposure(mi);
auto foot = std::make_shared<afwDetection::Footprint>(std::make_shared<afwGeom::SpanSet>(exposure->getBBox(
afwImage::LOCAL)));

Expand Down
4 changes: 2 additions & 2 deletions src/PsfCandidate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ namespace {
* Return an Image initialized from a Mask (possibly modified by func)
*/
template<typename LhsT, typename RhsT>
typename afwImage::Image<LhsT>::Ptr
std::shared_ptr<afwImage::Image<LhsT>>
makeImageFromMask(afwImage::Mask<RhsT> const& rhs, ///< mask to process
afwImage::pixelOp1<RhsT> const& func=noop<RhsT>() ///< functor to call
)
{
typename afwImage::Image<LhsT>::Ptr lhs =
std::shared_ptr<afwImage::Image<LhsT>> lhs =
std::make_shared<afwImage::Image<LhsT> >(rhs.getDimensions());
lhs->setXY0(rhs.getXY0());

Expand Down
56 changes: 28 additions & 28 deletions src/SpatialModelPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class SetPcaImageVisitor : public afwMath::CandidateVisitor {
}

try {
typename MaskedImageT::Ptr im = imCandidate->getOffsetImage(WARP_ALGORITHM,
WARP_BUFFER);
std::shared_ptr<MaskedImageT> im = imCandidate->getOffsetImage(WARP_ALGORITHM,
WARP_BUFFER);


//static int count = 0;
Expand Down Expand Up @@ -170,14 +170,14 @@ class countVisitor : public afwMath::CandidateVisitor {
/// We place the kernel in an oversized image (dimensions expanded by WARP_BUFFER*2) and resample that,
/// so that edge effects from resampling are minimised.
template<typename ImageT>
std::vector<typename ImageT::Ptr> offsetKernel(
std::vector<std::shared_ptr<ImageT>> offsetKernel(
afwMath::LinearCombinationKernel const& kernel, ///< the Kernel to offset
float dx, float dy ///< Offset to apply
)
{
afwMath::KernelList kernels = kernel.getKernelList(); // The Kernels that kernel adds together
unsigned int const nKernel = kernels.size(); // Number of kernel components
std::vector<typename ImageT::Ptr> kernelImages(nKernel); // Images of each Kernel in kernels
std::vector<std::shared_ptr<ImageT>> kernelImages(nKernel); // Images of each Kernel in kernels
if (nKernel == 0) {
throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
"Kernel has no components");
Expand All @@ -196,14 +196,14 @@ std::vector<typename ImageT::Ptr> offsetKernel(

/************************************************************************************************************/
/**
* Return a Kernel::Ptr and a list of eigenvalues resulting from analysing the provided SpatialCellSet
* Return a Kernel pointer and a list of eigenvalues resulting from analysing the provided SpatialCellSet
*
* The Kernel is a LinearCombinationKernel of the first nEigenComponents eigenImages
*
* N.b. This is templated over the Pixel type of the science image
*/
template<typename PixelT>
std::pair<afwMath::LinearCombinationKernel::Ptr, std::vector<double> > createKernelFromPsfCandidates(
std::pair<std::shared_ptr<afwMath::LinearCombinationKernel>, std::vector<double> > createKernelFromPsfCandidates(
afwMath::SpatialCellSet const& psfCells, ///< A SpatialCellSet containing PsfCandidates
lsst::afw::geom::Extent2I const& dims, ///< Dimensions of image
lsst::afw::geom::Point2I const& xy0, ///< Origin of image
Expand Down Expand Up @@ -260,7 +260,7 @@ std::pair<afwMath::LinearCombinationKernel::Ptr, std::vector<double> > createKer
imagePca.analyze();
}

std::vector<typename MaskedImageT::Ptr> eigenImages = imagePca.getEigenImages();
std::vector<std::shared_ptr<MaskedImageT>> eigenImages = imagePca.getEigenImages();
std::vector<double> eigenValues = imagePca.getEigenValues();
int const nEigen = static_cast<int>(eigenValues.size());

Expand Down Expand Up @@ -327,7 +327,7 @@ std::pair<afwMath::LinearCombinationKernel::Ptr, std::vector<double> > createKer
}
}

kernelList.push_back(afwMath::Kernel::Ptr(new afwMath::FixedKernel(
kernelList.push_back(std::shared_ptr<afwMath::Kernel>(new afwMath::FixedKernel(

Choose a reason for hiding this comment

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

make_shared

afwImage::Image<afwMath::Kernel::Pixel>(*eigenImages[i]->getImage(),true)
)));

Expand All @@ -338,7 +338,7 @@ std::pair<afwMath::LinearCombinationKernel::Ptr, std::vector<double> > createKer
spatialFunctionList.push_back(spatialFunction);
}

afwMath::LinearCombinationKernel::Ptr
std::shared_ptr<afwMath::LinearCombinationKernel>
psf(new afwMath::LinearCombinationKernel(kernelList, spatialFunctionList));

return std::make_pair(psf, eigenValues);
Expand Down Expand Up @@ -458,7 +458,7 @@ class evalChi2Visitor : public afwMath::CandidateVisitor {
) :
afwMath::CandidateVisitor(),
_chi2(0.0), _kernel(kernel), _lambda(lambda),
_kImage(KImage::Ptr(new KImage(kernel.getDimensions()))) {
_kImage(std::shared_ptr<KImage>(new KImage(kernel.getDimensions()))) {

Choose a reason for hiding this comment

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

make_shared

}

void reset() {
Expand All @@ -477,7 +477,7 @@ class evalChi2Visitor : public afwMath::CandidateVisitor {
double const ycen = imCandidate->getSource()->getY();

_kernel.computeImage(*_kImage, true, xcen, ycen);
typename MaskedImage::ConstPtr data;
std::shared_ptr<MaskedImage const> data;
try {
data = imCandidate->getOffsetImage(WARP_ALGORITHM, WARP_BUFFER);
} catch(lsst::pex::exceptions::LengthError &) {
Expand Down Expand Up @@ -509,7 +509,7 @@ class evalChi2Visitor : public afwMath::CandidateVisitor {
double mutable _chi2; // the desired chi^2
afwMath::Kernel const& _kernel; // the kernel
double _lambda; // floor for variance is _lambda*data
typename KImage::Ptr mutable _kImage; // The Kernel at this point; a scratch copy
std::shared_ptr<KImage> mutable _kImage; // The Kernel at this point; a scratch copy
};

/********************************************************************************************************/
Expand Down Expand Up @@ -778,7 +778,7 @@ class FillABVisitor : public afwMath::CandidateVisitor {
//
afwMath::KernelList const& kernels = _kernel.getKernelList(); // Kernel's components
for (int i = 0; i != _nComponents; ++i) {
_basisImgs[i] = typename KImage::Ptr(new KImage(kernels[i]->getDimensions()));
_basisImgs[i] = std::shared_ptr<KImage>(new KImage(kernels[i]->getDimensions()));

Choose a reason for hiding this comment

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

make_shared

kernels[i]->computeImage(*_basisImgs[i], false);
}

Expand Down Expand Up @@ -827,7 +827,7 @@ class FillABVisitor : public afwMath::CandidateVisitor {
* If we set the amplitude to be A = I(0)/phi(0) (i.e. the central value of the data and best-fit phi)
* then the coefficient of N0 becomes 1/(1 + b*y) which makes the model non-linear in y.
*/
std::pair<afwMath::Kernel::Ptr, std::pair<double, double> > ret =
std::pair<std::shared_ptr<afwMath::Kernel>, std::pair<double, double> > ret =
fitKernelToImage(_kernel, *data, afwGeom::Point2D(xcen, ycen));
double const amp = ret.second.first;
#endif
Expand All @@ -841,11 +841,11 @@ class FillABVisitor : public afwMath::CandidateVisitor {
params[ic] = _kernel.getSpatialFunction(ic)->getDFuncDParameters(xcen, ycen);
}

std::vector<typename KImage::Ptr> basisImages = offsetKernel<KImage>(_kernel, dx, dy);
std::vector<std::shared_ptr<KImage>> basisImages = offsetKernel<KImage>(_kernel, dx, dy);

// Prepare values for basis dot data
// Scale data and subtract 0th component as part of unit kernel sum construction
typename Image::Ptr dataImage(new Image(*data->getImage(), true));
std::shared_ptr<Image> dataImage(new Image(*data->getImage(), true));

Choose a reason for hiding this comment

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

make_shared

typename KImage::fast_iterator bPtr = basisImages[0]->begin(true);
for (typename Image::fast_iterator dPtr = dataImage->begin(true), end = dataImage->end(true);
dPtr != end; ++dPtr, ++bPtr) {
Expand Down Expand Up @@ -876,7 +876,7 @@ class FillABVisitor : public afwMath::CandidateVisitor {
double _tau2; // variance floor added in quadrature to true candidate variance
int const _nSpatialParams; // number of spatial parameters
int const _nComponents; // number of basis functions
std::vector<typename KImage::Ptr> _basisImgs; // basis function images from _kernel
std::vector<std::shared_ptr<KImage>> _basisImgs; // basis function images from _kernel
Eigen::MatrixXd _A; // We'll solve the matrix equation A x = b for the Kernel's coefficients
Eigen::VectorXd _b;
Eigen::MatrixXd _basisDotBasis; // the inner products of the Kernel components
Expand Down Expand Up @@ -1020,14 +1020,14 @@ double subtractPsf(afwDetection::Psf const& psf, ///< the PSF to subtract
//
// Get Psf candidate
//
afwDetection::Psf::Image::Ptr kImage = psf.computeImage(afwGeom::PointD(x, y));
std::shared_ptr<afwDetection::Psf::Image> kImage = psf.computeImage(afwGeom::PointD(x, y));

//
// Now find the proper sub-Image
//
afwGeom::BoxI bbox = kImage->getBBox();

typename MaskedImageT::Ptr subData(new MaskedImageT(*data, bbox, afwImage::PARENT, false)); // shallow copy
std::shared_ptr<MaskedImageT> subData(new MaskedImageT(*data, bbox, afwImage::PARENT, false)); // shallow copy

Choose a reason for hiding this comment

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

make_shared

//
// Now we've got both; find the PSF's amplitude
//
Expand All @@ -1047,7 +1047,7 @@ double subtractPsf(afwDetection::Psf const& psf, ///< the PSF to subtract
//
// Convert kImage to the proper type so that I can subtract it.
//
typename MaskedImageT::Image::Ptr
std::shared_ptr<typename MaskedImageT::Image>
kImageF(new typename MaskedImageT::Image(*kImage, true)); // of data's type

*kImageF *= amp;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ fitKernelParamsToImage(
* Go through all the kernels, get a copy centered at the desired sub-pixel position, and then
* extract a subImage from the parent image at the same place
*/
std::vector<KernelT::Ptr> kernelImages = offsetKernel<KernelT>(kernel, pos[0], pos[1]);
std::vector<std::shared_ptr<KernelT>> kernelImages = offsetKernel<KernelT>(kernel, pos[0], pos[1]);
afwGeom::BoxI bbox(kernelImages[0]->getBBox());
Image const& subImage(Image(image, bbox, afwImage::PARENT, false)); // shallow copy

Expand Down Expand Up @@ -1120,7 +1120,7 @@ fitKernelParamsToImage(
afwMath::KernelList newKernels(nKernel);
std::vector<double> params(nKernel);
for (int i = 0; i != nKernel; ++i) {
afwMath::Kernel::Ptr newKernel(new afwMath::FixedKernel(*kernelImages[i]));
std::shared_ptr<afwMath::Kernel> newKernel(new afwMath::FixedKernel(*kernelImages[i]));

Choose a reason for hiding this comment

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

make_shared

newKernel->setCtrX(x0 + static_cast<int>(newKernel->getWidth()/2));
newKernel->setCtrY(y0 + static_cast<int>(newKernel->getHeight()/2));

Expand All @@ -1139,7 +1139,7 @@ fitKernelParamsToImage(
* @return std::pair(best-fit kernel, std::pair(amp, chi^2))
*/
template<typename Image>
std::pair<afwMath::Kernel::Ptr, std::pair<double, double> >
std::pair<std::shared_ptr<afwMath::Kernel>, std::pair<double, double> >
fitKernelToImage(
afwMath::LinearCombinationKernel const& kernel, ///< the Kernel to fit
Image const& image, ///< the image to be fit
Expand All @@ -1155,12 +1155,12 @@ fitKernelToImage(

double amp = 0.0;
for (int i = 0; i != nKernel; ++i) {
afwMath::Kernel::Ptr base = kernels[i];
afwMath::FixedKernel::Ptr k = std::static_pointer_cast<afwMath::FixedKernel>(base);
std::shared_ptr<afwMath::Kernel> base = kernels[i];
std::shared_ptr<afwMath::FixedKernel> k = std::static_pointer_cast<afwMath::FixedKernel>(base);
amp += params[i] * k->getSum();
}

afwMath::Kernel::Ptr outputKernel(new afwMath::LinearCombinationKernel(kernels, params));
std::shared_ptr<afwMath::Kernel> outputKernel(new afwMath::LinearCombinationKernel(kernels, params));

Choose a reason for hiding this comment

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

make_shared

double chisq = 0.0;
outputKernel->setCtrX(kernels[0]->getCtrX());
outputKernel->setCtrY(kernels[0]->getCtrY());
Expand All @@ -1177,7 +1177,7 @@ fitKernelToImage(
typedef float Pixel;

template
std::pair<afwMath::LinearCombinationKernel::Ptr, std::vector<double> >
std::pair<std::shared_ptr<afwMath::LinearCombinationKernel>, std::vector<double> >
createKernelFromPsfCandidates<Pixel>(afwMath::SpatialCellSet const&, afwGeom::Extent2I const&,
afwGeom::Point2I const&, int const, int const, int const,
int const, bool const, int const);
Expand All @@ -1202,7 +1202,7 @@ fitKernelToImage(
afwImage::MaskedImage<Pixel> const&, afwGeom::Point2D const&);

template
std::pair<afwMath::Kernel::Ptr, std::pair<double, double> >
std::pair<std::shared_ptr<afwMath::Kernel>, std::pair<double, double> >
fitKernelToImage(afwMath::LinearCombinationKernel const&,
afwImage::MaskedImage<Pixel> const&, afwGeom::Point2D const&);
/// \endcond
Expand Down
2 changes: 1 addition & 1 deletion tests/testPsfAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(PsfAttributes) {
int xwid = static_cast<int>(12*sigma0);
int ywid = xwid;

afwDetection::Psf::Ptr psf(new measAlg::SingleGaussianPsf(xwid, ywid, sigma0));
std::shared_ptr<afwDetection::Psf> psf(new measAlg::SingleGaussianPsf(xwid, ywid, sigma0));

Choose a reason for hiding this comment

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

make_shared


measAlg::PsfAttributes psfAttrib(psf, xwid/2.0, ywid/2.0);
double sigma = psfAttrib.computeGaussianWidth(measAlg::PsfAttributes::ADAPTIVE_MOMENT);
Expand Down