28 LOG_LOGGER _log =
LOG_GET(
"jointcal.Associations");
44 auto ccdImage = std::make_shared<CcdImage>(catalog, wcs, visitInfo, bbox, filter, photoCalib, detector,
52 _commonTangentPoint =
Point(commonTangentPoint.getX(), commonTangentPoint.getY());
53 for (
auto &
ccdImage : ccdImageList)
ccdImage->setCommonTangentPoint(_commonTangentPoint);
57 const bool enlargeFittedList) {
62 for (
auto &item : fittedStarList) {
63 item->clearBeforeAssoc();
66 if (!useFittedList) fittedStarList.clear();
68 for (
auto &
ccdImage : ccdImageList) {
69 const Gtransfo *toCommonTangentPlane =
ccdImage->getPix2CommonTangentPlane();
74 ccdImage->getCatalogForFit().clear();
84 ccdImageFrameCPT = ccdImageFrameCPT.
rescale(1.10);
90 for (
auto const &fittedStar : fittedStarList) {
91 if (ccdImageFrameCPT.inFrame(*fittedStar)) {
98 toCommonTangentPlane, matchCutInArcSec / 3600.);
101 LOGLS_DEBUG(_log,
"Measured-to-Fitted matches before removing ambiguities " << starMatchList->size());
102 starMatchList->removeAmbiguities(*toCommonTangentPlane);
103 LOGLS_DEBUG(_log,
"Measured-to-Fitted matches after removing ambiguities " << starMatchList->size());
108 int matchedCount = 0;
109 for (
auto const &starMatch : *starMatchList) {
110 auto bs = starMatch.s1;
113 auto bs2 = starMatch.s2;
116 ms->setFittedStar(fs);
119 LOGLS_INFO(_log,
"Matched " << matchedCount <<
" objects in " <<
ccdImage->getName());
122 int unMatchedCount = 0;
123 for (
auto const &mstar : catalog) {
125 if (mstar->getFittedStar())
continue;
126 if (enlargeFittedList) {
127 auto fs = std::make_shared<FittedStar>(*mstar);
130 fittedStarList.push_back(fs);
131 mstar->setFittedStar(fs);
135 LOGLS_INFO(_log,
"Unmatched objects: " << unMatchedCount);
145 if (refCat.
size() == 0) {
147 " reference catalog is empty : stop here "));
151 auto fluxKey = refCat.
getSchema().find<
double>(fluxField).key;
155 fluxErrKey = refCat.
getSchema().find<
double>(fluxField +
"Sigma").key;
158 << fluxField <<
"Sigma" 159 <<
") not found in reference catalog. Not using ref flux errors.");
162 _filterMap.reserve(refFluxMap.size());
164 for (
auto const &filter : refFluxMap) {
165 _filterMap[filter.first] = nFilters;
170 for (
size_t i = 0; i < refCat.
size(); i++) {
171 auto const &record = refCat.
get(i);
175 double defaultFluxErr;
176 if (fluxErrKey.isValid()) {
183 for (
auto const &filter : _filterMap) {
184 fluxList[filter.second] = refFluxMap.
at(filter.first).at(i) /
JanskyToMaggy;
185 fluxErrList[filter.second] = refFluxErrMap.
at(filter.first).at(i) /
JanskyToMaggy;
189 auto star = std::make_shared<RefStar>(ra, dec, defaultFlux, defaultFluxErr, fluxList, fluxErrList);
199 refStarList.push_back(star);
211 Frame tangentPlaneFrame;
213 for (
auto const &
ccdImage : ccdImageList) {
216 if (tangentPlaneFrame.
getArea() == 0)
217 tangentPlaneFrame = CTPFrame;
219 tangentPlaneFrame += CTPFrame;
234 void Associations::associateRefStars(
double matchCutInArcSec,
const Gtransfo *
gtransfo) {
238 matchCutInArcSec / 3600.);
240 LOGLS_DEBUG(_log,
"Refcat matches before removing ambiguities " << starMatchList->size());
241 starMatchList->removeAmbiguities(*gtransfo);
242 LOGLS_DEBUG(_log,
"Refcat matches after removing ambiguities " << starMatchList->size());
245 for (
auto const &starMatch : *starMatchList) {
249 const BaseStar &bs2 = *starMatch.s2;
257 "Associated " << starMatchList->size() <<
" reference stars among " << refStarList.size());
261 LOGLS_INFO(_log,
"Fitted stars before measurement # cut: " << fittedStarList.size());
265 for (
auto const &
ccdImage : ccdImageList) {
279 if (!fstar->getRefStar() && fstar->getMeasurementCount() < minMeasurements) {
282 mi = catalog.
erase(mi);
292 if ((*fi)->getMeasurementCount() == 0)
293 fi = fittedStarList.erase(fi);
298 LOGLS_INFO(_log,
"Fitted stars after measurement # cut: " << fittedStarList.size());
301 void Associations::assignMags() {
302 for (
auto const &
ccdImage : ccdImageList) {
304 for (
auto const &mstar : catalog) {
305 auto fstar = mstar->getFittedStar();
306 if (!fstar)
continue;
317 if (!fittedStarList.inTangentPlaneCoordinates) {
319 "DeprojectFittedStars: Fitted stars are already in sidereal coordinates, nothing done ");
324 fittedStarList.applyTransfo(ctp2Sky);
325 fittedStarList.inTangentPlaneCoordinates =
false;
329 void Associations::collectMCStars(
int realization) {
333 for (I = ccdImageList.begin(); I != ccdImageList.end(); I++) {
335 string dbimdir = ccdImage.Dir();
336 string mctruth = dbimdir +
"/mc/mctruth.list";
338 if (realization >= 0) {
340 sstrm << dbimdir <<
"/mc/mctruth_" << realization <<
".list";
341 mctruth = sstrm.
str();
348 DicStarList mctruthlist(mctruth);
352 for (smI = starMatchList->begin(); smI != starMatchList->end(); smI++) {
357 DicStar *dstar =
dynamic_cast<DicStar *
>(bs);
359 mcstar->GetMCInfo().iflux = dstar->getval(
"iflux");
360 mcstar->GetMCInfo().tflux = dstar->getval(
"sflux");
367 LOGLS_FATAL(_log,
"CollectMCStars Unable to match MCTruth w/ catalog!");
372 double matchCutArcSec) {
374 size_t pos_minus = color.
find(
'-');
375 bool compute_diff = (pos_minus != string::npos);
377 c1 = color.
substr(0, pos_minus);
378 if (compute_diff) c2 = color.
substr(pos_minus + 1, string::npos);
379 DicStarList cList(dicStarListName);
380 if (!cList.HasKey(c1))
381 throw(GastroException(
"Associations::SetFittedstarColors : " + dicStarListName +
382 " misses a key named \"" + c1 +
"\""));
383 if (compute_diff && !cList.HasKey(c2))
384 throw(GastroException(
"Associations::SetFittedstarColors : " + dicStarListName +
385 " misses a key named \"" + c2 +
"\""));
393 if (fittedStarList.inTangentPlaneCoordinates) id_or_proj = &id;
398 id_or_proj, matchCutArcSec / 3600);
400 LOGLS_INFO(_log,
"Matched " << starMatchList->size() <<
'/' << fittedStarList.size()
401 <<
" FittedStars to color catalog");
403 for (
auto i = starMatchList->begin(); i != starMatchList->end(); ++i) {
407 const TStar *ts =
dynamic_cast<const TStar *
>(s2);
408 const DicStar *ds =
dynamic_cast<const DicStar *
>(ts->get_original());
409 fs->
color = ds->getval(c1);
410 if (compute_diff) fs->
color -= ds->getval(c2);
Objects used as position anchors, typically USNO stars.
implements the linear transformations (6 real coefficients).
lsst::afw::geom::Angle getLongitude() const
MeasuredStarList::iterator MeasuredStarIterator
A hanger for star associations.
the transformation that handles pix to sideral transfos (Gnomonic, possibly with polynomial distortio...
void addMagMeasurement(double magValue, double magWeight)
this routine will hopefully soon disappear.
int getMeasurementCount() const
double xMin
coordinate of boundary.
constexpr double asArcseconds() const noexcept
#define LOGLS_FATAL(logger, message)
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::AddImage.
lsst::afw::geom::Angle getLatitude() const
Frame rescale(const double factor) const
rescale it. The center does not move.
#define LOGLS_INFO(logger, message)
void selectFittedStars(int minMeasurements)
Set the color field of FittedStar 's from a colored catalog.
The base class for handling stars. Used by all matching routines.
void collectRefStars(lsst::afw::table::SortedCatalogT< lsst::afw::table::SimpleRecord > &refCat, afw::geom::Angle matchCut, std::string const &fluxField, std::map< std::string, std::vector< double >> const &refFluxMap, std::map< std::string, std::vector< double >> const &refFluxErrMap)
Collect stars from an external reference catalog and associate them with fittedStars.
rectangle with sides parallel to axes.
Class for a simple mapping implementing a generic Gtransfo.
void setRefStar(const RefStar *_refStar)
Set the astrometric reference star associated with this star.
FittedStarList::iterator FittedStarIterator
A list of FittedStar s. Such a list is typically constructed by Associations.
std::unique_ptr< StarMatchList > listMatchCollect(const BaseStarList &list1, const BaseStarList &list2, const Gtransfo *guess, const double maxDist)
assembles star matches.
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const
objects measured on actual images.
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...
void setCommonTangentPoint(lsst::afw::geom::Point2D const &commonTangentPoint)
Sets a shared tangent point for all ccdImages.
A do-nothing transformation. It anyway has dummy routines to mimick a Gtransfo.
#define LSST_EXCEPT(type,...)
std::shared_ptr< const FittedStar > getFittedStar() const
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
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)
a virtual (interface) class for geometric transformations.
std::shared_ptr< const BaseStar > s2
const lsst::afw::geom::Box2D getRaDecBBox()
BaseStarList & Measured2Base(MeasuredStarList &This)
#define LOGLS_DEBUG(logger, message)
constexpr double radToDeg(double x) noexcept
std::shared_ptr< RecordT > const get(size_type i) const
std::shared_ptr< const BaseStar > s1
Frame applyTransfo(const Frame &inputframe, const Gtransfo >ransfo, const WhichTransformed which)
Transform a Frame through a Transfo.
std::string sourceFluxField
"name of flux field in source catalog" ;
Handler of an actual image from a single CCD.
const double JanskyToMaggy
The objects which have been measured several times.
#define LOGLS_WARN(logger, message)
BaseStarList & Ref2Base(RefStarList &This)
void addImage(lsst::afw::table::SortedCatalogT< lsst::afw::table::SourceRecord > &catalog, std::shared_ptr< lsst::afw::image::TanWcs > 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.