28 #include "boost/format.hpp" 29 #include "lsst/pex/exceptions.h" 46 struct FlattenWithSetter {
47 FlattenWithSetter(T val) : _val(val) {}
61 FlattenWithSetter(T val) : _mask(~val) {}
73 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
80 _variance(
ndarray::allocate(
ndarray::makeVector(foot.getArea()))) {
109 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
117 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
125 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
130 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
150 return std::make_shared<HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>>(*foot, im1);
153 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
157 typedef typename ndarray::Array<ImagePixelT const, 1, 1>::Iterator ArrayIter;
162 while (lhsIter != lhsEnd && rhsIter != rhsEnd) {
163 geom::Span const &lhsSpan = *lhsIter, rhsSpan = *rhsIter;
164 int const yLhs = lhsSpan.
getY(), yRhs = rhsSpan.getY();
166 int const x0Lhs = lhsSpan.
getX0(), x1Lhs = lhsSpan.
getX1();
167 int const x0Rhs = rhsSpan.getX0(), x1Rhs = rhsSpan.getX1();
170 lhsArray += xMin - x0Lhs;
171 rhsArray += xMin - x0Rhs;
172 for (
int x = xMin;
x <= xMax; ++
x, ++lhsArray, ++rhsArray) {
173 sum += (*lhsArray) * (*rhsArray);
176 lhsArray -= xMax + 1 - x0Lhs;
177 rhsArray -= xMax + 1 - x0Rhs;
179 if (x1Lhs <= x1Rhs) {
183 rhsArray += rhsSpan.getWidth();
187 }
else if (yLhs < yRhs) {
188 while (lhsIter != lhsEnd && lhsIter->getY() < yRhs) {
189 lhsArray += lhsIter->getWidth();
194 while (rhsIter != rhsEnd && rhsIter->getY() < yLhs) {
195 rhsArray += rhsIter->getWidth();
213 struct HeavyFootprintPersistenceHelper {
215 afw::table::Key<afw::table::Array<ImagePixelT>>
image;
216 afw::table::Key<afw::table::Array<MaskPixelT>>
mask;
217 afw::table::Key<afw::table::Array<VariancePixelT>>
variance;
219 static HeavyFootprintPersistenceHelper
const&
get() {
220 static HeavyFootprintPersistenceHelper
const instance;
225 HeavyFootprintPersistenceHelper()
227 image(schema.addField<afw::table::Array<ImagePixelT>>(
228 "image",
"image pixels for HeavyFootprint",
"count")),
229 mask(schema.addField<afw::table::Array<MaskPixelT>>(
"mask",
"mask pixels for HeavyFootprint")),
230 variance(schema.addField<afw::table::Array<VariancePixelT>>(
231 "variance",
"variance pixels for HeavyFootprint",
"count^2")) {
232 schema.getCitizen().markPersistent();
243 struct ComputeSuffix;
245 struct ComputeSuffix<std::uint16_t> {
246 static std::string apply() {
return "U"; }
249 struct ComputeSuffix<float> {
250 static std::string apply() {
return "F"; }
253 struct ComputeSuffix<double> {
254 static std::string apply() {
return "D"; }
257 struct ComputeSuffix<int> {
258 static std::string apply() {
return "I"; }
263 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
265 return "HeavyFootprint" + ComputeSuffix<ImagePixelT, MaskPixelT, VariancePixelT>::apply();
268 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
270 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>
const& keys =
271 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>::get();
276 std::shared_ptr<afw::table::BaseRecord> record = cat.
addNew();
280 record->set(keys.image, ndarray::const_array_cast<ImagePixelT>(
getImageArray()));
281 record->set(keys.mask, ndarray::const_array_cast<MaskPixelT>(
getMaskArray()));
282 record->set(keys.variance, ndarray::const_array_cast<VariancePixelT>(
getVarianceArray()));
286 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
290 explicit Factory(std::string
const&
name) : afw::table::io::PersistableFactory(name) {}
294 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>
const& keys =
295 HeavyFootprintPersistenceHelper<ImagePixelT, MaskPixelT, VariancePixelT>::get();
296 HeavyFootprintPersistenceHelper<ImagePixelT, std::uint16_t, VariancePixelT>
const& legacyKeys =
297 HeavyFootprintPersistenceHelper<ImagePixelT, std::uint16_t, VariancePixelT>::get();
301 std::shared_ptr<Footprint> loadedFootprint =
readSpanSet(catalogs[0], archive);
303 readPeaks(catalogs[1], *loadedFootprint);
308 std::make_shared<HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>>(*loadedFootprint);
309 result->_image = ndarray::const_array_cast<ImagePixelT>(record.
get(keys.image));
312 if (catalogs[2].getSchema() == legacyKeys.schema) {
313 auto legacyMask = ndarray::const_array_cast<std::uint16_t>(record.
get(legacyKeys.mask));
314 result->_mask.deep() = legacyMask;
316 result->_mask = ndarray::const_array_cast<MaskPixelT>(record.
get(keys.mask));
318 result->_variance = ndarray::const_array_cast<VariancePixelT>(record.
get(keys.variance));
326 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
329 "HeavyFootprint" + ComputeSuffix<ImagePixelT, MaskPixelT, VariancePixelT>::apply());
335 #define INSTANTIATE(TYPE) \ 336 template class HeavyFootprint<TYPE>; \ 337 template std::shared_ptr<HeavyFootprint<TYPE>> mergeHeavyFootprints<TYPE>(HeavyFootprint<TYPE> const&, \ 338 HeavyFootprint<TYPE> const&);
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
table::Key< std::string > name
An object passed to Persistable::write to allow it to persist itself.
A custom container class for records, based on std::vector.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A range of pixels within one row of an Image.
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
A base class for factory classes used to reconstruct objects from records.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
An integer coordinate rectangle.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
int getWidth() const
Return the number of pixels.
int getX0() const
Return the starting x-value.
A base class for image defects.
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.
details::ImageNdGetter< T, inA, inB > ndImage(ndarray::Array< T, inA, inB > const &array, afwGeom::Point2I xy0=afwGeom::Point2I())
Marks a ndarray to be interpreted as an image when applying a functor from a SpanSet.
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.
A vector of catalogs used by Persistable.
Base class for all records.
int getX1() const
Return the ending x-value.
int getY() const
Return the y-value.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
float VariancePixel
default type for MaskedImage variance images
A class to represent a 2-dimensional array of pixels.
geom::Point2I getXY0() const
Return the image's origin.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
geom::Point2I getXY0() const
Return the image's origin.