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

Tickets/dm 2961 - psfex port #1

Merged
merged 25 commits into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0ebadc7
Updated pex exceptions to format in DM-746.
natelust Jul 6, 2015
bc20bb8
Removed dependency on atlas
natelust Jul 6, 2015
039fe8b
update config to use slot strings
natelust Jul 17, 2015
aa9ff0d
Unset the VERSION variable from IFDEFINE in psfex.
natelust Jul 17, 2015
b2eac69
eupspkg build script created
natelust Jul 17, 2015
f74a977
updated compound fields to functor keys (DM-2535)
natelust Jul 17, 2015
3adea1e
Code to successfully run on LSST stack
natelust Jul 17, 2015
725772a
Fix for a dangling pointer issue.
natelust Jul 17, 2015
45837ce
Update test with appropriate LSST configs
natelust Jul 17, 2015
f271090
Updated table file with required dependancies
Jul 21, 2015
cc52389
Added meas_base in addition to algorithms
natelust Jul 27, 2015
15f55ec
Removed unneeded eupspkg script
natelust Jul 28, 2015
1ac6006
Inserted spacing for readability
natelust Jul 28, 2015
4586f37
Updated argument description
natelust Aug 11, 2015
252ca17
Assigned descriptive variable name to bool object
natelust Aug 11, 2015
618727c
[Added comments describing why a vector is created
natelust Aug 11, 2015
aecb8d6
Remove unneeded comments
natelust Aug 11, 2015
64aca56
Whitespace changes
natelust Aug 11, 2015
ea300d1
Remove unneeded comments
natelust Aug 11, 2015
d229054
Change config file to depend on fftw package
natelust Aug 11, 2015
9b6219b
Update explicit dependancies
natelust Aug 11, 2015
89ba518
Added comment on wrapping headers
natelust Aug 11, 2015
d8ec3d2
Removed un-needed variables from python script
natelust Aug 11, 2015
2ffdbe2
updated slot according to DM-3108
natelust Aug 11, 2015
6ff9fc8
Only import what is needed, not *, and formatting
natelust Aug 12, 2015
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
8 changes: 4 additions & 4 deletions config/default-lsst.psfex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ PSF_ACCURACY 0.01 # Accuracy to expect from PSF "pixel" values

#------------------------- Point source measurements -------------------------

CENTER_KEYS initial.centroid.sdss.x,initial.centroid.sdss.y # Catalogue parameters for source pre-centering
PHOTFLUX_KEY initial.flux.sinc # Catalogue parameter for photometric norm.
PHOTFLUXERR_KEY initial.flux.sinc.err # Catalogue parameter for photometric error
CENTER_KEYS slot_Centroid_x,slot_Centroid_y # Catalogue parameters for source pre-centering
PHOTFLUX_KEY slot_ApFlux_flux # Catalogue parameter for photometric norm.
PHOTFLUXERR_KEY slot_ApFlux_fluxErr # Catalogue parameter for photometric error

#----------------------------- PSF variability -------------------------------

PSFVAR_KEYS initial.centroid.sdss.x,initial.centroid.sdss.y # Catalogue or FITS (preceded by :) params
PSFVAR_KEYS slot_Centroid_x,slot_Centroid_y # Catalogue or FITS (preceded by :) params
PSFVAR_GROUPS 1,1 # Group tag for each context key
PSFVAR_DEGREES 2 # Polynom degree for each group

Expand Down
1 change: 1 addition & 0 deletions include/lsst/meas/extensions/psfex/Field.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct structtab; typedef struct structtab tabstruct;

#include "define.h"
#include "field.h"
#undef VERSION
}

namespace lsst { namespace meas { namespace extensions { namespace psfex {
Expand Down
1 change: 1 addition & 0 deletions include/lsst/meas/extensions/psfex/prefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct structtab; typedef struct structtab tabstruct;

#include "define.h"
#include "prefs.h"
#undef VERSION
}

namespace lsst { namespace meas { namespace extensions { namespace psfex {
Expand Down
5 changes: 3 additions & 2 deletions python/lsst/meas/extensions/psfex/psfexPsfDeterminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ def determinePsf(self, exposure, psfCandidateList, metadata=None, flagKey=None):

context = psfex.Context(prefs.getContextName(), prefs.getContextGroup(),
prefs.getGroupDeg(),
psfex.Context.REMOVEHIDDEN if False else psfex.Context.KEEPHIDDEN)
bool(psfex.Context.REMOVEHIDDEN if False
else psfex.Context.KEEPHIDDEN))
Copy link
Member Author

Choose a reason for hiding this comment

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

Two comments:

  • I think the original was more readable (when everything was on a single line). It's good practice to keep the ternary operator if always all on one line; use a regular if if it can't fit.
  • Is this a manual debugging switch (if False will always eval to False, of course)?

set = psfex.Set(context)
set.setVigSize(pixKernelSize, pixKernelSize)
set.setFwhm(2*np.sqrt(2*np.log(2))*np.median(sizes))
set.setRecentroid(self.config.recentroid)

catindex, ext = 0, 0
backnoise2 = afwMath.makeStatistics(mi.getImage(), afwMath.VARIANCECLIP).getValue()
ccd = afwCG.cast_Ccd(exposure.getDetector())
ccd = exposure.getDetector()
if ccd:
gain = np.mean(np.array([a.getElectronicParams().getGain() for a in ccd]))
else:
Expand Down
13 changes: 8 additions & 5 deletions src/PsfexPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern "C" {
}
#include "lsst/meas/extensions/psfex/PsfexPsf.h"
#include "lsst/meas/algorithms/KernelPsfFactory.h"
#include "lsst/afw/table/aggregates.h"

namespace lsst { namespace meas { namespace extensions { namespace psfex {

Expand Down Expand Up @@ -98,7 +99,7 @@ PsfexPsf::getKernel(afw::geom::Point2D position) const
double pos[MAXCONTEXT];
int const ndim = _context.size();
if (ndim != 2) { // we're only handling spatial variation for now
throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterException,
throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
str(boost::format("Only spatial variation (ndim == 2) is supported; saw %d")
% ndim));

Expand Down Expand Up @@ -188,7 +189,7 @@ PsfexPsf::_doComputeImage(afw::geom::Point2D const& position,
double pos[MAXCONTEXT];
int const ndim = _context.size();
if (ndim != 2) { // we're only handling spatial variation for now
throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterException,
throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
str(boost::format("Only spatial variation (ndim == 2) is supported; saw %d")
% ndim));

Expand Down Expand Up @@ -279,8 +280,9 @@ class PsfexPsfSchema1 {
_comp_size(schema.addField<int>("_comp_size", "Size of _comp array")),
_context_size(schema.addField<int>("_context_size", "Size of _context array")),
// Other scalars
averagePosition(schema.addField< afw::table::Point<double> >(
"averagePosition", "average position of stars used to make the PSF")),
//averagePosition(schema.addField< afw::table::Point<double> >(
// "averagePosition", "average position of stars used to make the PSF")),
averagePosition(afw::table::PointKey<double>::addFields(schema,"averagePosition","average position of stars used to make the PSF","pixels")),
_pixstep(schema.addField<float>("_pixstep", "oversampling", "pixel"))
{
;
Expand All @@ -297,7 +299,8 @@ class PsfexPsfSchema1 {
table::Key<int> _comp_size;
table::Key<int> _context_size;
// Other scalars
table::Key<table::Point<double> > averagePosition;
//table::Key<table::Point<double> > averagePosition;
table::PointKey<double> averagePosition;
table::Key<float> _pixstep;
};

Expand Down
6 changes: 4 additions & 2 deletions src/prefsImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ Prefs::Prefs(std::string const& filename, lsst::daf::base::PropertySet const* va
std::vector<char *> argkey(narg);
std::vector<char *> argval(narg);
std::vector<std::string> const names = values->paramNames();
std::vector<std::string> paramvalues(narg);

for (int i = 0; i != narg; ++i) {
std::string const& name = names[i];
argkey[i] = const_cast<char *>(name.c_str());
argval[i] = const_cast<char *>(values->getAsString(name).c_str());
paramvalues[i] = values->getAsString(name);
argval[i] = const_cast<char *>(paramvalues[i].c_str());
}

readprefs(cfilename, &argkey[0], &argval[0], narg);
Expand Down Expand Up @@ -56,7 +58,7 @@ Prefs::setCommandLine(std::vector<std::string> const& argv)
void
Prefs::addCatalog(std::string const& filename) {
if (prefs.ncat >= MAXFILE) {
throw LSST_EXCEPT(lsst::pex::exceptions::LengthErrorException, "Too many input catalogues");
throw LSST_EXCEPT(lsst::pex::exceptions::LengthError, "Too many input catalogues");
}
_catalogs.push_back(filename);
prefs.incat_name[prefs.ncat++] = const_cast<char *>((_catalogs.end() - 1)->c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/psfImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void Sample::setVig(ndarray::Array<float,2,2> const& img)
int const w = img.getSize<0>(), h = img.getSize<1>();

if (_vigsize[0]*_vigsize[1] != w*h) {
throw LSST_EXCEPT(lsst::pex::exceptions::LengthErrorException,
throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
str(boost::format("Expected %dx%d array, but was passed %dx%d")
% _vigsize[0] % _vigsize[1] % w % h));
}
Expand Down Expand Up @@ -146,7 +146,7 @@ Psf::build(double x, double y,
}

psf_build(impl, &pos[0]);
}
}

RETURN_IMAGE_FIELD(Psf::getLoc, loc, impl->size)
RETURN_IMAGE_FIELD(Psf::getResi, resi, impl->size)
Expand Down
2 changes: 1 addition & 1 deletion src/psfexAdaptors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ makeit(std::vector<boost::shared_ptr<Field> > &fields_,
)
{
if (sets.size() > MAXFILE) {
throw LSST_EXCEPT(lsst::pex::exceptions::LengthErrorException,
throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
(boost::format("Too many sets: %d") % sets.size()).str());
}

Expand Down
49 changes: 15 additions & 34 deletions tests/testPsfexPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import lsst.meas.algorithms.utils as maUtils
import lsst.afw.cameraGeom as cameraGeom
import lsst.meas.extensions.psfex.psfexPsfDeterminer as psfexPsfDeterminer
from lsst.meas.base import SingleFrameMeasurementTask
from lsst.meas.algorithms.detection import SourceDetectionTask

try:
type(verbose)
Expand Down Expand Up @@ -84,32 +86,21 @@ class SpatialModelPsfTestCase(unittest.TestCase):
@staticmethod
def measure(footprintSet, exposure):
"""Measure a set of Footprints, returning a SourceCatalog"""
config = measAlg.SourceMeasurementConfig()
config.prefix = "initial."
config.algorithms.names = ["flags.pixel", "flux.psf", "flux.sinc", "flux.gaussian", "shape.sdss"]
config.centroider.name = "centroid.sdss"
config.algorithms["flux.naive"].radius = 3.0
config.slots.centroid = "initial.centroid.sdss"
config.slots.psfFlux = "initial.flux.psf"
config.slots.apFlux = "initial.flux.sinc"
config.slots.modelFlux = None
config.slots.instFlux = None
config.slots.calibFlux = None
config.slots.shape = "initial.shape.sdss"

config = SingleFrameMeasurementTask.ConfigClass()
config.slots.apFlux = 'base_CircularApertureFlux_3'
schema = afwTable.SourceTable.makeMinimalSchema()
measureSources = config.makeMeasureSources(schema)

measureSources = SingleFrameMeasurementTask(schema,config=config)

tab = afwTable.SourceTable.make(schema)
catalog = afwTable.SourceCatalog(schema)
config.slots.setupTable(catalog.table)

if display:
ds9.mtv(exposure, title="Original", frame=0)

footprintSet.makeSources(catalog)

for i, source in enumerate(catalog):
measureSources.applyWithPeak(source, exposure)

measureSources.run(catalog,exposure)
return catalog

def setUp(self):
Expand All @@ -134,14 +125,6 @@ def setUp(self):
wcs = afwImage.makeWcs(crval, afwGeom.PointD(0, 0), 1.0, 0, 0, 1.0)
self.exposure.setWcs(wcs)

ccd = cameraGeom.Ccd(cameraGeom.Id(1))
ccd.addAmp(cameraGeom.Amp(cameraGeom.Id(0),
afwGeom.BoxI(afwGeom.PointI(0,0), self.exposure.getDimensions()),
afwGeom.BoxI(afwGeom.PointI(0,0), afwGeom.ExtentI(0,0)),
afwGeom.BoxI(afwGeom.PointI(0,0), self.exposure.getDimensions()),
cameraGeom.ElectronicParams(1.0, 100.0, 65535)))
self.exposure.setDetector(ccd)
self.exposure.getDetector().setDistortion(None)
#
# Make a kernel with the exactly correct basis functions. Useful for debugging
#
Expand Down Expand Up @@ -218,6 +201,7 @@ def setUp(self):
self.footprintSet = afwDetection.FootprintSet(self.mi, afwDetection.Threshold(100), "DETECTED")

self.catalog = SpatialModelPsfTestCase.measure(self.footprintSet, self.exposure)
#self.catalog = SpatialModelPsfTestCase.measure(self.exposure)

for source in self.catalog:
try:
Expand All @@ -241,13 +225,12 @@ def setupDeterminer(exposure):
starSelectorFactory = measAlg.starSelectorRegistry["objectSize"]
starSelectorConfig = starSelectorFactory.ConfigClass()

starSelectorConfig.sourceFluxField = "initial.flux.gaussian"
starSelectorConfig.badFlags = ["initial.flags.pixel.edge",
"initial.flags.pixel.interpolated.center",
"initial.flags.pixel.saturated.center",
"initial.flags.pixel.cr.center",
starSelectorConfig.sourceFluxField = "base_GaussianFlux_flux"
starSelectorConfig.badFlags = ["base_PixelFlags_flag_edge",
"base_PixelFlags_flag_interpolatedCenter",
"base_PixelFlags_flag_saturatedCenter",
"base_PixelFlags_flag_crCenter",
]
starSelectorConfig.widthStdAllowed = 0.5

starSelector = starSelectorFactory(starSelectorConfig)

Expand All @@ -270,7 +253,6 @@ def subtractStars(self, exposure, catalog, chi_lim=-1):
mi, psf = exposure.getMaskedImage(), exposure.getPsf()

subtracted = mi.Factory(mi, True)

for s in catalog:
xc, yc = s.getX(), s.getY()
bbox = subtracted.getBBox(afwImage.PARENT)
Expand All @@ -279,7 +261,6 @@ def subtractStars(self, exposure, catalog, chi_lim=-1):
measAlg.subtractPsf(psf, subtracted, xc, yc)
except:
pass

chi = subtracted.Factory(subtracted, True)
var = subtracted.getVariance()
np.sqrt(var.getArray(), var.getArray()) # inplace sqrt
Expand Down
4 changes: 2 additions & 2 deletions ups/meas_extensions_psfex.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import lsst.sconsUtils

dependencies = {
"required": [],
"buildRequired": ["afw", "boost_test", "daf_base", "meas_algorithms",
"swig", "utils", "psfex"],
"buildRequired": ["afw", "boost_test", "daf_base", "fftw_float",
"meas_base","meas_algorithms","swig", "utils", "psfex"],
}

config = lsst.sconsUtils.Configuration(
Expand Down
2 changes: 1 addition & 1 deletion ups/meas_extensions_psfex.table
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setupRequired(meas_base)
setupRequired(meas_algorithms)
setupRequired(psfex)
Copy link
Member

Choose a reason for hiding this comment

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

Either delete it or uncomment it please.

Copy link
Contributor

Choose a reason for hiding this comment

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

Strange, I don't have that on my local copy. I wonder If I forgot to push that change

#setupRequired(pyfits)

envPrepend(PATH, ${PRODUCT_DIR}/bin)

Expand Down