[Pymoul-svn] SF.net SVN: pymoul: [238] juliandate/trunk
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-03-08 02:07:23
|
Revision: 238 http://pymoul.svn.sourceforge.net/pymoul/?rev=238&view=rev Author: tiran Date: 2007-03-07 18:07:12 -0800 (Wed, 07 Mar 2007) Log Message: ----------- Implemented julian day module Fixed naming typo Modified Paths: -------------- juliandate/trunk/Makefile juliandate/trunk/julianday.egg-info/PKG-INFO juliandate/trunk/julianday.egg-info/SOURCES.txt juliandate/trunk/julianday.egg-info/top_level.txt juliandate/trunk/setup.py Added Paths: ----------- juliandate/trunk/julianday.egg-info/ juliandate/trunk/julianday.py juliandate/trunk/tests.py Removed Paths: ------------- juliandate/trunk/juliandate.egg-info/ juliandate/trunk/juliandate.py Property Changed: ---------------- juliandate/trunk/ Property changes on: juliandate/trunk ___________________________________________________________________ Name: svn:ignore + dist build Modified: juliandate/trunk/Makefile =================================================================== --- juliandate/trunk/Makefile 2007-03-07 15:49:42 UTC (rev 237) +++ juliandate/trunk/Makefile 2007-03-08 02:07:12 UTC (rev 238) @@ -32,7 +32,7 @@ # What should the default be? test: - $(PYTHON) src/enumprocess/processinfo.py + $(PYTHON) tests.py egg: egg24 egg25 Deleted: juliandate/trunk/juliandate.py =================================================================== --- juliandate/trunk/juliandate.py 2007-03-07 15:49:42 UTC (rev 237) +++ juliandate/trunk/juliandate.py 2007-03-08 02:07:12 UTC (rev 238) @@ -1,6 +0,0 @@ -"""Julian date module - -Sources: - http://en.wikipedia.org/wiki/Julian_Date - http://www.vsg.cape.com/~pbaum/date/date0.htm -""" Copied: juliandate/trunk/julianday.egg-info (from rev 237, juliandate/trunk/juliandate.egg-info) Modified: juliandate/trunk/julianday.egg-info/PKG-INFO =================================================================== --- juliandate/trunk/juliandate.egg-info/PKG-INFO 2007-03-07 15:49:42 UTC (rev 237) +++ juliandate/trunk/julianday.egg-info/PKG-INFO 2007-03-08 02:07:12 UTC (rev 238) @@ -1,5 +1,5 @@ Metadata-Version: 1.0 -Name: juliandate +Name: julianday Version: 0.1 Summary: UNKNOWN Home-page: http://sourceforge.net/projects/pymoul/ @@ -9,6 +9,7 @@ Download-URL: http://cheeseshop.python.org/pypi/ Description: +Keywords: julian,julian day number,jdn,mjd,rjd,astronomy Platform: Independent Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Modified: juliandate/trunk/julianday.egg-info/SOURCES.txt =================================================================== --- juliandate/trunk/juliandate.egg-info/SOURCES.txt 2007-03-07 15:49:42 UTC (rev 237) +++ juliandate/trunk/julianday.egg-info/SOURCES.txt 2007-03-08 02:07:12 UTC (rev 238) @@ -2,15 +2,16 @@ GPL.txt INSTALL.txt LICENSE.txt -MANIFEST.in Makefile README.txt ez_setup.py -juliandate.py +julianday.py setup.py +tests.py version.txt -juliandate.egg-info/PKG-INFO -juliandate.egg-info/SOURCES.txt -juliandate.egg-info/dependency_links.txt -juliandate.egg-info/top_level.txt -juliandate.egg-info/zip-safe +julianday.egg-info/PKG-INFO +julianday.egg-info/SOURCES.txt +julianday.egg-info/dependency_links.txt +julianday.egg-info/requires.txt +julianday.egg-info/top_level.txt +julianday.egg-info/zip-safe Modified: juliandate/trunk/julianday.egg-info/top_level.txt =================================================================== --- juliandate/trunk/juliandate.egg-info/top_level.txt 2007-03-07 15:49:42 UTC (rev 237) +++ juliandate/trunk/julianday.egg-info/top_level.txt 2007-03-08 02:07:12 UTC (rev 238) @@ -1 +1 @@ -juliandate +julianday Copied: juliandate/trunk/julianday.py (from rev 237, juliandate/trunk/juliandate.py) =================================================================== --- juliandate/trunk/julianday.py (rev 0) +++ juliandate/trunk/julianday.py 2007-03-08 02:07:12 UTC (rev 238) @@ -0,0 +1,119 @@ +# Julian Day Number +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""Julian day number module + +Sources: + http://en.wikipedia.org/wiki/Julian_Date + http://www.vsg.cape.com/~pbaum/date/date0.htm + http://www.hermetic.ch/cal_stud/jdn.htm + http://www.merlyn.demon.co.uk/daycount.htm +""" + +try: + import pkg_resources +except ImportError: + pass +else: + pkg_resources.require("pytz>=2006p") + +from datetime import datetime +from math import floor + +from pytz import UTC + + +#D_MONTHS = [306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275] + +def dt2jdn(dt, precision=5): + """datetime to julian day number + + >>> from datetime import datetime + >>> dt2jdn(datetime(1582, 10, 15, 0, 0, 0, tzinfo=UTC)) + 2299160.5 + >>> dt2jdn(datetime(2007, 1, 14, 13, 18, 59, 900, tzinfo=UTC)) + 2454115.05486 + """ + dt = UTC.normalize(dt.astimezone(UTC)) + y, m, d = dt.year, dt.month, dt.day + a = (14-m)//12 # 0 if m < 3: 1 + y = y + 4800 -a + m = m + 12*a - 3 + # integer divison + jdn = d + (153*m+2)//5 + 365*y + y//4 - y//100 + y//400 - 32045 + # real division + jdhms = round((dt.hour-12.0)/24.0 + dt.minute/1440.0 + dt.second/86400.0 + + dt.microsecond/86400000.0, precision) + return jdn + jdhms + +def dt2mjd(dt, precision=5): + """datetime to modified julian day number + """ + return dt2jdn(dt, precision) - 2400000.5 + +def dt2rjd(dt, precision=5): + """datetime to reduced julian day number + """ + return dt2jdn(dt, precision) - 2400000.0 + +def jdn2dt(jdn): + """Julian day number to Gregorian date + + >>> jdn2dt(2299160.5) + datetime.datetime(1582, 10, 15, 0, 0, tzinfo=<UTC>) + >>> jdn2dt(2454115.05486) + datetime.datetime(2007, 1, 14, 13, 18, 59, 904, tzinfo=<UTC>) + """ + jd, hms = divmod(jdn+0.5, 1) + # ydm part + w = (jd - 1867216.25)//36524.25 + b = jd + w - w//4 + 1525 + c = (b-122.1)//365.25 + d = int(365.25*c) + e = (b-d)//30.6001 + f = int(30.6001*e) + D = int(b - d - f) + if e>12: + M = int(e - 13) + else: + M = int(e - 1) + Y = int(c - 4716) + if M <3: + Y += 1 + # hms part + hms, ms = divmod(hms*86400.0, 1) + hms = int(hms) + h = hms//3600 + m = hms//60 % 60 + s = hms % 60 + ms = int(ms * 1000) + return datetime(Y, M, D, h, m ,s , ms, tzinfo=UTC) + +def mjd2dt(mjd): + """Modified julian day number to datetime + """ + return jdn2dt(mjd + 2400000.5) + +def dt2rjd(dt, precision=5): + """Reduced julian day number to datetime + """ + return jdn2dt(mjd + 2400000) + +def jdn2isoweekday(jdn): + """Julian day number to ISO weekday (mon=1, sun=7) + """ + return (jdn % 7)+1 Modified: juliandate/trunk/setup.py =================================================================== --- juliandate/trunk/setup.py 2007-03-07 15:49:42 UTC (rev 237) +++ juliandate/trunk/setup.py 2007-03-08 02:07:12 UTC (rev 238) @@ -23,7 +23,7 @@ VERSION = "0.1" setup_infos = dict( - name = "juliandate", + name = "julianday", version = VERSION, description = __doc__[:__doc__.find('\n')].strip(), long_description = '\n'.join([line @@ -35,7 +35,7 @@ url = "http://sourceforge.net/projects/pymoul/", download_url= "http://cheeseshop.python.org/pypi/", license = "GPL", - keywords = [], + keywords = ["julian", "julian day number", "jdn", "mjd", "rjd", "astronomy"], platforms = ['Independent'], classifiers = ( 'Development Status :: 4 - Beta', @@ -46,10 +46,9 @@ 'Programming Language :: Python', 'Topic :: Software Development :: Libraries' ), - setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - #packages = [], - #package_dir = {'' : 'src'}, - py_modules = ['juliandate'], + setup_requires = ["setuptools>="+SETUPTOOLS_VERSION], + install_requires = ["pytz>=2006p"], + py_modules = ['julianday'], zip_safe = True, ) Added: juliandate/trunk/tests.py =================================================================== --- juliandate/trunk/tests.py (rev 0) +++ juliandate/trunk/tests.py 2007-03-08 02:07:12 UTC (rev 238) @@ -0,0 +1,17 @@ +"""julian day number unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id: tests.py 216 2007-02-28 12:06:48Z tiran $" +__revision__ = "$Revision: 216 $" + +import os +import unittest +from doctest import DocTestSuite + +def test_suite(): + return unittest.TestSuite(( + DocTestSuite('juliandate'), + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") Property changes on: juliandate/trunk/tests.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |