LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst::jointcal::Associations Class Reference

The class that implements the relations between MeasuredStar and FittedStar. More...

#include <Associations.h>

Public Member Functions

size_t refStarListSize ()
 
size_t fittedStarListSize ()
 
 Associations ()
 Source selection is performed in python, so Associations' constructor only initializes a couple of variables. More...
 
 Associations (CcdImageList const &imageList)
 Create an Associations object from a pre-built list of ccdImages. More...
 
 Associations (Associations const &)=delete
 No moves or copies: jointcal only ever needs one Associations object. More...
 
 Associations (Associations &&)=delete
 
Associationsoperator= (Associations const &)=delete
 
Associationsoperator= (Associations &&)=delete
 
void computeCommonTangentPoint ()
 Sets a shared tangent point for all ccdImages, using the mean of the centers of all ccdImages. More...
 
void setCommonTangentPoint (lsst::afw::geom::Point2D const &commonTangentPoint)
 Sets a shared tangent point for all ccdImages. More...
 
Point getCommonTangentPoint () const
 can be used to project sidereal coordinates related to the image set on a plane. More...
 
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. More...
 
void associateCatalogs (const double matchCutInArcsec=0, const bool useFittedList=false, const bool enlargeFittedList=true)
 incrementaly builds a merged catalog of all image catalogs More...
 
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. More...
 
void deprojectFittedStars ()
 Sends back the fitted stars coordinates on the sky FittedStarsList::inTangentPlaneCoordinates keeps track of that. More...
 
void prepareFittedStars (int minMeasurements)
 Set the color field of FittedStar 's from a colored catalog. More...
 
CcdImageList const & getCcdImageList () const
 
unsigned getNFilters () const
 Number of different bands in the input image list. Not implemented so far. More...
 
const lsst::afw::geom::Box2D getRaDecBBox ()
 
int nCcdImagesValidForFit () const
 return the number of CcdImages with non-empty catalogs to-be-fit. More...
 
size_t nFittedStarsWithAssociatedRefStar () const
 Return the number of fittedStars that have an associated refStar. More...
 

Public Attributes

CcdImageList ccdImageList
 
RefStarList refStarList
 
FittedStarList fittedStarList
 

Detailed Description

The class that implements the relations between MeasuredStar and FittedStar.

Definition at line 53 of file Associations.h.

Constructor & Destructor Documentation

◆ Associations() [1/4]

lsst::jointcal::Associations::Associations ( )
inline

Source selection is performed in python, so Associations' constructor only initializes a couple of variables.

Definition at line 68 of file Associations.h.

◆ Associations() [2/4]

lsst::jointcal::Associations::Associations ( CcdImageList const &  imageList)
inline

Create an Associations object from a pre-built list of ccdImages.

This is primarily useful for tests that build their own ccdImageList, but it could be used to help parallelize the creation of the ccdImages.

Parameters
imageListA pre-built ccdImage list.

Definition at line 80 of file Associations.h.

◆ Associations() [3/4]

lsst::jointcal::Associations::Associations ( Associations const &  )
delete

No moves or copies: jointcal only ever needs one Associations object.

◆ Associations() [4/4]

lsst::jointcal::Associations::Associations ( Associations &&  )
delete

Member Function Documentation

◆ associateCatalogs()

void lsst::jointcal::Associations::associateCatalogs ( const double  matchCutInArcsec = 0,
const bool  useFittedList = false,
const bool  enlargeFittedList = true 
)

incrementaly builds a merged catalog of all image catalogs

Definition at line 88 of file Associations.cc.

89  {
90  // clear reference stars
92 
93  // clear measurement counts and associations to refstars, but keep fittedStars themselves.
94  for (auto &item : fittedStarList) {
95  item->clearBeforeAssoc();
96  }
97  // clear fitted stars
98  if (!useFittedList) fittedStarList.clear();
99 
100  for (auto &ccdImage : ccdImageList) {
101  std::shared_ptr<AstrometryTransform> toCommonTangentPlane = ccdImage->getPixelToCommonTangentPlane();
102 
103  // Clear the catalog to fit and copy the whole catalog into it.
104  // This allows reassociating from scratch after a fit.
105  ccdImage->resetCatalogForFit();
106  MeasuredStarList &catalog = ccdImage->getCatalogForFit();
107 
108  // Associate with previous lists.
109  /* To speed up the match (more precisely the contruction of the FastFinder), select in the
110  fittedStarList the objects that are within reach of the current ccdImage */
111  Frame ccdImageFrameCPT = toCommonTangentPlane->apply(ccdImage->getImageFrame(), false);
112  ccdImageFrameCPT = ccdImageFrameCPT.rescale(1.10); // add 10 % margin.
113  // We cannot use FittedStarList::ExtractInFrame, because it does an actual copy, which we don't want
114  // here: we want the pointers in the StarMatch to refer to fittedStarList elements.
115  FittedStarList toMatch;
116 
117  for (auto const &fittedStar : fittedStarList) {
118  if (ccdImageFrameCPT.inFrame(*fittedStar)) {
119  toMatch.push_back(fittedStar);
120  }
121  }
122 
123  // divide by 3600 because coordinates in CTP are in degrees.
124  auto starMatchList = listMatchCollect(Measured2Base(catalog), Fitted2Base(toMatch),
125  toCommonTangentPlane.get(), matchCutInArcSec / 3600.);
126 
127  /* should check what this removeAmbiguities does... */
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());
131 
132  // Associate MeasuredStar -> FittedStar using the surviving matches.
133 
134  int matchedCount = 0;
135  for (auto const &starMatch : *starMatchList) {
136  auto bs = starMatch.s1;
137  auto ms_const = std::dynamic_pointer_cast<const MeasuredStar>(bs);
138  auto ms = std::const_pointer_cast<MeasuredStar>(ms_const);
139  auto bs2 = starMatch.s2;
140  auto fs_const = std::dynamic_pointer_cast<const FittedStar>(bs2);
141  auto fs = std::const_pointer_cast<FittedStar>(fs_const);
142  ms->setFittedStar(fs);
143  matchedCount++;
144  }
145  LOGLS_INFO(_log, "Matched " << matchedCount << " objects in " << ccdImage->getName());
146 
147  // add unmatched objets to FittedStarList
148  int unMatchedCount = 0;
149  for (auto const &mstar : catalog) {
150  // to check if it was matched, just check if it has a fittedStar Pointer assigned
151  if (mstar->getFittedStar()) continue;
152  if (enlargeFittedList) {
153  auto fs = std::make_shared<FittedStar>(*mstar);
154  // transform coordinates to CommonTangentPlane
155  toCommonTangentPlane->transformPosAndErrors(*fs, *fs);
156  fittedStarList.push_back(fs);
157  mstar->setFittedStar(fs);
158  }
159  unMatchedCount++;
160  }
161  LOGLS_INFO(_log, "Unmatched objects: " << unMatchedCount);
162  } // end of loop on CcdImages
163 
164  // !!!!!!!!!!!!!!!!!
165  // TODO: DO WE REALLY NEED THIS???
166  // Why do we need to do this, instead of directly computing them in normalizeFittedStars?
167  // What makes the magnitudes special here?
168  // !!!!!!!!!!!!!!!!!
169  // assignMags();
170 }
std::unique_ptr< StarMatchList > listMatchCollect(const BaseStarList &list1, const BaseStarList &list2, const AstrometryTransform *guess, const double maxDist)
assembles star matches.
Definition: ListMatch.cc:569
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Definition: Log.h:593
T dynamic_pointer_cast(T... args)
T clear(T... args)
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
Definition: Log.h:613
T get(T... args)
BaseStarList & Fitted2Base(FittedStarList &This)
Definition: FittedStar.cc:64
BaseStarList & Measured2Base(MeasuredStarList &This)
Definition: MeasuredStar.cc:58
FittedStarList fittedStarList
Definition: Associations.h:57

◆ collectRefStars()

void lsst::jointcal::Associations::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.

Parameters
refCatThe catalog of reference sources
[in]matchCutSeparation radius to match fitted and reference stars.
fluxFieldThe field name in refCat to get the flux from.
rejectBadFluxesReject reference sources with flux=NaN or 0 and/or fluxErr=NaN or 0. Typically false for astrometry and true for photometry.

Definition at line 172 of file Associations.cc.

173  {
174  if (refCat.size() == 0) {
175  throw(LSST_EXCEPT(pex::exceptions::InvalidParameterError,
176  " reference catalog is empty : stop here "));
177  }
178 
179  afw::table::CoordKey coordKey = refCat.getSchema()["coord"];
180  auto fluxKey = refCat.getSchema().find<double>(fluxField).key;
181  // Don't blow up if the reference catalog doesn't contain errors.
182  afw::table::Key<double> fluxErrKey;
183  try {
184  fluxErrKey = refCat.getSchema().find<double>(fluxField + "Err").key;
185  } catch (pex::exceptions::NotFoundError &) {
186  LOGLS_WARN(_log, "Flux error field ("
187  << fluxField << "Err"
188  << ") not found in reference catalog. Not using ref flux errors.");
189  }
190 
191  refStarList.clear();
192  for (size_t i = 0; i < refCat.size(); i++) {
193  auto const &record = refCat.get(i);
194 
195  auto coord = record->get(coordKey);
196  double flux = record->get(fluxKey);
197  double fluxErr;
198  if (fluxErrKey.isValid()) {
199  fluxErr = record->get(fluxErrKey);
200  } else {
202  }
203  double ra = lsst::afw::geom::radToDeg(coord.getLongitude());
204  double dec = lsst::afw::geom::radToDeg(coord.getLatitude());
205  auto star = std::make_shared<RefStar>(ra, dec, flux, fluxErr);
206 
207  // TODO DM-10826: RefCats aren't guaranteed to have position errors.
208  // TODO: Need to devise a way to check whether the refCat has position errors
209  // TODO: and use them instead, if available.
210  // cook up errors: 100 mas per cooordinate
211  star->vx = std::pow(0.1 / 3600 / cos(coord.getLatitude()), 2);
212  star->vy = std::pow(0.1 / 3600, 2);
213  star->vxy = 0.;
214 
215  // Reject sources with non-finite fluxes and flux errors, and fluxErr=0 (which gives chi2=inf).
216  if (rejectBadFluxes && (!std::isfinite(flux) || !std::isfinite(fluxErr) || fluxErr <= 0)) continue;
217  refStarList.push_back(star);
218  }
219 
220  // project on CTP (i.e. RaDec2CTP), in degrees
221  AstrometryTransformLinear identity;
222  TanRaDecToPixel raDecToCommonTangentPlane(identity, _commonTangentPoint);
223 
224  associateRefStars(matchCut.asArcseconds(), &raDecToCommonTangentPlane);
225 }
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:633
constexpr double radToDeg(double x) noexcept
Definition: Angle.h:52
double dec
Definition: Match.cc:41
double cos(Angle const &a)
Definition: Angle.h:103
T push_back(T... args)
T isfinite(T... args)
T clear(T... args)
T get(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Key< U > key
Definition: Schema.cc:281
T pow(T... args)
T quiet_NaN(T... args)

◆ computeCommonTangentPoint()

void lsst::jointcal::Associations::computeCommonTangentPoint ( )

Sets a shared tangent point for all ccdImages, using the mean of the centers of all ccdImages.

Definition at line 72 of file Associations.cc.

72  {
74  centers.reserve(ccdImageList.size());
75  for (auto const &ccdImage : ccdImageList) {
76  centers.push_back(ccdImage->getBoresightRaDec());
77  }
78  auto commonTangentPoint = afw::geom::averageSpherePoint(centers);
79  LOGLS_DEBUG(_log, "Using common tangent point: " << commonTangentPoint.getPosition(afw::geom::degrees));
80  setCommonTangentPoint(commonTangentPoint.getPosition(afw::geom::degrees));
81 }
T push_back(T... args)
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Definition: Log.h:593
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:109
void setCommonTangentPoint(lsst::afw::geom::Point2D const &commonTangentPoint)
Sets a shared tangent point for all ccdImages.
Definition: Associations.cc:83
T size(T... args)
STL class.
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
Definition: SpherePoint.cc:235
T reserve(T... args)

◆ createCcdImage()

void lsst::jointcal::Associations::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.

Parameters
[in]catalogThe extracted source catalog, selected for good astrometric sources.
[in]wcsThe exposure's original wcs
[in]visitInfoThe exposure's visitInfo object
[in]bboxThe bounding box of the exposure
[in]filterThe exposure's filter
[in]photoCalibThe exposure's photometric calibration
[in]detectorThe exposure's detector
[in]visitThe visit identifier
[in]ccdThe ccd identifier
[in]controlThe JointcalControl object

Definition at line 58 of file Associations.cc.

64  {
65  auto ccdImage = std::make_shared<CcdImage>(catalog, wcs, visitInfo, bbox, filter, photoCalib, detector,
66  visit, ccd, control.sourceFluxField);
68  LOGLS_DEBUG(_log, "Catalog " << ccdImage->getName() << " has " << ccdImage->getWholeCatalog().size()
69  << " objects.");
70 }
Key< int > visitInfo
Definition: Exposure.cc:68
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
T push_back(T... args)
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Definition: Log.h:593
table::Key< int > detector
table::Box2IKey bbox
Definition: Detector.cc:166

◆ deprojectFittedStars()

void lsst::jointcal::Associations::deprojectFittedStars ( )

Sends back the fitted stars coordinates on the sky FittedStarsList::inTangentPlaneCoordinates keeps track of that.

Definition at line 368 of file Associations.cc.

368  {
369  // By default, Associations::fittedStarList is expressed on the Associations::commonTangentPlane.
370  // For AstrometryFit, we need it on the sky.
372  LOGLS_WARN(_log,
373  "DeprojectFittedStars: Fitted stars are already in sidereal coordinates, nothing done ");
374  return;
375  }
376 
377  TanPixelToRaDec ctp2Sky(AstrometryTransformLinear(), getCommonTangentPoint());
380 }
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:633
void applyTransform(const Operator &op)
enables to apply a geometrical transform if Star is Basestar or derives from it.
Definition: StarList.h:98
Point getCommonTangentPoint() const
can be used to project sidereal coordinates related to the image set on a plane.
Definition: Associations.h:104
FittedStarList fittedStarList
Definition: Associations.h:57

◆ fittedStarListSize()

size_t lsst::jointcal::Associations::fittedStarListSize ( )
inline

Definition at line 62 of file Associations.h.

62 { return fittedStarList.size(); }
T size(T... args)
FittedStarList fittedStarList
Definition: Associations.h:57

◆ getCcdImageList()

CcdImageList const& lsst::jointcal::Associations::getCcdImageList ( ) const
inline

Definition at line 162 of file Associations.h.

162 { return ccdImageList; }

◆ getCommonTangentPoint()

Point lsst::jointcal::Associations::getCommonTangentPoint ( ) const
inline

can be used to project sidereal coordinates related to the image set on a plane.

Definition at line 104 of file Associations.h.

104 { return _commonTangentPoint; }

◆ getNFilters()

unsigned lsst::jointcal::Associations::getNFilters ( ) const
inline

Number of different bands in the input image list. Not implemented so far.

Definition at line 165 of file Associations.h.

165 { return 1; }

◆ getRaDecBBox()

const lsst::afw::geom::Box2D lsst::jointcal::Associations::getRaDecBBox ( )

Definition at line 227 of file Associations.cc.

227  {
228  // compute the frame on the CTP that contains all input images
229  Frame tangentPlaneFrame;
230 
231  for (auto const &ccdImage : ccdImageList) {
232  Frame CTPFrame = ccdImage->getPixelToCommonTangentPlane()->apply(ccdImage->getImageFrame(), false);
233  if (tangentPlaneFrame.getArea() == 0)
234  tangentPlaneFrame = CTPFrame;
235  else
236  tangentPlaneFrame += CTPFrame;
237  }
238 
239  // convert tangent plane coordinates to RaDec:
240  AstrometryTransformLinear identity;
241  TanPixelToRaDec commonTangentPlaneToRaDec(identity, _commonTangentPoint);
242  Frame raDecFrame = commonTangentPlaneToRaDec.apply(tangentPlaneFrame, false);
243 
244  lsst::afw::geom::Point<double> min(raDecFrame.xMin, raDecFrame.yMin);
245  lsst::afw::geom::Point<double> max(raDecFrame.xMax, raDecFrame.yMax);
247 
248  return box;
249 }
A floating-point coordinate rectangle geometry.
Definition: Box.h:294
A coordinate class intended to represent absolute positions.
int min
int max

◆ nCcdImagesValidForFit()

int lsst::jointcal::Associations::nCcdImagesValidForFit ( ) const

return the number of CcdImages with non-empty catalogs to-be-fit.

Definition at line 382 of file Associations.cc.

382  {
384  return item->getCatalogForFit().size() > 0;
385  });
386 }
T end(T... args)
T count_if(T... args)
T begin(T... args)

◆ nFittedStarsWithAssociatedRefStar()

size_t lsst::jointcal::Associations::nFittedStarsWithAssociatedRefStar ( ) const

Return the number of fittedStars that have an associated refStar.

Definition at line 388 of file Associations.cc.

388  {
389  size_t count = 0;
390  for (auto const &fittedStar : fittedStarList) {
391  if ((fittedStar != nullptr) & (fittedStar->getRefStar() != nullptr)) count++;
392  }
393  return count;
394 }
T count(T... args)
FittedStarList fittedStarList
Definition: Associations.h:57

◆ operator=() [1/2]

Associations& lsst::jointcal::Associations::operator= ( Associations const &  )
delete

◆ operator=() [2/2]

Associations& lsst::jointcal::Associations::operator= ( Associations &&  )
delete

◆ prepareFittedStars()

void lsst::jointcal::Associations::prepareFittedStars ( int  minMeasurements)

Set the color field of FittedStar 's from a colored catalog.

Prepare the fittedStar list by making quality cuts and normalizing measurements.

Parameters
[in]minMeasurementsThe minimum number of measuredStars for a FittedStar to be included.

Definition at line 277 of file Associations.cc.

277  {
278  selectFittedStars(minMeasurements);
279  normalizeFittedStars();
280 }

◆ refStarListSize()

size_t lsst::jointcal::Associations::refStarListSize ( )
inline

Definition at line 61 of file Associations.h.

61 { return refStarList.size(); }
T size(T... args)

◆ setCommonTangentPoint()

void lsst::jointcal::Associations::setCommonTangentPoint ( lsst::afw::geom::Point2D const &  commonTangentPoint)

Sets a shared tangent point for all ccdImages.

Parameters
commonTangentPointThe common tangent point of all input images (decimal degrees).

Definition at line 83 of file Associations.cc.

83  {
84  _commonTangentPoint = Point(commonTangentPoint.getX(), commonTangentPoint.getY()); // a jointcal::Point
85  for (auto &ccdImage : ccdImageList) ccdImage->setCommonTangentPoint(_commonTangentPoint);
86 }

Member Data Documentation

◆ ccdImageList

CcdImageList lsst::jointcal::Associations::ccdImageList

Definition at line 55 of file Associations.h.

◆ fittedStarList

FittedStarList lsst::jointcal::Associations::fittedStarList

Definition at line 57 of file Associations.h.

◆ refStarList

RefStarList lsst::jointcal::Associations::refStarList

Definition at line 56 of file Associations.h.


The documentation for this class was generated from the following files: