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-20566: Replace afwGeom with geom #46

Merged
merged 5 commits into from
Jul 17, 2019
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
1 change: 0 additions & 1 deletion bin.src/psfex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
from lsst.meas.extensions.psfex import psfex, readPrefs, makeitLsst, makeit, showPsf, dafBase

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Wrapper for Point Spread Function Extractor (PSFEX)")
Expand Down
8 changes: 4 additions & 4 deletions include/lsst/meas/extensions/psfex/Field.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public:
);
~Field();
//
void finalize() { _finalize(true); }
void finalize() { _finalize(true); }

void addExt(lsst::afw::geom::SkyWcs const& wcs, int const naxis1, int const naxis2, int const nobj=0);

/// Return the number of extensions
int getNext() const { return impl->next; }
/// Return the Psfs
std::vector<Psf> getPsfs() const;

private:
fieldstruct* impl;
mutable std::vector<Psf> _psfs;
Expand Down
34 changes: 17 additions & 17 deletions include/lsst/meas/extensions/psfex/PsfexPsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# if !defined(LSST_MEAS_EXTENSIONS_PSFEX_PSFEX_H)
#define LSST_MEAS_EXTENSIONS_PSFEX_PSFEX_H 1

#include "lsst/afw/geom/Box.h"
#include "lsst/geom/Box.h"
#include "lsst/meas/algorithms/ImagePsf.h"
#include "lsst/meas/extensions/psfex/psf.hh"

Expand All @@ -45,7 +45,7 @@ class PsfexPsf : public lsst::afw::table::io::PersistableFacade<PsfexPsf>,
*/
explicit PsfexPsf(
lsst::meas::extensions::psfex::Psf const& psf, ///< [in] Psfex PSF model to be wrapped into an LSST Psf
lsst::afw::geom::Point2D const & averagePosition=lsst::afw::geom::Point2D()
lsst::geom::Point2D const & averagePosition=lsst::geom::Point2D()
///< [in] Average position of stars used to construct the Psf.
);
virtual ~PsfexPsf();
Expand All @@ -57,20 +57,20 @@ class PsfexPsf : public lsst::afw::table::io::PersistableFacade<PsfexPsf>,
virtual PTR(afw::detection::Psf) resized(int width, int height) const;

/// Return average position of stars; used as default position.
virtual lsst::afw::geom::Point2D getAveragePosition() const { return _averagePosition; }
virtual lsst::geom::Point2D getAveragePosition() const { return _averagePosition; }

/// Return the PSF's basis functions as a spatially-invariant LinearCombinationKernel
/// with unit weights
PTR(lsst::afw::math::LinearCombinationKernel const)
getKernel(lsst::afw::geom::Point2D =
lsst::afw::geom::Point2D(std::numeric_limits<double>::quiet_NaN())) const;
getKernel(lsst::geom::Point2D =
lsst::geom::Point2D(std::numeric_limits<double>::quiet_NaN())) const;

/// Is this object persistable?
virtual bool isPersistable() const noexcept override { return true; }

void write(lsst::afw::table::io::OutputArchiveHandle & handle) const;
private:
lsst::afw::geom::Point2D _averagePosition;
lsst::geom::Point2D _averagePosition;
// Here are the unpacked fields from the psfex psf struct
struct poly *_poly; // Polynom describing the PSF variations
float _pixstep; // Mask oversampling (pixel)
Expand All @@ -84,35 +84,35 @@ class PsfexPsf : public lsst::afw::table::io::PersistableFacade<PsfexPsf>,

/// Compute an image of the Psf at the specified position/colour, at pixel position in the output image
virtual PTR(lsst::afw::detection::Psf::Image) _doComputeImage(
lsst::afw::geom::Point2D const & position, ///< position within the chip
lsst::geom::Point2D const & position, ///< position within the chip
lsst::afw::image::Color const& color, ///< colour of object
lsst::afw::geom::Point2D const& center ///< position of center of image in the output image
lsst::geom::Point2D const& center ///< position of center of image in the output image
) const;

/// Compute an image of the Psf at the specified position/colour, at pixel (0.0, 0.0) in the output image
virtual PTR(lsst::afw::detection::Psf::Image) doComputeKernelImage(
lsst::afw::geom::Point2D const & position, ///< position within the chip
lsst::geom::Point2D const & position, ///< position within the chip
lsst::afw::image::Color const& color ///< colour of object
) const;

/// Compute an image of the Psf at the specified position/colour, at pixel position in the output image
virtual PTR(lsst::afw::detection::Psf::Image) doComputeImage(
lsst::afw::geom::Point2D const & position, ///< position within the chip
lsst::geom::Point2D const & position, ///< position within the chip
lsst::afw::image::Color const& color ///< colour of object
) const;

/// Compute the bbox of the kernel image at the specified position/color
virtual lsst::afw::geom::Box2I doComputeBBox(
lsst::afw::geom::Point2D const & position,
virtual lsst::geom::Box2I doComputeBBox(
lsst::geom::Point2D const & position,
lsst::afw::image::Color const & color
) const;

/// Compute bbox of either image or kernel image, depending on provided center
/// Does not depend on color, which is left out of parameter list to permit reuse
/// by doComputeBBox, doCompute[Kernel]Image, and getKernel.
lsst::afw::geom::Box2I _doComputeBBox(
lsst::afw::geom::Point2D const & position, ///< position within the chip
lsst::afw::geom::Point2D const & center ///< center of output image. Use (0., 0.) for a kernel image
lsst::geom::Box2I _doComputeBBox(
lsst::geom::Point2D const & position, ///< position within the chip
lsst::geom::Point2D const & center ///< center of output image. Use (0., 0.) for a kernel image
) const;

/// Name used in table persistence
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/meas/extensions/psfex/prefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public:
int getPhotfluxerrNum() const { return prefs.photfluxerr_num; }
double getProfAccuracy() const { return prefs.prof_accuracy; }
int getVerboseType() const { return prefs.verbose_type; }

std::vector<std::string> const& getContextName() const { return _context_names; }
std::vector<int> const& getContextGroup() const { return _context_groups; }
std::vector<int> const& getGroupDeg() const { return _group_degs; }
Expand Down
10 changes: 5 additions & 5 deletions include/lsst/meas/extensions/psfex/psf.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Context {
friend class Set;
public:
enum { KEEPHIDDEN=CONTEXT_KEEPHIDDEN, REMOVEHIDDEN=CONTEXT_REMOVEHIDDEN };

Context(std::vector<std::string> const& names, ///< names of fields to use
std::vector<int> const& group, ///< tags for each member of names
std::vector<int> const& degree, ///< polynomial degree for each group
Expand Down Expand Up @@ -77,7 +77,7 @@ public:
ndarray::Array<float,2,2> getVigWeight() const;
std::pair<double, double> getXY() const { return std::pair<double,double>(impl->x, impl->y); }
float getNorm() const { return impl->norm; }

private:
Sample(samplestruct *s, bool recentroid, int *vigsize) : impl(s), _recentroid(recentroid),
_fluxrad(0.0), _vigsize(vigsize) { }
Expand All @@ -89,7 +89,7 @@ private:
};

/************************************************************************************************************/

class Set {
friend class Psf;
friend void makeit(std::vector<std::shared_ptr<Field> > &fields,
Expand Down Expand Up @@ -163,7 +163,7 @@ public:
Psf() : impl(0) {}
explicit Psf(psfstruct *psf) : impl(psf) {}
~Psf();

ndarray::Array<float,2,2> getLoc() const;
ndarray::Array<float,2,2> getResi() const;
#if 0
Expand All @@ -179,7 +179,7 @@ public:
void clip() {
psf_clip(impl);
}

protected:
psfstruct *impl;
};
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/meas/extensions/psfex/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/
#include "pybind11/pybind11.h"
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/meas/extensions/psfex/prefs.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LSST Data Management System
*
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
* See the COPYRIGHT file
Expand All @@ -9,14 +9,14 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/
#include "pybind11/pybind11.h"
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/meas/extensions/psfex/psf.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LSST Data Management System
*
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
* See the COPYRIGHT file
Expand All @@ -9,14 +9,14 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/
#include "pybind11/pybind11.h"
Expand Down
33 changes: 19 additions & 14 deletions python/lsst/meas/extensions/psfex/psfex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
except ImportError:
plt = None

import lsst.geom as geom
import lsst.afw.geom as afwGeom
from lsst.afw.fits import readMetadata
import lsst.afw.image as afwImage
Expand Down Expand Up @@ -182,16 +183,17 @@ def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, contex

n = prefs.getPhotfluxNum() - 1
if n:
assert False, "Code to handle e.g. FLUX_APER(3) isn't yet converted"
if key.naxis == 1 and n < key.naxisn[0]:
raise RuntimeError("Code to handle e.g. FLUX_APER(3) isn't yet converted")
if key.naxis == 1 and n < key.naxisn[0]: # noqa: F821
flux += n
else:
print("Not enough apertures for %s in catalogue %s: using first aperture" %
(prefs.getPhotfluxRkey(), filename), file=sys.stderr)

n = prefs.getPhotfluxerrNum() - 1
if n:
if key.naxis == 1 and n < key.naxisn[0]:
raise RuntimeError("Code for getPhotfluxerrNum is broken")
if key.naxis == 1 and n < key.naxisn[0]: # noqa: F821
fluxerr += n
else:
print("Not enough apertures for %s in catalogue %s: using first aperture" %
Expand Down Expand Up @@ -238,7 +240,8 @@ def read_samples(prefs, set, filename, frmin, frmax, ext, next, catindex, contex
# Insert the good candidates into the set
#
if not vignet.dtype.isnative:
# without the swap setVig fails with "ValueError: 'unaligned arrays cannot be converted to C++'"
# without the swap setVig fails with
# "ValueError: 'unaligned arrays cannot be converted to C++'"
vignet = vignet.byteswap()

for i in np.where(good)[0]:
Expand Down Expand Up @@ -395,7 +398,7 @@ class _LSST():


def setDataType(t):
_dataType = _dataTypes[t]
_dataType = _dataTypes[t] # noqa: F841


def getFlags():
Expand Down Expand Up @@ -598,10 +601,10 @@ def showPsf(psf, set, ext=None, wcsData=None, trim=0, nspot=5,
bbox = mos.getBBox(i)
mosx = bbox.getMinX() + 0.5*(bbox.getWidth() - 1)
mosy = bbox.getMinY() + 0.5*(bbox.getHeight() - 1)
pos.append([afwGeom.PointD(mosx, mosy), wcs.pixelToSky(afwGeom.PointD(x, y))])
pos.append([geom.PointD(mosx, mosy), wcs.pixelToSky(geom.PointD(x, y))])
else:
pos.append([afwGeom.PointD(0, 0), wcs.pixelToSky(afwGeom.PointD(0, 0))])
pos.append([afwGeom.PointD(*mosaic.getDimensions()), wcs.pixelToSky(afwGeom.PointD(naxis1, naxis2))])
pos.append([geom.PointD(0, 0), wcs.pixelToSky(geom.PointD(0, 0))])
pos.append([geom.PointD(*mosaic.getDimensions()), wcs.pixelToSky(geom.PointD(naxis1, naxis2))])

CD = []
for i in range(2):
Expand Down Expand Up @@ -716,16 +719,17 @@ def makeitLsst(prefs, context, saveWcs=False, plot=dict()):
wcss = []
wcssList.append(wcss)
with fits.open(cat):
# Hack: I want the WCS so I'll guess where the calexp is to be found
# Hack: I want the WCS so I'll guess where the calexp is to be
# found
calexpFile = guessCalexp(cat)
md = readMetadata(calexpFile)
wcs = afwGeom.makeSkyWcs(md)

if not wcs:
cdMatrix = np.array([1.0, 0.0, 0.0, 1.0])
cdMatrix.shape = (2, 2)
wcs = afwGeom.makeSkyWcs(crpix=afwGeom.PointD(0, 0),
crval=afwGeom.SpherePoint(0.0, 0.0, afwGeom.degrees),
wcs = afwGeom.makeSkyWcs(crpix=geom.PointD(0, 0),
crval=geom.SpherePoint(0.0, 0.0, geom.degrees),
cdMatrix=cdMatrix)

naxis1, naxis2 = md.getScalar("NAXIS1"), md.getScalar("NAXIS2")
Expand Down Expand Up @@ -851,7 +855,8 @@ def read_samplesLsst(prefs, set, filename, frmin, frmax, ext, next, catindex, co
# Insert the good candidates into the set
#
if not vignet.dtype.isnative:
# without the swap setVig fails with "ValueError: 'unaligned arrays cannot be converted to C++'"
# without the swap setVig fails with
# "ValueError: 'unaligned arrays cannot be converted to C++'"
vignet = vignet.byteswap()

for i in np.where(good)[0]:
Expand Down Expand Up @@ -1006,8 +1011,8 @@ def load_samplesLsst(prefs, context, ext=psfexLib.Prefs.ALL_EXTENSIONS, next=1,


def makeit(prefs, context, saveWcs=False, plot=dict()):
"""This is the python wrapper for the original psfex that reads SExtractor outputs
"""
"""This is the python wrapper for the original psfex that reads SExtractor
outputs"""
# Create an array of PSFs (one PSF for each extension)
if prefs.getVerboseType() != prefs.QUIET:
print("----- %d input catalogues:" % prefs.getNcat())
Expand Down
18 changes: 9 additions & 9 deletions python/lsst/meas/extensions/psfex/psfexPsf.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
/*
* LSST Data Management System
*
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
* See the COPYRIGHT file
Expand All @@ -9,14 +9,14 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/
#include "pybind11/pybind11.h"
Expand Down Expand Up @@ -58,13 +58,13 @@ PYBIND11_MODULE(psfexPsf, mod) {

py::class_<PsfexPsf, std::shared_ptr<PsfexPsf>, lsst::afw::table::io::PersistableFacade<PsfexPsf>, lsst::meas::algorithms::ImagePsf> clsPsfexPsf(mod, "PsfexPsf");

clsPsfexPsf.def(py::init<lsst::meas::extensions::psfex::Psf const&, lsst::afw::geom::Point2D const &>(),
"psf"_a, "averagePosition"_a=lsst::afw::geom::Point2D());
clsPsfexPsf.def(py::init<lsst::meas::extensions::psfex::Psf const&, lsst::geom::Point2D const &>(),
"psf"_a, "averagePosition"_a=lsst::geom::Point2D());

clsPsfexPsf.def("clone", &PsfexPsf::clone);
clsPsfexPsf.def("getAveragePosition", &PsfexPsf::getAveragePosition);
clsPsfexPsf.def("getKernel", &PsfexPsf::getKernel,
"position"_a=lsst::afw::geom::Point2D(std::numeric_limits<double>::quiet_NaN()));
"position"_a=lsst::geom::Point2D(std::numeric_limits<double>::quiet_NaN()));
clsPsfexPsf.def("isPersistable", &PsfexPsf::isPersistable);
clsPsfexPsf.def("write", &PsfexPsf::write);
}
Expand Down