Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding zonetab from openastro and working on natal information. For n…

…ow, solar returns and lunar returns still are not on calendar.
  • Loading branch information...
commit d94adac583a59f674c7a40b47858f75bbb78f3d5 1 parent 136aed6
@ShadowKyogre authored
View
81 astro_rewrite.py
@@ -16,6 +16,24 @@
#ascmc[7] = "polar ascendant" (M. Munkasey)
zodiac =['Aries','Taurus','Gemini','Cancer','Leo','Virgo','Libra','Scorpio','Sagittarius','Capricorn','Aquarius','Pisces']
zodiac_element = ['fire','earth','air','water','fire','earth','air','water','fire','earth','air','water']
+aspects = { 'conjunction': 0.0,
+ 'semi-sextile':30.0,
+ 'semi=square':45.0,
+ 'sextile':60.0,
+ 'quintile':72.0,
+ 'square':90.0,
+ 'trine':120.0,
+ 'sesiquadrate':135.0,
+ 'biquintile':144.0,
+ 'inconjunct':150.0,
+ 'opposition':180.0,
+ }
+special_aspects = { 'grand trine':((1,120),(2,120)),
+ 'grand cross':((1,90),(3,90)),
+ 'yod':((1,150),(2,60)),
+ 'stellium':((1,0),(2,0)),
+ 't square':((2,180),(1,90)),
+ }
##Formalhaut
#stars=["Aldebaran", "Regulus", "Antares", "Fomalhaut", \#major stars
#"Alpheratz" , "Baten Kaitos", \#Aries stars
@@ -45,6 +63,9 @@ def check_distance(degrees, orb, zodiacal1, zodiacal2):
math.fabs(true_measurement-true_measurement2) \
<= degrees + orb
+def create_aspect_table(zodiac,natal_data,orbs):
+ print "To do"
+
def solar_return(date,year,data): #data contains the angular information, date is for a reasonable baseline
day=datetime_to_julian(date.replace(year=year))
origday=day
@@ -57,29 +78,29 @@ def solar_return(date,year,data): #data contains the angular information, date i
delta_seconds=this_degree[3]-data[3]
if same_sign:
if delta_degrees < 0:
- day=day+0.0013020833 #1.875 minutes increment
+ day=day+0.0013020833
elif delta_degrees > 0:
day=day-0.0013020833
else:
if delta_minutes < 0:
- day=day+0.00065104169 #0.93750003 minutes increment
+ day=day+0.00065104169
elif delta_minutes > 0:
day=day-0.00065104169
else:
if delta_seconds < 0: #move forward
if math.fabs(delta_seconds) <= 5:
- day=day+0.000081380211 #+7.5 minutes
+ day=day+0.000081380211
elif math.fabs(delta_seconds) <= 10:
- day=day+0.00016276042 #+7.5 minutes
+ day=day+0.00016276042
else:
- day=day+0.00032552084 #+15 minutes
+ day=day+0.00032552084
elif delta_seconds > 0:
if math.fabs(delta_seconds) <= 5:
- day=day-0.000081380211 #+7.5 minutes
+ day=day-0.000081380211
elif math.fabs(delta_seconds) <= 10:
- day=day-0.00016276042 #+7.5 minutes
+ day=day-0.00016276042
else:
- day=day-0.00032552084 #+15 minutes
+ day=day-0.00032552084
else:
return revjul_to_datetime(swisseph.revjul(day))
else:
@@ -92,13 +113,14 @@ def solar_return(date,year,data): #data contains the angular information, date i
#off by +-10ish seconds for now
def lunar_return(date,month,year,data): #data contains the angular information, date is for a reasonable baseline
start_of_last_lunar_cycle=previous_new_moon(date)
- if month==1:
- this_month=date.replace(month=12,year=year-1)
- else:
- this_month=date.replace(month=month-1,year=year)
+ this_month=date.replace(month=month,year=year)
+ #if month==1:
+ #this_month=date.replace(month=12,year=year-1)
+ #else:
+ #this_month=date.replace(month=month-1,year=year)
time_elapsed=date-start_of_last_lunar_cycle #get the progress of the cycle
start_of_month_lunar_cycle=previous_new_moon(this_month) #get the cycle for this month
- day=datetime_to_julian(start_of_month_lunar_cycle+time_elapsed) #get the middle of the month
+ day=datetime_to_julian(start_of_month_lunar_cycle+time_elapsed)
origday=day
while math.fabs(origday-day) <= 30:#
this_degree=format_zodiacal_longitude(swisseph.calc_ut(day,swisseph.MOON)[0])
@@ -109,35 +131,35 @@ def lunar_return(date,month,year,data): #data contains the angular information,
delta_seconds=this_degree[3]-data[3]
if same_sign:
if delta_degrees < 0: #move forward
- day=day+0.00032552084 #+1 hr
+ day=day+0.00032552084
elif delta_degrees > 0: #move backward
- day=day-0.00032552084 #+1 hr
+ day=day-0.00032552084
else:
if delta_minutes < 0:
- day=day+0.00016276042 #30 minutes
+ day=day+0.00016276042
elif delta_minutes > 0:
- day=day-0.00016276042 #30 minutes
+ day=day-0.00016276042
else:
if delta_seconds < 0: #move forward
if math.fabs(delta_seconds) <= 3:
- day=day+0.000010172526 #+7.5 minutes
+ day=day+0.000010172526
elif math.fabs(delta_seconds) <= 5:
- day=day+0.000020345053 #+7.5 minutes
+ day=day+0.000020345053
elif math.fabs(delta_seconds) <= 10:
- day=day+0.000040690105 #+7.5 minutes
+ day=day+0.000040690105
else:
- day=day+0.000081380211 #+15 minutes
+ day=day+0.000081380211
elif delta_seconds > 0:
if math.fabs(delta_seconds) <= 3:
- day=day-0.000010172526 #+7.5 minutes
+ day=day-0.000010172526
if math.fabs(delta_seconds) <= 5:
- day=day-0.000020345053 #+7.5 minutes
+ day=day-0.000020345053
elif math.fabs(delta_seconds) <= 10:
- day=day-0.000040690105 #+7.5 minutes
+ day=day-0.000040690105
else:
- day=day-0.000081380211 #+15 minutes
+ day=day-0.000081380211
else:
- return revjul_to_datetime(swisseph.revjul(day-0.0002055))
+ return revjul_to_datetime(swisseph.revjul(day))
else:
if zodiac.index(this_degree[1]) < zodiac.index(data[1]) or \
this_degree[1]=="Aries" and data[1]=="Pisces":
@@ -250,6 +272,7 @@ def get_house(planet, observer, date):
#float[12],#float[8]
#note: houses move along!
cusps,asmc=swisseph.houses(day, observer.lat, observer.long)
+ #get REALLY precise house position
hom=swisseph.house_pos(asmc[2], observer.lat, obliquity, objlon, objlat=oblt)
swisseph.close()
return hom,objlon,format_zodiacal_longitude(objlon)
@@ -395,9 +418,9 @@ def get_moon_cycle(date):
def revjul_to_datetime(revjul):
hours=int(math.modf(revjul[3])[1])
- minutedouble=math.modf(revjul[3])
- minutes=int(minutedouble[0]*60)
- seconds=int(math.modf(minutedouble[0])[0]*60)
+ minutedouble=math.modf(revjul[3])[0]*60
+ minutes=int(minutedouble)
+ seconds=int(math.modf(minutedouble)[0]*60)
utc=datetime(int(revjul[0]), int(revjul[1]), int(revjul[2]), hour=hours,minute=minutes,second=seconds)
return utc_to_timezone(utc)
View
53 chronosconfig.py
@@ -7,6 +7,7 @@
from astro_rewrite import *
#import dateutil
from dateutil import tz
+import zonetab
#from dateutil.parser import *
class Observer:
@@ -19,7 +20,7 @@ class ChronosLNXConfig:
def __init__(self):
self.APPNAME="ChronosLNX"
- self.APPVERSION="0.6.0"
+ self.APPVERSION="0.7.0"
self.AUTHOR="ShadowKyogre"
self.DESCRIPTION="A simple tool for checking planetary hours and moon phases."
self.YEAR="2011"
@@ -30,8 +31,12 @@ def __init__(self):
self.AUTHOR,
self.APPNAME)
#self.settings=QtCore.QSettings(self.AUTHOR,self.APPNAME)
-
+ if os.uname()[0] != 'Linux':
+ self.zt=os.sys.path[0]+"/zone.tab" #use the local copy if this isn't a Linux
+ else:
+ self.zt="/usr/share/zoneinfo/zone.tab"
self.observer=Observer()
+ self.baby=Observer()
self.reset_settings()
self.load_schedule()
@@ -97,18 +102,32 @@ def prepare_icons(self):
'Pisces': QtGui.QIcon(self.grab_icon_path(self.current_theme, "signs", 'pisces')),
}
+ def generate_timezone(self, birth=False):
+ timezone=zonetab.nearest_tz(self.baby.lat, \
+ self.baby.long, \
+ zonetab.timezones(zonetab=self.zt))[2]
+ print "Detected natal timezone to be %s" % timezone
+ return tz.gettz(timezone)
+
#resets to what the values are on file if 'apply' was just clicked and user wants to undo
def reset_settings(self):
- self.settings.beginGroup("User")
+ self.settings.beginGroup("Location")
+ self.observer.lat=float(self.settings.value("latitude", 0.0).toPyObject())
+ self.observer.long=float(self.settings.value("longitude", 0.0).toPyObject())
+ self.observer.elevation=float(self.settings.value("elevation", 0.0).toPyObject())
+ self.settings.endGroup()
+ self.settings.beginGroup("Birth")
+ self.birthzone=self.settings.value("birthZone",QtCore.QVariant())
+ self.baby.lat=float(self.settings.value("latitude", 0.0).toPyObject())
+ self.baby.long=float(self.settings.value("longitude", 0.0).toPyObject())
+ self.baby.elevation=float(self.settings.value("elevation", 0.0).toPyObject())
+ self.tz=self.generate_timezone()
try:
self.birthtime=self.settings.value("birthTime", \
- QtCore.QVariant(datetime(2000,1,1,tzinfo=tz.gettz()))).toPyObject()
+ QtCore.QVariant(datetime(2000,1,1,tzinfo=self.tz))).toPyObject()
except ValueError:
- self.birthtime=datetime(2000,1,1,tzinfo=tz.gettz())
+ self.birthtime=datetime(2000,1,1,tzinfo=self.tz)
#add bday
- self.observer.lat=float(self.settings.value("latitude", 0.0).toPyObject())
- self.observer.long=float(self.settings.value("longitude", 0.0).toPyObject())
- self.observer.elevation=float(self.settings.value("elevation", 0.0).toPyObject())
self.settings.endGroup()
self.settings.beginGroup("Appearance")
self.current_theme=str(self.settings.value("iconTheme", QtCore.QString("DarkGlyphs")).toPyObject())
@@ -144,16 +163,18 @@ def reset_settings(self):
str(QtCore.QString("Capricorn"))).toPyObject())
except ValueError: #denotes that config was from previous version
self.capricorn_alt="Capricorn"
+ self.settings.endGroup()
+
self.prepare_icons()
+ self.load_natal_data()
+ def load_natal_data(self):
print "Loading natal data..."
- self.natal_data=get_signs(self.birthtime,self.observer,self.show_nodes)
+ self.natal_data=get_signs(self.birthtime,self.baby,self.show_nodes)
#keep a copy of natal information for transits
self.natal_sun=format_zodiacal_longitude(self.natal_data[0][3])
#keep a formatted copy for solar returns
self.natal_moon=format_zodiacal_longitude(self.natal_data[1][3])
- #keep a formatted copy for lunar returns
- self.settings.endGroup()
def load_schedule(self):
self.schedule=QtGui.QStandardItemModel()
@@ -254,13 +275,19 @@ def get_available_themes(self):
return themes
def save_settings(self):
- self.settings.beginGroup("User")
- self.settings.setValue("birthTime", self.birthtime)
+ self.settings.beginGroup("Location")
self.settings.setValue("latitude", self.observer.lat)
self.settings.setValue("longitude", self.observer.long)
self.settings.setValue("elevation", self.observer.elevation)
self.settings.endGroup()
+ self.settings.beginGroup("Birth")
+ self.settings.setValue("birthTime", self.birthtime)
+ self.settings.setValue("latitude", self.baby.lat)
+ self.settings.setValue("longitude", self.baby.long)
+ self.settings.setValue("elevation", self.baby.elevation)
+ self.settings.endGroup()
+
self.settings.beginGroup("Appearance")
self.settings.setValue("iconTheme", self.current_theme)
self.settings.endGroup()
View
2  geolocationwidget.py
@@ -51,7 +51,7 @@ class GeoLocationWidget(QWidget):
Provides a custom geographical location widget.
"""
- __pyqtSignals__ = ("latitudeChanged(double)", "longitudeChanged(double)")
+ __pyqtSignals__ = ("latitudeChanged(double)", "longitudeChanged(double)", "elevationChanged(double)")
def __init__(self, parent = None):
View
61 main.py
@@ -58,7 +58,7 @@ def add_widgets(self):
self.leftLayout.addWidget(self.calendar)
natalButton=QtGui.QPushButton("&View Natal Data",self)
- natalButton.clicked.connect(lambda: self.get_info_for_date(CLNXConfig.birthtime))
+ natalButton.clicked.connect(lambda: self.get_info_for_date(CLNXConfig.birthtime, birth=True))
natalButton.setIcon(QtGui.QIcon.fromTheme("view-calendar-list"))
self.leftLayout.addWidget(natalButton)
@@ -182,7 +182,11 @@ def show_notification(self, title, text, ptrigger):
##datepicking related
#http://eli.thegreenplace.net/2011/04/25/passing-extra-arguments-to-pyqt-slot/
- def get_info_for_date(self, date):
+ def get_info_for_date(self, date, birth=False):
+ if birth:
+ ob=CLNXConfig.baby
+ else:
+ ob=CLNXConfig.observer
info_dialog=QtGui.QDialog(self)
info_dialog.setFixedSize(400,400)
info_dialog.setWindowTitle("Info for %s" %(date.strftime("%m/%d/%Y")))
@@ -212,10 +216,10 @@ def get_info_for_date(self, date):
dayData=QtGui.QTabWidget(info_dialog)
- hoursToday.prepareHours(date,CLNXConfig.observer)
+ hoursToday.prepareHours(date,ob)
moonToday.get_moon_cycle(date)
moonToday.highlight_cycle_phase(date)
- signsToday.get_constellations(date, CLNXConfig.observer)
+ signsToday.get_constellations(date, ob)
dayData.addTab(hoursToday,"Planetary Hours")
dayData.addTab(moonToday,"Moon Phases")
@@ -366,17 +370,17 @@ def get_cal_menu(self, qpoint):
if idx.row() is 1 and day > 7:
replace_month=month-1
if replace_month == 0:
- date=datetime(year=year-1,month=12,day=day, hour=12).replace(tzinfo=tz.gettz())
+ date=datetime(year=year-1,month=12,day=day, hour=12, tzinfo=tz.gettz())
else:
- date=datetime(year=year,month=month-1,day=day, hour=12).replace(tzinfo=tz.gettz())
+ date=datetime(year=year,month=month-1,day=day, hour=12, tzinfo=tz.gettz())
elif (idx.row() is 6 or idx.row() is 5) and day < 24:
replace_month=(month+1)%12
if replace_month == 1:
- date=datetime(year=year+1,month=replace_month,day=day).replace(tzinfo=tz.gettz())
+ date=datetime(year=year+1,month=replace_month,day=day, tzinfo=tz.gettz())
else:
- date=datetime(year=year,month=replace_month,day=day).replace(tzinfo=tz.gettz())
+ date=datetime(year=year,month=replace_month,day=day, tzinfo=tz.gettz())
else:
- date=datetime(year=year,month=month,day=day).replace(tzinfo=tz.gettz())
+ date=datetime(year=year,month=month,day=day, tzinfo=tz.gettz())
#self.calendar.setGridVisible(True)
menu=QtGui.QMenu()
infoitem=menu.addAction("Info for %s" %(date.strftime("%m/%d/%Y")))
@@ -438,7 +442,11 @@ def update_settings_widgets(self):
self.settings_dialog.location_widget.setLatitude(CLNXConfig.observer.lat)
self.settings_dialog.location_widget.setLongitude(CLNXConfig.observer.long)
self.settings_dialog.location_widget.setElevation(CLNXConfig.observer.elevation)
+
self.settings_dialog.date.setDateTime(CLNXConfig.birthtime)
+ self.settings_dialog.birth_widget.setLatitude(CLNXConfig.baby.lat)
+ self.settings_dialog.birth_widget.setLongitude(CLNXConfig.baby.long)
+ self.settings_dialog.birth_widget.setElevation(CLNXConfig.baby.elevation)
idx=self.settings_dialog.appearance_icons.findText(CLNXConfig.current_theme)
self.settings_dialog.appearance_icons.setCurrentIndex(idx)
@@ -458,14 +466,24 @@ def settings_change(self):
lat=float(self.settings_dialog.location_widget.latitude)
lng=float(self.settings_dialog.location_widget.longitude)
elv=float(self.settings_dialog.location_widget.elevation)
+
+ blat=float(self.settings_dialog.birth_widget.latitude)
+ blng=float(self.settings_dialog.birth_widget.longitude)
+ belv=float(self.settings_dialog.birth_widget.elevation)
+
thm=str(self.settings_dialog.appearance_icons.currentText())
cp=str(self.settings_dialog.c_check.currentText())
- CLNXConfig.birthtime=self.settings_dialog.date.dateTime()\
- .toPyDateTime().replace(tzinfo=tz.gettz())
CLNXConfig.observer.lat=lat
CLNXConfig.observer.long=lng
CLNXConfig.observer.elevation=elv
+
+ CLNXConfig.baby.lat=blat
+ CLNXConfig.baby.long=blng
+ CLNXConfig.baby.elevation=belv
+ date=self.settings_dialog.date.dateTime().toPyDateTime()
+ CLNXConfig.birthtime=date.replace(tzinfo=CLNXConfig.generate_timezone())
+
CLNXConfig.current_theme=thm
CLNXConfig.show_sign=self.settings_dialog.s_check.isChecked()
CLNXConfig.show_moon=self.settings_dialog.m_check.isChecked()
@@ -475,11 +493,8 @@ def settings_change(self):
CLNXConfig.capricorn_alt=cp
CLNXConfig.prepare_icons()
- CLNXConfig.natal_data=get_signs(CLNXConfig.birthtime,CLNXConfig.observer,CLNXConfig.show_nodes)
- #keep a copy of natal information for transits
- CLNXConfig.natal_sun=format_zodiacal_longitude(CLNXConfig.natal_data[0][3])
- #keep a formatted copy for solar returns
- CLNXConfig.natal_moon=format_zodiacal_longitude(CLNXConfig.natal_data[1][3])
+ CLNXConfig.load_natal_data()
+
self.calendar.setIcons(CLNXConfig.moon_icons)
self.hoursToday.setIcons(CLNXConfig.main_icons)
self.moonToday.setIcons(CLNXConfig.moon_icons)
@@ -509,23 +524,29 @@ def make_settings_dialog(self):
tabs=QtGui.QTabWidget(self.settings_dialog)
self.settings_dialog.setFixedSize(500,400)
+ location_page=QtGui.QFrame()
user_info_page=QtGui.QFrame()
appearance_page=QtGui.QFrame()
events_page=QtGui.QFrame()
tweaks_page=QtGui.QFrame()
- tabs.addTab(user_info_page,"Info on You")
+ tabs.addTab(location_page,"Location")
+ tabs.addTab(user_info_page,"Birth Information")
tabs.addTab(appearance_page,"Appearance")
tabs.addTab(events_page,"Events")
tabs.addTab(tweaks_page,"Tweaks")
- tgrid=QtGui.QGridLayout(user_info_page)
- self.settings_dialog.location_widget = geolocationwidget.GeoLocationWidget(user_info_page)
+ self.settings_dialog.location_widget = geolocationwidget.GeoLocationWidget(location_page)
+ vbox=QtGui.QVBoxLayout(location_page)
+ vbox.addWidget(self.settings_dialog.location_widget)
+
+ self.settings_dialog.birth_widget = geolocationwidget.GeoLocationWidget(user_info_page)
self.settings_dialog.date = QtGui.QDateTimeEdit(user_info_page)
self.settings_dialog.date.setDateRange(QtCore.QDate(1902,1,1),QtCore.QDate(2037,1,1))
self.settings_dialog.date.setDisplayFormat("MM/dd/yyyy - HH:mm:ss")
- tgrid.addWidget(self.settings_dialog.location_widget,0,0,3,2)
+ tgrid=QtGui.QGridLayout(user_info_page)
+ tgrid.addWidget(self.settings_dialog.birth_widget,0,0,3,2)
tgrid.addWidget(QtGui.QLabel("Birth time"),3,0)
tgrid.addWidget(self.settings_dialog.date,3,1)
View
131 zonetab.py
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+""" convert lat/long to timezone, offset using the zoneinfo database
+
+see http://www.twinsun.com/tz/tz-link.htm ,
+ http://en.wikipedia.org/wiki/Zoneinfo
+"""
+
+import re, struct, math
+from datetime import datetime
+from dateutil.tz import tzfile
+
+def nearest_tz(lat, lon, zones):
+ """
+ >>> nearest_tz(39.2975, -94.7139, timezones())[2]
+ 'America/Indiana/Vincennes'
+
+ >>> nearest_tz(39.2975, -94.7139, timezones(exclude=["Indiana"]))[2]
+ 'America/Chicago'
+
+ """
+ def d(tzrec):
+ return distance(lat, lon, tzrec[1][0], tzrec[1][1])
+ return optimize(zones, d)
+
+def optimize(seq, metric):
+ best = None
+ m = None
+
+ for candidate in seq:
+ x = metric(candidate)
+ if best is None or x < m:
+ m = x
+ best = candidate
+ return best
+
+def distance(lat_1, long_1, lat_2, long_2):
+ # thanks http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393241
+ # Submitter: Kevin Ryan (other recipes)
+ # Last Updated: 2006/04/25
+ lat_1, long_1, lat_2, long_2 = [ v * math.pi / 180.0
+ for v in lat_1, long_1, lat_2, long_2]
+ dlong = long_2 - long_1
+ dlat = lat_2 - lat_1
+ a = (math.sin(dlat / 2))**2 + math.cos(lat_1) * math.cos(lat_2) \
+ * (math.sin(dlong / 2))**2
+ return 2 * math.asin(min(1, math.sqrt(a)))
+
+def timezones(zonetab="/usr/share/zoneinfo/zone.tab",
+ exclude=[]):
+ """iterate over timezones in zone.tab; yield (country, (lat, lon), name)
+
+ @param zonetab: filename of zone.tab file
+ @param exclude: exclude timezones with these strings in the name,
+ e.g. convexity exceptions like Indiana
+ """
+ for line in file(zonetab):
+ if line.startswith("#"): continue
+ values = line.split()
+ if len(values) >= 3:
+ country, coords, tz = values[:3]
+ for s in exclude:
+ if s in tz:
+ break
+ else:
+ yield country, latlong(coords), tz
+
+
+def stdtime(tz, year, month, day, hour, min, sec ,
+ zoneinfo="/usr/share/zoneinfo"
+ ):
+ """Use /usr/share/zoneinfo to interpret a time in a timezone.
+
+ >>> stdtime("America/Chicago", "2007-04-02T21:53:27")
+ '2007-04-02T21:53:27-05:00'
+ """
+ return datetime(year, month, day, hour, min, sec,
+ tzinfo=tzfile("%s/%s" % (zoneinfo, tz))
+ )
+
+
+
+def latlong(coords):
+ """decode ISO 6709. ugh.
+
+ >>> latlong("-1247+04514")
+ (-12.783333333333333, 45.233333333333334)
+
+ >>> latlong("-690022+0393524")
+ (-69.00611111111111, 39.590000000000003)
+ """
+ m = re.search(r'([^\d])(\d+)([^\d])(\d+)', coords)
+ if not m:
+ raise ValueError, coords
+ return coord(m.group(1), m.group(2)), coord(m.group(3), m.group(4))
+
+def coord(sign, digits):
+ """
+ >>> coord("-", "1247")
+ -12.783333333333333
+ >>> coord("+", "04514")
+ 45.233333333333334
+ >>> coord("-", "690022")
+ -69.00611111111111
+ >>> coord("+", "0393524")
+ 39.590000000000003
+ """
+
+ if len(digits) == 4:
+ d, m, s = int(digits[:2]), int(digits[2:]), 0
+ elif len(digits) == 5:
+ d, m, s = int(digits[:3]), int(digits[3:]), 0
+ elif len(digits) == 6:
+ d, m, s = int(digits[:2]), int(digits[2:4]), int(digits[4:])
+ elif len(digits) == 7:
+ d, m, s = int(digits[:3]), int(digits[3:5]), int(digits[5:])
+ else:
+ raise RuntimeError, "not implemented", digits
+
+ if sign == '+': kludge = 'N'
+ else: kludge = 'S'
+
+ return dms(kludge, d, m, s)
+
+def dms(o, d, m, s):
+ """
+ >>> abs(dms(u'N', 30, 11, u'40.3') - 30.194527777777779) <.001
+ True
+ """
+ return (o in ('N', 'E') and 1 or -1) * (d + \
+ (m + float(s)/60)/60)
Please sign in to comment.
Something went wrong with that request. Please try again.