DESCRIPTION.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. jdcal
  2. =====
  3. .. _TPM: http://www.sal.wisc.edu/~jwp/astro/tpm/tpm.html
  4. .. _Jeffrey W. Percival: http://www.sal.wisc.edu/~jwp/
  5. .. _IAU SOFA: http://www.iausofa.org/
  6. .. _pip: https://pypi.org/project/pip/
  7. .. _easy_install: https://setuptools.readthedocs.io/en/latest/easy_install.html
  8. .. image:: https://travis-ci.org/phn/jdcal.svg?branch=master
  9. :target: https://travis-ci.org/phn/jdcal
  10. This module contains functions for converting between Julian dates and
  11. calendar dates.
  12. A function for converting Gregorian calendar dates to Julian dates, and
  13. another function for converting Julian calendar dates to Julian dates
  14. are defined. Two functions for the reverse calculations are also
  15. defined.
  16. Different regions of the world switched to Gregorian calendar from
  17. Julian calendar on different dates. Having separate functions for Julian
  18. and Gregorian calendars allow maximum flexibility in choosing the
  19. relevant calendar.
  20. Julian dates are stored in two floating point numbers (double). Julian
  21. dates, and Modified Julian dates, are large numbers. If only one number
  22. is used, then the precision of the time stored is limited. Using two
  23. numbers, time can be split in a manner that will allow maximum
  24. precision. For example, the first number could be the Julian date for
  25. the beginning of a day and the second number could be the fractional
  26. day. Calculations that need the latter part can now work with maximum
  27. precision.
  28. All the above functions are "proleptic". This means that they work for
  29. dates on which the concerned calendar is not valid. For example,
  30. Gregorian calendar was not used prior to around October 1582.
  31. A function to test if a given Gregorian calendar year is a leap year is
  32. also defined.
  33. Zero point of Modified Julian Date (MJD) and the MJD of 2000/1/1
  34. 12:00:00 are also given as module level constants.
  35. Examples
  36. --------
  37. Some examples are given below. For more information see
  38. https://oneau.wordpress.com/2011/08/30/jdcal/.
  39. Gregorian calendar:
  40. .. code-block:: python
  41. >>> from jdcal import gcal2jd, jd2gcal
  42. >>> gcal2jd(2000,1,1)
  43. (2400000.5, 51544.0)
  44. >>> 2400000.5 + 51544.0 + 0.5
  45. 2451545.0
  46. >>> gcal2jd(2000,2,30)
  47. (2400000.5, 51604.0)
  48. >>> gcal2jd(2000,3,1)
  49. (2400000.5, 51604.0)
  50. >>> gcal2jd(2001,2,30)
  51. (2400000.5, 51970.0)
  52. >>> gcal2jd(2001,3,2)
  53. (2400000.5, 51970.0)
  54. >>> jd2gcal(*gcal2jd(2000,1,1))
  55. (2000, 1, 1, 0.0)
  56. >>> jd2gcal(*gcal2jd(1950,1,1))
  57. (1950, 1, 1, 0.0)
  58. >>> gcal2jd(2000,1,1)
  59. (2400000.5, 51544.0)
  60. >>> jd2gcal(2400000.5, 51544.0)
  61. (2000, 1, 1, 0.0)
  62. >>> jd2gcal(2400000.5, 51544.5)
  63. (2000, 1, 1, 0.5)
  64. >>> jd2gcal(2400000.5, 51544.245)
  65. (2000, 1, 1, 0.24500000000261934)
  66. >>> jd2gcal(2400000.5, 51544.1)
  67. (2000, 1, 1, 0.099999999998544808)
  68. >>> jd2gcal(2400000.5, 51544.75)
  69. (2000, 1, 1, 0.75)
  70. Julian calendar:
  71. .. code-block:: python
  72. >>> jd2jcal(*jcal2jd(2000, 1, 1))
  73. (2000, 1, 1, 0.0)
  74. >>> jd2jcal(*jcal2jd(-4000, 10, 11))
  75. (-4000, 10, 11, 0.0)
  76. Gregorian leap year:
  77. .. code-block:: python
  78. >>> from jdcal import is_leap
  79. >>> is_leap(2000)
  80. True
  81. >>> is_leap(2100)
  82. False
  83. JD for zero point of MJD, and MJD for JD2000.0:
  84. .. code-block:: python
  85. >>> from jdcal import MJD_0, MJD_JD2000
  86. >>> print MJD_0
  87. 2400000.5
  88. >>> print MJD_JD2000
  89. 51544.5
  90. Installation
  91. ------------
  92. The module can be installed using `pip`_ or `easy_install`_::
  93. $ pip install jdcal
  94. or,
  95. ::
  96. $ easy_install jdcal
  97. Tests are in ``test_jdcal.py``.
  98. Credits
  99. --------
  100. 1. A good amount of the code is based on the excellent `TPM`_ C library
  101. by `Jeffrey W. Percival`_.
  102. 2. The inspiration to split Julian dates into two numbers came from the
  103. `IAU SOFA`_ C library. No code or algorithm from the SOFA library is
  104. used in `jdcal`.
  105. License
  106. -------
  107. Released under BSD; see LICENSE.txt.
  108. For comments and suggestions, email to user `prasanthhn` in the `gmail.com`
  109. domain.