74 centers.
reserve(ccdImageList.size());
75 for (
auto const &
ccdImage : ccdImageList) {
84 _commonTangentPoint =
Point(commonTangentPoint.getX(), commonTangentPoint.getY());
85 for (
auto &
ccdImage : ccdImageList)
ccdImage->setCommonTangentPoint(_commonTangentPoint);
89 const bool enlargeFittedList) {
94 for (
auto &item : fittedStarList) {
95 item->clearBeforeAssoc();
98 if (!useFittedList) fittedStarList.clear();
100 for (
auto &
ccdImage : ccdImageList) {
111 Frame ccdImageFrameCPT = toCommonTangentPlane->apply(
ccdImage->getImageFrame(),
false);
112 ccdImageFrameCPT = ccdImageFrameCPT.
rescale(1.10);
117 for (
auto const &fittedStar : fittedStarList) {
118 if (ccdImageFrameCPT.
inFrame(*fittedStar)) {
125 toCommonTangentPlane.
get(), matchCutInArcSec / 3600.);
128 LOGLS_DEBUG(_log,
"Measured-to-Fitted matches before removing ambiguities " << starMatchList->size());
129 starMatchList->removeAmbiguities(*toCommonTangentPlane);
130 LOGLS_DEBUG(_log,
"Measured-to-Fitted matches after removing ambiguities " << starMatchList->size());
134 int matchedCount = 0;
135 for (
auto const &starMatch : *starMatchList) {
136 auto bs = starMatch.s1;
139 auto bs2 = starMatch.s2;
142 ms->setFittedStar(fs);
145 LOGLS_INFO(_log,
"Matched " << matchedCount <<
" objects in " <<
ccdImage->getName());
148 int unMatchedCount = 0;
149 for (
auto const &mstar : catalog) {
151 if (mstar->getFittedStar())
continue;
152 if (enlargeFittedList) {
153 auto fs = std::make_shared<FittedStar>(*mstar);
155 toCommonTangentPlane->transformPosAndErrors(*
fs, *
fs);
156 fittedStarList.push_back(
fs);
157 mstar->setFittedStar(
fs);
161 LOGLS_INFO(_log,
"Unmatched objects: " << unMatchedCount);
173 std::string const &fluxField,
bool rejectBadFluxes) {
174 if (refCat.
size() == 0) {
176 " reference catalog is empty : stop here "));
187 << fluxField <<
"Err" 188 <<
") not found in reference catalog. Not using ref flux errors.");
192 for (
size_t i = 0; i < refCat.
size(); i++) {
193 auto const &record = refCat.
get(i);
195 auto coord = record->
get(coordKey);
196 double flux = record->get(fluxKey);
198 if (fluxErrKey.isValid()) {
199 fluxErr = record->get(fluxErrKey);
205 auto star = std::make_shared<RefStar>(ra,
dec, flux, fluxErr);
211 star->vx =
std::pow(0.1 / 3600 /
cos(coord.getLatitude()), 2);
217 refStarList.push_back(star);
222 TanRaDecToPixel raDecToCommonTangentPlane(identity, _commonTangentPoint);
224 associateRefStars(matchCut.
asArcseconds(), &raDecToCommonTangentPlane);
229 Frame tangentPlaneFrame;
231 for (
auto const &
ccdImage : ccdImageList) {
233 if (tangentPlaneFrame.
getArea() == 0)
234 tangentPlaneFrame = CTPFrame;
236 tangentPlaneFrame += CTPFrame;
241 TanPixelToRaDec commonTangentPlaneToRaDec(identity, _commonTangentPoint);
242 Frame raDecFrame = commonTangentPlaneToRaDec.
apply(tangentPlaneFrame,
false);
255 matchCutInArcSec / 3600.);
257 LOGLS_DEBUG(_log,
"Refcat matches before removing ambiguities " << starMatchList->size());
258 starMatchList->removeAmbiguities(*transform);
259 LOGLS_DEBUG(_log,
"Refcat matches after removing ambiguities " << starMatchList->size());
262 for (
auto const &starMatch : *starMatchList) {
266 const BaseStar &bs2 = *starMatch.s2;
274 "Associated " << starMatchList->size() <<
" reference stars among " << refStarList.size());
278 selectFittedStars(minMeasurements);
279 normalizeFittedStars();
282 void Associations::selectFittedStars(
int minMeasurements) {
283 LOGLS_INFO(_log,
"Fitted stars before measurement # cut: " << fittedStarList.size());
286 for (
auto const &
ccdImage : ccdImageList) {
294 if (fittedStar ==
nullptr) {
301 if (!fittedStar->getRefStar() && fittedStar->getMeasurementCount() < minMeasurements) {
302 fittedStar->getMeasurementCount()--;
303 mi = catalog.
erase(mi);
312 if ((*fi)->getMeasurementCount() == 0) {
313 fi = fittedStarList.erase(fi);
319 LOGLS_INFO(_log,
"Fitted stars after measurement # cut: " << fittedStarList.size());
322 void Associations::normalizeFittedStars()
const {
324 for (
auto &fittedStar : fittedStarList) {
327 fittedStar->setFlux(0.0);
328 fittedStar->getMag() = 0.0;
332 for (
auto const &
ccdImage : ccdImageList) {
335 for (
auto &mi : catalog) {
336 auto fittedStar = mi->getFittedStar();
337 if (fittedStar ==
nullptr)
340 "All measuredStars must have a fittedStar: did you call selectFittedStars()?"));
341 auto point = toCommonTangentPlane->apply(*mi);
342 fittedStar->x += point.x;
343 fittedStar->y += point.y;
344 fittedStar->getFlux() += mi->getFlux();
348 for (
auto &fi : fittedStarList) {
349 auto measurementCount = fi->getMeasurementCount();
350 fi->x /= measurementCount;
351 fi->y /= measurementCount;
352 fi->getFlux() /= measurementCount;
357 void Associations::assignMags() {
358 for (
auto const &
ccdImage : ccdImageList) {
360 for (
auto const &mstar : catalog) {
361 auto fstar = mstar->getFittedStar();
362 if (!fstar)
continue;
363 fstar->addMagMeasurement(mstar->getMag(), mstar->getMagWeight());
371 if (!fittedStarList.inTangentPlaneCoordinates) {
373 "DeprojectFittedStars: Fitted stars are already in sidereal coordinates, nothing done ");
378 fittedStarList.applyTransform(ctp2Sky);
379 fittedStarList.inTangentPlaneCoordinates =
false;
384 return item->getCatalogForFit().size() > 0;
390 for (
auto const &fittedStar : fittedStarList) {
391 if ((fittedStar !=
nullptr) & (fittedStar->getRefStar() !=
nullptr)) count++;
397 void Associations::collectMCStars(
int realization) {
401 for (I = ccdImageList.begin(); I != ccdImageList.end(); I++) {
403 string dbimdir = ccdImage.Dir();
404 string mctruth = dbimdir +
"/mc/mctruth.list";
406 if (realization >= 0) {
408 sstrm << dbimdir <<
"/mc/mctruth_" << realization <<
".list";
409 mctruth = sstrm.
str();
416 DicStarList mctruthlist(mctruth);
420 for (smI = starMatchList->begin(); smI != starMatchList->end(); smI++) {
425 DicStar *dstar =
dynamic_cast<DicStar *
>(bs);
427 mcstar->GetMCInfo().iflux = dstar->getval(
"iflux");
428 mcstar->GetMCInfo().tflux = dstar->getval(
"sflux");
435 LOGLS_FATAL(_log,
"CollectMCStars Unable to match MCTruth w/ catalog!");
440 double matchCutArcSec) {
442 size_t pos_minus = color.
find(
'-');
443 bool compute_diff = (pos_minus != string::npos);
445 c1 = color.
substr(0, pos_minus);
446 if (compute_diff) c2 = color.
substr(pos_minus + 1, string::npos);
447 DicStarList cList(dicStarListName);
448 if (!cList.HasKey(c1))
449 throw(GastroException(
"Associations::SetFittedstarColors : " + dicStarListName +
450 " misses a key named \"" + c1 +
"\""));
451 if (compute_diff && !cList.HasKey(c2))
452 throw(GastroException(
"Associations::SetFittedstarColors : " + dicStarListName +
453 " misses a key named \"" + c2 +
"\""));
461 if (fittedStarList.inTangentPlaneCoordinates) id_or_proj = &
id;
466 id_or_proj, matchCutArcSec / 3600);
468 LOGLS_INFO(_log,
"Matched " << starMatchList->size() <<
'/' << fittedStarList.size()
469 <<
" FittedStars to color catalog");
471 for (
auto i = starMatchList->begin(); i != starMatchList->end(); ++i) {
475 const TStar *ts =
dynamic_cast<const TStar *
>(s2);
476 const DicStar *ds =
dynamic_cast<const DicStar *
>(ts->get_original());
477 fs->
color = ds->getval(c1);
478 if (compute_diff) fs->
color -= ds->getval(c2);
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Objects used as position anchors, typically USNO stars.
The transformation that handles pixels to sideral transformations (Gnomonic, possibly with polynomial...
int nCcdImagesValidForFit() const
return the number of CcdImages with non-empty catalogs to-be-fit.
MeasuredStarList::iterator MeasuredStarIterator
A hanger for star associations.
A floating-point coordinate rectangle geometry.
constexpr double radToDeg(double x) noexcept
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
Transform pixels to ICRS RA, Dec in degrees.
double xMin
coordinate of boundary.
Schema getSchema() const
Return the schema associated with the catalog's table.
std::unique_ptr< StarMatchList > listMatchCollect(const BaseStarList &list1, const BaseStarList &list2, const AstrometryTransform *guess, const double maxDist)
assembles star matches.
A class representing an angle.
void associateCatalogs(const double matchCutInArcsec=0, const bool useFittedList=false, const bool enlargeFittedList=true)
incrementaly builds a merged catalog of all image catalogs
A list of MeasuredStar. They are usually filled in Associations::createCcdImage.
table::Key< table::Array< std::uint8_t > > wcs
Frame rescale(const double factor) const
rescale it. The center does not move.
double cos(Angle const &a)
LSST DM logging module built on log4cxx.
The base class for handling stars. Used by all matching routines.
void prepareFittedStars(int minMeasurements)
Set the color field of FittedStar 's from a colored catalog.
void collectRefStars(afw::table::SimpleCatalog &refCat, afw::geom::Angle matchCut, std::string const &fluxField, bool rejectBadFluxes=false)
Collect stars from an external reference catalog and associate them with fittedStars.
size_t nFittedStarsWithAssociatedRefStar() const
Return the number of fittedStars that have an associated refStar.
Reports attempts to access elements using an invalid key.
rectangle with sides parallel to axes.
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
AngleUnit constexpr degrees
constant with units of degrees
A base class for image defects.
void setRefStar(const RefStar *_refStar)
Set the astrometric reference star associated with this star.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
void computeCommonTangentPoint()
Sets a shared tangent point for all ccdImages, using the mean of the centers of all ccdImages...
FittedStarList::iterator FittedStarIterator
A list of FittedStar s. Such a list is typically constructed by Associations.
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
objects measured on actual images.
table::Key< int > detector
T dynamic_pointer_cast(T... args)
::std::list< StarMatch >::iterator StarMatchIterator
void deprojectFittedStars()
Sends back the fitted stars coordinates on the sky FittedStarsList::inTangentPlaneCoordinates keeps t...
constexpr double asArcseconds() const noexcept
Return an Angle's value in arcseconds.
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
void setCommonTangentPoint(lsst::afw::geom::Point2D const &commonTangentPoint)
Sets a shared tangent point for all ccdImages.
bool inFrame(double x, double y) const
inside?
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
double nanojanskyToABMagnitude(double flux)
Convert a flux in nanojansky to AB magnitude.
void createCcdImage(afw::table::SourceCatalog &catalog, std::shared_ptr< lsst::afw::geom::SkyWcs > wcs, std::shared_ptr< lsst::afw::image::VisitInfo > visitInfo, lsst::afw::geom::Box2I const &bbox, std::string const &filter, std::shared_ptr< afw::image::PhotoCalib > photoCalib, std::shared_ptr< afw::cameraGeom::Detector > detector, int visit, int ccd, lsst::jointcal::JointcalControl const &control)
Create a ccdImage from an exposure catalog and metadata, and add it to the list.
MeasuredStarList const & getCatalogForFit() const
Gets the catalog to be used for fitting, which may have been cleaned-up.
Combinatorial searches for linear transformations to go from list1 to list2.
BaseStarList & Fitted2Base(FittedStarList &This)
std::shared_ptr< const BaseStar > s2
const lsst::afw::geom::Box2D getRaDecBBox()
BaseStarList & Measured2Base(MeasuredStarList &This)
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
std::shared_ptr< const BaseStar > s1
Reports invalid arguments.
size_type size() const
Return the number of elements in the catalog.
std::string sourceFluxField
"name of flux field in source catalog" ;
#define LOGLS_FATAL(logger, message)
Log a fatal-level message using an iostream-based interface.
Handler of an actual image from a single CCD.
#define LOG_GET(logger)
Returns a Log object associated with logger.
std::shared_ptr< FittedStar > getFittedStar() const
An integer coordinate rectangle.
The objects which have been measured several times.
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
A FunctorKey used to get or set celestial coordinates from a pair of lsst::geom::Angle keys...
Reports errors that are due to events beyond the control of the program.
BaseStarList & Ref2Base(RefStarList &This)