LSSTApplications  17.0+103,17.0+11,17.0+61,18.0.0+13,18.0.0+25,18.0.0+5,18.0.0+52,18.0.0-4-g68ffd23,18.1.0-1-g0001055+8,18.1.0-1-g03d53ef+1,18.1.0-1-g1349e88+28,18.1.0-1-g2505f39+22,18.1.0-1-g380d4d4+27,18.1.0-1-g5315e5e+1,18.1.0-1-g5e4b7ea+10,18.1.0-1-g7e8fceb+1,18.1.0-1-g85f8cd4+23,18.1.0-1-g9a6769a+13,18.1.0-1-ga1a4c1a+22,18.1.0-1-gd55f500+17,18.1.0-12-g42eabe8e+10,18.1.0-14-gd04256d+15,18.1.0-16-g430f6a53+1,18.1.0-17-gd2166b6e4,18.1.0-18-gb5d19ff+1,18.1.0-2-gfbf3545+7,18.1.0-2-gfefb8b5+16,18.1.0-3-g52aa583+13,18.1.0-3-g62b5e86+14,18.1.0-3-g8f4a2b1+17,18.1.0-3-g9bc06b8+7,18.1.0-3-gb69f684+9,18.1.0-4-g1ee41a7+1,18.1.0-5-g6dbcb01+13,18.1.0-5-gc286bb7+3,18.1.0-6-g48bdcd3+2,18.1.0-6-gd05e160+9,18.1.0-7-gc4d902b+2,18.1.0-7-gebc0338+8,18.1.0-9-gae7190a+10,w.2019.38
LSSTDataManagementBasePackage
Classes | Public Member Functions | List of all members
lsst::meas::extensions::astrometryNet::Solver Class Reference

A thin C++ wrapper around astrometry.net's solver_t struct. More...

#include <astrometry_net.h>

Public Member Functions

 Solver ()
 
 ~Solver ()
 
lsst::afw::table::SimpleCatalog getCatalog (std::vector< index_t *> inds, lsst::geom::SpherePoint const &ctrCoord, lsst::geom::Angle const &radius, const char *idCol, std::vector< std::string > const &filterNameList, std::vector< std::string > const &magColList, std::vector< std::string > const &magErrColList, const char *starGalCol, const char *varCol, bool uniqueIds=true)
 Load reference objects in a region of the sky described by a center coordinate and a radius. More...
 
std::shared_ptr< lsst::daf::base::PropertyListgetSolveStats () const
 
std::shared_ptr< lsst::afw::geom::SkyWcsgetWcs ()
 
bool didSolve () const
 
void run (double cpulimit)
 
std::pair< double, double > getQuadSizeRangeArcsec () const
 
void addIndices (std::vector< index_t *> inds)
 Add indices to the solver. More...
 
void setParity (bool flipped)
 Set parity to flipped (if true) or normal (if false) More...
 
void setMatchThreshold (double threshold)
 
void setPixelScaleRange (double low, double high)
 
void setRaDecRadius (double ra, double dec, double radius_deg)
 
void setImageSize (int width, int height)
 
void setMaxStars (int maxStars)
 
void setStars (lsst::afw::table::SourceCatalog const &srcs, int x0, int y0)
 

Detailed Description

A thin C++ wrapper around astrometry.net's solver_t struct.

This provide memory management and methods used by LSST.

Definition at line 120 of file astrometry_net.h.

Constructor & Destructor Documentation

◆ Solver()

lsst::meas::extensions::astrometryNet::Solver::Solver ( )
explicit

Definition at line 63 of file astrometry_net.cc.

63 : _solver(solver_new()) {}

◆ ~Solver()

lsst::meas::extensions::astrometryNet::Solver::~Solver ( )

Definition at line 65 of file astrometry_net.cc.

65  {
66  // Working around a bug in Astrometry.net: doesn't take ownership of the field.
67  // unseemly familiarity with the innards... but valgrind-clean.
68  starxy_free(_solver->fieldxy);
69  _solver->fieldxy = NULL;
70 }

Member Function Documentation

◆ addIndices()

void lsst::meas::extensions::astrometryNet::Solver::addIndices ( std::vector< index_t *>  inds)

Add indices to the solver.

The indices are bare pointers whose memory is managed by the caller. Typically the indices are owned by a MultiIndex object owned by the caller.

Definition at line 181 of file astrometry_net.cc.

181  {
182  for (std::vector<index_t*>::iterator pind = inds.begin();
183  pind != inds.end(); ++pind) {
184  detail::IndexManager man(*pind);
185 // printf("Checking index \"%s\"\n", man.index->indexname);
186  if (_solver->use_radec) {
187  double ra,dec,radius;
188  xyzarr2radecdeg(_solver->centerxyz, &ra, &dec);
189  radius = distsq2deg(_solver->r2);
190  if (!index_is_within_range(man.index, ra, dec, radius)) {
191  //printf("Not within RA,Dec range\n");
192  continue;
193  }
194  }
195  // qlo,qhi in arcsec
196  double qlo, qhi;
197  solver_get_quad_size_range_arcsec(_solver.get(), &qlo, &qhi);
198  if (!index_overlaps_scale_range(man.index, qlo, qhi)) {
199 // printf("Not within quad scale range\n");
200  continue;
201  }
202 // printf("Adding index.\n");
203  if (index_reload(man.index)) {
205  "Failed to index_reload() an astrometry_net_data index file -- out of file descriptors?");
206  }
207 
208  solver_add_index(_solver.get(), man.index);
209  }
210 }
double dec
Definition: Match.cc:41
T end(T... args)
Reports errors in external input/output operations.
Definition: Runtime.h:160
T get(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
STL class.
T begin(T... args)

◆ didSolve()

bool lsst::meas::extensions::astrometryNet::Solver::didSolve ( ) const
inline

Definition at line 171 of file astrometry_net.h.

171  {
172  return solver_did_solve(_solver.get());
173  }
T get(T... args)

◆ getCatalog()

lsst::afw::table::SimpleCatalog lsst::meas::extensions::astrometryNet::Solver::getCatalog ( std::vector< index_t *>  inds,
lsst::geom::SpherePoint const &  ctrCoord,
lsst::geom::Angle const &  radius,
const char *  idCol,
std::vector< std::string > const &  filterNameList,
std::vector< std::string > const &  magColList,
std::vector< std::string > const &  magErrColList,
const char *  starGalCol,
const char *  varCol,
bool  uniqueIds = true 
)

Load reference objects in a region of the sky described by a center coordinate and a radius.

Parameters
[in]indslist of star kd-trees from astrometry.net
[in]ctrCoordcenter of search region
[in]radiussearch radius
[in]idColname of ID column in astrometry.net data
[in]filterNameListnames of filters in astrometry.net data
[in]magColListnames of magnitude columns in astrometry.net data
[in]magErrColListnames of magnitude uncertainty (sigma) columns in astrometry.net data
[in]starGalColname of "starGal" column (true if object is a star) in astrometry.net data
[in]varColname of "var" column (true if brightness is variable) in astrometry.net data
[in]uniqueIdsif true then only return unique IDs (the first of each seen)

Returned schema:

  • id
  • coord: ICRS sky position (an lsst::geom::SpherePoint)
  • centroid: centroid on some exposure, if relevant (an lsst::geom::Point2D); returned value is not set
  • hasCentroid: if true then centroid has been set; returned value is false
  • filterName_flux: flux in the specified filter (double)
  • filterName_fluxErr: flux uncertainty in the specified filter (double)
  • resolved (if starGalCol specified): true if object is not resolved
  • variable (if varCol specified): true if brightness is variable
  • photometric: true if not resolved (or starGalCol blank) and not variable (or varCol blank); note that if starGalCol and varCol both blank then all objects are claimed to be photometric

Definition at line 72 of file astrometry_net.cc.

83 {
84  if ((filterNameList.size() != magColList.size()) || (filterNameList.size() != magErrColList.size())) {
86  "Filter name, mag column, and mag error column vectors must be the same length.");
87  }
88  std::vector<detail::MagColInfo> magColInfoList;
89  for (size_t i=0; i<filterNameList.size(); ++i) {
90  astrometryNet::detail::MagColInfo mc;
91  mc.filterName = filterNameList[i];
92  mc.magCol = magColList[i];
93  mc.magErrCol = magErrColList[i];
94  magColInfoList.push_back(mc);
95  }
96  return detail::getCatalogImpl(inds, ctrCoord, radius,
97  idCol, magColInfoList, starGalCol, varCol, uniqueIds);
98 }
T push_back(T... args)
lsst::afw::table::SimpleCatalog getCatalogImpl(std::vector< index_t *> inds, lsst::geom::SpherePoint const &ctrCoord, lsst::geom::Angle const &radius, const char *idCol, std::vector< MagColInfo > const &magColInfoList, const char *starGalCol, const char *varCol, bool uniqueIds=true)
Implementation for index_t::getCatalog method.
Definition: utils.cc:61
T size(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
STL class.
Reports invalid arguments.
Definition: Runtime.h:66

◆ getQuadSizeRangeArcsec()

std::pair<double, double> lsst::meas::extensions::astrometryNet::Solver::getQuadSizeRangeArcsec ( ) const
inline

Definition at line 177 of file astrometry_net.h.

177  {
178  double qlo,qhi;
179  solver_get_quad_size_range_arcsec(_solver.get(), &qlo, &qhi);
180  return std::make_pair(qlo, qhi);
181  }
T make_pair(T... args)
T get(T... args)

◆ getSolveStats()

std::shared_ptr< lsst::daf::base::PropertyList > lsst::meas::extensions::astrometryNet::Solver::getSolveStats ( ) const

Definition at line 100 of file astrometry_net.cc.

100  {
101  // Gather solve stats...
102  auto qa = std::make_shared<daf::base::PropertyList>();
103  // FIXME -- Ticket #1875 prevents dotted-names from working with toString().
104  qa->set("meas_astrom*an*n_tried", _solver->numtries);
105  qa->set("meas_astrom*an*n_matched", _solver->nummatches);
106  qa->set("meas_astrom*an*n_scaleok", _solver->numscaleok);
107  qa->set("meas_astrom*an*n_cxdxcut", _solver->num_cxdx_skipped);
108  qa->set("meas_astrom*an*n_meanxcut", _solver->num_meanx_skipped);
109  qa->set("meas_astrom*an*n_radeccut", _solver->num_radec_skipped);
110  qa->set("meas_astrom*an*n_scalecut", _solver->num_abscale_skipped);
111  qa->set("meas_astrom*an*n_verified", _solver->num_verified);
112  qa->set("meas_astrom*an*time_used", _solver->timeused);
113  qa->set("meas_astrom*an*best_logodds", _solver->best_logodds);
114  if (_solver->best_index) {
115  index_t* ind = _solver->best_index;
116  qa->set("meas_astrom*an*best_index*id", ind->indexid);
117  qa->set("meas_astrom*an*best_index*hp", ind->healpix);
118  qa->set("meas_astrom*an*best_index*nside", ind->hpnside);
119  qa->set("meas_astrom*an*best_index*name", std::string(ind->indexname));
120  }
121  if (_solver->have_best_match) {
122  MatchObj* mo = &(_solver->best_match);
123  std::string s = boost::str(boost::format("%i") % mo->star[0]);
124  for (int i=1; i<mo->dimquads; i++)
125  s = s + boost::str(boost::format(", %i") % mo->star[i]);
126  qa->set("meas_astrom*an*best_match*starinds", s);
127  qa->set("meas_astrom*an*best_match*coderr", std::sqrt(mo->code_err));
128  qa->set("meas_astrom*an*best_match*nmatch", mo->nmatch);
129  qa->set("meas_astrom*an*best_match*ndistract", mo->ndistractor);
130  qa->set("meas_astrom*an*best_match*nconflict", mo->nconflict);
131  qa->set("meas_astrom*an*best_match*nfield", mo->nfield);
132  qa->set("meas_astrom*an*best_match*nindex", mo->nindex);
133  qa->set("meas_astrom*an*best_match*nbest", mo->nbest);
134  qa->set("meas_astrom*an*best_match*logodds", mo->logodds);
135  qa->set("meas_astrom*an*best_match*parity", mo->parity ? 0 : 1);
136  qa->set("meas_astrom*an*best_match*nobjs", mo->objs_tried);
137  }
138  return qa;
139 }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:167
STL class.
solver_t * s
T sqrt(T... args)

◆ getWcs()

std::shared_ptr< lsst::afw::geom::SkyWcs > lsst::meas::extensions::astrometryNet::Solver::getWcs ( )

Definition at line 141 of file astrometry_net.cc.

141  {
142  MatchObj* match = solver_get_best_match(_solver.get());
143  if (!match)
145  tan_t* wcs = &(match->wcstan);
146 
147  geom::Point2D crpix(wcs->crpix[0], wcs->crpix[1]);
148  auto const crval = geom::SpherePoint(wcs->crval[0] * geom::degrees,
149  wcs->crval[1] * geom::degrees);
150  Eigen::Matrix2d cdMatrix;
151  for (int i = 0; i < 2; ++i) {
152  for (int j = 0; j < 2; ++j) {
153  cdMatrix(i, j) = wcs->cd[i][j];
154  }
155  }
156  return afw::geom::makeSkyWcs(crpix, crval, cdMatrix);
157 }
table::PointKey< double > crpix
Definition: OldWcs.cc:131
table::PointKey< double > crval
Definition: OldWcs.cc:130
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:109
T get(T... args)
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:506
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35

◆ run()

void lsst::meas::extensions::astrometryNet::Solver::run ( double  cpulimit)

Definition at line 159 of file astrometry_net.cc.

159  {
160  solver_log_params(_solver.get());
161  struct timer_baton tt;
162  if (cpulimit > 0.) {
163  tt.s = _solver.get();
164  tt.timelimit = cpulimit;
165  _solver->userdata = &tt;
166  _solver->timer_callback = timer_callback;
167  }
168  solver_run(_solver.get());
169  if (cpulimit > 0.) {
170  _solver->timer_callback = NULL;
171  _solver->userdata = NULL;
172  }
173 }
T get(T... args)

◆ setImageSize()

void lsst::meas::extensions::astrometryNet::Solver::setImageSize ( int  width,
int  height 
)

Definition at line 212 of file astrometry_net.cc.

212  {
213  solver_set_field_bounds(_solver.get(), 0, width, 0, height);
214  double hi = hypot(width, height);
215  double lo = 0.1 * std::min(width, height);
216  solver_set_quad_size_range(_solver.get(), lo, hi);
217 }
T min(T... args)
T hypot(T... args)
T get(T... args)

◆ setMatchThreshold()

void lsst::meas::extensions::astrometryNet::Solver::setMatchThreshold ( double  threshold)
inline

Definition at line 198 of file astrometry_net.h.

198  {
199  solver_set_keep_logodds(_solver.get(), threshold);
200  }
T get(T... args)

◆ setMaxStars()

void lsst::meas::extensions::astrometryNet::Solver::setMaxStars ( int  maxStars)
inline

Definition at line 213 of file astrometry_net.h.

213  {
214  _solver->endobj = maxStars;
215  }

◆ setParity()

void lsst::meas::extensions::astrometryNet::Solver::setParity ( bool  flipped)
inline

Set parity to flipped (if true) or normal (if false)

Definition at line 194 of file astrometry_net.h.

194  {
195  _solver->parity = flipped ? PARITY_FLIP : PARITY_NORMAL;
196  }

◆ setPixelScaleRange()

void lsst::meas::extensions::astrometryNet::Solver::setPixelScaleRange ( double  low,
double  high 
)
inline

Definition at line 202 of file astrometry_net.h.

202  {
203  _solver->funits_lower = low;
204  _solver->funits_upper = high;
205  }

◆ setRaDecRadius()

void lsst::meas::extensions::astrometryNet::Solver::setRaDecRadius ( double  ra,
double  dec,
double  radius_deg 
)
inline

Definition at line 207 of file astrometry_net.h.

207  {
208  solver_set_radec(_solver.get(), ra, dec, radius_deg);
209  }
double dec
Definition: Match.cc:41
T get(T... args)

◆ setStars()

void lsst::meas::extensions::astrometryNet::Solver::setStars ( lsst::afw::table::SourceCatalog const &  srcs,
int  x0,
int  y0 
)

Definition at line 219 of file astrometry_net.cc.

219  {
220  // convert to Astrometry.net "starxy_t"
221  starxy_free(_solver->fieldxy);
222  const size_t N = srcs.size();
223  starxy_t *starxy = starxy_new(N, true, false);
224  for (size_t i=0; i<N; ++i) {
225  double const x = srcs[i].getX();
226  double const y = srcs[i].getY();
227  double const flux = srcs[i].getPsfInstFlux();
228  starxy_set(starxy, i, x - x0, y - y0);
229  starxy_set_flux(starxy, i, flux);
230  }
231  // Sort the array
232  starxy_sort_by_flux(starxy);
233 
234  starxy_free(solver_get_field(_solver.get()));
235  solver_free_field(_solver.get());
236  solver_set_field(_solver.get(), starxy);
237  solver_reset_field_size(_solver.get());
238  // Find field boundaries and precompute kdtree
239  solver_preprocess_field(_solver.get());
240 }
int y
Definition: SpanSet.cc:49
double x
T get(T... args)

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