LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Namespaces | Classes | Functions
lsst::ap::utils Namespace Reference

Namespaces

 config
 
 mapperUtils
 
 skyTileUtils
 

Classes

class  Arena
 
class  CsvReader
 
class  CsvWriter
 
struct  CsvControl
 Parameters that define a Character-Separated-Value dialect. More...
 
struct  CsvConversionControl
 Catalog to CSV conversion parameters. More...
 
class  PT1SkyTile
 
class  SmallPtrVector
 

Functions

void writeCsv (BaseCatalog const &catalog, CsvConversionControl const &cnvControl, CsvControl const &csvControl, std::string const &csvFile, bool truncate, bool append)
 
Eigen::Vector3d const earthPosition (double const epoch)
 
void makeSourceHistogram (lsst::afw::image::Image< unsigned short >::Ptr histogram, lsst::afw::table::SourceCatalog const &sources, lsst::afw::image::Wcs::Ptr wcs, bool ignoreOffImage)
 
void rasterizePolygon (std::vector< Point2D > const &verts, lsst::afw::image::Image< float >::Ptr img)
 
void updateCoverageMap (lsst::afw::image::Image< float >::Ptr covMap, lsst::afw::image::Wcs::Ptr covMapWcs, lsst::afw::image::Wcs::Ptr wcs, int width, int height, int step)
 
void thetaRangeReduce (Angle &min, Angle &max)
 
Angle const maxAlpha (Angle radius, Angle centerPhi)
 
void positionAndVelocity (Eigen::Vector3d &p, Eigen::Vector3d &v, Angle ra, Angle decl, double muRa, double muDecl, double vRadial, Angle parallax)
 
Eigen::Vector2d const cartesianToSpherical (Eigen::Vector3d const &v)
 
template<>
std::string CsvReader::_null< std::string > ()
 
template<>
std::string CsvReader::_get< std::string > (char const *field) const
 
template<typename T >
CsvWriteroperator<< (CsvWriter &w, T const &v)
 
CsvWriterendr (CsvWriter &w)
 
CsvWriterflush (CsvWriter &w)
 
CsvWriternullf (CsvWriter &w)
 
template<typename T >
CsvWriteroperator<< (CsvWriter &w, CsvWriter &(*manip)(CsvWriter &))
 
template<typename T >
CsvWriteroperator<< (CsvWriter &, CsvWriter &(*)(CsvWriter &))
 
void writeCsv (lsst::afw::table::BaseCatalog const &catalog, CsvConversionControl const &cnvControl, CsvControl const &csvControl, std::string const &csvFile, bool truncate, bool append)
 Convert an afw Catalog to a CSV file. More...
 
void rasterizePolygon (std::vector< lsst::afw::geom::Point2D > const &verts, lsst::afw::image::Image< float >::Ptr img)
 
lsst::afw::geom::Angle const clampPhi (lsst::afw::geom::Angle const a)
 
lsst::afw::coord::IcrsCoord const cartesianToIcrs (Eigen::Vector3d const &v)
 
lsst::afw::geom::Angle const angularSeparation (Eigen::Vector3d const &v1, Eigen::Vector3d const &v2)
 

Function Documentation

lsst::afw::geom::Angle const lsst::ap::utils::angularSeparation ( Eigen::Vector3d const &  v1,
Eigen::Vector3d const &  v2 
)
inline

Returns the angular separation between two 3-vectors of arbitrary magnitude.

Definition at line 83 of file SpatialUtils.h.

86 {
89 
90  double ss = v1.cross(v2).norm();
91  double cs = v1.dot(v2);
92  if (ss != 0.0 || cs != 0.0) {
93  return Angle(std::atan2(ss, cs), radians);
94  }
95  return Angle(0.0, radians);
96 }
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
Point2D const * v2
Definition: ImageUtils.cc:89
Point2D const * v1
Definition: ImageUtils.cc:88
lsst::afw::geom::Angle Angle
Definition: misc.h:42
lsst::afw::coord::IcrsCoord const lsst::ap::utils::cartesianToIcrs ( Eigen::Vector3d const &  v)
inline

Definition at line 74 of file SpatialUtils.h.

74  {
75  Eigen::Vector2d sc = cartesianToSpherical(v);
77  sc.y() * lsst::afw::geom::radians);
78 }
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
lsst::afw::coord::IcrsCoord IcrsCoord
Definition: misc.h:41
Eigen::Vector2d const cartesianToSpherical(Eigen::Vector3d const &v)
Eigen::Vector2d const lsst::ap::utils::cartesianToSpherical ( Eigen::Vector3d const &  v)

Converts the input position vector, which need not have unit magnitude, to spherical coordinates (rad).

Definition at line 161 of file SpatialUtils.cc.

161  {
162  double d2 = v.x()*v.x() + v.y()*v.y();
163  double theta = (d2 == 0.0) ? 0.0 : std::atan2(v.y(), v.x());
164  double phi = (v.z() == 0.0) ? 0.0 : std::atan2(v.z(), std::sqrt(d2));
165  return Eigen::Vector2d(theta, phi);
166 }
lsst::afw::geom::Angle const lsst::ap::utils::clampPhi ( lsst::afw::geom::Angle const  a)
inline

Clamps the given latitude/declination to [-PI/2, PI/2] radians.

Definition at line 45 of file SpatialUtils.h.

45  {
49 
50  if (a.asRadians() < -HALFPI) {
51  return Angle(-HALFPI, radians);
52  } else if (a.asRadians() > HALFPI) {
53  return Angle(HALFPI, radians);
54  }
55  return a;
56 }
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
lsst::afw::geom::Angle Angle
Definition: misc.h:42
double const HALFPI
Definition: Angle.h:20
template<>
std::string lsst::ap::utils::CsvReader::_get< std::string > ( char const *  field) const
inline

Definition at line 243 of file Csv.cc.

243  {
244  return std::string(field);
245 }
template<>
std::string lsst::ap::utils::CsvReader::_null< std::string > ( )
inline

Definition at line 193 of file Csv.cc.

193  {
194  return std::string();
195 }
Eigen::Vector3d const lsst::ap::utils::earthPosition ( double const  epoch)

Returns the barycentric coordinates (in AU) of the earth at the specified epoch. Note that this is a relatively expensive function - one invocation will result in the evaluation of several thousand cosines. The cost is independent of the input epoch, but the accuracy of the method deteriorates for epochs not in the 1900-2100 timespan.

This function is nearly identical to the IAU SOFA iauEpv00 C astronomy library routine, available at: http://www.iausofa.org/2009_1231_C/sofa/epv00.c

It differs from the IAU reference function in the following ways:

  • Only the barycentric coordinates of the earth are computed. The IAU function computes both barycentric and heliocentric earth positions and velocities.
  • The computation is organized into easily vectorizable loops, at the cost of a small amount of stack space.
  • The input epoch is expected to be in MJD rather than JD.
  • Rather than being layed out in AOS form as (amplitude, phase, frequency) triplets, the internal model coefficients are arranged in SOA form, i.e. as arrays of amplitudes, phases, and frequencies.

Comparisons of the IAU iauEpv00() function with the JPL DE405 ephemeris over the 1900-2100 time span yields a maximum deviation of 13.4 km with an RMS of 4.6 km. Comparisons with the JPL DE406 ephemeris show that by 1800 and 2200 the position errors are approximately double their 1900-2100 size. By 1500 and 2500 the deterioration is a factor of 10 and by 1000 and 3000 a factor of 60.

Parameters
epochepoch, MJD TDB. Using TT is acceptable for most applications.

Definition at line 1794 of file EarthPosition.cc.

1796  {
1797  // maximum number of coeffs is 501, pad to the next power of 2.
1798  double angle[512];
1799  double tmp[512];
1800  double earth[3];
1801 
1802  // Compute time delta t from reference epoch (J2000) in Julian years
1803  double const t = (epoch - J2000_MJD) / DAYS_PER_JY;
1804  double const t2 = t*t;
1805 
1806  for (int i = 0; i < 3; i++) {
1807  // Obtain component of Sun to Earth ecliptic vector
1808  // t^0 terms
1809  size_t n = NTERMS_SUN_TO_EARTH_T0[i];
1810  double const *amp = COEFFS_SUN_TO_EARTH_T0[i][0];
1811  double const *phase = COEFFS_SUN_TO_EARTH_T0[i][1];
1812  double const *freq = COEFFS_SUN_TO_EARTH_T0[i][2];
1813  double coord = 0.0;
1814  for (size_t j = 0; j < n; ++j) {
1815  angle[j] = phase[j] + t*freq[j];
1816  }
1817  for (size_t j = 0; j < n; ++j) {
1818  tmp[j] = std::cos(angle[j]);
1819  }
1820  for (size_t j = 0; j < n; ++j) {
1821  coord += amp[j]*tmp[j];
1822  }
1823  // t^1 terms
1824  n = NTERMS_SUN_TO_EARTH_T1[i];
1825  amp = COEFFS_SUN_TO_EARTH_T1[i][0];
1826  phase = COEFFS_SUN_TO_EARTH_T1[i][1];
1827  freq = COEFFS_SUN_TO_EARTH_T1[i][2];
1828  for (size_t j = 0; j < n; ++j) {
1829  angle[j] = phase[j] + t*freq[j];
1830  }
1831  for (size_t j = 0; j < n; ++j) {
1832  tmp[j] = std::cos(angle[j]);
1833  }
1834  for (size_t j = 0; j < n; ++j) {
1835  coord += amp[j]*t*tmp[j];
1836  }
1837  // t^2 terms
1838  n = NTERMS_SUN_TO_EARTH_T2[i];
1839  amp = COEFFS_SUN_TO_EARTH_T2[i][0];
1840  phase = COEFFS_SUN_TO_EARTH_T2[i][1];
1841  freq = COEFFS_SUN_TO_EARTH_T2[i][2];
1842  for (size_t j = 0; j < n; ++j) {
1843  angle[j] = phase[j] + t*freq[j];
1844  }
1845  for (size_t j = 0; j < n; ++j) {
1846  tmp[j] = std::cos(angle[j]);
1847  }
1848  for (size_t j = 0; j < n; ++j) {
1849  coord += amp[j]*t2*tmp[j];
1850  }
1851  // Add component of SSB to Sun ecliptic vector
1852  // t^0 terms
1853  n = NTERMS_SSB_TO_SUN_T0[i];
1854  amp = COEFFS_SSB_TO_SUN_T0[i][0];
1855  phase = COEFFS_SSB_TO_SUN_T0[i][1];
1856  freq = COEFFS_SSB_TO_SUN_T0[i][2];
1857  for (size_t j = 0; j < n; ++j) {
1858  angle[j] = phase[j] + t*freq[j];
1859  }
1860  for (size_t j = 0; j < n; ++j) {
1861  tmp[j] = std::cos(angle[j]);
1862  }
1863  for (size_t j = 0; j < n; ++j) {
1864  coord += amp[j]*tmp[j];
1865  }
1866  // t^1 terms
1867  n = NTERMS_SSB_TO_SUN_T1[i];
1868  amp = COEFFS_SSB_TO_SUN_T1[i][0];
1869  phase = COEFFS_SSB_TO_SUN_T1[i][1];
1870  freq = COEFFS_SSB_TO_SUN_T1[i][2];
1871  for (size_t j = 0; j < n; ++j) {
1872  angle[j] = phase[j] + t*freq[j];
1873  }
1874  for (size_t j = 0; j < n; ++j) {
1875  tmp[j] = std::cos(angle[j]);
1876  }
1877  for (size_t j = 0; j < n; ++j) {
1878  coord += amp[j]*t*tmp[j];
1879  }
1880  // t^2 terms
1881  n = NTERMS_SSB_TO_SUN_T2[i];
1882  amp = COEFFS_SSB_TO_SUN_T2[i][0];
1883  phase = COEFFS_SSB_TO_SUN_T2[i][1];
1884  freq = COEFFS_SSB_TO_SUN_T2[i][2];
1885  for (size_t j = 0; j < n; ++j) {
1886  angle[j] = phase[j] + t*freq[j];
1887  }
1888  for (size_t j = 0; j < n; ++j) {
1889  tmp[j] = std::cos(angle[j]);
1890  }
1891  for (size_t j = 0; j < n; ++j) {
1892  coord += amp[j]*t2*tmp[j];
1893  }
1894  earth[i] = coord;
1895  }
1896 
1897  // Rotate from ecliptic to BCRS coordinates
1898  return Eigen::Vector3d(
1899  earth[0] + AM12*earth[1] + AM13*earth[2],
1900  AM21*earth[0] + AM22*earth[1] + AM23*earth[2],
1901  AM32*earth[1] + AM33*earth[2]
1902  );
1903 }
CsvWriter & lsst::ap::utils::endr ( CsvWriter &  w)
inline

Manipulator to end a CSV record.

Definition at line 330 of file Csv.cc.

330  {
331  w.endRecord();
332  return w;
333 }
double w
Definition: CoaddPsf.cc:57
CsvWriter & lsst::ap::utils::flush ( CsvWriter &  w)
inline

Manipulator to flush a CSV writer.

Definition at line 337 of file Csv.cc.

337  {
338  w.flush();
339  return w;
340 }
double w
Definition: CoaddPsf.cc:57
void lsst::ap::utils::makeSourceHistogram ( lsst::afw::image::Image< unsigned short >::Ptr  histogram,
lsst::afw::table::SourceCatalog const &  sources,
lsst::afw::image::Wcs::Ptr  wcs,
bool  ignoreOffImage 
)

Fills in a histogram of positions for the given sources. The value of each histogram pixel is set to the number of sources falling within that pixel. Sources falling outside the histogram image are either ignored or cause an exception to be raised.

Parameters
[in,out]histogramHistogram image to update.
[in]sourcesSources to generate a position histogram from.
[in]wcsWCS of histogram image.
[in]ignoreOffImageIf true ignore off image sources, otherwise raise an exception.

Definition at line 412 of file ImageUtils.cc.

417 {
418  typedef table::SourceCatalog::const_iterator SourceIter;
419  for (SourceIter i = sources.begin(), e = sources.end(); i != e; ++i) {
420  Point2D xy = wcs->skyToPixel(i->getCoord());
421  int x = histogram->positionToIndex(xy[0], image::X).first;
422  int y = histogram->positionToIndex(xy[1], image::Y).first;
423  if (x < 0 || x >= histogram->getWidth() ||
424  y < 0 || y >= histogram->getHeight()) {
425  if (!ignoreOffImage) {
426  throw LSST_EXCEPT(except::RuntimeError,
427  "SourceCatalog contains sources lying "
428  "outside the histogram image");
429  }
430  continue;
431  }
432  histogram->operator()(x, y) += 1;
433  }
434 }
int y
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
int x
std::pair< int, double > positionToIndex(double const pos, lsst::afw::image::xOrY const xy) const
Convert image position to index (nearest integer and fractional parts)
Definition: Image.h:271
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Point< double, 2 > Point2D
Definition: Point.h:286
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
Base::const_iterator const_iterator
Definition: SortedCatalog.h:49
lsst::afw::geom::Angle const lsst::ap::utils::maxAlpha ( Angle  radius,
Angle  centerPhi 
)

Computes the extent in longitude angle [-alpha, alpha] of the circle with radius radius and center at latitude angle centerPhi.

Precondition
radius >= 0.0 && radius <= PI/2

Note that centerPhi is clamped to lie in [-PI/2, PI/2].

Parameters
radiuscircle radius
centerPhilatitude angle of circle center

Definition at line 79 of file SpatialUtils.cc.

82  {
83  static const double POLE_EPSILON = 1e-7;
84 
85  if (radius < 0.0 || radius > HALFPI) {
86  throw LSST_EXCEPT(InvalidParameterError,
87  "radius must be in range [0, PI/2] deg");
88  }
89  if (radius == 0.0) {
90  return 0.0 * radians;
91  }
92  centerPhi = clampPhi(centerPhi);
93  if (std::fabs(centerPhi.asRadians()) + radius.asRadians() > HALFPI - POLE_EPSILON) {
94  return PI*(1 + 2.0*DBL_EPSILON) * radians;
95  }
96  double y = std::sin(radius.asRadians());
97  double x = std::sqrt(std::fabs(std::cos(centerPhi.asRadians() - radius.asRadians()) *
98  std::cos(centerPhi.asRadians() + radius.asRadians())));
99  return std::fabs(std::atan(y / x)) * radians;
100 }
int y
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
double asRadians() const
Definition: Angle.h:122
int x
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
double const HALFPI
Definition: Angle.h:20
double const PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:18
float POLE_EPSILON
Definition: geometry.py:35
CsvWriter & lsst::ap::utils::nullf ( CsvWriter &  w)
inline

Manipulator to append a NULL field to a CSV writer.

Definition at line 344 of file Csv.cc.

344  {
345  w.appendNull();
346  return w;
347 }
double w
Definition: CoaddPsf.cc:57
template<typename T >
CsvWriter& lsst::ap::utils::operator<< ( CsvWriter &  ,
CsvWriter &  *)(CsvWriter & 
)
inline
template<typename T >
CsvWriter & lsst::ap::utils::operator<< ( CsvWriter &  w,
T const &  v 
)
inline

Formatted output operator for CSV writers.

Definition at line 323 of file Csv.cc.

323  {
324  w.appendField(v);
325  return w;
326 }
double w
Definition: CoaddPsf.cc:57
template<typename T >
CsvWriter& lsst::ap::utils::operator<< ( CsvWriter &  w,
CsvWriter &(*)(CsvWriter &)  manip 
)
inline

Output operator that applies a manipulator to a CSV writer.

Definition at line 352 of file Csv.cc.

352  {
353  return manip(w);
354 }
double w
Definition: CoaddPsf.cc:57
void lsst::ap::utils::positionAndVelocity ( Eigen::Vector3d &  p,
Eigen::Vector3d &  v,
Angle  ra,
Angle  decl,
double  muRa,
double  muDecl,
double  vRadial,
Angle  parallax 
)

Converts from spherical coordinates, proper motions, parallax and radial velocity to position (AU) and velocity (AU/day) 3-vectors.

See the following paper for details:
Rigorous Computation of Proper Motions and their Effects on Star Positions Eichhorn, H. & Rust, A. Journal: Astronomische Nachrichten, volume 292, p.37 Bibliographic Code: 1970AN....292...37E
A more accurate approach (including special-relativistic effects) is discussed in Stumpff, P., 1985, Astron.Astrophys. 144, 232-240 and implemented in the IAU SOFA astronomy library iauStarpv C routine available here: http://www.iausofa.org/2009_1231_C/sofa/starpv.c
Note that the input and output data are for an observer situated at the solar system barycenter.
See Also
earthPosition(double)
Parameters
[out]pposition, AU
[out]vvelocity, AU/day
raright ascension
decldeclination
muRaproper motion in RA, rad/day
muDeclproper motion in Dec, rad/day
vRadialradial velocity, AU/day
parallaxparallax

Definition at line 126 of file SpatialUtils.cc.

135  {
136  // distance (AU)
137  double r = 1.0 / parallax.asRadians();
138 
139  // convert to position and velocity vector (AU, AU/day)
140  double sinRa = sin(ra.asRadians());
141  double cosRa = cos(ra.asRadians());
142  double sinDecl = sin(decl.asRadians());
143  double cosDecl = cos(decl.asRadians());
144  double s = r*cosDecl;
145  double t = r*muDecl*sinDecl;
146  double u = cosDecl*vRadial;
147  p = Eigen::Vector3d(s*cosRa, s*sinRa, r*sinDecl);
148  v = Eigen::Vector3d(cosRa*u - p.y()*muRa - cosRa*t,
149  sinRa*u + p.x()*muRa - sinRa*t,
150  sinDecl*vRadial + s*muDecl);
151  if (v.squaredNorm() > 0.25*C_AU_PER_DAY*C_AU_PER_DAY) {
152  throw LSST_EXCEPT(RuntimeError,
153  "star velocity vector magnitude exceeds half "
154  "the speed of light");
155  }
156 }
double asRadians() const
Definition: Angle.h:122
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst::ap::utils::rasterizePolygon ( std::vector< lsst::afw::geom::Point2D > const &  verts,
lsst::afw::image::Image< float >::Ptr  img 
)
void lsst::ap::utils::rasterizePolygon ( std::vector< Point2D > const &  verts,
lsst::afw::image::Image< float >::Ptr  img 
)

Rasterizes the (not necessarily convex) polygon obtained by connecting the the given vertices. For each pixel in the output image, the fraction of the pixel area overlapping the input polygon is stored.

Parameters
[in,out]imgImage to rasterize to.
[in]vertsPolygon vertices

Definition at line 443 of file ImageUtils.cc.

446 {
447  typedef std::vector<Point2D>::const_iterator VertexIter;
448  typedef std::vector<Edge>::iterator EdgeIter;
449 
450  if (img->getWidth() <= 0 || img->getHeight() <= 0) {
451  throw LSST_EXCEPT(except::InvalidParameterError,
452  "image width/height must be at least 1");
453  }
454  if (verts.size() < 3) {
455  throw LSST_EXCEPT(except::InvalidParameterError,
456  "polygon must have at least 3 vertices");
457  }
458  std::vector<Edge> edges;
459  edges.reserve(verts.size());
460  double minY = image::indexToPosition(0) - 0.5;
461  double maxY = image::indexToPosition(img->getHeight()) - 0.5;
462  for (VertexIter v2 = verts.begin(), e = verts.end(), v1 = e - 1;
463  v2 != e; ++v2) {
464  VertexIter v = v1;
465  v1 = v2;
466  if (v->getY() == v2->getY()) {
467  continue; // omit horizontal and degenerate edges
468  } else if (v->getY() < v2->getY()) {
469  if (v->getY() >= maxY || v2->getY() < minY) {
470  continue; // edge not in y-range
471  }
472  } else {
473  if (v2->getY() >= maxY || v->getY() < minY) {
474  continue; // edge not in y-range
475  }
476  }
477  edges.push_back(Edge(*v, *v2));
478  }
479  if (edges.size() > 0) {
480  std::sort(edges.begin(), edges.end());
481  SweepLine sweeper(img, edges.front().v1->getY());
482  EdgeIter i = edges.begin(), e = edges.end();
483  // add all edges intersecting minY to sweep line
484  for (; i != e && i->v1->getY() <= minY; ++i) {
485  sweeper.add(*i);
486  }
487  while (i != e) {
488  double y = i->v1->getY();
489  sweeper.advance(y);
490  sweeper.add(*i);
491  for (++i; i != e && i->v1->getY() == y; ++i) {
492  sweeper.add(*i);
493  }
494  }
495  sweeper.finish();
496  }
497 }
int y
double indexToPosition(double ind)
Convert image index to image position.
Definition: ImageUtils.h:54
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
Point2D const * v2
Definition: ImageUtils.cc:89
Point2D const * v1
Definition: ImageUtils.cc:88
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
void lsst::ap::utils::thetaRangeReduce ( Angle min,
Angle max 
)

Reduces a theta (longitude/right-ascension) range. The resulting range will have min > max if it wraps across the 0/2*PI radiandiscontinuity. Valid inputs are:

  • any min, max with min <= max
  • min > max so long as min <= 2*PI && max >= 0.0

Definition at line 56 of file SpatialUtils.cc.

56  {
57  if (min > max) {
58  if (max < 0.0 || min >= TWOPI) {
59  throw LSST_EXCEPT(InvalidParameterError,
60  "Invalid longitude angle interval");
61  }
62  } else if (max - min >= TWOPI) {
63  min = 0.0 * radians;
64  max = TWOPI * radians;
65  } else if (min < 0.0 || max >= TWOPI) {
66  // range reduce
67  min.wrap();
68  max.wrap();
69  }
70 }
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
double const TWOPI
Definition: Angle.h:19
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst::ap::utils::updateCoverageMap ( lsst::afw::image::Image< float >::Ptr  covMap,
lsst::afw::image::Wcs::Ptr  covMapWcs,
lsst::afw::image::Wcs::Ptr  wcs,
int  width,
int  height,
int  step 
)

Updates a coverage map to include contributions from the given image (specified by a WCS and a pair of dimensions).

Parameters
[in,out]covMapCoverage map to update.
[in]covMapWcsWCS of coverage map.
[in]wcsWCS of image to rasterize.
[in]widthWidth of image to rasterize.
[in]heightHeight of image to rasterize.
[in]stepIf <= 0, the input image is rasterized as a polygon formed by connecting the positions of the 4 image corners with straight lines in coverage-map pixel space. Otherwise, the boundary of the input image is rasterize by connecting step boundary pixels at a time (corners are always included).

Definition at line 515 of file ImageUtils.cc.

522 {
523  typedef std::vector<Point2D>::iterator VertexIter;
524  if (width <= 0 || height <= 0) {
525  throw LSST_EXCEPT(except::InvalidParameterError,
526  "Width/height of input image must be positive");
527  }
528  std::vector<Point2D> v;
529  if (step <= 0) {
530  v.reserve(4);
531  v.push_back(Point2D(-0.5, -0.5));
532  v.push_back(Point2D(width - 0.5, -0.5));
533  v.push_back(Point2D(width - 0.5, height - 0.5));
534  v.push_back(Point2D(-0.5, height - 0.5));
535  } else {
536  v.reserve(2 * width + 2 * height + 2);
537  for (int i = 0; i < width; i += step) {
538  v.push_back(Point2D(i - 0.5, -0.5));
539  }
540  for (int i = 0; i < height; i += step) {
541  v.push_back(Point2D(width - 0.5, i - 0.5));
542  }
543  for (int i = width; i > 0; i -= step) {
544  v.push_back(Point2D(i - 0.5, height - 0.5));
545  }
546  for (int i = height; i > 0; i -= step) {
547  v.push_back(Point2D(-0.5, i - 0.5));
548  }
549  }
550  // Convert from image pixel space to coverage map pixel space.
551  for (VertexIter i = v.begin(), e = v.end(); i != e; ++i) {
552  *i = covMapWcs->skyToPixel(*wcs->pixelToSky(*i));
553  }
554  // rasterize polygon
555  rasterizePolygon(v, covMap);
556 }
void rasterizePolygon(std::vector< Point2D > const &verts, lsst::afw::image::Image< float >::Ptr img)
Definition: ImageUtils.cc:443
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Point< double, 2 > Point2D
Definition: Point.h:286
void lsst::ap::utils::writeCsv ( lsst::afw::table::BaseCatalog const &  catalog,
CsvConversionControl const &  cnvControl,
CsvControl const &  csvControl,
std::string const &  csvFile,
bool  truncate,
bool  append 
)

Convert an afw Catalog to a CSV file.

Parameters
catalog
[in]catalogCatalog to convert.
cnvControl
[in]cnvControlConversion parameters.
csvControl
[in]csvControlCSV dialect.
csvFile
[in]csvFileName of file to write to
truncate
[in]truncateTruncate csvFile if it already exists?
append
[in]appendAppend to csvFile if it exists and truncate is false?
void lsst::ap::utils::writeCsv ( BaseCatalog const &  catalog,
CsvConversionControl const &  cnvControl,
CsvControl const &  csvControl,
std::string const &  csvFile,
bool  truncate,
bool  append 
)

Definition at line 335 of file csvUtils.cc.

341 {
342  CsvWriter writer(csvFile, csvControl, truncate, append);
343  Schema schema = catalog.getSchema();
344  CsvConverter cnv(writer, schema, cnvControl);
345  boost::reference_wrapper<CsvConverter> cnvRef = boost::ref(cnv);
346  for (BaseCatalog::const_iterator i = catalog.begin(), e = catalog.end(); i != e; ++i) {
347  cnv.startRecord(i);
348  schema.forEach(cnvRef);
349  cnv.endRecord();
350  }
351  writer.flush();
352 }
Extent< int, N > truncate(Extent< double, N > const &input)
Defines the fields and offsets for a table.
Definition: Schema.h:46
tbl::Schema schema
Definition: CoaddPsf.cc:324
void forEach(F func) const
Apply a functor to each SchemaItem in the Schema.
Definition: Schema.h:204