4 #include "astrometry/solver.h" 5 #include "astrometry/index.h" 6 #include "astrometry/starkd.h" 7 #include "astrometry/fitsioutils.h" 8 #include "astrometry/fitstable.h" 19 #include "boost/format.hpp" 26 #pragma clang diagnostic push 27 #pragma clang diagnostic ignored "-Wunused-variable" 30 #pragma clang diagnostic pop 37 namespace extensions {
38 namespace astrometryNet {
48 char const *indexName)
50 float *
col =
static_cast<float*
>(fitstable_read_column_inds(tag, colName, type, starinds, nstars));
53 str(
boost::format(
"Unable to read data for %s from %s") % colName % indexName));
66 char const* isStarCol,
75 size_t const nMag = magColInfoList.
size();
77 for (
auto mc = magColInfoList.
cbegin(); mc != magColInfoList.
cend(); ++mc) {
78 if (mc->filterName.empty()) {
80 "Magnitude names cannot be empty strings.");
84 if (mc->magCol.empty()) {
86 "Magnitude column names cannot be empty strings.");
94 radecdeg2xyzarr(raDeg, decDeg, xyz);
95 double r2 = deg2distsq(radius.
asDegrees());
100 "centroid on some exposure; invalid unless \"hasCentroid\" is true)",
"pixels");
101 auto hasCentroidKey = schema.addField<afwTable::Flag>(
"hasCentroid",
102 "true if centroid field has been set");
109 for (
auto mc = magColInfoList.
cbegin(); mc != magColInfoList.
cend(); ++mc) {
113 schema.addField<
double>(
114 mc->filterName +
"_flux",
115 mc->filterName +
" flux"));
118 schema.addField<
double>(
119 mc->filterName +
"_fluxErr",
120 mc->filterName +
" flux uncertainty (sigma)"));
126 resolvedKey = schema.addField<afwTable::Flag>(
128 "set if the reference object is resolved");
132 variableKey = schema.addField<afwTable::Flag>(
134 "set if the reference object is variable");
138 "set if the reference object can be used in photometric calibration");
153 index_t* ind = (*pind);
155 double *radecs = NULL;
156 int *starinds = NULL;
158 startree_search_for(ind->starkd, xyz, r2, NULL, &radecs, &starinds, &nstars);
169 bool* stargal = NULL;
171 if (idCol || nMag || isStarCol || isVarCol) {
172 fitstable_t* tag = startree_get_tagalong(ind->starkd);
173 tfits_type flt = fitscolumn_float_type();
174 tfits_type boo = fitscolumn_boolean_type();
175 tfits_type i64 = fitscolumn_i64_type();
179 "astrometry_net_data index file %s does not contain a tag-along table, " 180 "so can't retrieve extra columns. idCol=%s, isStarCol=%s, isVarCol=%s") %
181 ind->indexname % idCol % isStarCol % isVarCol);
182 msg +=
", mag columns=[";
183 for (
unsigned int i=0; i<nMag; i++) {
187 msg +=
" name='" + magColInfoList[i].filterName +
188 "', mag='" + magColInfoList[i].magCol +
189 "', magErr='" + magColInfoList[i].magErrCol +
"'";
191 msg +=
" ]. You may need to edit the $ASTROMETRY_NET_DATA_DIR/andConfig.py file to set idColumn=None, etc.";
196 id =
static_cast<int64_t*
>(fitstable_read_column_inds(tag, idCol, i64, starinds, nstars));
199 str(
boost::format(
"Unable to read data for %s from %s") % idCol % ind->indexname));
202 if (
id && uniqueIds) {
212 for (
int i=0; i<nstars; i++) {
214 if (uids.
insert(
id[i]).second) {
218 starinds[nkeep] = starinds[i];
219 radecs[nkeep*2+0] = radecs[i*2+0];
220 radecs[nkeep*2+1] = radecs[i*2+1];
240 for (
auto mc = magColInfoList.
cbegin(); mc != magColInfoList.
cend(); ++mc) {
241 char const* col = mc->magCol.c_str();
242 mag.
push_back(read_column(tag, col, flt, starinds, nstars, ind->indexname));
244 char const* col = mc->magErrCol.c_str();
245 magErr.
push_back(read_column(tag, col, flt, starinds, nstars, ind->indexname));
255 uint8_t* sg =
static_cast<uint8_t*
>(fitstable_read_column_inds(
256 tag, isStarCol, fitscolumn_u8_type(), starinds, nstars));
257 stargal =
static_cast<bool*
>(malloc(nstars));
260 str(
boost::format(
"Unable to read data for %s from %s") % isStarCol % ind->indexname));
262 for (
int j=0; j<nstars; j++) {
263 stargal[j] = (sg[j] > 0);
268 var =
static_cast<bool*
>(fitstable_read_column_inds(tag, isVarCol, boo, starinds, nstars));
271 str(
boost::format(
"Unable to read data for %s from %s") % isVarCol % ind->indexname));
276 for (
int i=0; i<nstars; i++) {
292 src->set(hasCentroidKey,
false);
294 assert(fluxKey.size() == nMag);
296 assert(fluxErrKey.
size() == magErr.
size());
300 for (
auto mc = magColInfoList.
cbegin(); mc != magColInfoList.
cend(); ++mc, ++j) {
308 src->set(fluxKey[j], flux);
313 src->set(fluxErrKey[ej], fluxErr);
317 assert(ej == fluxErrKey.
size());
319 bool photometric =
true;
321 src->set(resolvedKey, !stargal[i]);
322 photometric &= stargal[i];
325 src->set(variableKey, var[i]);
326 photometric &= (!var[i]);
328 src->set(photometricKey, photometric);
332 for (
size_t j=0; j<mag.
size(); ++j) {
335 for (
size_t j=0; j<magErr.
size(); ++j) {
Defines the fields and offsets for a table.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
double fluxErrFromABMagErr(double magErr, double mag) noexcept
Compute flux error in Janskys from AB magnitude error and AB magnitude.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
Angle getLongitude() const noexcept
The longitude of this point.
A class representing an angle.
Reports attempts to access elements using an invalid key.
AngleUnit constexpr degrees
constant with units of degrees
A base class for image defects.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
std::shared_ptr< RecordT > src
Angle getLatitude() const noexcept
The latitude of this point.
double fluxFromABMag(double mag) noexcept
Compute flux in Janskys from AB magnitude.
A polymorphic functor base class for generating record IDs for a table.
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.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Point in an unspecified spherical coordinate system.
A class used as a handle to a particular field in a table.
Reports invalid arguments.
Record class that must contain a unique ID field and a celestial coordinate field.
SortedCatalogT< SimpleRecord > SimpleCatalog
static std::shared_ptr< SimpleTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.