28 #include "boost/format.hpp" 39 #include "lsst/afw/table/io/Persistable.cc" 47 struct FlattenWithSetter {
48 FlattenWithSetter(T
val) : _val(val) {}
62 FlattenWithSetter(T
val) : _mask(~val) {}
74 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
81 _variance(
ndarray::allocate(
ndarray::makeVector(foot.getArea()))) {
110 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
118 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
126 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
131 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
151 return std::make_shared<HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>>(*foot, im1);
154 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
163 while (lhsIter != lhsEnd && rhsIter != rhsEnd) {
164 geom::Span const &lhsSpan = *lhsIter, rhsSpan = *rhsIter;
165 int const yLhs = lhsSpan.
getY(), yRhs = rhsSpan.getY();
167 int const x0Lhs = lhsSpan.
getX0(), x1Lhs = lhsSpan.
getX1();
168 int const x0Rhs = rhsSpan.getX0(), x1Rhs = rhsSpan.getX1();
171 lhsArray += xMin - x0Lhs;
172 rhsArray += xMin - x0Rhs;
173 for (
int x = xMin;
x <= xMax; ++
x, ++lhsArray, ++rhsArray) {
174 sum += (*lhsArray) * (*rhsArray);
177 lhsArray -= xMax + 1 - x0Lhs;
178 rhsArray -= xMax + 1 - x0Rhs;
180 if (x1Lhs <= x1Rhs) {
184 rhsArray += rhsSpan.getWidth();
188 }
else if (yLhs < yRhs) {
189 while (lhsIter != lhsEnd && lhsIter->getY() < yRhs) {
190 lhsArray += lhsIter->getWidth();
195 while (rhsIter != rhsEnd && rhsIter->getY() < yLhs) {
196 rhsArray += rhsIter->getWidth();
214 struct HeavyFootprintPersistenceHelper {
216 afw::table::Key<afw::table::Array<ImagePixelT>>
image;
217 afw::table::Key<afw::table::Array<MaskPixelT>>
mask;
218 afw::table::Key<afw::table::Array<VariancePixelT>>
variance;
220 static HeavyFootprintPersistenceHelper
const&
get() {
221 static HeavyFootprintPersistenceHelper
const instance;
226 HeavyFootprintPersistenceHelper()
228 image(schema.addField<afw::table::Array<ImagePixelT>>(
229 "image",
"image pixels for HeavyFootprint",
"count")),
230 mask(schema.addField<afw::table::Array<MaskPixelT>>(
"mask",
"mask pixels for HeavyFootprint")),
231 variance(schema.addField<afw::table::Array<VariancePixelT>>(
232 "variance",
"variance pixels for HeavyFootprint",
"count^2")) {
233 schema.getCitizen().markPersistent();
244 struct ComputeSuffix;
246 struct ComputeSuffix<std::uint16_t> {
250 struct ComputeSuffix<float> {
254 struct ComputeSuffix<double> {
258 struct ComputeSuffix<int> {
264 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
266 return "HeavyFootprint" + ComputeSuffix<ImagePixelT, MaskPixelT, VariancePixelT>::apply();
269 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
271 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>
const&
keys =
272 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>::get();
281 record->set(keys.image, ndarray::const_array_cast<ImagePixelT>(
getImageArray()));
282 record->set(keys.mask, ndarray::const_array_cast<MaskPixelT>(
getMaskArray()));
283 record->set(keys.variance, ndarray::const_array_cast<VariancePixelT>(
getVarianceArray()));
287 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
295 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>
const&
keys =
296 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>::get();
297 HeavyFootprintPersistenceHelper<ImagePixelT, std::uint16_t, VariancePixelT>
const& legacyKeys =
298 HeavyFootprintPersistenceHelper<ImagePixelT, std::uint16_t, VariancePixelT>::get();
304 readPeaks(catalogs[1], *loadedFootprint);
309 std::make_shared<HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>>(*loadedFootprint);
310 result->_image = ndarray::const_array_cast<ImagePixelT>(record.
get(keys.image));
313 if (catalogs[2].getSchema() == legacyKeys.schema) {
314 auto legacyMask = ndarray::const_array_cast<
std::uint16_t>(record.
get(legacyKeys.mask));
315 result->_mask.deep() = legacyMask;
317 result->_mask = ndarray::const_array_cast<MaskPixelT>(record.
get(keys.mask));
319 result->_variance = ndarray::const_array_cast<VariancePixelT>(record.
get(keys.variance));
327 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
330 "HeavyFootprint" + ComputeSuffix<ImagePixelT, MaskPixelT, VariancePixelT>::apply());
337 #define INSTANTIATE(TYPE) \ 338 template std::shared_ptr<detection::HeavyFootprint<TYPE>> \ 339 table::io::PersistableFacade<detection::HeavyFootprint<TYPE>>::dynamicCast( \ 340 std::shared_ptr<table::io::Persistable> const&); \ 341 template class detection::HeavyFootprint<TYPE>; \ 342 template std::shared_ptr<detection::HeavyFootprint<TYPE>> detection::mergeHeavyFootprints<TYPE>( \ 343 detection::HeavyFootprint<TYPE> const&, detection::HeavyFootprint<TYPE> const&);
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
An object passed to Persistable::write to allow it to persist itself.
A range of pixels within one row of an Image.
A base class for factory classes used to reconstruct objects from records.
lsst::geom::Point2I getXY0() const
Return the image's origin.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
FastFinder::Iterator Iterator
A base class for image defects.
int getWidth() const noexcept
Return the number of pixels.
A class to manipulate images, masks, and variance as a single object.
details::FlatNdGetter< T, inA, inB > ndFlat(ndarray::Array< T, inA, inB > const &array)
Marks a ndarray to be interpreted as a 1D vector when applying a functor from a SpanSet.
std::shared_ptr< Footprint > mergeFootprints(Footprint const &footprint1, Footprint const &footprint2)
Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint...
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
std::shared_ptr< HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > mergeHeavyFootprints(HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h1, HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h2)
Sum the two given HeavyFootprints h1 and h2, returning a HeavyFootprint with the union footprint...
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
lsst::geom::Point2I getXY0() const
Return the image's origin.
A vector of catalogs used by Persistable.
Base class for all records.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
int getX1() const noexcept
Return the ending x-value.
int getY() const noexcept
Return the y-value.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
details::ImageNdGetter< T, inA, inB > ndImage(ndarray::Array< T, inA, inB > const &array, lsst::geom::Point2I xy0=lsst::geom::Point2I())
Marks a ndarray to be interpreted as an image when applying a functor from a SpanSet.
float VariancePixel
default type for MaskedImage variance images
An integer coordinate rectangle.
A class to represent a 2-dimensional array of pixels.
int getX0() const noexcept
Return the starting x-value.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.