def GetNextSankranti(startDate): zodiac = 0 step = 1.0 count = 0 prevday = GCGregorianDate() d = GCGregorianDate(date=startDate) prev = GCMath.putIn360( GCSunData.GetSunLongitude(d) - GCAyanamsha.GetAyanamsa(d.GetJulian())) prev_rasi = int(floor(prev / 30.0)) while count < 20: prevday.Set(d) d.shour += step d.NormalizeHours() ld = GCMath.putIn360( GCSunData.GetSunLongitude(d) - GCAyanamsha.GetAyanamsa(d.GetJulian())) new_rasi = int(floor(ld / 30.0)) if prev_rasi != new_rasi: zodiac = new_rasi step *= 0.5 d.Set(prevday) count += 1 continue return d, zodiac
def calculateAppDay(self, location, eventDate): d = self.details vc = GCGregorianDate(date=eventDate) vcsun = GCGregorianDate(date=eventDate) dprev = GCGregorianDate() dnext = GCGregorianDate() m_earth = location.GetEarthData() self.b_adhika = False self.eventTime.Set(eventDate) self.m_location.Set(location) vcsun.shour -= vcsun.tzone / 24.0 vcsun.NormalizeValues() vcsun.tzone = 0.0 d.sun.SunPosition(vcsun, m_earth, vcsun.shour - 0.5) d.moon.Calculate(vcsun.GetJulianComplete(), m_earth) d.msDistance = GCMath.putIn360(d.moon.longitude_deg - d.sun.longitude_deg - 180.0) d.msAyanamsa = GCAyanamsha.GetAyanamsa(vc.GetJulianComplete()) # tithi dd = d.msDistance / 12.0 d.nTithi = int(floor(dd)) d.nTithiElapse = (dd - floor(dd)) * 100.0 # naksatra dd = GCMath.putIn360(d.moon.longitude_deg - d.msAyanamsa) dd = (dd * 3.0) / 40.0 d.nNaksatra = int(floor(dd)) d.nNaksatraElapse = (dd - floor(dd)) * 100.0 d.nMasa = d.MasaCalc(vc, m_earth) d.nMoonRasi = GCRasi.GetRasi(d.moon.longitude_deg, d.msAyanamsa) d.nSunRasi = GCRasi.GetRasi(d.sun.longitude_deg, d.msAyanamsa) if (d.nMasa == ADHIKA_MASA): d.nMasa = GCRasi.GetRasi(d.sun.longitude_deg, d.msAyanamsa) self.b_adhika = True vc.Today() vc.tzone = m_earth.tzone m = 0 va = GCGaurabdaDate() vctemp = GCGregorianDate() va.tithi = d.nTithi va.masa = d.nMasa va.gyear = GCCalendar.GetGaurabdaYear(vc, m_earth) if (va.gyear < d.nGaurabdaYear): va.gyear = d.nGaurabdaYear for i in range(6): GCCalendar.Gaurabda2Gregorian(va, vctemp, m_earth) if (va.gyear > d.nGaurabdaYear): if (m < TRESULT_APP_CELEBS): self.celeb_date[m].Set(vctemp) self.celeb_gy[m] = va.gyear m += 1 va.gyear += 1
def DayCalc(self, date, earth): # sun position on sunrise on that day self.sun.SunCalc(date, earth) date.shour = self.sun.sunrise_deg / 360.0 # date.shour is [0..1] time of sunrise in local timezone time self.jdate = jdate = date.GetJulianDetailed() # moon position at sunrise on that day self.moon.Calculate(date.GetJulianDetailed(), earth) self.msDistance = GCMath.putIn360(self.moon.longitude_deg - self.sun.longitude_deg - 180.0) self.msAyanamsa = GCAyanamsha.GetAyanamsa(jdate) # tithi d = self.msDistance / 12.0 self.nTithi = int(floor(d)) self.nTithiElapse = (d - floor(d)) * 100.0 # naksatra d = GCMath.putIn360(self.moon.longitude_deg - self.msAyanamsa) d = (d * 3.0) / 40.0 self.nNaksatra = int(floor(d)) self.nNaksatraElapse = (d - floor(d)) * 100.0 # yoga d = GCMath.putIn360(self.moon.longitude_deg + self.sun.longitude_deg - 2 * self.msAyanamsa) d = (d * 3.0) / 40.0 self.nYoga = int(floor(d)) self.nYogaElapse = (d - floor(d)) * 100.0 # masa self.nMasa = -1 # rasi self.nSunRasi = GCRasi.GetRasi(self.sun.longitude_deg, self.msAyanamsa) self.nMoonRasi = GCRasi.GetRasi(self.moon.longitude_deg, self.msAyanamsa) moon = MOONDATA() date.shour = self.sun.sunset_deg / 360.0 moon.Calculate(date.GetJulianDetailed(), earth) d = GCMath.putIn360(moon.longitude_deg - self.sun.longitude_set_deg - 180) / 12.0 self.nTithiSunset = int(floor(d)) date.shour = self.sun.arunodaya_deg / 360.0 moon.Calculate(date.GetJulianDetailed(), earth) d = GCMath.putIn360(moon.longitude_deg - self.sun.longitude_arun_deg - 180) / 12.0 self.nTithiArunodaya = int(floor(d)) return 1
def GetNextMoonRasi(ed, startDate): nextDate = GCGregorianDate.GCGregorianDate(date=startDate) phi = 30.0 jday = startDate.GetJulianComplete() moon = MOONDATA() d = GCGregorianDate.GCGregorianDate(date=startDate) ayanamsa = GCAyanamsha.GetAyanamsa(jday) scan_step = 0.5 prev_naks = 0 new_naks = -1 xj = 0.0 xd = GCGregorianDate.GCGregorianDate() moon.Calculate(jday, ed) l1 = GCMath.putIn360(moon.longitude_deg - ayanamsa) prev_naks = int(GCMath.Floor(l1 / phi)) counter = 0 while counter < 20: xj = jday xd.Set(d) jday += scan_step d.shour += scan_step if d.shour > 1.0: d.shour -= 1.0 d.NextDay() moon.Calculate(jday, ed) l2 = GCMath.putIn360(moon.longitude_deg - ayanamsa) new_naks = int(GCMath.Floor(l2 / phi)) if prev_naks != new_naks: jday = xj d.Set(xd) scan_step *= 0.5 counter += 1 continue else: l1 = l2 nextDate.Set(d) return new_naks, nextDate
def GetNextYogaStart(ed, startDate, nextDate): phi = 40.0 / 3.0 jday = startDate.GetJulianComplete() moon = MOONDATA() d = GCGregorianDate(date=startDate) xd = GCGregorianDate() scan_step = 0.5 prev_tit = 0 new_tit = -1 ayanamsha = GCAyanamsha.GetAyanamsa(jday) moon.Calculate(jday, ed) sunl = GetSunLongitude(d) l1 = GCMath.putIn360(moon.longitude_deg + sunl - 2 * ayanamsha) prev_tit = int(floor(l1 / phi)) counter = 0 while counter < 20: xj = jday xd.Set(d) jday += scan_step d.shour += scan_step d.NormalizeHours() moon.Calculate(jday, ed) sunl = GetSunLongitude(d) l2 = GCMath.putIn360(moon.longitude_deg + sunl - 2 * ayanamsha) new_tit = int(floor(l2 / phi)) if prev_tit != new_tit: jday = xj d.Set(xd) scan_step *= 0.5 counter += 1 continue else: l1 = l2 nextDate.Set(d) return new_tit
def MasaCalc(self, date, earth): PREV_MONTHS = 6 L = [0] * 8 C = [GCGregorianDate() for i in range(8)] R = [0] * 8 ksaya_from = -1 ksaya_to = -1 date.shour = self.sun.sunrise_deg / 360.0 + earth.tzone / 24.0 # STEP 1: calculate position of the sun and moon # it is done by previous call of DayCalc # and results are in argument GCDayData day # *DayCalc(date, earth, day, moon, sun);* L[1] = GCConjunction.GetNextConjunctionEx(date, C[1], False, earth) L[0] = GCConjunction.GetNextConjunctionEx(C[1], C[0], True, earth) # on Pratipat (nTithi == 15) we need to look for previous conjunction # but this conjunction can occur on this date before sunrise # so we need to include this very date into looking for conjunction # on other days we cannot include it # and exclude it from looking for next because otherwise that will cause # incorrect detection of Purusottama adhika masa L[2] = GCConjunction.GetPrevConjunctionEx(date, C[2], False, earth) for n in range(3, PREV_MONTHS): L[n] = GCConjunction.GetPrevConjunctionEx(C[n - 1], C[n], True, earth) for n in range(0, PREV_MONTHS): R[n] = GCRasi.GetRasi(L[n], GCAyanamsha.GetAyanamsa(C[n].GetJulian())) # TRACE("TEST Date: %d %d %d\n", date.day, date.month, date.year) # TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[1].day, C[1].month, C[1].year, R[1]) # TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[2].day, C[2].month, C[2].year, R[2]) # TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[3].day, C[3].month, C[3].year, R[3]) # TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[4].day, C[4].month, C[4].year, R[4]) # TRACE("---\n") # look for ksaya month ksaya_from = -1 for n in range(PREV_MONTHS - 2, 0, -1): if (R[n + 1] + 2) % 12 == R[n]: ksaya_from = n break if ksaya_from >= 0: for n in range(ksaya_from, 0, -1): if R[n] == R[n - 1]: ksaya_to = n break if ksaya_to >= 0: pass # adhika masa found # now correct succession of rasis else: # adhika masa not found # there will be some break in masa queue ksaya_to = 0 current_rasi = R[ksaya_from + 1] + 1 for n in range(ksaya_from, ksaya_to - 1, -1): R[n] = current_rasi current_rasi = (current_rasi + 1) % 12 # STEP 3: test for adhika masa # test for adhika masa if R[1] == R[2]: # it is adhika masa masa = 12 rasi = R[1] else: # STEP 2. select nearest Conjunction if self.nPaksa == 0: masa = R[1] elif self.nPaksa == 1: masa = R[2] rasi = masa # calculation of Gaurabda year self.nGaurabdaYear = date.year - 1486 if (rasi > 7) and (rasi < 11): # Visnu if date.month < 6: self.nGaurabdaYear -= 1 self.nMasa = masa return masa
def GetHorizontDegrees(self, jday): return GCMath.putIn360( star_time(jday) - self.longitude_deg - GCAyanamsha.GetAyanamsa(jday) + 155)
def CalculateEvents(self, loc, vcStart, vcEnd): sun = SUNDATA() ndst = 0 self.m_location.Set(loc) self.m_vcStart.Set(vcStart) self.m_vcEnd.Set(vcEnd) vcNext = GCGregorianDate() earth = loc.GetEarthData() vc = GCGregorianDate(date=vcStart) vcAdd = GCGregorianDate(date=vcStart) vcAdd.InitWeekDay() previousLongitude = -100 todayLongitude = 0 fromTimeLimit = 0 while vcAdd.IsBeforeThis(vcEnd): if (GCDisplaySettings.getValue(COREEVENTS_SUN)): ndst = GCTimeZone.determineDaylightChange( vcAdd, loc.m_nTimezoneId) sun.SunCalc(vcAdd, earth) vcAdd.shour = sun.arunodaya.GetDayTime() self.AddEvent(vcAdd, CCTYPE_S_ARUN, 0, ndst) vcAdd.shour = sunRise = sun.rise.GetDayTime() self.AddEvent(vcAdd, CCTYPE_S_RISE, 0, ndst) vcAdd.shour = sun.noon.GetDayTime() self.AddEvent(vcAdd, CCTYPE_S_NOON, 0, ndst) vcAdd.shour = sunSet = sun.set.GetDayTime() self.AddEvent(vcAdd, CCTYPE_S_SET, 0, ndst) else: ndst = GCTimeZone.determineDaylightChange( vcAdd, loc.m_nTimezoneId) sun.SunCalc(vcAdd, earth) sunRise = sun.rise.GetDayTime() sunSet = sun.set.GetDayTime() if (GCDisplaySettings.getValue(COREEVENTS_ASCENDENT)): todayLongitude = sun.longitude_deg vcAdd.shour = sunRise todaySunriseHour = sunRise if (previousLongitude < -10): prevSunrise = GCGregorianDate(date=vcAdd) prevSunrise.PreviousDay() sun.SunCalc(prevSunrise, earth) previousSunriseHour = sun.rise.GetDayTime() - 1 previousLongitude = sun.longitude_deg fromTimeLimit = 0 jd = vcAdd.GetJulianComplete() ayan = GCAyanamsha.GetAyanamsa(jd) r1 = GCMath.putIn360(previousLongitude - ayan) / 30 r2 = GCMath.putIn360(todayLongitude - ayan) / 30 while (r2 > r1 + 13): r2 -= 12.0 while (r2 < r1 + 11): r2 += 12.0 a = (r2 - r1) / (todaySunriseHour - previousSunriseHour) b = r2 - a * todaySunriseHour tr = ceil(r1) for tr in range(ceil(r1), ceil(r2)): tm = (tr - b) / a if (tm > fromTimeLimit): vcNext.Set(vcAdd) vcNext.shour = tm vcNext.NormalizeValues() self.AddEvent(vcNext, CCTYPE_ASCENDENT, tr, ndst) previousLongitude = todayLongitude previousSunriseHour = todaySunriseHour - 1 fromTimeLimit = previousSunriseHour if (GCDisplaySettings.getValue(COREEVENTS_RAHUKALAM)): r1, r2 = CalculateKala(sunRise, sunSet, vcAdd.dayOfWeek, KT_RAHU_KALAM) vcAdd.shour = r1 self.AddEvent(vcAdd, CCTYPE_KALA_START, KT_RAHU_KALAM, ndst) vcAdd.shour = r2 self.AddEvent(vcAdd, CCTYPE_KALA_END, KT_RAHU_KALAM, ndst) if (GCDisplaySettings.getValue(COREEVENTS_YAMAGHANTI)): r1, r2 = CalculateKala(sunRise, sunSet, vcAdd.dayOfWeek, KT_YAMA_GHANTI) vcAdd.shour = r1 self.AddEvent(vcAdd, CCTYPE_KALA_START, KT_YAMA_GHANTI, ndst) vcAdd.shour = r2 self.AddEvent(vcAdd, CCTYPE_KALA_END, KT_YAMA_GHANTI, ndst) if (GCDisplaySettings.getValue(COREEVENTS_GULIKALAM)): r1, r2 = CalculateKala(sunRise, sunSet, vcAdd.dayOfWeek, KT_GULI_KALAM) vcAdd.shour = r1 self.AddEvent(vcAdd, CCTYPE_KALA_START, KT_GULI_KALAM, ndst) vcAdd.shour = r2 self.AddEvent(vcAdd, CCTYPE_KALA_END, KT_GULI_KALAM, ndst) if (GCDisplaySettings.getValue(COREEVENTS_ABHIJIT_MUHURTA)): r1, r2 = CalculateKala(sunRise, sunSet, vcAdd.dayOfWeek, KT_ABHIJIT) if (r1 > 0 and r2 > 0): vcAdd.shour = r1 self.AddEvent(vcAdd, CCTYPE_KALA_START, KT_ABHIJIT, ndst) vcAdd.shour = r2 self.AddEvent(vcAdd, CCTYPE_KALA_END, KT_ABHIJIT, ndst) vcAdd.NextDay() if (GCDisplaySettings.getValue(COREEVENTS_TITHI)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): nData = GCTithi.GetNextTithiStart(earth, vcAdd, vcNext) if (vcNext.GetDayInteger() < vcEnd.GetDayInteger()): vcNext.InitWeekDay() ndst = GCTimeZone.determineDaylightChange( vcNext, loc.m_nTimezoneId) self.AddEvent(vcNext, CCTYPE_TITHI, nData, ndst) else: break vcAdd.Set(vcNext) vcAdd.shour += 0.2 if (vcAdd.shour >= 1.0): vcAdd.shour -= 1.0 vcAdd.NextDay() if (GCDisplaySettings.getValue(COREEVENTS_NAKSATRA)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): nData = GCNaksatra.GetNextNaksatra(earth, vcAdd, vcNext) if (vcNext.GetDayInteger() < vcEnd.GetDayInteger()): vcNext.InitWeekDay() ndst = GCTimeZone.determineDaylightChange( vcNext, loc.m_nTimezoneId) self.AddEvent(vcNext, CCTYPE_NAKS, nData, ndst) else: break vcAdd.Set(vcNext) vcAdd.shour += 0.2 if (vcAdd.shour >= 1.0): vcAdd.shour -= 1.0 vcAdd.NextDay() if (GCDisplaySettings.getValue(COREEVENTS_YOGA)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): nData = GCYoga.GetNextYogaStart(earth, vcAdd, vcNext) if (vcNext.GetDayInteger() < vcEnd.GetDayInteger()): vcNext.InitWeekDay() ndst = GCTimeZone.determineDaylightChange( vcNext, loc.m_nTimezoneId) self.AddEvent(vcNext, CCTYPE_YOGA, nData, ndst) else: break vcAdd.Set(vcNext) vcAdd.shour += 0.2 if (vcAdd.shour >= 1.0): vcAdd.shour -= 1.0 vcAdd.NextDay() if (GCDisplaySettings.getValue(COREEVENTS_SANKRANTI)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): date, nData = GCSankranti.GetNextSankranti(vcAdd) vcNext.Set(date) if (vcNext.GetDayInteger() < vcEnd.GetDayInteger()): vcNext.InitWeekDay() ndst = GCTimeZone.determineDaylightChange( vcNext, loc.m_nTimezoneId) self.AddEvent(vcNext, CCTYPE_SANK, nData, ndst) else: break vcAdd.Set(vcNext) vcAdd.NextDay() if (GCDisplaySettings.getValue(COREEVENTS_MOONRASI)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): nData = GetNextMoonRasi(earth, vcAdd, vcNext) if (vcNext.GetDayInteger() < vcEnd.GetDayInteger()): vcNext.InitWeekDay() ndst = GCTimeZone.determineDaylightChange( vcNext, loc.m_nTimezoneId) self.AddEvent(vcNext, CCTYPE_M_RASI, nData, ndst) else: break vcAdd.Set(vcNext) vcAdd.shour += 0.5 vcAdd.NormalizeValues() if (GCDisplaySettings.getValue(COREEVENTS_CONJUNCTION)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): dlong = GCConjunction.GetNextConjunctionEx( vcAdd, vcNext, True, earth) if (vcNext.GetDayInteger() < vcEnd.GetDayInteger()): vcNext.InitWeekDay() ndst = GCTimeZone.determineDaylightChange( vcNext, loc.m_nTimezoneId) self.AddEvent( vcNext, CCTYPE_CONJ, GCRasi.GetRasi( dlong, GCAyanamsha.GetAyanamsa( vcNext.GetJulianComplete())), ndst) else: break vcAdd.Set(vcNext) vcAdd.NextDay() if (GCDisplaySettings.getValue(COREEVENTS_MOON)): vcAdd.Set(vc) vcAdd.shour = 0.0 while vcAdd.IsBeforeThis(vcEnd): vcNext.Set(MOONDATA.GetNextRise(earth, vcAdd, True)) self.AddEvent(vcNext, CCTYPE_M_RISE, 0, ndst) vcNext.Set(MOONDATA.GetNextRise(earth, vcNext, False)) self.AddEvent(vcNext, CCTYPE_M_SET, 0, ndst) vcNext.shour += 0.05 vcNext.NormalizeValues() vcAdd.Set(vcNext) if self.b_sorted: self.Sort()