From 3bf67e06cc03c664d1abb2fc76f155e32ad4a341 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 12 Nov 2019 17:23:50 +0100 Subject: [PATCH] Add GTime.julian_epoch() methods (#1854) --- NEWS | 6 +++++- include/GTime.hpp | 2 ++ pyext/GTime.i | 2 ++ src/obs/GTime.cpp | 51 +++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 516d652..f445ee7 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.7.0 -8 November 2019 +12 November 2019 1. Introduction @@ -24,6 +24,7 @@ The following classes have been renamed: The following methods have been added: - GTime.datetime() - Datetime conversion in Python interface +- GTime.julian_epoch() - Returns Julian epoch for time - GGti::overlap(GTime&, GTime&) - Compute overlap with time interval - GObservations::npred(string&, string&) - Compute predicted number of events - GObservations::npred(GModel&, string&) - Compute predicted number of events @@ -107,6 +108,9 @@ Add GTime.datetime() method to the Python interface to convert times from and to datetime.datetime objects. Add an optional precision argument to the GTime.utc() to set the number of digits after the comma for the seconds (#2909). +Add GTime.julian_epoch() methods that return the Julian epoch for a given time +(#1854). + 11. Optimization module ----------------------- diff --git a/include/GTime.hpp b/include/GTime.hpp index 8a8e0d5..abde8a6 100644 --- a/include/GTime.hpp +++ b/include/GTime.hpp @@ -92,6 +92,8 @@ public: double secs(const std::string& timesys) const; double days(void) const; double days(const std::string& timesys) const; + double julian_epoch(void) const; + double julian_epoch(const std::string& timesys) const; std::string utc(const int& precision = 0) const; double gmst(void) const; double gast(void) const; diff --git a/pyext/GTime.i b/pyext/GTime.i index ee096fa..bab3cd5 100644 --- a/pyext/GTime.i +++ b/pyext/GTime.i @@ -62,6 +62,8 @@ public: double secs(const std::string& timesys) const; double days(void) const; double days(const std::string& timesys) const; + double julian_epoch(void) const; + double julian_epoch(const std::string& timesys) const; std::string utc(const int& precision = 0) const; double gmst(void) const; double gast(void) const; diff --git a/src/obs/GTime.cpp b/src/obs/GTime.cpp index c105573..74bf0bf 100644 --- a/src/obs/GTime.cpp +++ b/src/obs/GTime.cpp @@ -291,7 +291,7 @@ double GTime::jd(void) const /***********************************************************************//** - * @brief Return time in Julian Days for various time system + * @brief Return time in Julian Days for time system * * @param[in] timesys Time system (one of "TT", "TAI", "UTC") * @return Time in Julian Days (days). @@ -327,7 +327,7 @@ double GTime::mjd(void) const /***********************************************************************//** - * @brief Return time in Modified Julian Days for various time system + * @brief Return time in Modified Julian Days for time system * * @param[in] timesys Time system (one of "TT", "TAI", "UTC") * @return Time in Modified Julian Days (days). @@ -346,7 +346,7 @@ double GTime::mjd(const std::string& timesys) const /***********************************************************************//** - * @brief Return time in seconds in native reference for various time systems + * @brief Return time in seconds in native reference for time system * * @param[in] timesys Time system (one of "TT", "TAI", "UTC") * @return Time (seconds). @@ -404,7 +404,7 @@ double GTime::days(void) const /***********************************************************************//** - * @brief Return time in days in native reference for various time system + * @brief Return time in days in native reference for time system * * @param[in] timesys Time system (one of "TT", "TAI", "UTC") * @return Time in native reference (days). @@ -417,6 +417,37 @@ double GTime::days(const std::string& timesys) const /***********************************************************************//** + * @brief Return Julian epoch in native reference (TT) + * + * @return Julian epoch (years). + ***************************************************************************/ +double GTime::julian_epoch(void) const +{ + // Compute Julian epoch + double julian_epoch = 2000.0 + (jd() - 2451545.0) / 365.25; + + // Return Julian epoch + return (julian_epoch); +} + + +/***********************************************************************//** + * @brief Return Julian epoch in native reference for time system + * + * @param[in] timesys Time system (one of "TT", "TAI", "UTC") + * @return Julian epoch (years). + ***************************************************************************/ +double GTime::julian_epoch(const std::string& timesys) const +{ + // Compute Julian epoch + double julian_epoch = 2000.0 + (jd(timesys) - 2451545.0) / 365.25; + + // Return Julian epoch + return (julian_epoch); +} + + +/***********************************************************************//** * @brief Return time as string in UTC time system * * @param[in] precision Digits of precision to show in the seconds field @@ -700,7 +731,7 @@ void GTime::jd(const double& time) /***********************************************************************//** - * @brief Set time in Julian Days in native reference for various time systems + * @brief Set time in Julian Days in native reference for time system * * @param[in] time Time in Julian Days (days). * @param[in] timesys Time system (one of "TT", "TAI", "UTC") @@ -734,8 +765,8 @@ void GTime::mjd(const double& time) /***********************************************************************//** - * @brief Set time in Modified Julian Days in native reference for various - * time systems + * @brief Set time in Modified Julian Days in native reference for time + * system * * @param[in] time Time in Modified Julian Days (days). * @param[in] timesys Time system (one of "TT", "TAI", "UTC") @@ -754,7 +785,7 @@ void GTime::mjd(const double& time, const std::string& timesys) /***********************************************************************//** - * @brief Set time in seconds in native reference for various time systems + * @brief Set time in seconds in native reference for time system * * @param[in] seconds Time in native reference (seconds). * @param[in] timesys Time system (one of "TT", "TAI", "UTC") @@ -807,7 +838,7 @@ void GTime::days(const double& days) /***********************************************************************//** - * @brief Set time in days in native reference for various time systems + * @brief Set time in days in native reference for time system * * @param[in] days Time (TT) (days). * @param[in] timesys Time system (one of "TT", "TAI", "UTC") @@ -1122,7 +1153,7 @@ GTimeReference GTime::reference(void) const /***********************************************************************//** * @brief Print time * - * @param[in] chatter Chattiness (defaults to NORMAL). + * @param[in] chatter Chattiness. * @return String containing time in seconds in native reference. * * Prints time in seconds in the native reference. -- libgit2 0.21.4