LSSTApplications
21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
33 #include "boost/iterator/iterator_adaptor.hpp"
34 #include "boost/iterator/transform_iterator.hpp"
35 #include "ndarray/eigen.h"
60 namespace algorithms {
71 explicit AvgPosItem(
double wx_ = 0.0,
double wy_ = 0.0,
double w_ = 0.0) :
wx(wx_),
wy(wy_),
w(w_) {}
77 bool operator<(AvgPosItem
const &
other)
const {
return w <
other.w; }
93 friend AvgPosItem
operator+(AvgPosItem
a, AvgPosItem
const &
b) {
return a +=
b; }
95 friend AvgPosItem
operator-(AvgPosItem
a, AvgPosItem
const &
b) {
return a -=
b; }
99 afw::geom::SkyWcs
const &
coaddWcs, afw::table::Key<double> weightKey) {
100 afw::table::Key<int> goodPixKey;
102 goodPixKey = catalog.getSchema()[
"goodpix"];
103 }
catch (pex::exceptions::NotFoundError &) {
106 items.reserve(catalog.size());
109 AvgPosItem item(p.getX(), p.getY(), i->get(weightKey));
110 if (goodPixKey.isValid()) {
111 item.w *= i->get(goodPixKey);
115 items.push_back(item);
132 "Could not find a valid average position for CoaddPsf");
152 mapper.addMapping(goodPixKey,
true);
159 _weightKey =
mapper.addMapping(weightKey, weightField);
164 record->assign(*i,
mapper);
165 _catalog.push_back(record);
167 _averagePosition = computeAveragePosition(_catalog, _coaddWcs, _weightKey);
182 for (
unsigned int i = 0; i < imgVector.size(); i++) {
195 assert(imgVector.size() == weightVector.
size());
196 for (
unsigned int i = 0; i < imgVector.size(); i++) {
198 double weight = weightVector[i];
199 double sum = ndarray::asEigenMatrix(componentImg->getArray()).sum();
217 if (subcat.empty()) {
220 (
boost::format(
"Cannot compute BBox at point %s; no input images at that point.") % ccdXY)
225 for (
auto const &exposureRecord : subcat) {
228 WarpedPsf warpedPsf =
WarpedPsf(exposureRecord.getPsf(), exposureToCoadd, _warpingControl);
240 if (subcat.empty()) {
243 (
boost::format(
"Cannot compute CoaddPsf at point %s; no input images at that point.") % ccdXY)
246 double weightSum = 0.0;
254 for (
auto const &exposureRecord : subcat) {
259 WarpedPsf warpedPsf =
WarpedPsf(exposureRecord.getPsf(), exposureToCoadd, _warpingControl);
263 exposureRecord.getId())
268 weightSum += exposureRecord.get(_weightKey);
269 weightVector.
push_back(exposureRecord.get(_weightKey));
288 return _catalog[index].getPsf();
295 return *_catalog[index].getWcs();
302 return _catalog[index].getValidPolygon();
309 return _catalog[index].get(_weightKey);
316 return _catalog[index].getId();
323 return _catalog[index].getBBox();
335 class CoaddPsfPersistenceHelper {
343 static CoaddPsfPersistenceHelper
const &get() {
344 static CoaddPsfPersistenceHelper
const instance;
349 CoaddPsfPersistenceHelper()
351 coaddWcs(
schema.addField<int>(
"coaddwcs",
"archive ID of the coadd's WCS")),
352 cacheSize(
schema.addField<int>(
"cachesize",
"size of the warping cache")),
354 schema,
"avgpos",
"PSF accessors default position",
"pixel")),
356 schema.addField<
std::string>(
"warpingkernelname",
"warping kernel name", 32)) {}
365 if (catalogs.size() == 1u) {
369 return readV0(archive, catalogs);
372 CoaddPsfPersistenceHelper
const &keys1 = CoaddPsfPersistenceHelper::get();
378 record1.
get(keys1.averagePosition), record1.
get(keys1.warpingKernelName),
379 record1.
get(keys1.cacheSize)));
391 auto coaddWcs = internalCat.back().getWcs();
392 internalCat.pop_back();
398 weightKey = internalCat.getSchema()[
"weight"];
401 auto averagePos = computeAveragePosition(internalCat, *
coaddWcs, weightKey);
410 std::string getCoaddPsfPersistenceName() {
return "CoaddPsf"; }
421 CoaddPsfPersistenceHelper
const &keys1 = CoaddPsfPersistenceHelper::get();
424 auto coaddWcsPtr = std::make_shared<afw::geom::SkyWcs>(_coaddWcs);
425 record1->set(keys1.coaddWcs, handle.
put(coaddWcsPtr));
426 record1->set(keys1.cacheSize, _warpingControl->getCacheSize());
427 record1->set(keys1.averagePosition, _averagePosition);
428 record1->set(keys1.warpingKernelName, _warpingKernelName);
437 _weightKey(_catalog.getSchema()[
"weight"]),
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
boost::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
afw::geom::SkyWcs getWcs(int index)
Get the Wcs of the component image at index.
An object passed to Persistable::write to allow it to persist itself.
afw::table::Key< int > cacheSize
boost::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy. Usually unnecessary, as Psfs are immutable.
Reports attempts to access elements using an invalid key.
Reports when the result of an operation cannot be represented by the destination type.
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
Custom catalog class for ExposureRecord/Table.
CoaddPsf(afw::table::ExposureCatalog const &catalog, afw::geom::SkyWcs const &coaddWcs, std::string const &weightFieldName="weight", std::string const &warpingKernelName="lanczos3", int cacheSize=10000)
Main constructors for CoaddPsf.
afw::table::PointKey< double > averagePosition
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Point< double, 2 > Point2D
static ExposureCatalogT readFromArchive(io::InputArchive const &archive, BaseCatalog const &catalog)
Convenience input function for Persistables that contain an ExposureCatalog.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
afw::table::Key< std::string > warpingKernelName
void scaledPlus(double const c, Image< PixelT > const &rhs)
Add Image c*rhs to lhs.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
geom::Box2I getOverallBBox(std::vector< boost::shared_ptr< afw::image::Image< double > >> const &imgVector)
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Base::const_iterator const_iterator
std::shared_ptr< afw::table::io::Persistable > readV0(InputArchive const &archive, CatalogVector const &catalogs) const
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
ItemVariant const * other
Base class for all records.
Reports errors in the logical structure of the program.
A mapping between the keys of two Schemas, used to copy data between them.
A vector of catalogs used by Persistable.
std::shared_ptr< Image< PixelT > > operator-(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
Overload operator-()
void addToImage(boost::shared_ptr< afw::image::Image< double > > image, std::vector< boost::shared_ptr< afw::image::Image< double > >> const &imgVector, std::vector< double > const &weightVector)
Iterator class for CatalogT.
A base class for factory classes used to reconstruct objects from records.
afw::table::Schema schema
geom::Box2I getBBox(int index)
Get the bounding box (in component image Pixel coordinates) of the component image at index.
A Psf class that maps an arbitrary Psf through a coordinate transformation.
Image< LhsPixelT > & operator-=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Subtract lhs from Image rhs (i.e. pixel-by-pixel subtraction) where types are different.
afw::table::Key< double > weight
A base class for image defects.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
afw::table::Key< int > coaddWcs
A base class for objects that can be persisted via afw::table::io Archive classes.
afw::table::RecordId getId(int index)
Get the exposure ID of the component image at index.
boost::shared_ptr< afw::geom::polygon::Polygon const > getValidPolygon(int index)
Get the validPolygon (in component image Pixel coordinates) of the component image at index.
std::vector< SchemaItem< Flag > > * items
A description of a field in a table.
Reports invalid arguments.
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
boost::shared_ptr< afw::detection::Psf const > getPsf(int index)
Get the Psf of the component image at index.
CoaddPsf is the Psf derived to be used for non-PSF-matched Coadd images.
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
std::shared_ptr< Image< PixelT > > operator+(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
Overload operator+()
lsst::geom::Box2I computeBBox(lsst::geom::Point2D position=makeNullPoint(), image::Color color=image::Color()) const
Return the bounding box of the image returned by computeKernelImage()
ExposureCatalogT subsetContaining(lsst::geom::SpherePoint const &coord, bool includeValidPolygon=false) const
Return a shallow subset of the catalog with only those records that contain the given point.
void writeToArchive(io::OutputArchiveHandle &handle, bool ignoreUnpersistable=true) const
Convenience output function for Persistables that contain an ExposureCatalog.
An integer coordinate rectangle.
Record class used to store exposure metadata.
geom::Box2I doComputeBBox(geom::Point2D const &position, afw::image::Color const &color) const override
Image< LhsPixelT > & operator+=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Add lhs to Image rhs (i.e. pixel-by-pixel addition) where types are different.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
A polymorphic base class for representing an image's Point Spread Function.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
ExposureCatalogT< ExposureRecord > ExposureCatalog
A class to represent a 2-dimensional array of pixels.
int getComponentCount() const
Return the number of component Psfs in this CoaddPsf.
std::shared_ptr< Image > computeKernelImage(lsst::geom::Point2D position=makeNullPoint(), image::Color color=image::Color(), ImageOwnerEnum owner=COPY) const
Return an Image of the PSF, in a form suitable for convolution.
#define CONST_PTR(...)
A shared pointer to a const object.
Factory(std::string const &name)
Describe the colour of a source.
double getWeight(int index)
Get the weight of the component image at index.