-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// -*- lsst-c++ -*- | ||
/* | ||
* LSST Data Management System | ||
* Copyright 2008-2015 AURA/LSST | ||
* | ||
* 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/pex/config.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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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""" | ||
|
@@ -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 | ||
|
@@ -62,7 +65,7 @@ def setDefaults(self): | |
## \ref DipoleMeasurementTask_ "DipoleMeasurementTask" | ||
## \copybrief DipoleMeasurementTask | ||
## \} | ||
class DipoleMeasurementTask(SourceMeasurementTask): | ||
class DipoleMeasurementTask(SingleFrameMeasurementTask): | ||
"""! | ||
\anchor DipoleMeasurementTask_ | ||
|
||
|
@@ -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. | ||
|
@@ -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 | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 exposure Exposure on which the diaSources were detected | ||
@param **kwds Sent to SingleFrameMeasurementTask | ||
""" | ||
|
||
SourceMeasurementTask.run(self, exposure, sources, **kwds) | ||
SingleFrameMeasurementTask.run(self, sources, exposure, **kwds) | ||
self.classify(sources) | ||
|
||
######### | ||
|
@@ -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) | ||
|
@@ -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): | ||
|
@@ -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 | ||
|
||
|
@@ -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() | ||
|
||
|
@@ -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 | ||
|
||
|
There was a problem hiding this comment.
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?