40 : _footprints(1, footprint), _source(sourceTable->makeRecord()) {
43 _source->set(
keys.footprint,
true);
49 newPeak->set(
keys.peak,
true);
50 newFootprint->getPeaks().push_back(newPeak);
52 _source->setFootprint(newFootprint);
86 KeyTuple const &
keys,
float minNewPeakDist = -1.,
float maxSamePeakDist = -1.) {
88 _footprints.push_back(footprint);
89 _source->set(
keys.footprint,
true);
90 _addPeaks(footprint->getPeaks(), &peakSchemaMapper, &
keys, minNewPeakDist, maxSamePeakDist,
nullptr);
108 float maxSamePeakDist = -1.) {
110 _footprints.insert(_footprints.end(), other._footprints.begin(), other._footprints.end());
112 for (
auto const &key :
keys) {
114 _source->set(flagKey, _source->
get(flagKey) || other._source->
get(flagKey));
116 _addPeaks(other.
getMergedFootprint()->getPeaks(),
nullptr,
nullptr, minNewPeakDist, maxSamePeakDist,
147 KeyTuple const *
keys,
float minNewPeakDist,
float maxSamePeakDist,
149 if (minNewPeakDist < 0 && maxSamePeakDist < 0)
return;
151 assert(peakSchemaMapper || filterMap);
157 float minNewPeakDist2 = minNewPeakDist * minNewPeakDist;
158 float maxSamePeakDist2 = maxSamePeakDist * maxSamePeakDist;
164 currentIter != currentPeaks.
end(); ++currentIter) {
165 float dist2 = otherIter->getI().distanceSquared(currentIter->getI());
167 if (dist2 < minDist2) {
169 nearestPeak = currentIter;
173 if (minDist2 < maxSamePeakDist2 && nearestPeak && maxSamePeakDist > 0) {
174 if (peakSchemaMapper) {
175 nearestPeak->set(
keys->peak,
true);
177 for (
auto const &i : *filterMap) {
178 afw::table::Key<afw::table::Flag>
const &flagKey = i.second.peak;
179 nearestPeak->set(flagKey, nearestPeak->
get(flagKey) || otherIter->get(flagKey));
182 }
else if (minDist2 > minNewPeakDist2 && !(minNewPeakDist < 0)) {
183 if (peakSchemaMapper) {
185 newPeak->assign(*otherIter, *peakSchemaMapper);
186 newPeak->set(
keys->peak,
true);
188 newPeaks.push_back(otherIter);
206 : _peakSchemaMapper(initialPeakSchema) {
207 _initialize(sourceSchema, filterList);
212 : _peakSchemaMapper(
PeakTable::makeMinimalSchema()) {
213 _initialize(sourceSchema, filterList);
226 for (
auto const &
iter : filterList) {
228 keys.footprint = sourceSchema.
addField<afw::table::Flag>(
229 "merge_footprint_" +
iter,
230 "Detection footprint overlapped with a detection from filter " +
iter);
232 "merge_peak_" +
iter,
"Peak detected in filter " +
iter);
239 float minNewPeakDist,
bool doMerge,
float maxSamePeakDist) {
240 FilterMap::const_iterator keyIter = _filterMap.
find(
filter);
241 if (keyIter == _filterMap.
end()) {
247 bool checkForMatches = !_mergeList.
empty() && doMerge;
252 if (srcIter->getParent() != 0)
continue;
260 if (checkForMatches) {
261 FootprintMergeVec::iterator
iter = _mergeList.
begin();
262 while (
iter != _mergeList.
end()) {
266 if (box.
overlaps(foot->getBBox()) && (**iter).overlaps(*foot)) {
274 first->addSpans(foot);
277 first->add(**
iter, _filterMap, minNewPeakDist, maxSamePeakDist);
288 first->add(foot, _peakSchemaMapper, keyIter->second, minNewPeakDist, maxSamePeakDist);
291 _mergeList.
push_back(std::make_shared<FootprintMerge>(foot, sourceTable, _peakTable,
292 _peakSchemaMapper, keyIter->second));
299 for (
auto const &
iter : _mergeList) {
300 outputCat.push_back((*iter).getSource());
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Table class for Peaks in Footprints.
static std::shared_ptr< PeakTable > make(afw::table::Schema const &schema, bool forceNew=false)
Obtain a table that can be used to create records with given schema.
Iterator class for CatalogT.
iterator begin()
Iterator access.
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Defines the fields and offsets for a table.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
A mapping between the keys of two Schemas, used to copy data between them.
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
void addMinimalSchema(Schema const &minimal, bool doMap=true)
Add the given minimal schema to the output schema.
Schema const getInputSchema() const
Return the input schema (copy-on-write).
typename Base::const_iterator const_iterator
An integer coordinate rectangle.
bool overlaps(Box2I const &other) const noexcept
Return true if any points in other are also in this.
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
Reports errors in the logical structure of the program.
afw::table::CatalogT< PeakRecord > PeakCatalog
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.