# Created by Leo from: C:\Python23\Tom\leo\mayaclock.leo # << Mayaclock declarations >> import os import Image import wx import time from math import * import copy import string import datetime import BmpImagePlugin,GifImagePlugin,JpegImagePlugin # -- end -- << Mayaclock declarations >> # << Mayaclock methods >> (1 of 24) def to_julian(time): "Converts a time tuple to julian day" year,month,day,hour,min,sec=time # d=day+(hour+(min+(sec/60.))/60.)/24. d=day+to_decimal(time[-3:])/24.0 if month<3: y=year-1 m=month+12 else: y=year m=month if (year>1582 or (year==1582 and month>10) or (year==1582 and month==10 and day >=15)): A=int(y/100) B=2-A+int(A/4.) else: B=0 if y<0: C=int((365.25*y)-0.75) else: C=int(365.25*y) D=int(30.6001*(m+1)) return B+C+D+d+1720994.5 # << Mayaclock methods >> (2 of 24) def to_calendar(day): "Converts a julian day to a time tuple" jd=0.5+day I=int(jd) F=jd-I if I>2229160: A=int((I-1867216.25)/36524.25) B=I+1+A-int(A/4.) else: B=I C=B+1524 D=int((C-122.1)/365.25) E=int(365.25*D) G=int((C-E)/30.6001) d=C-E+F-int(30.6001*G) if G<13.5: month=G-1 else: month=G-13 if month>2.5: year=D-4716 else: year=D-4715 day=int(d) h=(d-day)*24 hour,minute,sec=to_hms(h) return year,month,day,hour,minute,sec # << Mayaclock methods >> (3 of 24) def to_decimal(time): "Converts (hour,minute,second) format to decimal hours" hour,min,sec=time if hour<0:mult=-1 else:mult=1 return mult*(abs(hour)+((sec/60.0)+min)/60.0) # << Mayaclock methods >> (4 of 24) def to_hms(hourd): "Converts decimal hours to (hour,minute,second) format" hour=int(hourd) mind=abs(hourd-hour)*60 min=int(mind) sec=round((mind-min)*60,2) return hour,min,sec # << Mayaclock methods >> (5 of 24) def to_utc(time,lon,daylight=0): "Converts decimal localtime to utc decimal time" hour=time-daylight if lon>=0: zone=int(lon/15.) else: zone=int(lon/15.)-1 hour=hour-zone if hour>24: day=1 hour=hour-24 elif hour<0: day=-1 hour=hour+24 else: day=0 return day,hour # << Mayaclock methods >> (6 of 24) def to_gst(julian,utc): "Converts utc decima time to Greenwitch sidereal time" s=julian-2451545.0 t=s/36525.0 t0=divmod(6.697374558+(2400.051336*t)+(0.000025862*t*t),24)[1] gst=divmod(t0+utc*1.002737909,24)[1] return gst # << Mayaclock methods >> (7 of 24) def gst_to_utc(julian,gst): "Converts Greenwitch sidereal time to utc" t=(julian-2451545.0)/36525.0 t0=divmod(6.697374558+(2400.051336*t)+(0.000025862*t*t),24)[1] ut=divmod(divmod((gst-t0),24)[1]*0.9972695663,24)[1] return ut # << Mayaclock methods >> (8 of 24) def utc_to_local(utc,lon,savings=0): "Converts utc to localtime" hour=utc+savings if lon>=0: zone=int(lon/15.) else: zone=int(lon/15.)-1 hour=hour+zone if hour>24: day=1 hour=hour-24 elif hour<0: day=-1 hour=hour+24 else: day=0 return day,hour # << Mayaclock methods >> (9 of 24) def lst_to_gst(lst,lon): "Converts Local sidereal time to Greenwitch sidereal time" return divmod(lst-lon/15.0,24)[1] # << Mayaclock methods >> (10 of 24) def day_of_week(julian): "Given Julian day, returns day of the week" days={0:"Sunday",1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday"} a=(julian+1.5)/7.0 day=int(round((a-int(a))*7.0)) return days[day] # << Mayaclock methods >> (11 of 24) def rad_to_deg(rad): "Converts radians to degrees" return (rad*180.0)/pi # << Mayaclock methods >> (12 of 24) def deg_to_rad(deg): "Converts degrees to radians" return (deg/180.0)*pi # << Mayaclock methods >> (13 of 24) def eq_to_hor(h_angle,decl,lat): "Converts Equatorial coordinates to Horizon coordinates" [h_angle,decl,lat]=map(deg_to_rad,[h_angle,decl,lat]) h_angle=h_angle*15.0 alt=asin(sin(decl)*sin(lat)+cos(decl)*cos(lat)*cos(h_angle)) y=-cos(decl)*cos(lat)*sin(h_angle) x=sin(decl)-sin(lat)*sin(alt) alt=rad_to_deg(alt) azi=atan(y/x) if x<0: azi=rad_to_deg(azi)+180 elif x>=0 and y<0: azi=rad_to_deg(azi)+360 else: azi=rad_to_deg(azi) return azi,alt # << Mayaclock methods >> (14 of 24) def hor_to_eq(azimuth,altitude,lat): "Converts Horizon coordinates to Equatorial coordinates" azimuth=azimuth/15.0 h_angle,decl=eq_to_hor(azimuth,altitude,lat) h_angle=h_angle/15.0 return h_angle,decl # << Mayaclock methods >> (15 of 24) def ecl_to_eq(ecl_lon,beta,julian=2451545.0): "Converts Ecliptic coordiantes to Equatorial coordiantes" ##Find the obliquity of the ecliptic for given Julian day t=(julian-2451545.0)/36525.0 deps=(46.815*t+0.0006*t*t-0.00181*t*t*t)/3600.0 eps=23.439292-deps [ecl_lon,beta,eps]=map(deg_to_rad,[ecl_lon,beta,eps]) decl=asin(sin(beta)*cos(eps)+cos(beta)*sin(eps)*sin(ecl_lon)) decl=rad_to_deg(decl) y=sin(ecl_lon)*cos(eps)-tan(beta)*sin(eps) x=cos(ecl_lon) ascens=atan(y/x) if x<0: ascens=rad_to_deg(ascens)+180 elif x>=0 and y<0: ascens=rad_to_deg(ascens)+360 else: ascens=rad_to_deg(ascens) ascens=ascens/15.0 return ascens,decl # << Mayaclock methods >> (16 of 24) def eq_to_ecl(ascens,decl,julian=2451545.0): "Converts Equatorial coordinates to Ecliptic coordinates" ##Find the obliquity of the ecliptic for given Julian day t=(julian-2451545.0)/36525.0 deps=(46.815*t+0.0006*t*t-0.00181*t*t*t)/3600.0 eps=23.439292-deps ascens=ascens*15.0 [ascens,decl,eps]=map(deg_to_rad,[ascens,decl,eps]) beta=asin(sin(decl)*cos(eps)-cos(decl)*sin(eps)*sin(ascens)) beta=rad_to_deg(beta) y=sin(ascens)*cos(eps)+tan(decl)*sin(eps) x=cos(ascens) ecl_lon=atan(y/x) if x<0: ecl_lon=rad_to_deg(ecl_lon)+180 elif x>=0 and y<0: ecl_lon=rad_to_deg(ecl_lon)+360 else: ecl_lon=rad_to_deg(ecl_lon) return ecl_lon,beta # << Mayaclock methods >> (17 of 24) def solve_kepler(ecc,mean_anom): "Solves Kepler equation iteratively" e=mean_anom d=e-ecc*sin(e)-mean_anom while d>0.00000001: de=d/(1-ecc*cos(e)) e=e-de d=e-ecc*sin(e)-mean_anom return e # << Mayaclock methods >> (18 of 24) def sun(julian): "Calculates Sun's ecliptic longitude" T=(julian-2415020)/36525.0 ## eg=279.6966778+36000.76892*T+0.0003025*T*T eg=279.403303 wg=281.2208444+1.719175*T+0.000452778*T*T e=0.01675104-0.0000418*T-0.000000126*T*T days=julian-2447891.5 n=divmod(360*days/365.242191,360)[1] # if n<0:n=n+360 m=n+eg-wg if m<0:m=m+360 E=solve_kepler(e,deg_to_rad(m)) niou=rad_to_deg(2*atan(sqrt((1+e)/(1-e))*tan(E/2.0))) l=divmod(niou+wg,360)[1] if l<0:l=l+360 return l # << Mayaclock methods >> (19 of 24) def planet(julian,plan_elem,earth_elem): "Calculate orbital parameters of a planet" (t_p,eps_p,w_p,e_p,a_p,i,omega)=plan_elem (t_e,eps_e,w_e,e_e,a_e,tmp1,tmp2)=earth_elem # For planet d=julian-2447891.5 n_p=(360/365.242191)*(d/t_p)%360 m_p=n_p+eps_p-w_p l=(n_p+(360/pi)*e_p*sin(deg_to_rad(m_p))+eps_p)%360 niou_p=l-w_p r=a_p*(1-e_p*e_p)/(1+e_p*cos(deg_to_rad(niou_p))) ## For earth n_e=(360/365.242191)*(d/t_e)%360 m_e=n_e+eps_e-w_e L=(n_e+(360/pi)*e_e*sin(deg_to_rad(m_e))+eps_e)%360 niou_e=l-w_e R=a_e*(1-e_e*e_e)/(1+e_e*cos(deg_to_rad(niou_e))) psi=asin(sin(deg_to_rad(l-omega))*sin(deg_to_rad(i))) y=sin(deg_to_rad(l-omega))*cos(deg_to_rad(i)) x=cos(deg_to_rad(l-omega)) dl=atan(y/x) if x<0: dl=rad_to_deg(dl)+180 elif x>=0 and y<0: dl=rad_to_deg(dl)+360 else: dl=rad_to_deg(dl) l_dash=dl+omega r_dash=r*cos(psi) if a_p<1.0: A=rad_to_deg(atan((r_dash*sin(deg_to_rad(L-l_dash))) /(R-r_dash*cos(deg_to_rad(L-l_dash))))) ecl_lon=(180+L+A)%360 else: ecl_lon=(rad_to_deg(atan((R*sin(deg_to_rad(l_dash-L)))/(r_dash-R*cos(deg_to_rad(l_dash-L)))))+l_dash)%360 beta=rad_to_deg(atan((r_dash*tan(psi)*sin(deg_to_rad(ecl_lon-l_dash)))/(R*sin(deg_to_rad(l_dash-L))))) return ecl_lon,beta # << Mayaclock methods >> (20 of 24) class ViewerFrame(wx.Frame): # << class ViewerFrame methods >> (1 of 13) def __init__(self, parent, id, title): # First, call the base class' __init__ method to create the frame wx.Frame.__init__(self, parent, -1, "Maya Clock" , style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.clock) lat=34.73 lon=-112.035 self.astro = AstroTime(string.atof(lon),string.atof(lat),0) self.astro.set_now() self.venus=Planet('venus',self.astro) self.venus_ris,self.venus_set = self.venus.rising() #venusrizetime = datetime.datetime( self.venus_ris.AstroTime.local()[0], self.venus_ris.AstroTime.local()[1], self.venus_ris.AstroTime.local()[2], self.venus_ris.AstroTime.local()[3], self.venus_ris.AstroTime.local()[4], self.venus_ris.AstroTime.local()[5], microsecond = 0, tzinfo = None) if (time.localtime()[3] - self.venus_ris.AstroTime.local()[3])> 11: thehour = (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) - 12 elif (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) < 0: thehour = (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) + 12 else: thehour = (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) if (time.localtime()[4] - self.venus_ris.AstroTime.local()[4]) < 0: themin = (time.localtime()[4] - self.venus_ris.AstroTime.local()[4]) + 60 else: themin = (time.localtime()[4] - self.venus_ris.AstroTime.local()[4]) if (time.localtime()[5] - self.venus_ris.AstroTime.local()[5]) < 0: thesec = (time.localtime()[5] - self.venus_ris.AstroTime.local()[5]) + 60 else: thesec = (time.localtime()[5] - self.venus_ris.AstroTime.local()[5]) totalsec = (thehour * 3600) + (themin * 60) + thesec mayatime = int(totalsec / 166.15384615384615384615384615385) mayahour = mayatime while mayahour > 20: mayahour = mayahour - 20 self.hour = mayahour - 1 mayamin = mayatime while mayamin > 13: mayamin = mayamin - 13 self.min = mayamin - 1 self.sec = 0 ringname = 'ringmap.jpg' ring1name = 'ring1map.jpg' ring2name = 'ring2map.jpg' ring3name = 'ring3map.jpg' ring4name = 'ring4map.jpg' sunname = 'sunring.jpg' self.ring = Image.open(ringname) self.sunring = Image.open(sunname) self.ring1map = Image.open(ring1name) self.ring2map = Image.open(ring2name) self.ring3map = Image.open(ring3name) self.ring4map = Image.open(ring4name) self.hasShape = False self.delta = (0,0) self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.Bind(wx.EVT_RIGHT_UP, self.OnExit) self.Bind(wx.EVT_PAINT, self.OnPaint) self.bmp = self.PILToWX(self.GiveBitmap(self.min,self.hour,self.sec )) w, h = self.bmp.GetWidth(), self.bmp.GetHeight() self.SetClientSize( (w, h) ) if wx.Platform != "__WXMAC__": # wx.Mac clips the tooltip to the window shape, YUCK!!! self.SetToolTipString("Right-click to close the window\n" "Double-click the image to set preferences") if wx.Platform == "__WXGTK__": # wx.GTK requires that the window be created before you can # set its shape, so delay the call to SetWindowShape until # this event. self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape) else: # On wx.MSW and wx.Mac the window has already been created, so go for it. self.SetWindowShape() #self.SetWindowShape() dc = wx.ClientDC(self) dc.DrawBitmap(self.bmp, 0,0, True) self.timer.Start(462) # << class ViewerFrame methods >> (2 of 13) def OnCloseWindow(self, event): self.Destroy() # << class ViewerFrame methods >> (3 of 13) def OnOther(self, event): ring1 = Image.open('c:\\python23\\tom2\\maya\\ring1.jpg') ring1map = Image.open('c:\\python23\\tom2\\maya\\ring1map.jpg') ring2 = Image.open('c:\\python23\\tom2\\maya\\ring2.jpg') ring2map = Image.open('c:\\python23\\tom2\\maya\\ring2map.jpg') ring3 = Image.open('c:\\python23\\tom2\\maya\\ring3.jpg') ring3map = Image.open('c:\\python23\\tom2\\maya\\ring3map.jpg') ring4 = Image.open('c:\\python23\\tom2\\maya\\ring4.jpg') ring4map = Image.open('c:\\python23\\tom2\\maya\\ring4map.jpg') ## ##ring1 = Image.open('c:\\python23\\tom2\\maya\\sunstone1.jpg') ##ring1map = Image.open('c:\\python23\\tom2\\maya\\sunstone1map.jpg') ##ring2 = Image.open('c:\\python23\\tom2\\maya\\sunstone2.jpg') ##ring2map = Image.open('c:\\python23\\tom2\\maya\\sunstone2map.jpg') ##ring3 = Image.open('c:\\python23\\tom2\\maya\\sunstone3.jpg') ##ring3map = Image.open('c:\\python23\\tom2\\maya\\sunstone3map.jpg') ##ring4 = Image.open('c:\\python23\\tom2\\maya\\sunstone4.jpg') ##ring4map = Image.open('c:\\python23\\tom2\\maya\\sunstone4map.jpg') for i in range(19): newfile = Image.new('RGB',(630,630)) newimg = ring2.rotate(i * 18) newfile.paste(ring4,(0,0,632,632),ring4map) newfile.paste(ring3,(0,0,632,632),ring3map) newfile.paste(newimg,(0,0,632,632),ring2map) newfile.paste(ring1,(0,0,632,632),ring1map) newfile.save('c:\\python23\\tom2\\maya\\rintest' + str(i) + '.jpg') ##>>> newimg = ring1.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring1.jpg') ##>>> newimg = ring1map.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring1map.jpg') ##>>> newimg = ring2.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring2.jpg') ##>>> newimg = ring2map.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring2map.jpg') ##>>> newimg = ring3.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring3.jpg') ##>>> newimg = ring3map.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring3map.jpg') ##>>> newimg = ring4.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring4.jpg') ##>>> newimg = ring4map.crop((2,2,632,632)) ##>>> newimg.save('c:\\python23\\tom2\\maya\\ring4map.jpg') ##>>> #class TestFrame(wx.Frame): # << class ViewerFrame methods >> (4 of 13) def OnExit(self, evt): self.Close() # << class ViewerFrame methods >> (5 of 13) def OnLeftDown(self, evt): self.CaptureMouse() x, y = self.ClientToScreen(evt.GetPosition()) originx, originy = self.GetPosition() dx = x - originx dy = y - originy self.delta = ((dx, dy)) # << class ViewerFrame methods >> (6 of 13) def OnLeftUp(self, evt): if self.HasCapture(): self.ReleaseMouse() # << class ViewerFrame methods >> (7 of 13) def OnMouseMove(self, evt): if evt.Dragging() and evt.LeftIsDown(): x, y = self.ClientToScreen(evt.GetPosition()) fp = (x - self.delta[0], y - self.delta[1]) self.Move(fp) # << class ViewerFrame methods >> (8 of 13) def OnPaint(self, evt): dc = wx.PaintDC(self) dc.DrawBitmap(self.bmp, 0,0, True) # << class ViewerFrame methods >> (9 of 13) def OnDoubleClick(self, evt): dlg = wx.TextEntryDialog(self, 'Please Enter Latitude?', 'Latitude', '34.73')#dlg.SetValue('34.73') if dlg.ShowModal() == wx.ID_OK: lat = float(dlg.GetValue()) else: lat = 34.73 dlg.Destroy() dlg = wx.TextEntryDialog(self, 'Please Enter Longitude?','Longitude', '-112.035')#dlg.SetValue("-112.035") if dlg.ShowModal() == wx.ID_OK: lon = dlg.GetValue() else: lon = -112.035 dlg.Destroy() self.astro = AstroTime(string.atof(lon),string.atof(lat),0) self.astro.set_now() self.venus=Planet('venus',self.astro) self.venus_ris,self.venus_set = self.venus.rising() # << class ViewerFrame methods >> (10 of 13) def SetWindowShape(self, *evt): # Use the bitmap's mask to determine the region r = wx.RegionFromBitmap(self.PILToWX(self.ring)) self.hasShape = self.SetShape(r) # << class ViewerFrame methods >> (11 of 13) def PILToWX(self,image): "convert a PIL image to a wx.Image" if (image.mode == 'RGBA'): bk = Image.new("RGB", image.size, (255, 250, 255)) image = Image.composite(image, bk, image) if (image.mode != 'RGB'): image = image.convert('RGB') imageData = image.tostring('raw', 'RGB') imageWx = wx.EmptyImage(image.size[0], image.size[1]) imageWx.SetData(imageData) imageWx.SetMaskColour(0, 0, 0) return imageWx.ConvertToBitmap() # << class ViewerFrame methods >> (12 of 13) def GiveBitmap(self,min,hour,sec): newfile = Image.new('RGB',(590,590)) newimg = self.sunring.rotate(int(min * 27.6923)) newimg3 = self.sunring.rotate(sec) newimg2 = self.sunring.rotate(int(hour * 18) + 9) newfile.paste(self.sunring,(0,0,590,590),self.ring4map) newfile.paste(newimg2,(0,0,590,590),self.ring3map) newfile.paste(newimg,(0,0,590,590),self.ring2map) newfile.paste(newimg3,(0,0,590,590),self.ring1map) return newfile # << class ViewerFrame methods >> (13 of 13) def clock(self,evt): self.astro.set_now() self.venus=Planet('venus',self.astro) self.venus_ris,self.venus_set = self.venus.rising() if (time.localtime()[3] - self.venus_ris.AstroTime.local()[3])> 11: thehour = (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) - 12 elif (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) < 0: thehour = (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) + 12 else: thehour = (time.localtime()[3] - self.venus_ris.AstroTime.local()[3]) if (time.localtime()[4] - self.venus_ris.AstroTime.local()[4]) < 0: themin = (time.localtime()[4] - self.venus_ris.AstroTime.local()[4]) + 60 else: themin = (time.localtime()[4] - self.venus_ris.AstroTime.local()[4]) if (time.localtime()[5] - self.venus_ris.AstroTime.local()[5]) < 0: thesec = (time.localtime()[5] - self.venus_ris.AstroTime.local()[5]) + 60 else: thesec = (time.localtime()[5] - self.venus_ris.AstroTime.local()[5]) totalsec = (thehour * 3600) + (themin * 60) + thesec mayatime = int(totalsec / 166.15384615384615384615384615385) mayahour = mayatime while mayahour > 20: mayahour = mayahour - 20 self.hour = mayahour - 1 mayamin = mayatime while mayamin > 13: mayamin = mayamin - 13 self.min = mayamin - 1 self.sec = self.sec + 1 if self.sec == 360: self.sec = 0 self.bmp = self.PILToWX(self.GiveBitmap(self.min,self.hour,self.sec )) w, h = self.bmp.GetWidth(), self.bmp.GetHeight() self.SetClientSize( (w, h) ) dc = wx.ClientDC(self) dc.DrawBitmap(self.bmp, 0,0, True) # -- end -- << class ViewerFrame methods >> # << Mayaclock methods >> (21 of 24) class AstroTime: """ Class to handle time requirements. Initialize with 3 arguments: longitude, latitude and daylight savings time if applicable. Longitude can range from 0-360 or -180 to 180. Latitude -90 to 90. Example: >>> now=Time(-72,38,0) Class AstroTime defines the following methods: >>> now.set_now() Sets the time to the current time >>> now.local() With a tuple of six as argument sets the local time. With no argument it returns the local time: >>> now.local((1997,11,13,23,12,5)) The tuple has the form (year,month,date,hour,minute,second) Similarly for Greenwitch Sidereal Time (gst), Local Sidereal Time >>> (lst) and Universal Coordinated Time (utc). >>> now.gst() >>> now.utc() >>> now.lst() >>> now.julian() returns the julian day corresponding to 0hours of the given date. >>> now.day() returns the day The class defines the following (useful) attributes: x.lon longitude x.lat latitude x.savings daylight savings time x.utchour utc hour in decimal notation x.gsthour gst hour in decimal notation x.lsthour lst hour in decimal notation x.localhour local hour in decimal notation x.localtime a list of the local time (year,month,day,hour,min,sec) x.utctime a list of the utc time (year,month,day,hour,min,sec) x.gsttime a list of the gst time (year,month,day,hour,min,sec) x.lsttime a list of the lst time (year,month,day,hour,min,sec) """ # << class Time methods >> (1 of 8) def __init__(self,lon=0,lat=0,savings=0): if lon>180: self.lon=lon-360 else: self.lon=lon self.lat=lat self.savings=savings self.localtime=[0,0,0,0.0,0.0,0.0] # << class Time methods >> (2 of 8) def local(self,time=None): if time==None: return tuple(self.localtime) elif len(time)!=6: raise Error,"Requires a tuple of 6" self.localtime[0:len(time)]=list(time[:]) self.localhour=to_decimal(time[-3:]) # << class Time methods >> (3 of 8) def set_now(self): now=time.localtime(time.time())[0:6] self.local(now) # << class Time methods >> (4 of 8) def gst(self,time=None): if time==None: T=self.utc() self.gsthour=to_gst(to_julian(T[0:3]+(0.0,0.0,0.0)), self.utchour) return to_hms(self.gsthour) elif len(time)!=6: raise Error,"Requires a tuple of 6" self.date=list(time[0:3]) self.gsthour=to_decimal(time[-3:]) self.julianday=to_julian(time[0:3]+(0.0,0.0,0.0)) self.utchour=gst_to_utc(self.julianday,self.gsthour) self.localday,self.localhour=utc_to_local(self.utchour, self.lon,self.savings) self.localtime=self.date+list(to_hms(self.localhour)) self.localtime[2]=self.localtime[2]+self.localday # << class Time methods >> (5 of 8) def utc(self,time=None): if time==None: if not self.__dict__.has_key('localhour'): self.set_now() utcday,self.utchour=to_utc(self.localhour,self.lon,self.savings) hour=to_hms(self.utchour) self.utctime=self.localtime[:] self.utctime[-3:]=list(hour) self.utctime[2]=self.utctime[2]+utcday return tuple(self.utctime) elif len(time)!=6: raise Error,"Requires a tuple of 6" self.date=list(time[0:3]) self.utchour=to_decimal(time[-3:]) self.julianday=to_julian(time[0:3]+(0.0,0.0,0.0)) self.localday,self.localhour=utc_to_local(self.utchour, self.lon,self.savings) self.localtime=self.date+list(to_hms(self.localhour)) self.localtime[2]=self.localtime[2]+self.localday # << class Time methods >> (6 of 8) def lst(self,time=None): if time==None: self.gst() self.lsthour=divmod(self.gsthour+self.lon/float(15),24)[1] return to_hms(self.lsthour) elif len(time)!=6: raise Error,"Requires a tuple of 6" self.date=list(time[0:3]) self.lsthour=to_decimal(time[-3:]) self.gsthour=lst_to_gst(self.lsthour,self.lon) self.gst(time[0:3]+to_hms(self.gsthour)) # << class Time methods >> (7 of 8) def julian(self): if not self.__dict__.has_key('localhour'): self.set_now() return to_julian(tuple(self.localtime[0:3])+(0.0,0.0,0.0)) # << class Time methods >> (8 of 8) def day(self): return day_of_week(self.julian()) # -- end -- << class Time methods >> # << Mayaclock methods >> (22 of 24) class Coordinates: """ Fixes the coordinates of a heavenly body. provides methods to convert from one coordinate system to the other. Requires a Time object as an argument upon initialization.""" # << class Coordinates methods >> (1 of 9) def __init__(self,AstroTime): import copy self.AstroTime=copy.deepcopy(AstroTime) # << class Coordinates methods >> (2 of 9) def ecliptic(self,ecl_lon=None,beta=None): if ecl_lon==None and beta==None: if not (self.__dict__.has_key('Declination') and \ self.__dict__.has_key('right_ascension')): raise Error,"No location has been specified" ecl_lon,beta=eq_to_ecl(self.right_ascension,self.Declination, self.AstroTime.julian()) self.ecliptic_longitude,self.beta=ecl_lon,beta return to_hms(self.ecliptic_longitude),to_hms(self.beta) elif ecl_lon==None or beta==None: raise Error,"Requires 0 or 2 arguments" [ecl_lon,beta]=map(to_decimal,[ecl_lon,beta]) self.ecliptic_longitude=ecl_lon self.beta=beta ascens,self.Declination=ecl_to_eq(ecl_lon,beta,self.AstroTime.julian()) self.ascension(to_hms(ascens)) # << class Coordinates methods >> (3 of 9) def horizon(self,azi=None,alt=None): if azi==None and alt==None: if not (self.__dict__.has_key('Declination') and \ self.__dict__.has_key('right_ascension')): raise Error,"No location has been specified" azi,alt=eq_to_hor(self.hour_angle, self.Declination,self.AstroTime.lat) self.azimuth,self.altitude=azi,alt return to_hms(self.azimuth),to_hms(self.altitude) elif azi==None or alt==None: raise Error,"Requires 0 or 2 arguments" [azi,alt]=map(to_decimal,[azi,alt]) self.azimuth=azi self.altitude=alt h_angle,self.Declination=hor_to_eq(azi,alt,self.AstroTime.lat) self.hourangle(to_hms(h_angle)) # << class Coordinates methods >> (4 of 9) def hourangle(self,h_angle=None): if h_angle==None: try: return to_hms(self.hour_angle) except AttributeError: raise Error,"No location has been specified" h_angle=to_decimal(h_angle) self.hour_angle=h_angle ascens=to_decimal(self.AstroTime.lst())-h_angle if ascens<0:ascens=ascens+24 self.right_ascension=ascens # << class Coordinates methods >> (5 of 9) def ascension(self,ascens=None): if ascens==None: try: return to_hms(self.right_ascension) except AttributeError: raise Error,"No location has been specified" ascens=to_decimal(ascens) self.right_ascension=ascens h_angle=to_decimal(self.AstroTime.lst())-ascens if h_angle<0:h_angle=h_angle+24 self.hour_angle=h_angle # << class Coordinates methods >> (6 of 9) def declination(self,decl=None): if decl==None: try: return to_hms(self.Declination) except AttributeError: raise Error,"No location has been specified" self.Declination=to_decimal(decl) # << class Coordinates methods >> (7 of 9) def equatorial(self,ascens=None,decl=None): if ascens==None and decl==None: if not (self.__dict__.has_key('Declination') and self.__dict__.has_key('right_ascension')): raise Error,"No location has been specified" return to_hms(self.hour_angle),to_hms(self.Declination) elif ascens==None or decl==None: raise Error,"Requires 0 or 2 arguments" self.ascension(ascens) self.declination(decl) # << class Coordinates methods >> (8 of 9) def __sub__(self,other): [a1,a2,d1,d2]=map(deg_to_rad,[self.right_ascension*15, other.right_ascension*15, self.Declination,other.Declination]) d=acos(sin(d1)*sin(d2)+cos(d1)*cos(d2)*cos(a1-a2)) return to_hms(rad_to_deg(d)) # << class Coordinates methods >> (9 of 9) def rising(self): cosAr=sin(deg_to_rad(self.Declination))/cos(deg_to_rad(self.AstroTime.lat)) if cosAr<-1: raise Error,"Body is never rising" elif cosAr>1: raise Error,"Body is circumpolar" Ar=rad_to_deg(acos(cosAr)) As=360-Ar h=acos(-tan(deg_to_rad(self.Declination))* tan(deg_to_rad(self.AstroTime.lat))) LSTr=(24+self.right_ascension-rad_to_deg(h)/15.0)%24 LSTs=(self.right_ascension+rad_to_deg(h)/15.0)%24 Trising=AstroTime(self.AstroTime.lon,self.AstroTime.lat,self.AstroTime.savings) Tsetting=AstroTime(self.AstroTime.lon,self.AstroTime.lat,self.AstroTime.savings) Trising.lst(tuple(self.AstroTime.localtime[0:3])+to_hms(LSTr)) Tsetting.lst(tuple(self.AstroTime.localtime[0:3])+to_hms(LSTs)) Brising=Coordinates(Trising) Bsetting=Coordinates(Tsetting) Brising.horizon(to_hms(Ar),(0,0,0)) Bsetting.horizon(to_hms(As),(0,0,0)) return Brising,Bsetting # -- end -- << class Coordinates methods >> # << Mayaclock methods >> (23 of 24) class Planet(Coordinates): """Similar to Coordinates class. It is initialized with a string (the name of a planet) and a time object. It calculates the position of the planet or sun on the given time""" # << class Planet methods >> def __init__(self,name,time): self.elem = {'mercury': [0.24085200000000001, 60.750646000000003, 77.299833000000007, 0.20563300000000001, 0.38709900000000003, 7.0045400000000004, 48.212739999999997], 'neptune': [164.79246000000001, 282.34955600000001, 48.009757999999998, 0.0090030000000000006, 30.109570000000001, 1.7706459999999999, 131.67059900000001], 'pluto': [246.77027000000001, 221.4127, 224.13300000000001, 0.24623999999999999, 39.3414, 17.141999999999999, 110.14400000000001], 'epoch': [1990.0, 1.0, 0.0], 'jupiter': [11.863075, 90.638184999999993, 14.170747, 0.048481999999999997, 5.2025610000000002, 1.3036129999999999, 100.35314200000001], 'uranus': [84.039491999999996, 271.06314800000001, 172.88483299999999, 0.046321000000000001, 19.218139999999998, 0.77305900000000005, 73.926961000000006], 'mars': [1.880932, 240.739474, 335.87493899999998, 0.093396000000000007, 1.5236879999999999, 1.849736, 49.480308000000001], 'earth': [1.00004, 99.403307999999996, 102.768413, 0.016712999999999999, 1.0, 0.0, 0.0], 'venus': [0.61521099999999995, 88.455855, 131.43023600000001, 0.0067780000000000002, 0.72333199999999997, 3.3945349999999999, 76.589820000000003], 'saturn': [29.471361999999999, 287.69003300000003, 92.861407, 0.055580999999999998, 9.5547470000000008, 2.4889800000000002, 113.576139]} Coordinates.__init__(self,time) import string self.name=string.lower(name) self.epoch=self.elem['epoch'] self.earth=self.elem['earth'] if self.name=='sun': l=sun(self.AstroTime.julian()) self.ecliptic(to_hms(l),(0,0,0)) else: try: self.elements=self.elem[self.name] except KeyError: raise Error,'Element not available for such planet' lon,lat=planet(self.AstroTime.julian(),tuple(self.elements[0:7]), tuple(self.earth[0:7])) self.ecliptic(to_hms(lon),to_hms(lat)) # -- end -- << class Planet methods >> # << Mayaclock methods >> (24 of 24) class MyApp(wx.App): # << class MyApp methods >> def OnInit(self): # Create an instance of our customized Frame class frame = ViewerFrame(None, -1, "Maya Clock") frame.Show(True)# Tell wx.Windows that this is our main window self.SetTopWindow(frame) # Return a success flag return True # -- end -- << class MyApp methods >> # -- end -- << Mayaclock methods >> app = MyApp(0) # Create an instance of the application class app.MainLoop() # Tell it to start processing events