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

U/pgee/dm 980b #1

Merged
merged 2 commits into from
Mar 1, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
435 changes: 289 additions & 146 deletions include/lsst/ip/diffim/DipoleAlgorithms.h

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions python/lsst/ip/diffim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
from dipoleMeasurement import *
from diffimTools import *
from kernelCandidateQa import *
from lsst.meas.base import wrapSimpleAlgorithm

# automatically register ip_diffim Algorithms
import lsst.meas.algorithms
lsst.meas.algorithms.AlgorithmRegistry.register("centroid.dipole.naive", NaiveDipoleCentroidControl)
lsst.meas.algorithms.AlgorithmRegistry.register("flux.dipole.naive", NaiveDipoleFluxControl)
lsst.meas.algorithms.AlgorithmRegistry.register("flux.dipole.psf", PsfDipoleFluxControl)
wrapSimpleAlgorithm(NaiveDipoleCentroid, Control=DipoleCentroidControl, executionOrder=0.0)
wrapSimpleAlgorithm(NaiveDipoleFlux, Control=DipoleFluxControl, executionOrder=2.0)
wrapSimpleAlgorithm(PsfDipoleFlux, Control=PsfDipoleFluxControl, executionOrder=2.0)

del lsst # cleanup namespace
31 changes: 10 additions & 21 deletions python/lsst/ip/diffim/diffimLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace boost {
#include "lsst/afw/math.h"
#include "lsst/afw/geom.h"
#include "lsst/afw/image.h"
#include "lsst/afw/table/Source.h"
#include "lsst/afw/table.h"
#include "lsst/afw/cameraGeom.h"
#include "lsst/meas/algorithms.h"
#include "lsst/meas/base.h"

#include "lsst/ip/diffim.h"
%}
Expand All @@ -76,7 +76,6 @@ namespace boost {

/* Eigen / numpy. Info comes from $AFW_DIR/include/lsst/afw/numpyTypemaps.h */
%{
#define PY_ARRAY_UNIQUE_SYMBOL LSST_IP_DIFFIM_NUMPY_ARRAY_API
#include "numpy/arrayobject.h"
#include "ndarray/swig.h"
#include "ndarray/swig/eigen.h"
Expand All @@ -98,12 +97,17 @@ namespace boost {

%include "lsst/daf/base/persistenceMacros.i"
%include "lsst/pex/config.h" // LSST_CONTROL_FIELD.
%include "lsst/meas/base/constants.h"
%include "lsst/meas/base/exceptions.i"
%include "lsst/meas/base/utilities.i"
%include "lsst/meas/base/Algorithm.h"

%import "lsst/afw/image/imageLib.i"
%import "lsst/afw/math/mathLib.i"
%import "lsst/afw/math/objectVectors.i"
%import "lsst/afw/detection/detectionLib.i"
%import "lsst/meas/algorithms/algorithmsLib.i"

%include "lsst/afw/image/Exposure.h"
%include "lsst/afw/table/Source.h"
%lsst_exceptions();


Expand Down Expand Up @@ -269,23 +273,8 @@ lsst::afw::image::Image<PIXTYPE>

%include "lsst/ip/diffim/BasisLists.h"

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

%{
#include "lsst/ip/diffim/DipoleAlgorithms.h"
%}

%shared_ptr(lsst::ip::diffim::DipoleCentroidControl)
%shared_ptr(lsst::ip::diffim::DipoleFluxControl)
%shared_ptr(lsst::ip::diffim::DipoleCentroidAlgorithm)
%shared_ptr(lsst::ip::diffim::DipoleCentroidControl)
%shared_ptr(lsst::ip::diffim::DipoleFluxAlgorithm)
%shared_ptr(lsst::ip::diffim::DipoleFluxControl)
%shared_ptr(lsst::ip::diffim::NaiveDipoleCentroidControl)
%shared_ptr(lsst::ip::diffim::NaiveDipoleFluxControl)
%shared_ptr(lsst::ip::diffim::PsfDipoleFluxControl)

%include "lsst/ip/diffim/DipoleAlgorithms.h"
%include "lsst/ip/diffim/dipole.i"
Copy link
Author

Choose a reason for hiding this comment

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

There seems to be significant duplicated code between dipole.i and this file. Is it worth putting these few lines in a new file if it also requires a bunch of boilerplate as well?


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

Expand Down
102 changes: 102 additions & 0 deletions python/lsst/ip/diffim/dipole.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// -*- lsst-c++ -*-
/*
* LSST Data Management System
* Copyright 2008-2013 LSST Corporation.
Copy link
Author

Choose a reason for hiding this comment

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

copyleft is updated in other files. Might as well do it here as well.

*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* 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,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/

%define testlib_DOCSTRING
"
Basic routines to talk to test::foo:bar classes
"
%enddef

%feature("autodoc", "1");
%module(package="lsst.meas.base", docstring=testlib_DOCSTRING) testlib

%{
#include "lsst/pex/logging.h"
#include "lsst/afw/geom.h"
#include "lsst/afw/math.h"
#include "lsst/afw/table.h"
#include "lsst/afw/cameraGeom.h"
#include "lsst/afw/image.h"
#include "lsst/afw/detection.h"
#include "lsst/meas/base.h"
#define PY_ARRAY_UNIQUE_SYMBOL LSST_MEAS_BASE_NUMPY_ARRAY_API
#include "numpy/arrayobject.h"
#include "ndarray/swig.h"
#include "ndarray/swig/eigen.h"
%}

%init %{
import_array();
%}

%include "lsst/p_lsstSwig.i"
%include "lsst/base.h"
%include "std_complex.i"

%include "ndarray.i"

%declareNumPyConverters(lsst::meas::base::CentroidCov);

%lsst_exceptions();

%include "std_vector.i"
%import "lsst/afw/geom/geomLib.i"
%import "lsst/afw/table/tableLib.i"
%import "lsst/afw/image/imageLib.i"
%import "lsst/afw/detection/detectionLib.i"
%import "lsst/pex/config.h"
%import "lsst/afw/image/Exposure.h"

%include "lsst/meas/base/constants.h"
%include "lsst/meas/base/exceptions.i"
%include "lsst/meas/base/utilities.i"
%include "lsst/meas/base/Algorithm.h"

%{
#include "lsst/ip/diffim/DipoleAlgorithms.h"
%}

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

%feature("abstract") lsst::ip::diffim::DipoleCentroidAlgorithm;
%feature("abstract") lsst::ip::diffim::DipoleFluxAlgorithm;
%feature("notabstract") lsst::ip::diffim::PsfDipoleFlux;
%feature("notabstract") lsst::ip::diffim::NaiveDipoleFlux;
%feature("notabstract") lsst::ip::diffim::NaiveDipoleCentroid;


%shared_ptr(lsst::ip::diffim::DipoleCentroidControl)
%shared_ptr(lsst::ip::diffim::DipoleFluxControl)
%shared_ptr(lsst::ip::diffim::DipoleCentroidAlgorithm)
%shared_ptr(lsst::ip::diffim::DipoleCentroidControl)
%shared_ptr(lsst::ip::diffim::DipoleFluxAlgorithm)
%shared_ptr(lsst::ip::diffim::DipoleFluxControl)
%shared_ptr(lsst::ip::diffim::NaiveDipoleCentroidControl)
%shared_ptr(lsst::ip::diffim::NaiveDipoleFluxControl)
%shared_ptr(lsst::ip::diffim::PsfDipoleFluxControl)
%shared_ptr(lsst::ip::diffim::NaiveDipoleCentroid)
%shared_ptr(lsst::ip::diffim::PsfDipoleFlux)
%shared_ptr(lsst::ip::diffim::NaiveDipoleFlux)

%include "lsst/ip/diffim/DipoleAlgorithms.h"

72 changes: 40 additions & 32 deletions python/lsst/ip/diffim/dipoleMeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import lsst.pipe.base as pipeBase
import lsst.pex.logging as pexLog
import lsst.pex.config as pexConfig
import lsst.meas.algorithms as measAlg
import lsst.meas.deblender.baseline as deblendBaseline
from lsst.meas.algorithms import SourceMeasurementTask, SourceMeasurementConfig
from lsst.meas.base import SingleFrameMeasurementTask, SingleFrameMeasurementConfig
import lsst.afw.display.ds9 as ds9

__all__ = ("DipoleMeasurementConfig", "DipoleMeasurementTask", "DipoleAnalysis", "DipoleDeblender")


class DipoleClassificationConfig(pexConfig.Config):
"""!Classification of detected diaSources as dipole or not"""
Expand All @@ -43,17 +44,19 @@ class DipoleClassificationConfig(pexConfig.Config):
dtype = float, default = 0.65
)

class DipoleMeasurementConfig(SourceMeasurementConfig):
class DipoleMeasurementConfig(SingleFrameMeasurementConfig):
"""!Measurement of detected diaSources as dipoles"""
classification = pexConfig.ConfigField(
dtype=DipoleClassificationConfig,
doc="Dipole classification config"
)

def setDefaults(self):
self.algorithms.names.add("centroid.dipole.naive")
self.algorithms.names.add("flux.dipole.naive")
self.algorithms.names.add("flux.dipole.psf")
return
self.plugins = ["ipdiffim_NaiveDipoleCentroid",
"ipdiffim_NaiveDipoleFlux",
"ipdiffim_PsfDipoleFlux"
]
self.doReplaceWithNoise = False

## \addtogroup LSST_task_documentation
Expand All @@ -62,7 +65,7 @@ def setDefaults(self):
## \ref DipoleMeasurementTask_ "DipoleMeasurementTask"
## \copybrief DipoleMeasurementTask
## \}
class DipoleMeasurementTask(SourceMeasurementTask):
class DipoleMeasurementTask(SingleFrameMeasurementTask):
"""!
\anchor DipoleMeasurementTask_

Expand Down Expand Up @@ -263,7 +266,7 @@ def DebugInfo(name):
"""
ConfigClass = DipoleMeasurementConfig
_DefaultName = "dipoleMeasurement"
_ClassificationFlag = "classification.dipole"
_ClassificationFlag = "classification_dipole"

def __init__(self, schema, algMetadata=None, **kwds):
"""!Create the Task, and add Task-specific fields to the provided measurement table schema.
Expand All @@ -273,7 +276,7 @@ def __init__(self, schema, algMetadata=None, **kwds):
metadata by algorithms (e.g. radii for aperture photometry).
@param **kwds Passed to Task.__init__.
"""
SourceMeasurementTask.__init__(self, schema, algMetadata, **kwds)
SingleFrameMeasurementTask.__init__(self, schema, algMetadata, **kwds)
self.dipoleAnalysis = DipoleAnalysis()

@pipeBase.timeMethod
Expand All @@ -297,27 +300,26 @@ def classify(self, sources):
for source in sources:
passesSn = self.dipoleAnalysis.getSn(source) > ctrl.minSn

negFlux = np.abs(source.get("flux.dipole.psf.neg"))
posFlux = np.abs(source.get("flux.dipole.psf.pos"))
negFlux = np.abs(source.get("ip_diffim_PsfDipoleFlux_neg_flux"))
posFlux = np.abs(source.get("ip_diffim_PsfDipoleFlux_pos_flux"))
totalFlux = negFlux + posFlux
passesFluxNeg = (negFlux / (negFlux + posFlux)) < ctrl.maxFluxRatio
passesFluxPos = (posFlux / (negFlux + posFlux)) < ctrl.maxFluxRatio

if (passesSn and passesFluxPos and passesFluxNeg):
val = 1.0
else:
val = 0.0

source.set(key, val)

def run(self, exposure, sources, **kwds):
def run(self, sources, exposure, **kwds):
Copy link
Author

Choose a reason for hiding this comment

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

The parameter order was swapped. Please update the docstring to reflect the change.

What is the reason for the swap? The previous way agreed with the syntax for the parent task which seems like the right thing to do.

"""!Run dipole measurement and classification
@param exposure Exposure on which the diaSources were detected
@param sources diaSources that will be measured using dipole measurement
@param **kwds Sent to SourceMeasurementTask
@param **kwds Sent to SingleFrameMeasurementTask
"""

SourceMeasurementTask.run(self, exposure, sources, **kwds)
SingleFrameMeasurementTask.run(self, exposure, sources, **kwds)
self.classify(sources)

#########
Expand All @@ -335,7 +337,7 @@ def __init__(self, sources, badFlags=None):
The list of badFlags will be used to make a list of keys to check for measurement flags on. By
default the centroid keys are added to this list"""

self.badFlags = ['flags.pixel.edge', 'flags.pixel.interpolated.center', 'flags.pixel.saturated.center']
self.badFlags = ['base_PixelFlags_flag_edge', 'base_PixelFlags_flag_interpolatedCenter', 'base_PixelFlags_flag_saturatedCenter']
if badFlags is not None:
for flag in badFlags:
self.badFlags.append(flag)
Expand Down Expand Up @@ -368,10 +370,10 @@ def getSn(self, source):

@param source The source that will be examined"""

posflux = source.get("flux.dipole.psf.pos")
posfluxErr = source.get("flux.dipole.psf.pos.err")
negflux = source.get("flux.dipole.psf.neg")
negfluxErr = source.get("flux.dipole.psf.neg.err")
posflux = source.get("ip_diffim_PsfDipoleFlux_pos_flux")
posfluxErr = source.get("ip_diffim_PsfDipoleFlux_pos_fluxSigma")
negflux = source.get("ip_diffim_PsfDipoleFlux_neg_flux")
negfluxErr = source.get("ip_diffim_PsfDipoleFlux_neg_fluxSigma")

# Not a dipole!
if (posflux < 0) is (negflux < 0):
Expand All @@ -384,26 +386,30 @@ def getCentroid(self, source):

@param source The source that will be examined"""

negCen = source.get("flux.dipole.psf.neg.centroid")
posCen = source.get("flux.dipole.psf.pos.centroid")
if (False in np.isfinite(negCen)) or (False in np.isfinite(posCen)):
negCenX = source.get("ip_diffim_PsfDipoleFlux_neg_centroid_x")
negCenY = source.get("ip_diffim_PsfDipoleFlux_neg_centroid_y")
posCenX = source.get("ip_diffim_PsfDipoleFlux_pos_centroid_x")
posCenY = source.get("ip_diffim_PsfDipoleFlux_pos_centroid_y")
if (np.isinf(negCenX) or np.isinf(negCenY) or np.isinf(posCenX) or np.isinf(posCenY)):
return None

center = afwGeom.Point2D(0.5*(negCen[0]+posCen[0]),
0.5*(negCen[1]+posCen[1]))
center = afwGeom.Point2D(0.5*(negCenX+posCenX),
0.5*(negCenY+posCenY))
return center

def getOrientation(self, source):
"""!Calculate the orientation of dipole; vector from negative to positive lobe

@param source The source that will be examined"""

negCen = source.get("flux.dipole.psf.neg.centroid")
posCen = source.get("flux.dipole.psf.pos.centroid")
if (False in np.isfinite(negCen)) or (False in np.isfinite(posCen)):
negCenX = source.get("ip_diffim_PsfDipoleFlux_neg_centroid_x")
negCenY = source.get("ip_diffim_PsfDipoleFlux_neg_centroid_y")
posCenX = source.get("ip_diffim_PsfDipoleFlux_pos_centroid_x")
posCenY = source.get("ip_diffim_PsfDipoleFlux_pos_centroid_y")
if (np.isinf(negCenX) or np.isinf(negCenY) or np.isinf(posCenX) or np.isinf(posCenY)):
return None

dx, dy = posCen[0]-negCen[0], posCen[1]-negCen[1]
dx, dy = posCenX-negCenX, posCenY-negCenY
angle = afwGeom.Angle(np.arctan2(dx, dy), afwGeom.radians)
return angle

Expand All @@ -429,7 +435,7 @@ def displayDipoles(self, exposure, sources):
if display and displayDiaSources:
with ds9.Buffering():
for source in sources:
cenX, cenY = source.get("flux.dipole.psf.centroid")
cenX, cenY = source.get("ipdiffim_DipolePsfFlux_centroid")
if np.isinf(cenX) or np.isinf(cenY):
cenX, cenY = source.getCentroid()

Expand All @@ -443,8 +449,10 @@ def displayDipoles(self, exposure, sources):

ds9.dot("o", cenX, cenY, size=2, ctype=ctype, frame=lsstDebug.frame)

negCenX, negCenY = source.get("flux.dipole.psf.neg.centroid")
posCenX, posCenY = source.get("flux.dipole.psf.pos.centroid")
negCenX = source.get("ip_diffim_PsfDipoleFlux_neg_centroid_x")
negCenY = source.get("ip_diffim_PsfDipoleFlux_neg_centroid_y")
posCenX = source.get("ip_diffim_PsfDipoleFlux_pos_centroid_x")
posCenY = source.get("ip_diffim_PsfDipoleFlux_pos_centroid_y")
if (np.isinf(negCenX) or np.isinf(negCenY) or np.isinf(posCenX) or np.isinf(posCenY)):
continue

Expand Down