Commit 866742065bb229897df1ef4b7e9ecd3ddd0cb129
1 parent
9400e0a3
implement coordinate transformation
Showing
3 changed files
with
161 additions
and
7 deletions
include/GSkyDir.hpp
| ... | ... | @@ -45,11 +45,17 @@ public: |
| 45 | 45 | |
| 46 | 46 | // Methods |
| 47 | 47 | void radec(const double& ra, const double& dec); |
| 48 | + void radec_deg(const double& ra, const double& dec); | |
| 48 | 49 | void lb(const double& l, const double& b); |
| 50 | + void lb_deg(const double& l, const double& b); | |
| 49 | 51 | double l(void); |
| 52 | + double l_deg(void); | |
| 50 | 53 | double b(void); |
| 54 | + double b_deg(void); | |
| 51 | 55 | double ra(void); |
| 56 | + double ra_deg(void); | |
| 52 | 57 | double dec(void); |
| 58 | + double dec_deg(void); | |
| 53 | 59 | |
| 54 | 60 | private: |
| 55 | 61 | // Private methods | ... | ... |
pyext/GSkyDir.i
| ... | ... | @@ -35,11 +35,17 @@ public: |
| 35 | 35 | |
| 36 | 36 | // Methods |
| 37 | 37 | void radec(const double& ra, const double& dec); |
| 38 | + void radec_deg(const double& ra, const double& dec); | |
| 38 | 39 | void lb(const double& l, const double& b); |
| 40 | + void lb_deg(const double& l, const double& b); | |
| 39 | 41 | double l(void); |
| 42 | + double l_deg(void); | |
| 40 | 43 | double b(void); |
| 44 | + double b_deg(void); | |
| 41 | 45 | double ra(void); |
| 46 | + double ra_deg(void); | |
| 42 | 47 | double dec(void); |
| 48 | + double dec_deg(void); | |
| 43 | 49 | }; |
| 44 | 50 | |
| 45 | 51 | ... | ... |
src/GSkyDir.cpp
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | +#include <cmath> | |
| 16 | 17 | #include "GException.hpp" |
| 17 | 18 | #include "GTools.hpp" |
| 18 | 19 | #include "GSkyDir.hpp" |
| ... | ... | @@ -27,7 +28,9 @@ |
| 27 | 28 | |
| 28 | 29 | /* __ Debug definitions __________________________________________________ */ |
| 29 | 30 | |
| 30 | - | |
| 31 | +/* __ Prototype __________________________________________________________ */ | |
| 32 | +void euler(const int& type, const double& xin, const double &yin, | |
| 33 | + double* xout, double *yout); | |
| 31 | 34 | |
| 32 | 35 | /*========================================================================== |
| 33 | 36 | = = |
| ... | ... | @@ -116,7 +119,7 @@ GSkyDir& GSkyDir::operator= (const GSkyDir& dir) |
| 116 | 119 | ==========================================================================*/ |
| 117 | 120 | |
| 118 | 121 | /***********************************************************************//** |
| 119 | - * @brief Set equatorial sky direction | |
| 122 | + * @brief Set equatorial sky direction (radians) | |
| 120 | 123 | * |
| 121 | 124 | * @param[in] ra Right Ascension in radians. |
| 122 | 125 | * @param[in] dec Declination in radians. |
| ... | ... | @@ -137,7 +140,28 @@ void GSkyDir::radec(const double& ra, const double& dec) |
| 137 | 140 | |
| 138 | 141 | |
| 139 | 142 | /***********************************************************************//** |
| 140 | - * @brief Set galactic sky direction | |
| 143 | + * @brief Set equatorial sky direction (degrees) | |
| 144 | + * | |
| 145 | + * @param[in] ra Right Ascension in degrees. | |
| 146 | + * @param[in] dec Declination in degrees. | |
| 147 | + ***************************************************************************/ | |
| 148 | +void GSkyDir::radec_deg(const double& ra, const double& dec) | |
| 149 | +{ | |
| 150 | + // Set attributes | |
| 151 | + m_has_lb = 0; | |
| 152 | + m_has_radec = 1; | |
| 153 | + | |
| 154 | + // Set direction | |
| 155 | + m_ra = ra * deg2rad; | |
| 156 | + m_dec = dec * deg2rad; | |
| 157 | + | |
| 158 | + // Return | |
| 159 | + return; | |
| 160 | +} | |
| 161 | + | |
| 162 | + | |
| 163 | +/***********************************************************************//** | |
| 164 | + * @brief Set galactic sky direction (radians) | |
| 141 | 165 | * |
| 142 | 166 | * @param[in] l Galactic longitude in radians. |
| 143 | 167 | * @param[in] b Galactic latitude in radians. |
| ... | ... | @@ -158,6 +182,27 @@ void GSkyDir::lb(const double& l, const double& b) |
| 158 | 182 | |
| 159 | 183 | |
| 160 | 184 | /***********************************************************************//** |
| 185 | + * @brief Set galactic sky direction (degrees) | |
| 186 | + * | |
| 187 | + * @param[in] l Galactic longitude in degrees. | |
| 188 | + * @param[in] b Galactic latitude in degrees. | |
| 189 | + ***************************************************************************/ | |
| 190 | +void GSkyDir::lb_deg(const double& l, const double& b) | |
| 191 | +{ | |
| 192 | + // Set attributes | |
| 193 | + m_has_lb = 1; | |
| 194 | + m_has_radec = 0; | |
| 195 | + | |
| 196 | + // Set direction | |
| 197 | + m_l = l * deg2rad; | |
| 198 | + m_b = b * deg2rad; | |
| 199 | + | |
| 200 | + // Return | |
| 201 | + return; | |
| 202 | +} | |
| 203 | + | |
| 204 | + | |
| 205 | +/***********************************************************************//** | |
| 161 | 206 | * @brief Returns galactic longitude in radians |
| 162 | 207 | ***************************************************************************/ |
| 163 | 208 | double GSkyDir::l(void) |
| ... | ... | @@ -172,6 +217,20 @@ double GSkyDir::l(void) |
| 172 | 217 | |
| 173 | 218 | |
| 174 | 219 | /***********************************************************************//** |
| 220 | + * @brief Returns galactic longitude in degrees | |
| 221 | + ***************************************************************************/ | |
| 222 | +double GSkyDir::l_deg(void) | |
| 223 | +{ | |
| 224 | + // If we have no galactic coordinates then get them now | |
| 225 | + if (!m_has_lb && m_has_radec) | |
| 226 | + equ2gal(); | |
| 227 | + | |
| 228 | + // Return galactic longitude | |
| 229 | + return m_l * rad2deg; | |
| 230 | +} | |
| 231 | + | |
| 232 | + | |
| 233 | +/***********************************************************************//** | |
| 175 | 234 | * @brief Returns galactic latitude in radians |
| 176 | 235 | ***************************************************************************/ |
| 177 | 236 | double GSkyDir::b(void) |
| ... | ... | @@ -186,6 +245,20 @@ double GSkyDir::b(void) |
| 186 | 245 | |
| 187 | 246 | |
| 188 | 247 | /***********************************************************************//** |
| 248 | + * @brief Returns galactic latitude in degrees | |
| 249 | + ***************************************************************************/ | |
| 250 | +double GSkyDir::b_deg(void) | |
| 251 | +{ | |
| 252 | + // If we have no galactic coordinates then get them now | |
| 253 | + if (!m_has_lb && m_has_radec) | |
| 254 | + equ2gal(); | |
| 255 | + | |
| 256 | + // Return galactic latitude | |
| 257 | + return m_b * rad2deg; | |
| 258 | +} | |
| 259 | + | |
| 260 | + | |
| 261 | +/***********************************************************************//** | |
| 189 | 262 | * @brief Returns Right Ascension in radians |
| 190 | 263 | ***************************************************************************/ |
| 191 | 264 | double GSkyDir::ra(void) |
| ... | ... | @@ -200,6 +273,20 @@ double GSkyDir::ra(void) |
| 200 | 273 | |
| 201 | 274 | |
| 202 | 275 | /***********************************************************************//** |
| 276 | + * @brief Returns Right Ascension in degrees | |
| 277 | + ***************************************************************************/ | |
| 278 | +double GSkyDir::ra_deg(void) | |
| 279 | +{ | |
| 280 | + // If we have no equatorial coordinates then get them now | |
| 281 | + if (!m_has_radec && m_has_lb) | |
| 282 | + gal2equ(); | |
| 283 | + | |
| 284 | + // Return Right Ascension | |
| 285 | + return m_ra * rad2deg; | |
| 286 | +} | |
| 287 | + | |
| 288 | + | |
| 289 | +/***********************************************************************//** | |
| 203 | 290 | * @brief Returns Declination in radians |
| 204 | 291 | ***************************************************************************/ |
| 205 | 292 | double GSkyDir::dec(void) |
| ... | ... | @@ -213,6 +300,20 @@ double GSkyDir::dec(void) |
| 213 | 300 | } |
| 214 | 301 | |
| 215 | 302 | |
| 303 | +/***********************************************************************//** | |
| 304 | + * @brief Returns Declination in degrees | |
| 305 | + ***************************************************************************/ | |
| 306 | +double GSkyDir::dec_deg(void) | |
| 307 | +{ | |
| 308 | + // If we have no equatorial coordinates then get them now | |
| 309 | + if (!m_has_radec && m_has_lb) | |
| 310 | + gal2equ(); | |
| 311 | + | |
| 312 | + // Return Declination | |
| 313 | + return m_dec * rad2deg; | |
| 314 | +} | |
| 315 | + | |
| 316 | + | |
| 216 | 317 | /*========================================================================== |
| 217 | 318 | = = |
| 218 | 319 | = GSkyDir private methods = |
| ... | ... | @@ -273,11 +374,12 @@ void GSkyDir::free_members(void) |
| 273 | 374 | |
| 274 | 375 | /***********************************************************************//** |
| 275 | 376 | * @brief Convert equatorial to galactic coordinates |
| 276 | - * | |
| 277 | - * @todo Needs to be implemented | |
| 278 | 377 | ***************************************************************************/ |
| 279 | 378 | void GSkyDir::equ2gal(void) |
| 280 | 379 | { |
| 380 | + // Convert from equatorial to galactic | |
| 381 | + euler(0, m_ra, m_dec, &m_l, &m_b); | |
| 382 | + | |
| 281 | 383 | // Return |
| 282 | 384 | return; |
| 283 | 385 | } |
| ... | ... | @@ -285,11 +387,12 @@ void GSkyDir::equ2gal(void) |
| 285 | 387 | |
| 286 | 388 | /***********************************************************************//** |
| 287 | 389 | * @brief Convert galactic to equatorial coordinates |
| 288 | - * | |
| 289 | - * @todo Needs to be implemented | |
| 290 | 390 | ***************************************************************************/ |
| 291 | 391 | void GSkyDir::gal2equ(void) |
| 292 | 392 | { |
| 393 | + // Convert from galactic to equatorial | |
| 394 | + euler(1, m_l, m_b, &m_ra, &m_dec); | |
| 395 | + | |
| 293 | 396 | // Return |
| 294 | 397 | return; |
| 295 | 398 | } |
| ... | ... | @@ -325,3 +428,42 @@ ostream& operator<< (ostream& os, const GSkyDir& dir) |
| 325 | 428 | = Other functions used by GSkyDir = |
| 326 | 429 | = = |
| 327 | 430 | ==========================================================================*/ |
| 431 | + | |
| 432 | +/***********************************************************************//** | |
| 433 | + * @brief General coordinate transformation routine for J2000 | |
| 434 | + * | |
| 435 | + * @param[in] type Conversion type (0=equ2gal, 1=gal2equ) | |
| 436 | + * @param[in] xin Input longitude (RA or GLON) in radians. | |
| 437 | + * @param[in] yin Input latitude (Dec or GLAT) in radians. | |
| 438 | + * @param[out] xout Output longitude in radians. | |
| 439 | + * @param[out] yout Output latitude in radians. | |
| 440 | + ***************************************************************************/ | |
| 441 | +void euler(const int& type, const double& xin, const double &yin, | |
| 442 | + double* xout, double *yout) | |
| 443 | +{ | |
| 444 | + // Set transformation constants | |
| 445 | + const double psi[] = {0.57477043300, 4.9368292465}; | |
| 446 | + const double stheta[] = {0.88998808748, -0.88998808748}; | |
| 447 | + const double ctheta[] = {0.45598377618, 0.45598377618}; | |
| 448 | + const double phi[] = {4.9368292465, 0.57477043300}; | |
| 449 | + | |
| 450 | + // Perform transformation | |
| 451 | + double a = xin - phi[type]; | |
| 452 | + double b = yin; | |
| 453 | + double sb = sin(b); | |
| 454 | + double cb = cos(b); | |
| 455 | + double cbsa = cb * sin(a); | |
| 456 | + | |
| 457 | + // | |
| 458 | + a = atan2(ctheta[type] * cbsa + stheta[type] * sb, cb * cos(a)); | |
| 459 | + b = -stheta[type] * cbsa + ctheta[type] * sb; | |
| 460 | + if (b > 1.0) | |
| 461 | + b = 1.0; | |
| 462 | + | |
| 463 | + // | |
| 464 | + *yout = asin(b); | |
| 465 | + *xout = modulo((a+psi[type] + fourpi), twopi); | |
| 466 | + | |
| 467 | + // Return | |
| 468 | + return; | |
| 469 | +} | ... | ... |