GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyDir Class Reference

Sky direction class. More...

#include <GSkyDir.hpp>

Inheritance diagram for GSkyDir:
GBase

Public Member Functions

 GSkyDir (void)
 Constructor. More...
 
 GSkyDir (const GSkyDir &dir)
 Copy constructor. More...
 
virtual ~GSkyDir (void)
 Destructor. More...
 
GSkyDiroperator= (const GSkyDir &dir)
 Assignment operator. More...
 
void clear (void)
 Clear sky direction. More...
 
GSkyDirclone (void) const
 Clone sky direction. More...
 
std::string classname (void) const
 Return class name. More...
 
void radec (const double &ra, const double &dec)
 Set equatorial sky direction (radians) More...
 
void radec_deg (const double &ra, const double &dec)
 Set equatorial sky direction (degrees) More...
 
void lb (const double &l, const double &b)
 Set galactic sky direction (radians) More...
 
void lb_deg (const double &l, const double &b)
 Set galactic sky direction (degrees) More...
 
void celvector (const GVector &vector)
 Set sky direction from 3D vector in celestial coordinates. More...
 
void rotate_deg (const double &phi, const double &theta)
 Rotate sky direction by zenith and azimuth angle. More...
 
void precess (const double &from_epoch, const double &to_epoch)
 Precess sky direction. More...
 
void sun (const GTime &time, const double &epoch=2000.0)
 Set sky direction to direction of Sun. More...
 
void moon (const GTime &time, const double &epoch=2000.0)
 Set sky direction to direction of Moon. More...
 
const double & l (void) const
 Return galactic longitude in radians. More...
 
const double & b (void) const
 Return galactic latitude in radians. More...
 
const double & ra (void) const
 Return Right Ascension in radians. More...
 
const double & dec (void) const
 Return Declination in radians. More...
 
double l_deg (void) const
 Return galactic longitude in degrees. More...
 
double b_deg (void) const
 Returns galactic latitude in degrees. More...
 
double ra_deg (void) const
 Returns Right Ascension in degrees. More...
 
double dec_deg (void) const
 Returns Declination in degrees. More...
 
GVector celvector (void) const
 Return sky direction as 3D vector in celestial coordinates. More...
 
double cos_dist (const GSkyDir &dir) const
 Compute cosine of angular distance between sky directions. More...
 
double dist (const GSkyDir &dir) const
 Compute angular distance between sky directions in radians. More...
 
double dist_deg (const GSkyDir &dir) const
 Compute angular distance between sky directions in degrees. More...
 
double posang (const GSkyDir &dir) const
 Compute position angle between sky directions in radians. More...
 
double posang_deg (const GSkyDir &dir) const
 Compute position angle between sky directions in degrees. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print sky direction information. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Private Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GSkyDir &dir)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void equ2gal (void) const
 Convert equatorial to galactic coordinates. More...
 
void gal2equ (void) const
 Convert galactic to equatorial coordinates. More...
 
void euler (const int &type, const double &xin, const double &yin, double *xout, double *yout) const
 General coordinate transformation routine for J2000. More...
 

Private Attributes

bool m_has_lb
 Has galactic coordinates. More...
 
bool m_has_radec
 Has equatorial coordinates. More...
 
double m_l
 Galactic longitude in radians. More...
 
double m_b
 Galactic latitude in radians. More...
 
double m_ra
 Right Ascension in radians. More...
 
double m_dec
 Declination in radians. More...
 
bool m_has_lb_cache
 
bool m_has_radec_cache
 
double m_sin_b
 
double m_cos_b
 
double m_sin_dec
 
double m_cos_dec
 

Friends

bool operator== (const GSkyDir &a, const GSkyDir &b)
 Equality operator. More...
 
bool operator!= (const GSkyDir &a, const GSkyDir &b)
 Non equality operator. More...
 

Detailed Description

Sky direction class.

This class implements a spherical coordinate on the sky. Two coordinate systems are supported: celestial (or equatorial), defined by Right Ascension and Declination, and Galactic, defined by galactic longitude and galactic latitude. The class provides automatic conversion between both systems if required. Coordinates are stored in either of the systems (in units of radians), and conversion is performed (and stored) if requested. Coordinates can be given and returned in radians or in degrees. Note that the epoch for celestial coordinates is fixed to J2000.

Definition at line 62 of file GSkyDir.hpp.

Constructor & Destructor Documentation

GSkyDir::GSkyDir ( void  )

Constructor.

Definition at line 59 of file GSkyDir.cpp.

References init_members().

Referenced by clone().

GSkyDir::GSkyDir ( const GSkyDir dir)

Copy constructor.

Parameters
[in]dirSky direction.

Definition at line 74 of file GSkyDir.cpp.

References copy_members(), and init_members().

GSkyDir::~GSkyDir ( void  )
virtual

Destructor.

Definition at line 90 of file GSkyDir.cpp.

References free_members().

Member Function Documentation

const double & GSkyDir::b ( void  ) const
inline

Return galactic latitude in radians.

Returns
Galactic latitude in radians.

Definition at line 181 of file GSkyDir.hpp.

References equ2gal(), m_b, m_has_lb, and m_has_radec.

Referenced by b_deg(), cos_dist(), GHealpix::dir2pix(), equ2gal(), euler(), GHealpix::interpolator(), lb(), operator==(), posang(), and precess().

double GSkyDir::b_deg ( void  ) const
inline

Returns galactic latitude in degrees.

Returns
Galactic latitude in degrees.

Definition at line 196 of file GSkyDir.hpp.

References b(), and gammalib::rad2deg.

Referenced by GWcs::dir2pix().

void GSkyDir::celvector ( const GVector vector)

Set sky direction from 3D vector in celestial coordinates.

Parameters
[in]vector3D vector.

Convert a 3-dimensional vector in celestial coordinates into a sky direction. The transformation is given by

\[ \alpha = \arctan \left( \frac{x_1}{x_0} \right) \]

\[ \delta = \arcsin x_2 \]

Definition at line 291 of file GSkyDir.cpp.

References asin(), gammalib::atan2(), m_dec, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, and m_ra.

Referenced by cta_nroi_radial_kern_omega::eval(), cta_nroi_elliptical_kern_omega::eval(), cta_irf_diffuse_kern_phi::eval(), cta_nroi_diffuse_kern_phi::eval(), cta_psf_diffuse_kern_phi::eval(), GCTAPointing::instdir(), GCTAPointing::skydir(), and GWcs::solidangle().

GVector GSkyDir::celvector ( void  ) const

Return sky direction as 3D vector in celestial coordinates.

Returns
Sky direction as 3D vector in celestial coordinates.

Definition at line 877 of file GSkyDir.cpp.

References cos(), gal2equ(), m_cos_dec, m_dec, m_has_lb, m_has_radec, m_has_radec_cache, m_ra, m_sin_dec, and sin().

Referenced by precess(), and rotate_deg().

std::string GSkyDir::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GSkyDir").

Implements GBase.

Definition at line 142 of file GSkyDir.hpp.

GSkyDir * GSkyDir::clone ( void  ) const
virtual

Clone sky direction.

Returns
Pointer to deep copy of sky direction.

Implements GBase.

Definition at line 160 of file GSkyDir.cpp.

References GSkyDir().

void GSkyDir::copy_members ( const GSkyDir dir)
private

Copy class members.

Parameters
[in]dirSky direction.

Definition at line 1175 of file GSkyDir.cpp.

References m_b, m_cos_b, m_cos_dec, m_dec, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, m_l, m_ra, m_sin_b, and m_sin_dec.

Referenced by GSkyDir(), and operator=().

double GSkyDir::cos_dist ( const GSkyDir dir) const

Compute cosine of angular distance between sky directions.

Parameters
[in]dirSky direction to which cosine of distance is to be computed.
Returns
Cosine of angular distance.

Computes the cosine of the angular distance between two sky directions in radians.

Definition at line 914 of file GSkyDir.cpp.

References b(), cos(), dec(), l(), m_b, m_cos_b, m_cos_dec, m_dec, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, m_l, m_ra, m_sin_b, m_sin_dec, ra(), and sin().

Referenced by dist().

const double & GSkyDir::dec ( void  ) const
inline

Return Declination in radians.

Returns
Declination in radians.

Definition at line 235 of file GSkyDir.hpp.

References gal2equ(), m_dec, m_has_lb, and m_has_radec.

Referenced by cos_dist(), dec_deg(), GHealpix::dir2pix(), gal2equ(), GHealpix::interpolator(), moon(), operator==(), posang(), radec(), and sun().

void GSkyDir::equ2gal ( void  ) const
private

Convert equatorial to galactic coordinates.

Definition at line 1213 of file GSkyDir.cpp.

References b(), euler(), l(), m_b, m_dec, m_has_lb, m_l, and m_ra.

Referenced by b(), and l().

void GSkyDir::euler ( const int &  type,
const double &  xin,
const double &  yin,
double *  xout,
double *  yout 
) const
private

General coordinate transformation routine for J2000.

Parameters
[in]typeConversion type (0=equ2gal, 1=gal2equ)
[in]xinInput longitude (RA or GLON) in radians.
[in]yinInput latitude (Dec or GLAT) in radians.
[out]xoutOutput longitude in radians.
[out]youtOutput latitude in radians.

Definition at line 1263 of file GSkyDir.cpp.

References asin(), gammalib::atan2(), b(), cos(), gammalib::fourpi, gammalib::modulo(), sin(), and gammalib::twopi.

Referenced by equ2gal(), and gal2equ().

void GSkyDir::free_members ( void  )
private

Delete class members.

Definition at line 1203 of file GSkyDir.cpp.

Referenced by clear(), operator=(), and ~GSkyDir().

void GSkyDir::gal2equ ( void  ) const
private

Convert galactic to equatorial coordinates.

Definition at line 1235 of file GSkyDir.cpp.

References dec(), euler(), m_b, m_dec, m_has_radec, m_l, m_ra, and ra().

Referenced by celvector(), dec(), ra(), and rotate_deg().

void GSkyDir::init_members ( void  )
private

Initialise class members.

Definition at line 1145 of file GSkyDir.cpp.

References m_b, m_cos_b, m_cos_dec, m_dec, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, m_l, m_ra, m_sin_b, and m_sin_dec.

Referenced by clear(), GSkyDir(), and operator=().

const double & GSkyDir::l ( void  ) const
inline

Return galactic longitude in radians.

Returns
Galactic longitude in radians.

Definition at line 154 of file GSkyDir.hpp.

References equ2gal(), m_has_lb, m_has_radec, and m_l.

Referenced by cos_dist(), GHealpix::dir2pix(), equ2gal(), GHealpix::interpolator(), l_deg(), lb(), operator==(), and posang().

double GSkyDir::l_deg ( void  ) const
inline

Return galactic longitude in degrees.

Returns
Galactic longitude in degrees.

Definition at line 169 of file GSkyDir.hpp.

References l(), and gammalib::rad2deg.

Referenced by GWcs::dir2pix().

void GSkyDir::lb ( const double &  l,
const double &  b 
)

Set galactic sky direction (radians)

Parameters
[in]lGalactic longitude in radians.
[in]bGalactic latitude in radians.

Sets Galactic longitude and latitude in radians.

Definition at line 229 of file GSkyDir.cpp.

References b(), l(), m_b, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, and m_l.

Referenced by GHealpix::loc2dir(), GHealpix::pix2dir(), and GCOMEventList::read_events().

void GSkyDir::lb_deg ( const double &  l,
const double &  b 
)

Set galactic sky direction (degrees)

Parameters
[in]lGalactic longitude in degrees.
[in]bGalactic latitude in degrees.

Sets Galactic longitude and latitude in degrees.

Definition at line 256 of file GSkyDir.cpp.

References gammalib::deg2rad, m_b, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, and m_l.

Referenced by GWcs::pix2dir(), GModelSpatialPointSource::read(), GCTAPointing::read(), GSkyRegionCircle::read(), GModelSpatialRadial::read(), GModelSpatialElliptical::read(), and GCOMEventList::read_events().

void GSkyDir::moon ( const GTime time,
const double &  epoch = 2000.0 
)

Set sky direction to direction of Moon.

Parameters
[in]timeTime.
[in]epochJulian epoch.

Sets the sky direction to the direction of the Moon at a given time.

The equations are derived from the Chapront ELP2000/82 Lunar Theory (Chapront-Touze' and Chapront, 1983, 124, 50), as described by Jean Meeus in Chapter 47 of ``Astronomical Algorithms'' (Willmann-Bell, Richmond), 2nd edition, 1998. Meeus quotes an approximate accuracy of 10 arcsec in longitude and 4 arcsec in latitude, but he does not give the time range for this accuracy.

The method was compared to the results obtained using PyEphem for the period 2000 - 2050. Differences in Right Ascension and Declination are always smaller than 0.015 degrees, corresponding to about 1 arcmin. The differences increase over time, meaning that the largest distances are reached by the end of the period.

Definition at line 518 of file GSkyDir.cpp.

References abs(), asin(), gammalib::atan2(), cos(), dec(), gammalib::deg2rad, GTime::jd(), GTime::julian_epoch(), precess(), ra(), gammalib::rad2deg, radec_deg(), sin(), and tan().

GSkyDir & GSkyDir::operator= ( const GSkyDir dir)

Assignment operator.

Parameters
[in]dirSky direction.
Returns
Sky direction.

Definition at line 112 of file GSkyDir.cpp.

References copy_members(), free_members(), and init_members().

double GSkyDir::posang ( const GSkyDir dir) const

Compute position angle between sky directions in radians.

Parameters
[in]dirSky direction.
Returns
Position angle in radians.

Computes the position angle using

\[PA = \arctan \left( \frac{\sin( \alpha_1 - \alpha_0 )} {\cos \delta_0 \tan \delta_1 - \sin \delta_0 \cos(\alpha_1 - \alpha_0)} \right)\]

where \((\alpha_0,\delta_0)\) are the coordinates of the reference point, and \((\alpha_1,\delta_1)\) are the coordinates of sky direction for which the position angle is to be computed.

The position angle is counted counterclockwise from north.

Definition at line 1022 of file GSkyDir.cpp.

References gammalib::atan2(), b(), cos(), dec(), l(), m_b, m_cos_b, m_cos_dec, m_dec, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, m_l, m_ra, m_sin_b, m_sin_dec, ra(), sin(), and tan().

Referenced by GCTAOnOffObservation::compute_arf_cut(), GCTAOnOffObservation::compute_rmf(), GModelSpatialElliptical::eval(), GCTAPointing::instdir(), GCTAResponseCube::irf_elliptical(), GCTAResponseIrf::irf_elliptical(), GCTAResponseIrf::nroi_elliptical(), GCTAResponseIrf::nroi_radial(), and posang_deg().

double GSkyDir::posang_deg ( const GSkyDir dir) const
inline

Compute position angle between sky directions in degrees.

Parameters
[in]dirSky direction.
Returns
Position angle in degrees.

Returns the position angle of a sky direction in degrees.

See the posang() method for more information about the computation of the position angle.

Definition at line 298 of file GSkyDir.hpp.

References posang(), and gammalib::rad2deg.

Referenced by GCOMOad::phi().

void GSkyDir::precess ( const double &  from_epoch,
const double &  to_epoch 
)

Precess sky direction.

Parameters
[in]from_epochEpoch of the current coordinate.
[in]to_epochEpoch of the returned precessed coordinate.

Precesses the sky direction from one epoch to another.

The method is adapted from a set of fortran subroutines based on (a) pages 30-34 of the Explanatory Supplement to the AE, (b) Lieske, et al. (1977) A&A 58, 1-16, and (c) Lieske (1979) A&A 73, 282-284.

Definition at line 371 of file GSkyDir.cpp.

References b(), celvector(), cos(), gammalib::pi, and sin().

Referenced by moon(), and sun().

std::string GSkyDir::print ( const GChatter chatter = NORMAL) const
virtual

Print sky direction information.

Parameters
[in]chatterChattiness.
Returns
String containing sky direction information.

Implements GBase.

Definition at line 1108 of file GSkyDir.cpp.

References m_b, m_dec, m_has_lb, m_has_radec, m_l, m_ra, gammalib::rad2deg, SILENT, and gammalib::str().

Referenced by GCOMInstDir::print(), GModelSpatialDiffuseMap::print(), and GCTAEventCube::print().

const double & GSkyDir::ra ( void  ) const
inline

Return Right Ascension in radians.

Returns
Right Ascension in radians.

Definition at line 208 of file GSkyDir.hpp.

References gal2equ(), m_has_lb, m_has_radec, and m_ra.

Referenced by cos_dist(), GHealpix::dir2pix(), gal2equ(), GHealpix::interpolator(), moon(), operator==(), posang(), ra_deg(), radec(), and sun().

void GSkyDir::radec ( const double &  ra,
const double &  dec 
)

Set equatorial sky direction (radians)

Parameters
[in]raRight Ascension in radians.
[in]decDeclination in radians.

Sets Right Ascension and Declination in radians.

Definition at line 175 of file GSkyDir.cpp.

References dec(), m_dec, m_has_lb, m_has_lb_cache, m_has_radec, m_has_radec_cache, m_ra, and ra().

Referenced by GHealpix::loc2dir(), GHealpix::pix2dir(), GCOMOads::read(), and GCTABackground3D::solid_angle().

void GSkyDir::radec_deg ( const double &  ra,
const double &  dec 
)
void GSkyDir::rotate_deg ( const double &  phi,
const double &  theta 
)

Rotate sky direction by zenith and azimuth angle.

Parameters
[in]phiAzimuth angle (deg).
[in]thetaZenith angle (deg).

Rotate sky direction by a zenith and azimuth angle given in the system of the sky direction and aligned in celestial coordinates. The azimuth angle is counted counter clockwise from celestial north (this is identical to the astronomical definition of a position angle).

Definition at line 321 of file GSkyDir.cpp.

References celvector(), cos(), gammalib::deg2rad, GMatrix::eulery(), GMatrix::eulerz(), gal2equ(), m_dec, m_has_lb, m_has_radec, m_ra, gammalib::rad2deg, and sin().

Referenced by GSkyRegionMap::contains(), GModelSpatialDiffuseConst::mc(), GModelSpatialRadialDisk::mc(), GModelSpatialRadialGauss::mc(), GModelSpatialEllipticalDisk::mc(), GCTAModelAeffBackground::mc(), GModelSpatialRadialProfile::mc(), GModelSpatialEllipticalGauss::mc(), GModelSpatialDiffuseMap::mc(), GModelSpatialRadialShell::mc(), GModelSpatialDiffuseCube::mc(), and GCTAResponseIrf::mc().

void GSkyDir::sun ( const GTime time,
const double &  epoch = 2000.0 
)

Set sky direction to direction of Sun.

Parameters
[in]timeTime.
[in]epochJulian epoch.

Sets the sky direction to the direction of the Sun at a given time.

The equations were taken from the Astronomical Almanac. They calculate the apparent coordinates of the Sun to a precision of about 0.01 degrees (36 arcsec), for dates between 1950 and 2050.

See https://en.wikipedia.org/wiki/Position_of_the_Sun

Definition at line 448 of file GSkyDir.cpp.

References asin(), gammalib::atan2(), cos(), dec(), gammalib::deg2rad, GTime::jd(), GTime::julian_epoch(), precess(), ra(), gammalib::rad2deg, radec_deg(), and sin().

Friends And Related Function Documentation

bool operator!= ( const GSkyDir a,
const GSkyDir b 
)
friend

Non equality operator.

Parameters
[in]aFirst sky direction.
[in]bSecond sky direction.

Definition at line 1376 of file GSkyDir.cpp.

bool operator== ( const GSkyDir a,
const GSkyDir b 
)
friend

Equality operator.

Parameters
[in]aFirst sky direction.
[in]bSecond sky direction.

Compare two sky directions. If the coordinate is at the pole, the Right Ascension or Longitude value is irrelevant.

Comparisons are done dependent on the available coordinate system. This speeds up things and avoids unnecessary coordinate transformations.

Definition at line 1312 of file GSkyDir.cpp.

Member Data Documentation

double GSkyDir::m_b
private

Galactic latitude in radians.

Definition at line 120 of file GSkyDir.hpp.

Referenced by b(), copy_members(), cos_dist(), equ2gal(), gal2equ(), init_members(), lb(), lb_deg(), operator==(), posang(), and print().

double GSkyDir::m_cos_b
mutableprivate

Definition at line 129 of file GSkyDir.hpp.

Referenced by copy_members(), cos_dist(), init_members(), and posang().

double GSkyDir::m_cos_dec
mutableprivate

Definition at line 131 of file GSkyDir.hpp.

Referenced by celvector(), copy_members(), cos_dist(), init_members(), and posang().

double GSkyDir::m_dec
private

Declination in radians.

Definition at line 122 of file GSkyDir.hpp.

Referenced by celvector(), copy_members(), cos_dist(), dec(), equ2gal(), gal2equ(), init_members(), operator==(), posang(), print(), radec(), radec_deg(), and rotate_deg().

bool GSkyDir::m_has_lb
mutableprivate

Has galactic coordinates.

Definition at line 117 of file GSkyDir.hpp.

Referenced by b(), celvector(), copy_members(), cos_dist(), dec(), equ2gal(), init_members(), l(), lb(), lb_deg(), operator==(), posang(), print(), ra(), radec(), radec_deg(), and rotate_deg().

bool GSkyDir::m_has_lb_cache
mutableprivate
bool GSkyDir::m_has_radec
mutableprivate

Has equatorial coordinates.

Definition at line 118 of file GSkyDir.hpp.

Referenced by b(), celvector(), copy_members(), cos_dist(), dec(), gal2equ(), init_members(), l(), lb(), lb_deg(), operator==(), posang(), print(), ra(), radec(), radec_deg(), and rotate_deg().

bool GSkyDir::m_has_radec_cache
mutableprivate
double GSkyDir::m_l
private

Galactic longitude in radians.

Definition at line 119 of file GSkyDir.hpp.

Referenced by copy_members(), cos_dist(), equ2gal(), gal2equ(), init_members(), l(), lb(), lb_deg(), operator==(), posang(), and print().

double GSkyDir::m_ra
private

Right Ascension in radians.

Definition at line 121 of file GSkyDir.hpp.

Referenced by celvector(), copy_members(), cos_dist(), equ2gal(), gal2equ(), init_members(), operator==(), posang(), print(), ra(), radec(), radec_deg(), and rotate_deg().

double GSkyDir::m_sin_b
mutableprivate

Definition at line 128 of file GSkyDir.hpp.

Referenced by copy_members(), cos_dist(), init_members(), and posang().

double GSkyDir::m_sin_dec
mutableprivate

Definition at line 130 of file GSkyDir.hpp.

Referenced by celvector(), copy_members(), cos_dist(), init_members(), and posang().


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