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 1218 #8

Merged
merged 5 commits into from
Jan 27, 2015
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
8 changes: 5 additions & 3 deletions examples/runSingleFrameTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
# Copyright 2008-2015 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -72,9 +72,10 @@ def run(display=False):
#
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should update the copyright statement on this file when editing it.

Copy link
Member

Choose a reason for hiding this comment

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

Done.

config = SingleFrameMeasurementTask.ConfigClass()
config.plugins.names.clear()
for plugin in ["base_SdssCentroid", "base_SdssShape", "base_SincFlux", "base_GaussianFlux"]:
for plugin in ["base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux", "base_GaussianFlux"]:
config.plugins.names.add(plugin)
config.slots.psfFlux = None
config.slots.apFlux = "base_CircularApertureFlux_0"

measureTask = SingleFrameMeasurementTask(schema, config=config)

Expand Down Expand Up @@ -106,7 +107,8 @@ def run(display=False):
xy = s.getCentroid()
ds9.dot('+', *xy, ctype=ds9.CYAN if s.get("flags_negative") else ds9.GREEN, frame=frame)
ds9.dot(s.getShape(), *xy, ctype=ds9.RED, frame=frame)
ds9.dot('o', *xy, size=config.plugins["base_SincFlux"].radius2, ctype=ds9.YELLOW, frame=frame)
ds9.dot('o', *xy, size=config.plugins["base_CircularApertureFlux"].radii[0],
ctype=ds9.YELLOW, frame=frame)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down
4 changes: 1 addition & 3 deletions include/lsst/meas/base.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- lsst-c++ -*-
/*
* LSST Data Management System
* Copyright 2008-2013 LSST Corporation.
* Copyright 2008-2015 LSST Corporation.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -32,13 +32,11 @@
#include "lsst/meas/base/InputUtilities.h"
#include "lsst/meas/base/Algorithm.h"
#include "lsst/meas/base/PsfFlux.h"
#include "lsst/meas/base/SincFlux.h"
#include "lsst/meas/base/SdssCentroid.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should update the copyright statement on this file when editing it.

#include "lsst/meas/base/SdssShape.h"
#include "lsst/meas/base/PixelFlags.h"
#include "lsst/meas/base/GaussianFlux.h"
#include "lsst/meas/base/GaussianCentroid.h"
#include "lsst/meas/base/NaiveFlux.h"
#include "lsst/meas/base/NaiveCentroid.h"
#include "lsst/meas/base/PeakLikelihoodFlux.h"
#include "lsst/meas/base/ApertureFlux.h"
Expand Down
83 changes: 39 additions & 44 deletions include/lsst/meas/base/ApertureFlux.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- lsst-c++ -*-
/*
* LSST Data Management System
* Copyright 2008-2014 LSST Corporation.
* Copyright 2008-2015 LSST Corporation.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -61,46 +61,34 @@ class ApertureFluxControl {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can take the copyright thing as read, I guess!

Copy link
Member

Choose a reason for hiding this comment

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

Yup, think I've got them all now.

};


class ApertureFluxResult;


/**
* Base class for multiple-aperture photometry algorithms
*
* ApertureFluxAlgorithm provides concrete implementations for single-aperture flux measurements,
* ApertureFluxAlgorithm serves as an intermediate base class for all aperture fluxes, which it assumes
* have that capability of measuring multiple apertures (even if they are not always configured to do
* so).
*
* Concrete implementations for single-aperture flux measurements are provided as static methods,
* as well as a consistent interface and control object for its derived classes. Currently, we only
* have one such derived class, CircularApertureFluxAlgorithm, but in the future we anticipate adding
* have one derived class, CircularApertureFluxAlgorithm, but in the future we anticipate adding
* more derived classes for e.g. elliptical apertures, or apertures that are circular in sky coordinates
* rather than pixel coordinates.
*
* Because the Result/ResultMapper system doesn't support the kind of flags ApertureFluxAlgorithm needs,
* we mostly don't use it here (though we use a Result object for the output of the single-aperture
* static methods), and that makes for a bit more boilerplate when creating Python plugins for
* these algorithms. Hopefully that will be resolved in DM-1130. In the meantime, this means that
* ApertureFluxAlgorithm and its subclasses cannot be wrapped using the WrappedSingleFramePlugin
* class, as most of the other C++ algorithm classes are. Instead, manual plugin classes must be
* created that call the C++ measure() method.
*
* Ultimately, ApertureFlux derived classes will fully replace the existing single-aperture plugins,
* SincFlux and NaiveFlux. We can't do that yet, though, as we still can't use ApertureFlux outputs
* in slots (DM-1218).
*/
class ApertureFluxAlgorithm : public SimpleAlgorithm {
public:

/// @copydoc PsfFluxAlgorithm::FlagBits

enum {
enum FlagBits {
FAILURE=0,
N_FLAGS
};

enum ResultFlagBits {
APERTURE_TRUNCATED=0,
APERTURE_TRUNCATED,
SINC_COEFFS_TRUNCATED,
RESULT_N_FLAGS
N_FLAGS
};


/// Typedef to the control object associated with this algorithm, defined above.
typedef ApertureFluxControl Control;

Expand Down Expand Up @@ -194,6 +182,10 @@ class ApertureFluxAlgorithm : public SimpleAlgorithm {
daf::base::PropertySet & metadata
);

virtual ~ApertureFluxAlgorithm() {}

protected:

/**
* Measure the configured apertures on the given image.
*
Expand All @@ -207,47 +199,50 @@ class ApertureFluxAlgorithm : public SimpleAlgorithm {
afw::image::Exposure<float> const & exposure
) const = 0;

/// @copydoc BaseAlgorithm::fail
virtual void fail(
afw::table::SourceRecord & measRecord,
MeasurementError * error=NULL
) const;

virtual ~ApertureFluxAlgorithm() {}
void copyResultToRecord(Result const & result, afw::table::SourceRecord & record, int index) const;

protected:
FlagHandler const & getFlagHandler(int index) const { return _keys[index].flags; }

Control const _ctrl;
SafeCentroidExtractor _centroidExtractor;

struct FlagKeys {
private:

FlagKeys(std::string const & name, afw::table::Schema & schema, int index);
struct Keys {
FluxResultKey fluxKey;
FlagHandler flags;

afw::table::Key<afw::table::Flag> failed;
afw::table::Key<afw::table::Flag> apertureTruncated;
afw::table::Key<afw::table::Flag> sincCoeffsTruncated;
Keys(afw::table::Schema & schema, std::string const & prefix, std::string const & doc, bool isSinc);
};

void copyResultToRecord(Result const & result, afw::table::SourceRecord & record, int index) const;

Control const _ctrl;
SafeCentroidExtractor _centroidExtractor;
FlagHandler _flagHandler;
afw::table::ArrayKey<Flux> _fluxKey;
afw::table::ArrayKey<FluxErrElement> _fluxSigmaKey;
std::vector<FlagKeys> _flagKeys;
std::vector<Keys> _keys;
};


/**
* A Result struct for running an aperture flux algorithm with a single radius.
*
* This simply extends FluxResult to add the appropriate error flags for aperture fluxes.
*/
struct ApertureFluxResult : public FluxResult {

/// Return the flag value associated with the given bit
bool getFlag(ApertureFluxAlgorithm::ResultFlagBits bit) const { return _flags[bit]; }
bool getFlag(ApertureFluxAlgorithm::FlagBits bit) const { return _flags[bit]; }

/// Set the flag value associated with the given bit
void setFlag(ApertureFluxAlgorithm::ResultFlagBits bit, bool value=true) { _flags[bit] = value; }
void setFlag(ApertureFluxAlgorithm::FlagBits bit, bool value=true) { _flags[bit] = value; }

/// Clear (i.e. set to false) the flag associated with the given bit
void unsetFlag(ApertureFluxAlgorithm::ResultFlagBits bit) { _flags[bit] = false; }
void unsetFlag(ApertureFluxAlgorithm::FlagBits bit) { _flags[bit] = false; }

private:

std::bitset<ApertureFluxAlgorithm::RESULT_N_FLAGS> _flags;
std::bitset<ApertureFluxAlgorithm::N_FLAGS> _flags;
};


Expand Down
2 changes: 1 addition & 1 deletion include/lsst/meas/base/CircularApertureFlux.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- lsst-c++ -*-
/*
* LSST Data Management System
* Copyright 2008-2014 LSST Corporation.
* Copyright 2008-2015 LSST Corporation.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
Expand Down
114 changes: 0 additions & 114 deletions include/lsst/meas/base/NaiveFlux.h

This file was deleted.