Skip to content

Commit

Permalink
Merge pull request #17 from lsst/tickets/DM-5642
Browse files Browse the repository at this point in the history
Use and enforce Astropy compliant units
  • Loading branch information
Pim Schellart authored and Pim Schellart committed May 10, 2016
2 parents 3e4671a + 14dcda9 commit ad2afe7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions include/lsst/ip/diffim/DipoleAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ class NaiveDipoleFlux : public DipoleFluxAlgorithm {

NaiveDipoleFlux(Control const & ctrl, std::string const & name, afw::table::Schema & schema) :
DipoleFluxAlgorithm(ctrl, name, schema, "raw flux counts"),
_numPositiveKey(schema.addField<int>(name+"_npos", "number of positive pixels", "dn")),
_numNegativeKey(schema.addField<int>(name+"_nneg", "number of negative pixels", "dn"))
_numPositiveKey(schema.addField<int>(name+"_npos", "number of positive pixels", "count")),
_numNegativeKey(schema.addField<int>(name+"_nneg", "number of negative pixels", "count"))
{
}

Expand Down
7 changes: 4 additions & 3 deletions include/lsst/ip/diffim/ImageStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@

#include <limits>
#include <memory>
#include <cmath>

#include "lsst/afw/image.h"
#include "lsst/pex/policy/Policy.h"
#include "lsst/pex/logging/Trace.h"
#include "lsst/utils/ieee.h"

namespace lsst {
namespace ip {
Expand Down Expand Up @@ -108,15 +109,15 @@ namespace diffim {
ptr != end; ++ptr) {
if (!((*ptr).mask() & _bpMask)) {
double const ivar = 1. / (*ptr).variance();
if (lsst::utils::lsst_isfinite(ivar)) {
if (std::isfinite(ivar)) {
_xsum += (*ptr).image() * sqrt(ivar);
_x2sum += (*ptr).image() * (*ptr).image() * ivar;
_npix += 1;
}
}
}
}
if ((!lsst::utils::lsst_isfinite(_xsum)) || (!lsst::utils::lsst_isfinite(_x2sum))) {
if ((!std::isfinite(_xsum)) || (!std::isfinite(_x2sum))) {
throw LSST_EXCEPT(pexExcept::Exception,
"Nan/Inf in ImageStatistics.apply");
}
Expand Down
12 changes: 6 additions & 6 deletions python/lsst/ip/diffim/dipoleFitTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,37 +843,37 @@ def _setupSchema(self, config, name, schema, metadata):
for pos_neg in ['pos', 'neg']:

key = schema.addField(
schema.join(name, pos_neg, "flux"), type=float, units="dn",
schema.join(name, pos_neg, "flux"), type=float, units="count",
doc="Dipole {0} lobe flux".format(pos_neg))
setattr(self, ''.join((pos_neg, 'FluxKey')), key)

key = schema.addField(
schema.join(name, pos_neg, "fluxSigma"), type=float, units="pixels",
schema.join(name, pos_neg, "fluxSigma"), type=float, units="pixel",
doc="1-sigma uncertainty for {0} dipole flux".format(pos_neg))
setattr(self, ''.join((pos_neg, 'FluxSigmaKey')), key)

for x_y in ['x', 'y']:
key = schema.addField(
schema.join(name, pos_neg, "centroid", x_y), type=float, units="pixels",
schema.join(name, pos_neg, "centroid", x_y), type=float, units="pixel",
doc="Dipole {0} lobe centroid".format(pos_neg))
setattr(self, ''.join((pos_neg, 'CentroidKey', x_y.upper())), key)

for x_y in ['x', 'y']:
key = schema.addField(
schema.join(name, "centroid", x_y), type=float, units="pixels",
schema.join(name, "centroid", x_y), type=float, units="pixel",
doc="Dipole centroid")
setattr(self, ''.join(('centroidKey', x_y.upper())), key)

self.fluxKey = schema.addField(
schema.join(name, "flux"), type=float, units="dn",
schema.join(name, "flux"), type=float, units="count",
doc="Dipole overall flux")

self.orientationKey = schema.addField(
schema.join(name, "orientation"), type=float, units="deg",
doc="Dipole orientation")

self.separationKey = schema.addField(
schema.join(name, "separation"), type=float, units="pixels",
schema.join(name, "separation"), type=float, units="pixel",
doc="Pixel separation between positive and negative lobes of dipole")

self.chi2dofKey = schema.addField(
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/ip/diffim/kernelCandidateQa.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def makeMetricMap(self):
("Anderson-Darling significance levels for the Normal distribution", 5),
("Reduced chi^2 of the residual.", "likelihood"),
("Mean squared error in diffim : Variance + Bias**2",),
("Centroid in X for this Kernel", "pixels"),
("Centroid in Y for this Kernel", "pixels"),
("Standard deviation in X for this Kernel", "pixels"),
("Standard deviation in Y for this Kernel", "pixels"),
("Centroid in X for this Kernel", "pixel"),
("Centroid in Y for this Kernel", "pixel"),
("Standard deviation in X for this Kernel", "pixel"),
("Standard deviation in Y for this Kernel", "pixel"),
("Id for this KernelCandidate",)]
metricMap = {}
for name, mtype, comment in zip(nameList, typeList, commentList):
Expand Down
2 changes: 1 addition & 1 deletion tests/KernelCandidateAndSolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DiffimTestCases(unittest.TestCase):

def setUp(self):
schema = afwTable.SourceTable.makeMinimalSchema()
afwTable.Point2DKey.addFields(schema, "Centroid", "input centroid", "pixels")
afwTable.Point2DKey.addFields(schema, "Centroid", "input centroid", "pixel")
schema.addField("PsfFlux_flux", type=float)
schema.addField("PsfFlux_fluxSigma", type=float)
schema.addField("PsfFlux_flag", type="Flag")
Expand Down
Binary file modified tests/compareToHotpants/scienceMI.fits
Binary file not shown.
Binary file modified tests/compareToHotpants/templateMI.fits
Binary file not shown.

0 comments on commit ad2afe7

Please sign in to comment.