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-15244: Change fluxSigma to fluxErr and similarly for apCorr and covariances #65

Merged
merged 1 commit into from
Aug 7, 2018
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
4 changes: 2 additions & 2 deletions include/lsst/meas/modelfit/CModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ struct CModelStageResult {
PTR(OptimizerObjective) objfunc; ///< Objective class used by the optimizer
PTR(UnitTransformedLikelihood) likelihood; ///< Object used to evaluate models and compare to data.
Scalar flux; ///< Flux measured from just this stage fit.
Scalar fluxSigma; ///< Flux uncertainty from just this stage fit.
Scalar fluxErr; ///< Flux uncertainty from just this stage fit.
Scalar fluxInner; ///< Flux measured strictly within the fit region (no extrapolation).
Scalar objective; ///< Value of the objective function at the best fit point: chisq/2 - ln(prior)
Scalar time; ///< Time spent in this fit in seconds.
Expand Down Expand Up @@ -357,7 +357,7 @@ struct CModelResult {
CModelResult();

Scalar flux; ///< Flux from the final linear fit
Scalar fluxSigma; ///< Flux uncertainty from the final linear fit
Scalar fluxErr; ///< Flux uncertainty from the final linear fit
Scalar fluxInner; ///< Flux measured strictly within the fit region (no extrapolation).
Scalar fracDev; ///< Fraction of flux from the final linear fit in the de Vaucouleur component
/// (always between 0 and 1).
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/meas/modelfit/cmodel/cmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static PyCModelStageResult declareCModelStageResult(py::module &mod) {
cls.def_readonly("objfunc", &CModelStageResult::objfunc);
cls.def_readonly("likelihood", &CModelStageResult::likelihood);
cls.def_readonly("flux", &CModelStageResult::flux);
cls.def_readonly("fluxSigma", &CModelStageResult::fluxSigma);
cls.def_readonly("fluxErr", &CModelStageResult::fluxErr);
cls.def_readonly("fluxInner", &CModelStageResult::fluxInner);
cls.def_readonly("objective", &CModelStageResult::objective);
cls.def_readonly("time", &CModelStageResult::time);
Expand Down Expand Up @@ -156,7 +156,7 @@ static PyCModelResult declareCModelResult(py::module &mod) {
// they should only be set by the C++ algorithm code that uses
// this class to communicate its outputs.
cls.def_readonly("flux", &CModelResult::flux);
cls.def_readonly("fluxSigma", &CModelResult::fluxSigma);
cls.def_readonly("fluxErr", &CModelResult::fluxErr);
cls.def_readonly("fluxInner", &CModelResult::fluxInner);
cls.def_readonly("fracDev", &CModelResult::fracDev);
cls.def_readonly("objective", &CModelResult::objective);
Expand Down
26 changes: 13 additions & 13 deletions src/CModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ PTR(Prior) CModelStageControl::getPrior() const {

CModelStageResult::CModelStageResult() :
flux(std::numeric_limits<Scalar>::quiet_NaN()),
fluxSigma(std::numeric_limits<Scalar>::quiet_NaN()),
fluxErr(std::numeric_limits<Scalar>::quiet_NaN()),
fluxInner(std::numeric_limits<Scalar>::quiet_NaN()),
objective(std::numeric_limits<Scalar>::quiet_NaN()),
ellipse(std::numeric_limits<Scalar>::quiet_NaN(), std::numeric_limits<Scalar>::quiet_NaN(),
Expand All @@ -109,7 +109,7 @@ CModelStageResult::CModelStageResult() :

CModelResult::CModelResult() :
flux(std::numeric_limits<Scalar>::quiet_NaN()),
fluxSigma(std::numeric_limits<Scalar>::quiet_NaN()),
fluxErr(std::numeric_limits<Scalar>::quiet_NaN()),
fluxInner(std::numeric_limits<Scalar>::quiet_NaN()),
fracDev(std::numeric_limits<Scalar>::quiet_NaN()),
objective(std::numeric_limits<Scalar>::quiet_NaN())
Expand Down Expand Up @@ -141,9 +141,9 @@ struct CModelStageKeys {
"count"
)
),
fluxSigma(
fluxErr(
schema.addField<meas::base::FluxErrElement>(
schema.join(prefix, "fluxSigma"),
schema.join(prefix, "fluxErr"),
"flux uncertainty from the " + stage + " fit",
"count"
)
Expand Down Expand Up @@ -226,7 +226,7 @@ struct CModelStageKeys {
std::string const & prefix
) :
flux(schema[prefix]["flux"]),
fluxSigma(schema[prefix]["fluxSigma"]),
fluxErr(schema[prefix]["fluxErr"]),
fluxFlag(schema[prefix]["flag"]),
nonlinear(schema[prefix]["nonlinear"]),
fixed(schema[prefix]["fixed"])
Expand All @@ -246,7 +246,7 @@ struct CModelStageKeys {

void copyResultToRecord(CModelStageResult const & result, afw::table::BaseRecord & record) {
record.set(flux, result.flux);
record.set(fluxSigma, result.fluxSigma);
record.set(fluxErr, result.fluxErr);
record.set(fluxFlag, result.flags[CModelStageResult::FAILED]);
record.set(fluxInner, result.fluxInner);
if (objective.isValid()) {
Expand Down Expand Up @@ -294,7 +294,7 @@ struct CModelStageKeys {
}

afw::table::Key<meas::base::Flux> flux;
afw::table::Key<meas::base::FluxErrElement> fluxSigma;
afw::table::Key<meas::base::FluxErrElement> fluxErr;
afw::table::Key<afw::table::Flag> fluxFlag;
afw::table::Key<Scalar> fluxInner;
afw::table::QuadrupoleKey ellipse;
Expand Down Expand Up @@ -330,9 +330,9 @@ struct CModelKeys {
"flux from the final cmodel fit"
)
),
fluxSigma(
fluxErr(
schema.addField<meas::base::FluxErrElement>(
schema.join(prefix, "fluxSigma"),
schema.join(prefix, "fluxErr"),
"flux uncertainty from the final cmodel fit"
)
),
Expand Down Expand Up @@ -456,7 +456,7 @@ struct CModelKeys {
exp.copyResultToRecord(result.exp, record);
dev.copyResultToRecord(result.dev, record);
record.set(flux, result.flux);
record.set(fluxSigma, result.fluxSigma);
record.set(fluxErr, result.fluxErr);
if (ellipse.isValid()) {
double u = 1.0 - result.fracDev;
double v = result.fracDev;
Expand Down Expand Up @@ -514,7 +514,7 @@ struct CModelKeys {
CModelStageKeys dev;
shapelet::MultiShapeletFunctionKey psf;
afw::table::Key<meas::base::Flux> flux;
afw::table::Key<meas::base::FluxErrElement> fluxSigma;
afw::table::Key<meas::base::FluxErrElement> fluxErr;
afw::table::Key<afw::table::Flag> fluxFlag;
afw::table::Key<Scalar> fluxInner;
afw::table::Key<Scalar> fracDev;
Expand Down Expand Up @@ -696,7 +696,7 @@ class CModelStageImpl {
// flux is just the amplitude converted from fitSys to measSys
result.flux = data.amplitudes[0] * data.fitSysToMeasSys.flux;
result.fluxInner = sums.fluxInner;
result.fluxSigma = std::sqrt(sums.fluxVar)*result.flux/result.fluxInner;
result.fluxErr = std::sqrt(sums.fluxVar)*result.flux/result.fluxInner;
// to compute the ellipse, we need to first read the nonlinear parameters into the workspace
// ellipse vector, then transform from fitSys to measSys.
model->writeEllipses(data.nonlinear.begin(), data.fixed.begin(), ellipses.begin());
Expand Down Expand Up @@ -910,7 +910,7 @@ class CModelAlgorithm::Impl {
ndarray::asEigenMatrix(model) = ndarray::asEigenMatrix(modelMatrix) * amplitudes.cast<Pixel>();
WeightSums sums(model, unweightedData, likelihood.getVariance());
result.fluxInner = sums.fluxInner;
result.fluxSigma = std::sqrt(sums.fluxVar)*result.flux/result.fluxInner;
result.fluxErr = std::sqrt(sums.fluxVar)*result.flux/result.fluxInner;
result.flags[CModelResult::FAILED] = false;
result.fracDev = amplitudes[1] / amplitudes.sum();
result.objective = tg.evaluateLog()(amplitudes);
Expand Down
14 changes: 7 additions & 7 deletions tests/test_cModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def computePsfFlux(centroid, exposure):
record = table.makeRecord()
record.set(pointKey, centroid)
algorithm.measure(record, exposure)
return record.get("base_PsfFlux_flux"), record.get("base_PsfFlux_fluxSigma")
return record.get("base_PsfFlux_flux"), record.get("base_PsfFlux_fluxErr")


class CModelTestCase(lsst.utils.tests.TestCase):
Expand Down Expand Up @@ -104,22 +104,22 @@ def testNoNoise(self):
var = 1E-16
self.exposure.getMaskedImage().getVariance().getArray()[:, :] = var
psfImage = self.exposure.getPsf().computeKernelImage(self.xyPosition).getArray()
expectedFluxSigma = var**0.5 * (psfImage**2).sum()**(-0.5)
expectedFluxErr = var**0.5 * (psfImage**2).sum()**(-0.5)
result = algorithm.apply(
self.exposure, makeMultiShapeletCircularGaussian(self.psfSigma),
self.xyPosition, self.exposure.getPsf().computeShape()
)
self.assertFalse(result.initial.flags[result.FAILED])
self.assertFloatsAlmostEqual(result.initial.flux, self.trueFlux, rtol=0.01)
self.assertFloatsAlmostEqual(result.initial.fluxSigma, expectedFluxSigma, rtol=0.01)
self.assertFloatsAlmostEqual(result.initial.fluxErr, expectedFluxErr, rtol=0.01)
self.assertLess(result.initial.ellipse.getDeterminantRadius(), 0.2)
self.assertFalse(result.exp.flags[result.FAILED])
self.assertFloatsAlmostEqual(result.exp.flux, self.trueFlux, rtol=0.01)
self.assertFloatsAlmostEqual(result.exp.fluxSigma, expectedFluxSigma, rtol=0.01)
self.assertFloatsAlmostEqual(result.exp.fluxErr, expectedFluxErr, rtol=0.01)
self.assertLess(result.exp.ellipse.getDeterminantRadius(), 0.2)
self.assertFalse(result.dev.flags[result.FAILED])
self.assertFloatsAlmostEqual(result.dev.flux, self.trueFlux, rtol=0.01)
self.assertFloatsAlmostEqual(result.dev.fluxSigma, expectedFluxSigma, rtol=0.01)
self.assertFloatsAlmostEqual(result.dev.fluxErr, expectedFluxErr, rtol=0.01)
self.assertLess(result.dev.ellipse.getDeterminantRadius(), 0.2)
self.assertFalse(result.flags[result.FAILED])
self.assertFloatsAlmostEqual(result.flux, self.trueFlux, rtol=0.01)
Expand All @@ -141,9 +141,9 @@ def testVsPsfFlux(self):
exposure, makeMultiShapeletCircularGaussian(self.psfSigma),
self.xyPosition, self.exposure.getPsf().computeShape()
)
psfFlux, psfFluxSigma = computePsfFlux(self.xyPosition, exposure)
psfFlux, psfFluxErr = computePsfFlux(self.xyPosition, exposure)
self.assertFloatsAlmostEqual(psfFlux, cmodel.flux, rtol=0.1/fluxFactor**0.5)
self.assertFloatsAlmostEqual(psfFluxSigma, cmodel.fluxSigma, rtol=0.1/fluxFactor**0.5)
self.assertFloatsAlmostEqual(psfFluxErr, cmodel.fluxErr, rtol=0.1/fluxFactor**0.5)


class TestMemory(lsst.utils.tests.MemoryTestCase):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cModelPlugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def checkOutputs(self, measCat, truthCat=None):
self.assertFalse(measRecord.get("modelfit_CModel_dev_flag"))
self.assertFalse(measRecord.get("modelfit_CModel_flag"))
self.assertFloatsAlmostEqual(measRecord.get("modelfit_CModel_flux"), trueFlux, rtol=0.5)
self.assertGreater(measRecord.get("modelfit_CModel_fluxSigma"), 0.0)
self.assertGreater(measRecord.get("modelfit_CModel_fluxErr"), 0.0)
self.assertFloatsAlmostEqual(measRecord.get("modelfit_CModel_initial_flux"), trueFlux, rtol=0.5)
self.assertGreater(measRecord.get("modelfit_CModel_initial_fluxSigma"), 0.0)
self.assertGreater(measRecord.get("modelfit_CModel_initial_fluxErr"), 0.0)
self.assertFloatsAlmostEqual(measRecord.get("modelfit_CModel_exp_flux"), trueFlux, rtol=0.5)
self.assertGreater(measRecord.get("modelfit_CModel_exp_fluxSigma"), 0.0)
self.assertGreater(measRecord.get("modelfit_CModel_exp_fluxErr"), 0.0)
self.assertFloatsAlmostEqual(measRecord.get("modelfit_CModel_dev_flux"), trueFlux, rtol=0.5)
self.assertGreater(measRecord.get("modelfit_CModel_dev_fluxSigma"), 0.0)
self.assertGreater(measRecord.get("modelfit_CModel_dev_fluxErr"), 0.0)

def testPlugins(self):
"""Test that the plugin for single-frame measurement works, then use those outputs to test
Expand Down