def get_sunrise_and_sunset(date, observer): day = datetime_to_julian(date.replace(hour=12)) sunrise = revjul_to_datetime( swisseph.revjul( swisseph.rise_trans( day - 1, swisseph.SUN, observer.lng, observer.lat, alt=observer.elevation, rsmi=swisseph.CALC_RISE )[1][0] ) ) sunset = revjul_to_datetime( swisseph.revjul( swisseph.rise_trans( day, swisseph.SUN, observer.lng, observer.lat, observer.elevation, rsmi=swisseph.CALC_SET )[1][0] ) ) next_sunrise = revjul_to_datetime( swisseph.revjul( swisseph.rise_trans( day, swisseph.SUN, observer.lng, observer.lat, observer.elevation, rsmi=swisseph.CALC_RISE )[1][0] ) ) swisseph.close() return sunrise, sunset, next_sunrise
def trikalam(jd, place, option='rahu'): lat, lon, tz = place tz = place.timezone srise = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_RISE)[1][0] sset = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_SET)[1][0] day_dur = (sset - srise) weekday = vaara(jd) # value in each array is for given weekday (0 = sunday, etc.) offsets = { 'rahu': [0.875, 0.125, 0.75, 0.5, 0.625, 0.375, 0.25], 'gulika': [0.75, 0.625, 0.5, 0.375, 0.25, 0.125, 0.0], 'yamaganda': [0.5, 0.375, 0.25, 0.125, 0.0, 0.75, 0.625] } start_time = srise + day_dur * offsets[option][weekday] end_time = start_time + 0.125 * day_dur # to local timezone start_time = (start_time - jd) * 24 + tz end_time = (end_time - jd) * 24 + tz return [to_dms(start_time), to_dms(end_time)] # decimal hours to H:M:S
def get_last_dhanur_transit (jd_start,latitude,longitude): swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha for d in range(-25,0): jd = jd_start + d [y,m,d,t] = swisseph.revjul(jd) jd_sunrise=swisseph.rise_trans(jd_start=jd,body=swisseph.SUN,lon=longitude, lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0] jd_sunrise_tmrw=swisseph.rise_trans(jd_start=jd+1,body=swisseph.SUN, lon=longitude,lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0] jd_sunset =swisseph.rise_trans(jd_start=jd,body=swisseph.SUN,lon=longitude, lat=latitude,rsmi=swisseph.CALC_SET|swisseph.BIT_DISC_CENTER)[1][0] longitude_sun=swisseph.calc_ut(jd_sunrise,swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_sunrise) longitude_sun_set=swisseph.calc_ut(jd_sunset,swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_sunset) sun_month_rise = int(1+math.floor(((longitude_sun)%360)/30.0)) sun_month = int(1+math.floor(((longitude_sun_set)%360)/30.0)) longitude_sun_tmrw=swisseph.calc_ut(jd_sunrise+1,swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_sunrise+1) sun_month_tmrw = int(1+math.floor(((longitude_sun_tmrw)%360)/30.0)) if sun_month_rise!=sun_month_tmrw: if sun_month!=sun_month_tmrw: return jd+1 else: return jd
def plan_hours(time_zone, city_longitude, city_latitude): local_timezone = pytz.timezone(time_zone) local_date = local_timezone.localize(date_passed, is_dst=None) date_start = datetime.datetime.today() # today's date planetary_hour_sequence = ('Saturn', 'Jupiter', 'Mars', 'Sun', 'Venus', 'Mercury', 'Moon') day_sequence = ('Moon', 'Mars', 'Mercury', 'Jupiter', 'Venus', 'Saturn', 'Sun') day_sequence_p = (6, 2, 5, 1, 4, 0, 3) # search this date's noon [12 PM] now_julian = swe.julday(date_start.year, date_start.month, date_start.day, 12) planet_rise_jul = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 1) planet_set_jul = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 2) sun_rise_tuple = swe.jdut1_to_utc(planet_rise_jul[1][0], 1) sun_rise_list = list(sun_rise_tuple) sun_rise1 = datetime.datetime(*sun_rise_list[0:5], tzinfo=pytz.utc) sun_rise = sun_rise1.astimezone(local_timezone) # sunset sun_set_tuple = swe.jdut1_to_utc(planet_set_jul[1][0], 1) sun_set_list = list(sun_set_tuple) sun_set1 = datetime.datetime(*sun_set_list[0:5], tzinfo=pytz.utc) sun_set = sun_set1.astimezone(local_timezone) # next day sun rise now_julian = swe.julday(date_start.year, date_start.month, date_start.day + 1, 12) planet_rise_jul_next_day = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 1) sun_rise_tuple_n = swe.jdut1_to_utc(planet_rise_jul_next_day[1][0], 1) sun_rise_list_n = list(sun_rise_tuple_n) sun_rise_n1 = datetime.datetime(*sun_rise_list_n[0:5], tzinfo=pytz.utc) sun_rise_n = sun_rise_n1.astimezone(local_timezone) print 'sun rise:', sun_rise.strftime('%m-%d-%Y: %H:%M') print 'sun set:', sun_set.strftime('%m-%d-%Y: %H:%M') print 'sun rise next', sun_rise_n.strftime('%m-%d-%Y: %H:%M') day_diff = (sun_set - sun_rise) day_diff_skip = day_diff.total_seconds() / 12 night_diff = (sun_rise_n - sun_set) night_diff_skip = night_diff.total_seconds() / 12 # print day_diff_skip, night_diff_skip day_of_week = sun_rise.weekday() start_sequence = day_sequence[day_of_week] # starting planet print 'Day:', start_sequence # , planetary_hour_sequence[day_sequence_p[day_of_week]] j = day_sequence_p[day_of_week] print 'Sunrise: Planetary hours' rezultss = {} for i in range(12): if j > 6: j = 0 rezultss[i] = {'time' : str(sun_rise.strftime('%m-%d-%Y: %H:%M')), 'time2' : str((sun_rise + day_diff / 12).strftime('%m-%d-%Y: %H:%M')), 'planet' : str(planetary_hour_sequence[j])} sun_rise += day_diff / 12 j += 1 print 'Sunset : Planetary hours' rezults = {} for i in range(12): if j > 6: j = 0 rezults[i]= {'time' : str(sun_set.strftime('%m-%d-%Y: %H:%M')), 'time2' : str((sun_set + night_diff / 12).strftime('%m-%d-%Y: %H:%M')), 'planet' : str(planetary_hour_sequence[j])} sun_set += night_diff / 12 j += 1 return rezults, rezultss ###########################################################################################################################################################################################################
def gauri_chogadiya(jd, place): lat, lon, tz = place tz = place.timezone srise = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_RISE)[1][0] sset = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_SET)[1][0] day_dur = (sset - srise) end_times = [] for i in range(1, 9): end_times.append(to_dms((srise + (i * day_dur) / 8 - jd) * 24 + tz)) # Night duration = time from today's sunset to tomorrow's sunrise srise = swe.rise_trans((jd + 1) - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_RISE)[1][0] night_dur = (srise - sset) for i in range(1, 9): end_times.append(to_dms((sset + (i * night_dur) / 8 - jd) * 24 + tz)) return end_times
def get_sunrise_and_sunset(date, observer): day = datetime_to_julian(date.replace(hour=12)) sunrise = revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day-1, swisseph.SUN, observer.lng, observer.lat, alt=observer.elevation, rsmi=swisseph.CALC_RISE)[1][0] ) ) sunset = revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day, swisseph.SUN, observer.lng, observer.lat, observer.elevation, rsmi=swisseph.CALC_SET)[1][0] ) ) next_sunrise = revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day, swisseph.SUN, observer.lng, observer.lat, observer.elevation, rsmi=swisseph.CALC_RISE)[1][0] ) ) swisseph.close() return sunrise, sunset, next_sunrise
def compute_flight_sunrise_sunsets(loc_origin, loc_dest, t_start, t_end): """ """ lat_origin, lon_origin = loc_origin lat_dest, lon_dest = loc_dest print(t_start, t_end) h = 15 / 1440 t = t_start while t < t_end: est_lat = lat_origin + (t - t_start) * ((lat_dest - lat_origin) / (t_end - t_start)) est_lon = lon_origin + (t - t_start) * ((lon_dest - lon_origin) / (t_end - t_start)) jd_sunrise = swe.rise_trans(jd_start=t, body=swe.SUN, lon=est_lon, lat=est_lat, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] jd_sunset = swe.rise_trans(jd_start=t, body=swe.SUN, lon=est_lon, lat=est_lat, rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] print('-' * 80) print(revjul(t)) print(revjul(jd_sunrise)) print(revjul(jd_sunset)) t += h
def compute_solar_day(self): """Compute the solar month and day for a given Julian day """ # If solar transition happens before the current sunset but after the previous sunset, then that is taken to be solar day 1. Number of sunsets since the past solar month transition gives the solar day number. if not hasattr(self, "jd_sunrise") or self.jd_sunrise is None: self.compute_sun_moon_transitions() self.solar_month = get_angam(self.jd_sunset, SOLAR_MONTH, ayanamsha_id=self.ayanamsha_id) target = floor(get_angam_float(self.jd_sunset, SOLAR_MONTH, ayanamsha_id=self.ayanamsha_id)) # logging.debug(jd_start) # logging.debug(jd_sunset) # logging.debug(target) # logging.debug(get_angam_float(jd_sunset - 34, SOLAR_MONTH, -target, ayanamsha_id, False)) # logging.debug(get_angam_float(jd_sunset + 1, SOLAR_MONTH, -target, ayanamsha_id, False)) jd_masa_transit = brentq(get_angam_float, self.jd_sunrise - 34, self.jd_sunset, args=(SOLAR_MONTH, -target, self.ayanamsha_id, False)) jd_next_sunset = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] jd_next_sunrise = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] if jd_next_sunset > jd_next_sunrise: # Masa begins after sunset and before sunrise # Therefore Masa 1 is on the day when the sun rises next solar_month_day = floor(self.jd_sunset - jd_next_sunrise) + 1 else: # Masa has started before sunset solar_month_day = round(self.jd_sunset - jd_next_sunset) + 1 self.solar_month_day = solar_month_day
def durmuhurtam(jd, place): lat, lon, tz = place tz = place.timezone # Night = today's sunset to tomorrow's sunrise sset = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_SET)[1][0] srise = swe.rise_trans((jd + 1) - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_RISE)[1][0] night_dur = (srise - sset) # Day = today's sunrise to today's sunset srise = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=_rise_flags + swe.CALC_RISE)[1][0] day_dur = (sset - srise) weekday = vaara(jd) # There is one durmuhurtam on Sun, Wed, Sat; the rest have two offsets = [ [10.4, 0.0], # Sunday [6.4, 8.8], # Monday [2.4, 4.8], # Tuesday, [day_duration , night_duration] [5.6, 0.0], # Wednesday [4.0, 8.8], # Thursday [2.4, 6.4], # Friday [1.6, 0.0] ] # Saturday # second durmuhurtam of tuesday uses night_duration instead of day_duration dur = [day_dur, day_dur] base = [srise, srise] if weekday == 2: dur[1] = night_dur base[1] = sset # compute start and end timings start_times = [0, 0] end_times = [0, 0] for i in range(0, 2): offset = offsets[weekday][i] if offset != 0.0: start_times[i] = base[i] + dur[i] * offsets[weekday][i] / 12 end_times[i] = start_times[i] + day_dur * 0.8 / 12 # convert to local time start_times[i] = (start_times[i] - jd) * 24 + tz end_times[i] = (end_times[i] - jd) * 24 + tz return [start_times, end_times] # in decimal hours
def plan_hours(time_zone, location_longitude, location_latitude): is_birth_time = True #lt_zone = -7 date_start = datetime.datetime.today() # today's date planetary_hour_sequence = ('saturn', 'jupiter', 'mars', 'sun', 'venus', 'mercury', 'moon') day_sequence = ('moon', 'mars', 'mercury', 'jupiter', 'venus', 'saturn', 'sun') day_sequence_p = (6, 2, 5, 1, 4, 0, 3) #search this date's noon [12 PM] now_julian = swe.julday(date_start.year, date_start.month, date_start.day, 12) planet_rise_jul = swe.rise_trans(now_julian, 0, location_longitude, location_latitude, 0.0, 0.0, 0.0, 1) planet_set_jul = swe.rise_trans(now_julian, 0, location_longitude, location_latitude, 0.0, 0.0, 0.0, 2) sun_rise_tuple = swe.jdut1_to_utc(planet_rise_jul[1][0],1) sun_rise_list = list(sun_rise_tuple) sun_rise_list[5] = int(sun_rise_list[5]) sun_rise = datetime.datetime(*sun_rise_list[0:6]) + datetime.timedelta(hours=time_zone) sun_rise_question = sun_rise sun_set_tuple = swe.jdut1_to_utc(planet_set_jul[1][0], 1) sun_set_list = list(sun_set_tuple) sun_set_list[5] = int(sun_set_list[5]) sun_set = datetime.datetime(*sun_set_list[0:6]) + datetime.timedelta(hours=time_zone) sun_set_question = sun_set # next day sun rise now_julian = swe.julday(date_start.year, date_start.month, date_start.day + 1, 12) planet_rise_jul_next_day = swe.rise_trans(now_julian, 0, location_longitude, location_latitude, 0.0, 0.0, 0.0, 1) sun_rise_tuple_n = swe.jdut1_to_utc(planet_rise_jul_next_day[1][0], 1) sun_rise_list_n = list(sun_rise_tuple_n) sun_rise_list_n[5] = int(sun_rise_list_n[5]) sun_rise_n = datetime.datetime(*sun_rise_list_n[0:6]) + datetime.timedelta(hours=time_zone) print 'sun rise:', sun_rise.strftime('%m-%d-%Y: %H:%M') print 'sun set:', sun_set.strftime('%m-%d-%Y: %H:%M') print 'sun rise next', sun_rise_n.strftime('%m-%d-%Y: %H:%M') day_diff = (sun_set - sun_rise) day_diff_skip = day_diff.total_seconds() / 12 night_diff = (sun_rise_n - sun_set) night_diff_skip = night_diff.total_seconds() / 12 #print day_diff_skip, night_diff_skip day_of_week = sun_rise.weekday() start_sequence = day_sequence[day_of_week] #starting planet print 'Day:',start_sequence#, planetary_hour_sequence[day_sequence_p[day_of_week]] j = day_sequence_p[day_of_week] #print 'Sunrise: Planetary hours' rezultss = [] for i in range(12): if j > 6: j = 0 rezultss+= sun_rise.strftime('%m-%d-%Y: %H:%M'), (sun_rise + day_diff / 12).strftime('%m-%d-%Y: %H:%M'), planetary_hour_sequence[j] sun_rise += day_diff / 12 j += 1 #print 'Sunset : Planetary hours' rezults = [] for i in range(12): if j > 6: j = 0 rezults+= sun_set.strftime('%m-%d-%Y: %H:%M'), (sun_set + night_diff / 12).strftime('%m-%d-%Y: %H:%M'), planetary_hour_sequence[j] sun_set += night_diff / 12 j += 1 return rezults, rezultss
def get_solar_month_day(jd_start, city): """Compute the solar month and day for a given Julian day Computes the solar month and day on the day corresponding to a given Julian day Args: float jd city Returns: int solar_month int solar_month_day Examples: >>> get_solar_month_day(2457023.27, city('Chennai', '13:05:24', \ '80:16:12', 'Asia/Calcutta')) (9, 17) """ jd_sunset = swe.rise_trans(jd_start=jd_start, body=swe.SUN, lon=city.longitude, lat=city.latitude, rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] solar_month = get_angam(jd_sunset, SOLAR_MONTH) target = floor(solar_month) - 1 jd_masa_transit = brentq(get_angam_float, jd_start - 34, jd_start + 1, args=(SOLAR_MONTH, -target, False)) jd_next_sunset = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=city.longitude, lat=city.latitude, rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] jd_next_sunrise = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=city.longitude, lat=city.latitude, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] if jd_next_sunset > jd_next_sunrise: # Masa begins after sunset and before sunrise # Therefore Masa 1 is on the day when the sun rises next solar_month_day = floor(jd_sunset - jd_next_sunrise) + 1 else: # Masa has started before sunset solar_month_day = round(jd_sunset - jd_next_sunset) + 1 return (solar_month, solar_month_day)
def get_transit(planet, observer, date): day = datetime_to_julian(date) if observer.lat < 0: transit=revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day-1, \ planet, observer.lng, observer.lat, alt=observer.elevation, \ rsmi=swisseph.CALC_MTRANSIT)[1][0])) else: transit=revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day-1, \ planet, observer.lng, observer.lat, alt=observer.elevation, \ rsmi=swisseph.CALC_ITRANSIT)[1][0])) swisseph.close() return transit
def abhijit_muhurta(jd, place): """Abhijit muhurta is the 8th muhurta (middle one) of the 15 muhurtas during the day_duration (~12 hours)""" lat, lon, tz = place tz = place.timezone srise = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE)[1][0] sset = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_SET)[1][0] day_dur = (sset - srise) start_time = srise + 7 / 15 * day_dur end_time = srise + 8 / 15 * day_dur # to local time return [(start_time - jd) * 24 + tz, (end_time - jd) * 24 + tz]
def sunset(jd, place): """Sunset when centre of disc is at horizon for given date and place""" lat, lon, tz = place result = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi=swe.BIT_DISC_CENTER + swe.CALC_SET) setting = result[1][0] # julian-day number # Convert to local time return [setting + tz/24., to_dms((setting - jd) * 24 + tz)]
def compute_lagna_data(jd, lat, lon, tz_off, debug=False): jd_sunrise = swe.rise_trans(jd_start=jd, body=swe.SUN, lon=lon, lat=lat, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] lagna_sunrise = 1 + floor(compute_lagna_float(jd_sunrise)) lagna_list = [(x + lagna_sunrise - 1) % 12 + 1 for x in range(12)] lbrack = jd_sunrise - 3 / 24 rbrack = jd_sunrise + 3 / 24 lagna_data = [] for lagna in lagna_list: # print('---\n', lagna) if (debug): print('lagna sunrise', compute_lagna_float(jd_sunrise)) print('lbrack', compute_lagna_float(lbrack, lat, lon, -lagna)) print('rbrack', compute_lagna_float(rbrack, lat, lon, -lagna)) lagna_end_time = brentq(compute_lagna_float, lbrack, rbrack, args=(lat, lon, -lagna, debug)) lbrack = lagna_end_time + 1 / 24 rbrack = lagna_end_time + 3 / 24 lagna_data.append((lagna, lagna_end_time)) # print(revjul(jd + 5.5 / 24), compute_lagnas(jd) / 30) return lagna_data
def moonrise(jd, place): """Moonrise when centre of disc is at horizon for given date and place""" lat, lon, tz = place result = swe.rise_trans(jd - tz/24, swe.MOON, lon, lat, rsmi=swe.BIT_DISC_CENTER + swe.CALC_RISE) rise = result[1][0] # julian-day number # Convert to local time return to_dms((rise - jd) * 24 + tz)
def sunrise(jd, place): """Sunrise when centre of disc is at horizon for given date and place""" lat, lon, tz = place result = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE) rise = result[1][0] # julian-day number # Convert to local time return [rise + tz/24., to_dms((rise - jd) * 24 + tz)]
def moonset(jd, place): """Moonset when centre of disc is at horizon for given date and place""" lat, lon, tz = place result = swe.rise_trans(jd - tz/24, swe.MOON, lon, lat, rsmi = _rise_flags + swe.CALC_SET) setting = result[1][0] # julian-day number # Convert to local time return to_dms((setting - jd) * 24 + tz)
def get_setting_time(self, julian_day_start, body): from jyotisha.panchaanga.temporal.body import Graha graha = Graha.singleton(body) # rise_trans expects UT time return swe.rise_trans( jd_start=julian_day_start, body=graha._get_swisseph_id(), lon=self.longitude, lat=self.latitude, rsmi=CALC_SET)[1][0]
def get_last_dhanur_transit(jd_start, latitude, longitude): swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha for d in range(-25, 0): jd = jd_start + d [y, m, d, t] = swisseph.revjul(jd) jd_rise = swisseph.rise_trans(jd_start=jd, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] jd_rise_tmrw = swisseph.rise_trans(jd_start=jd + 1, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] jd_set = swisseph.rise_trans(jd_start=jd, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_SET | swisseph.BIT_DISC_CENTER)[1][0] longitude_sun = swisseph.calc_ut( jd_rise, swisseph.SUN)[0] - swisseph.get_ayanamsa(jd_rise) longitude_sun_set = swisseph.calc_ut( jd_set, swisseph.SUN)[0] - swisseph.get_ayanamsa(jd_set) sun_month_rise = masa_names[int(1 + math.floor(( (longitude_sun) % 360) / 30.0))] sun_month = masa_names[int(1 + math.floor(( (longitude_sun_set) % 360) / 30.0))] longitude_sun_tmrw = swisseph.calc_ut( jd_rise + 1, swisseph.SUN)[0] - swisseph.get_ayanamsa(jd_rise + 1) sun_month_tmrw = masa_names[int(1 + math.floor(( (longitude_sun_tmrw) % 360) / 30.0))] #print '%f:%d-%d-%d: rise=%s, set=%s, tmrw=%s' %(jd,y,m,d,sun_month_rise,sun_month,sun_month_tmrw) if sun_month_rise != sun_month_tmrw: if sun_month != sun_month_tmrw: return jd + 1 else: return jd
def sweNextTransit(obj, jd, lat, lon, flag): """ Returns the julian date of the next transit of an object. The flag should be 'RISE' or 'SET'. """ sweObj = SWE_OBJECTS[obj] flag = swisseph.CALC_RISE if flag == 'RISE' else swisseph.CALC_SET trans = swisseph.rise_trans(jd, sweObj, lon, lat, 0, 0, 0, flag) return trans[1][0]
def gauri_chogadiya(jd, place): lat, lon, tz = place tz = place.timezone srise = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE)[1][0] sset = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_SET)[1][0] day_dur = (sset - srise) end_times = [] for i in range(1, 9): end_times.append(to_dms((srise + (i * day_dur) / 8 - jd) * 24 + tz)) # Night duration = time from today's sunset to tomorrow's sunrise srise = swe.rise_trans((jd + 1) - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE)[1][0] night_dur = (srise - sset) for i in range(1, 9): end_times.append(to_dms((sset + (i * night_dur) / 8 - jd) * 24 + tz)) return end_times
def compute_solar_transitions(self): self.jd_sunrise = swe.rise_trans(jd_start=self.julian_day_start, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] self.jd_sunset = swe.rise_trans(jd_start=self.jd_sunrise, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] if self.jd_sunset == 0.0: logging.error('No sunset was computed!') raise (ValueError( 'No sunset was computed. Perhaps the co-ordinates are beyond the polar circle (most likely a LAT-LONG swap! Please check your inputs.' ))
def durmuhurtam(jd, place): lat, lon, tz = place tz = place.timezone # Night = today's sunset to tomorrow's sunrise sset = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_SET)[1][0] srise = swe.rise_trans((jd + 1) - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE)[1][0] night_dur = (srise - sset) # Day = today's sunrise to today's sunset srise = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE)[1][0] day_dur = (sset - srise) weekday = vaara(jd) # There is one durmuhurtam on Sun, Wed, Sat; the rest have two offsets = [[10.4, 0.0], # Sunday [6.4, 8.8], # Monday [2.4, 4.8], # Tuesday, [day_duration , night_duration] [5.6, 0.0], # Wednesday [4.0, 8.8], # Thursday [2.4, 6.4], # Friday [1.6, 0.0]] # Saturday # second durmuhurtam of tuesday uses night_duration instead of day_duration dur = [day_dur, day_dur] base = [srise, srise] if weekday == 2: dur[1] = night_dur; base[1] = sset # compute start and end timings start_times = [0, 0] end_times = [0, 0] for i in range(0, 2): offset = offsets[weekday][i] if offset != 0.0: start_times[i] = base[i] + dur[i] * offsets[weekday][i] / 12 end_times[i] = start_times[i] + day_dur * 0.8 / 12 # convert to local time start_times[i] = (start_times[i] - jd) * 24 + tz end_times[i] = (end_times[i] - jd) * 24 + tz return [start_times, end_times] # in decimal hours
def get_transit(planet, observer, date): day = datetime_to_julian(date) if observer.lat < 0: transit = revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day-1, planet, observer.lng, observer.lat, alt=observer.elevation, rsmi=swisseph.CALC_MTRANSIT)[1][0] ) ) else: transit = revjul_to_datetime(swisseph.revjul(swisseph.rise_trans(day-1, planet, observer.lng, observer.lat, alt=observer.elevation, rsmi=swisseph.CALC_ITRANSIT)[1][0] ) ) swisseph.close() return transit
def moonrise(jd, place): """Moonrise when centre of disc is at horizon for given date and place""" lat, lon, tz = place result = swe.rise_trans(jd - tz / 24, swe.MOON, lon, lat, rsmi=swe.BIT_DISC_CENTER + swe.CALC_RISE) rise = result[1][0] # julian-day number # Convert to local time return to_dms((rise - jd) * 24 + tz)
def sunset(jd, place): """Sunset when centre of disc is at horizon for given date and place""" lat, lon, tz = place result = swe.rise_trans(jd - tz / 24, swe.SUN, lon, lat, rsmi=swe.BIT_DISC_CENTER + swe.CALC_SET) setting = result[1][0] # julian-day number # Convert to local time return [setting + tz / 24., to_dms((setting - jd) * 24 + tz)]
def trikalam(jd, place, option='rahu'): lat, lon, tz = place tz = place.timezone srise = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_RISE)[1][0] sset = swe.rise_trans(jd - tz/24, swe.SUN, lon, lat, rsmi = _rise_flags + swe.CALC_SET)[1][0] day_dur = (sset - srise) weekday = vaara(jd) # value in each array is for given weekday (0 = sunday, etc.) offsets = { 'rahu': [0.875, 0.125, 0.75, 0.5, 0.625, 0.375, 0.25], 'gulika': [0.75, 0.625, 0.5, 0.375, 0.25, 0.125, 0.0], 'yamaganda': [0.5, 0.375, 0.25, 0.125, 0.0, 0.75, 0.625] } start_time = srise + day_dur * offsets[option][weekday] end_time = start_time + 0.125 * day_dur # to local timezone start_time = (start_time - jd) * 24 + tz end_time = (end_time - jd) * 24 + tz return [to_dms(start_time), to_dms(end_time)] # decimal hours to H:M:S
longitude = -118.25 res_how = swe.lun_eclipse_how(res[1][0], longitude, lat) print res_how now = res[1][0] - 1 # now = swe.julday(2014, 4, 1) time_zone = -8 print '------------------------' print 'Next Eclipse for a given geographical position: Los Angeles'############################################### res = swe.lun_eclipse_when_loc(now, longitude, lat) res_how = swe.lun_eclipse_how(res[1][0], longitude, lat) if res[1][8] > 0: moon_rise = res[1][8] else: now1 = res[1][0] - 1 # swe.julday(2016, 3, 23) # rsmi=1 rise,2 set rise = swe.rise_trans(now1, 1, longitude, lat, rsmi=1) moon_rise = rise[1][0] if res[1][9] > 0: moon_set = res[1][9] else: now1 = res[1][0] # swe.julday(2016, 3, 23) rise = swe.rise_trans(now1, 1, longitude, lat, rsmi=2) moon_set = rise[1][0] print res print res_how eclipse_total = int('00000100', 2) central = res[0][0] & eclipse_total if central == 4: print 'Eclipse Total' print 'Moon Rise ', date_convert(moon_rise) + datetime.timedelta(hours=time_zone) if moon_rise < res[1][6]:
def main(): city_name = sys.argv[1] latitude = sexastr2deci(sys.argv[2]) longitude = sexastr2deci(sys.argv[3]) tz = sys.argv[4] start_year = int(sys.argv[5]) year = start_year jd=swisseph.julday(year,1,1,0) jd_start=jd start_date = datetime(year=year,month=1,day=1,hour=0,minute=0,second=0) day_of_year=0 swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha sun_month_day = jd-get_last_dhanur_transit(jd,latitude,longitude) #this has to be done in a generic fashion, by scanning for the transit into dhanur of the last year! month_start_after_set = 0 template_file=open('cal_template_compre.tex') template_lines=template_file.readlines() for i in range(0,len(template_lines)-3): print template_lines[i][:-1] samvatsara_id = (year - 1568)%60 + 1; #distance from prabhava samvatsara_names = '%s–%s' % (year_names[samvatsara_id], year_names[(samvatsara_id%60)+1]) print '\\mbox{}' print '{\\font\\x="Warnock Pro" at 60 pt\\x %d\\\\[0.3cm]}' % year print '\\mbox{\\font\\x="Sanskrit 2003:script=deva" at 48 pt\\x %s}\\\\[0.5cm]' % samvatsara_names print '{\\font\\x="Warnock Pro" at 48 pt\\x \\uppercase{%s}\\\\[0.3cm]}' % city_name print '\hrule' while year<=start_year: day_of_year = day_of_year + 1 [y,m,d,t] = swisseph.revjul(jd) weekday = (swisseph.day_of_week(jd) + 1)%7 #swisseph has Mon = 0, non-intuitively! local_time = pytz.timezone(tz).localize(datetime(y,m, d, 6, 0, 0)) #checking @ 6am local - can we do any better? tz_off=datetime.utcoffset(local_time).seconds/3600.0 #compute offset from UTC jd_rise=swisseph.rise_trans(jd_start=jd,body=swisseph.SUN,lon=longitude,lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0] jd_rise_tmrw=swisseph.rise_trans(jd_start=jd+1,body=swisseph.SUN,lon=longitude,lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0] jd_set =swisseph.rise_trans(jd_start=jd,body=swisseph.SUN,lon=longitude,lat=latitude,rsmi=swisseph.CALC_SET|swisseph.BIT_DISC_CENTER)[1][0] [_y,_m,_d, t_rise]=swisseph.revjul(jd_rise+tz_off/24.0) [_y,_m,_d, t_set]=swisseph.revjul(jd_set+tz_off/24.0) longitude_moon=swisseph.calc_ut(jd_rise,swisseph.MOON)[0]-swisseph.get_ayanamsa(jd_rise) longitude_moon_tmrw=swisseph.calc_ut(jd_rise+1,swisseph.MOON)[0]-swisseph.get_ayanamsa(jd_rise+1) longitude_sun=swisseph.calc_ut(jd_rise,swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_rise) longitude_sun_set=swisseph.calc_ut(jd_set,swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_set) sun_month_rise = masa_names[int(1+math.floor(((longitude_sun)%360)/30.0))] sun_month = masa_names[int(1+math.floor(((longitude_sun_set)%360)/30.0))] longitude_sun_tmrw=swisseph.calc_ut(jd_rise+1,swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_rise+1) sun_month_tmrw = masa_names[int(1+math.floor(((longitude_sun_tmrw)%360)/30.0))] daily_motion_moon = (longitude_moon_tmrw-longitude_moon)%360 daily_motion_sun = (longitude_sun_tmrw-longitude_sun)%360 #Solar month calculations if month_start_after_set==1: sun_month_day = 0 month_start_after_set = 0 if sun_month_rise!=sun_month_tmrw: if sun_month!=sun_month_tmrw: month_start_after_set=1 sun_month_day = sun_month_day + 1 #mAsa pirappu! #sun_month = sun_month_tmrw #sun moves into next rAsi before sunset -- check rules! else: sun_month_day = 1 month_remaining = 30-(longitude_sun%30.0) month_end = month_remaining/daily_motion_sun*24.0 me = deci2sexa(t_rise+month_end) if me[0]>=24: suff='(+1)' me[0] = me[0] - 24 else: suff='\\hspace{2ex}' sun_month_end_time = '{\\textsf{%s} {\\tiny \\RIGHTarrow} %02d:%02d%s}' % (last_sun_month,me[0],me[1],suff) else: sun_month_day = sun_month_day + 1 sun_month_end_time = '' month_data = '\\sunmonth{%s}{%d}{%s}' % (sun_month,sun_month_day,sun_month_end_time) #Compute tithi details tithi = int(1+math.floor((longitude_moon-longitude_sun)%360 / 12.0)) tithi_tmrw = int(1+math.floor((longitude_moon_tmrw-longitude_sun_tmrw)%360 / 12.0)) if (tithi_tmrw-tithi)%30 > 1: #double change tithi_2=(tithi%30)+1 if tithi_2%15 != 0: paksha = (paksha_names['shukla'] if tithi_2<15 else paksha_names['krishna']) else: if tithi_2 == 15: paksha = '\\fullmoon' elif tithi_2 == 30: paksha = '\\newmoon' if tithi_2%15 == 0: tithi_str_2 = paksha + tithi_names[tithi_2] else: tithi_str_2 = paksha + tithi_names[tithi_2%15] tithi_remaining_2 = 12+12-(((longitude_moon-longitude_sun)%360)%12) tithi_end_2 = tithi_remaining_2/(daily_motion_moon-daily_motion_sun)*24.0 tithi_end_str_2 = print_end_time(tithi_end_2,jd_rise_tmrw-jd_rise,t_rise) if tithi_end_str_2 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second tithi cannot be 'all day'! It's ending will reflect in tomorrow's calendar tithi_str_2 = '' tithi_end_str_2 = '' else: tithi_str_2 = '' tithi_end_str_2 = '' if tithi%15 != 0: paksha = (paksha_names['shukla'] if tithi<15 else paksha_names['krishna']) else: if tithi == 15: paksha = '\\fullmoon' elif tithi == 30: paksha = '\\newmoon' if tithi%15 == 0: tithi_str = paksha + tithi_names[tithi] else: tithi_str = paksha + tithi_names[tithi%15] tithi_remaining = 12-(((longitude_moon-longitude_sun)%360)%12) tithi_end = tithi_remaining/(daily_motion_moon-daily_motion_sun)*24.0 tithi_end_str = print_end_time(tithi_end,jd_rise_tmrw-jd_rise,t_rise) #Compute nakshatram details n_id = int(1+math.floor((longitude_moon%360) /(360.0/27))) n_id_tmrw = int(1+math.floor((longitude_moon_tmrw%360) /(360.0/27))) if (n_id_tmrw-n_id)%27 > 1: #there is a double change nakshatram_str_2 = nakshatra_names[n_id%27+1] nakshatram_remaining_2 = (360.0/27)+(360.0/27) - ((longitude_moon%360) % (360.0/27)) nakshatram_end_2 = nakshatram_remaining_2/daily_motion_moon*24 nakshatram_end_str_2 = print_end_time(nakshatram_end_2,jd_rise_tmrw-jd_rise,t_rise) if nakshatram_end_str_2 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second nakshatram cannot be 'all day'! It's ending will reflect in tomorrow's calendar nakshatram_str_2 = '' nakshatram_end_str_2 = '' else: nakshatram_str_2 = '' nakshatram_end_str_2 = '' nakshatram_str = nakshatra_names[n_id] nakshatram_remaining = (360.0/27) - ((longitude_moon%360) % (360.0/27)) nakshatram_end = nakshatram_remaining/daily_motion_moon*24 nakshatram_end_str = print_end_time(nakshatram_end,jd_rise_tmrw-jd_rise,t_rise) #Compute karanam details karanam = int(1+math.floor((longitude_moon-longitude_sun)%360 / 6.0)) karanam_tmrw = int(1+math.floor((longitude_moon_tmrw-longitude_sun_tmrw)%360 / 6.0)) # There cannot be more than 3 karanams in a day, because total arc ~ 12 deg and per yogam is 6 deg if (karanam_tmrw-karanam)%60 > 2: #triple change karanam_3=((karanam+1)%60)+1 karanam_str_3 = karanam_names[karanam_3] karanam_remaining_3 = 6*2+6-(((longitude_moon-longitude_sun)%360)%6) karanam_end_3 = karanam_remaining_3/(daily_motion_moon-daily_motion_sun)*24.0 karanam_end_str_3 = print_end_time(karanam_end_3,jd_rise_tmrw-jd_rise,t_rise) if karanam_end_str_3 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second karanam cannot be 'all day'! It's ending will reflect in tomorrow's calendar karanam_str_3 = '' karanam_end_str_3 = '' else: karanam_str_3 = '' karanam_end_str_3 = '' if (karanam_tmrw-karanam)%60 > 1: #double change karanam_2=(karanam%60)+1 karanam_str_2 = karanam_names[karanam_2] karanam_remaining_2 = 6+6-(((longitude_moon-longitude_sun)%360)%6) karanam_end_2 = karanam_remaining_2/(daily_motion_moon-daily_motion_sun)*24.0 karanam_end_str_2 = print_end_time(karanam_end_2,jd_rise_tmrw-jd_rise,t_rise) if karanam_end_str_2 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second karanam cannot be 'all day'! It's ending will reflect in tomorrow's calendar karanam_str_2 = '' karanam_end_str_2 = '' else: karanam_str_2 = '' karanam_end_str_2 = '' karanam_str = karanam_names[karanam] karanam_remaining = 6-(((longitude_moon-longitude_sun)%6)%6) karanam_end = karanam_remaining/(daily_motion_moon-daily_motion_sun)*24.0 karanam_end_str = print_end_time(karanam_end,jd_rise_tmrw-jd_rise,t_rise) #Compute yogam details yogam = int(1+math.floor((longitude_moon+longitude_sun)%360 / (360.0/27.0))) yogam_tmrw = int(1+math.floor((longitude_moon_tmrw+longitude_sun_tmrw)%360 / (360.0/27.0))) #There cannot be more than 2 yogams in a day, because total arc = 13 deg and per yogam is 13.333 deg if (yogam_tmrw-yogam)%27 > 1: #double change yogam_2=(yogam%27)+1 yogam_str_2 = yogam_names[yogam_2] yogam_remaining_2 = 2.0*(360.0/27.0)-(((longitude_moon+longitude_sun)%360)%(360.0/27.0)) yogam_end_2 = yogam_remaining_2/(daily_motion_moon+daily_motion_sun)*24.0 yogam_end_str_2 = print_end_time(yogam_end_2,jd_rise_tmrw-jd_rise,t_rise) if yogam_end_str_2 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second yogam cannot be 'all day'! It's ending will reflect in tomorrow's calendar yogam_str_2 = '' yogam_end_str_2 = '' else: yogam_str_2 = '' yogam_end_str_2 = '' yogam_str = yogam_names[yogam] yogam_remaining = (360.0/27.0)-(((longitude_moon+longitude_sun)%360)%(360.0/27.0)) yogam_end = yogam_remaining/(daily_motion_moon+daily_motion_sun)*24.0 yogam_end_str = print_end_time(yogam_end,jd_rise_tmrw-jd_rise,t_rise) #Sunrise/sunset and related stuff (like rahu, yama) [rh, rm, rs] = deci2sexa(t_rise) #rise_t hour, rise minute [sh, sm, ss] = deci2sexa(t_set) #set_t hour, set minute present_day = start_date + timedelta(days=day_of_year) rise_t = present_day + timedelta(hours=rh,minutes=rm) set_t = present_day + timedelta(hours=sh,minutes=sm) length_of_day = set_t-rise_t yamakandam_start = rise_t + timedelta(seconds=(1/8.0)*(yamakandam_octets[weekday]-1)*length_of_day.seconds) yamakandam_end = yamakandam_start + timedelta(seconds=(1/8.0)*length_of_day.seconds) rahukalam_start = rise_t + timedelta(seconds=(1/8.0)*(rahukalam_octets[weekday]-1)*length_of_day.seconds) rahukalam_end = rahukalam_start + timedelta(seconds=(1/8.0)*length_of_day.seconds) madhyahnikam_start = rise_t + timedelta(seconds=(1/5.0)*length_of_day.seconds) rise = '%02d:%02d' % (rh,rm) set = '%02d:%02d' % (sh,sm) madhya = print_time(madhyahnikam_start) rahu = '%s--%s' % (print_time(rahukalam_start), print_time(rahukalam_end)) yama = '%s--%s' % (print_time(yamakandam_start),print_time(yamakandam_end)) if nakshatram_end_str_2!='': nakshatram_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (nakshatram_str,nakshatram_end_str,nakshatram_str_2,nakshatram_end_str_2) else: nakshatram_data_string = '{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (nakshatram_str,nakshatram_end_str) if tithi_end_str_2!='': tithi_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (tithi_str,tithi_end_str,tithi_str_2,tithi_end_str_2) else: tithi_data_string = '{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (tithi_str,tithi_end_str) if karanam_end_str_3!='': karanam_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}\\\\\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (karanam_str,karanam_end_str,karanam_str_2,karanam_end_str_2,karanam_str_3,karanam_end_str_3) elif karanam_end_str_2!='': karanam_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (karanam_str,karanam_end_str,karanam_str_2,karanam_end_str_2) else: karanam_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (karanam_str,karanam_end_str) if yogam_end_str_2!='': yogam_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (yogam_str,yogam_end_str,yogam_str_2,yogam_end_str_2) else: yogam_data_string = '\\mbox{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % (yogam_str,yogam_end_str) #Layout calendar in LATeX format if d==1: if m>1: if weekday!=0: #Space till Sunday for i in range(weekday,6): print "{} &" print "\\\\ \hline" print '\end{tabular}' print '\n\n' #Begin tabular print '\\begin{tabular}{|c|c|c|c|c|c|c|}' print '\multicolumn{7}{c}{\Large \\bfseries %s %s}\\\\[3mm]' % (month[m],y) print '\hline' print '\\textbf{SUN} & \\textbf{MON} & \\textbf{TUE} & \\textbf{WED} & \\textbf{THU} & \\textbf{FRI} & \\textbf{SAT} \\\\ \hline' #print '\\textbf{भानु} & \\textbf{इन्दु} & \\textbf{भौम} & \\textbf{बुध} & \\textbf{गुरु} & \\textbf{भृगु} & \\textbf{स्थिर} \\\\ \hline' #Blanks for previous weekdays for i in range(0,weekday): print "{} &" print '\caldata{\\textcolor{%s}{%s}}{%s}{\\sundata{%s}{%s}{%s}}{\\tnyk{%s}{%s}{%s}{%s}}{\\textsf{राहु}~%s~~\\textsf{यम}~%s} ' % (daycol[weekday],d,month_data,rise,set,madhya,tithi_data_string,nakshatram_data_string,yogam_data_string,karanam_data_string,rahu,yama) if weekday==6: print "\\\\ \hline" else: print "&" jd = jd + 1 last_sun_month = sun_month if m==12 and d==31: year = year + 1 # For debugging specific dates #if m==4 and d==10: # break for i in range(weekday+1,6): print "{} &" if weekday!=6: print "\\\\ \hline" print '\end{tabular}' print '\n\n' print template_lines[-2][:-1] print template_lines[-1][:-1]
def plan_hours(time_zone, city_longitude, city_latitude): local_timezone = pytz.timezone(time_zone) local_date = local_timezone.localize(date_passed, is_dst=None) date_start = datetime.datetime.today() # today's date planetary_hour_sequence = ('Saturn', 'Jupiter', 'Mars', 'Sun', 'Venus', 'Mercury', 'Moon') day_sequence = ('Moon', 'Mars', 'Mercury', 'Jupiter', 'Venus', 'Saturn', 'Sun') day_sequence_p = (6, 2, 5, 1, 4, 0, 3) # search this date's noon [12 PM] now_julian = swe.julday(date_start.year, date_start.month, date_start.day, 12) planet_rise_jul = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 1) planet_set_jul = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 2) sun_rise_tuple = swe.jdut1_to_utc(planet_rise_jul[1][0], 1) sun_rise_list = list(sun_rise_tuple) sun_rise1 = datetime.datetime(*sun_rise_list[0:5], tzinfo=pytz.utc) sun_rise = sun_rise1.astimezone(local_timezone) # sunset sun_set_tuple = swe.jdut1_to_utc(planet_set_jul[1][0], 1) sun_set_list = list(sun_set_tuple) sun_set1 = datetime.datetime(*sun_set_list[0:5], tzinfo=pytz.utc) sun_set = sun_set1.astimezone(local_timezone) # next day sun rise now_julian = swe.julday(date_start.year, date_start.month, date_start.day + 1, 12) planet_rise_jul_next_day = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 1) sun_rise_tuple_n = swe.jdut1_to_utc(planet_rise_jul_next_day[1][0], 1) sun_rise_list_n = list(sun_rise_tuple_n) sun_rise_n1 = datetime.datetime(*sun_rise_list_n[0:5], tzinfo=pytz.utc) sun_rise_n = sun_rise_n1.astimezone(local_timezone) print 'sun rise:', sun_rise.strftime('%m-%d-%Y: %H:%M') print 'sun set:', sun_set.strftime('%m-%d-%Y: %H:%M') print 'sun rise next', sun_rise_n.strftime('%m-%d-%Y: %H:%M') day_diff = (sun_set - sun_rise) day_diff_skip = day_diff.total_seconds() / 12 night_diff = (sun_rise_n - sun_set) night_diff_skip = night_diff.total_seconds() / 12 # print day_diff_skip, night_diff_skip day_of_week = sun_rise.weekday() start_sequence = day_sequence[day_of_week] # starting planet print 'Day:', start_sequence # , planetary_hour_sequence[day_sequence_p[day_of_week]] j = day_sequence_p[day_of_week] print 'Sunrise: Planetary hours' rezultss = {} for i in range(12): if j > 6: j = 0 rezultss[i] = { 'time': str(sun_rise.strftime('%m-%d-%Y: %H:%M')), 'time2': str( (sun_rise + day_diff / 12).strftime('%m-%d-%Y: %H:%M')), 'planet': str(planetary_hour_sequence[j]) } sun_rise += day_diff / 12 j += 1 print 'Sunset : Planetary hours' rezults = {} for i in range(12): if j > 6: j = 0 rezults[i] = { 'time': str(sun_set.strftime('%m-%d-%Y: %H:%M')), 'time2': str( (sun_set + night_diff / 12).strftime('%m-%d-%Y: %H:%M')), 'planet': str(planetary_hour_sequence[j]) } sun_set += night_diff / 12 j += 1 return rezults, rezultss ###########################################################################################################################################################################################################
def calcTimes(self): #the date we get from julianday is the same as year, month day in Time-class but we didn't pass it to the init function. oyear, omonth, oday, otim = swisseph.revjul(self.jd, self.calflag) numangles = len(RiseSet.Angles) for i in range(planets.Planets.PLANETS_NUM): #Nodes are excluded ar = [] #Rise # TODO: ret, risetime = swisseph.rise_trans(jd, astrology.SE_SUN, lon, lat, float(altitude), 0.0, 10.0, astrology.SE_CALC_RISE, astrology.SEFLG_SWIEPH) ret, JDRise = swisseph.rise_trans(self.jd, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.RISE], astrology.SEFLG_SWIEPH) tyear, tmonth, tday, ttim = swisseph.revjul( JDRise[0], self.calflag) if oyear != tyear or omonth != tmonth or oday != tday: ret, JDRise = swisseph.rise_trans(self.jd - 1.0, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.RISE], astrology.SEFLG_SWIEPH) #MC ret, JDMC = swisseph.rise_trans(self.jd, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.MC], astrology.SEFLG_SWIEPH) tyear, tmonth, tday, ttim = swisseph.revjul(JDMC[0], self.calflag) if oyear != tyear or omonth != tmonth or oday != tday: ret, JDMC = swisseph.rise_trans(self.jd - 1.0, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.MC], astrology.SEFLG_SWIEPH) #Set ret, JDSet = swisseph.rise_trans(self.jd, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.SET], astrology.SEFLG_SWIEPH) tyear, tmonth, tday, ttim = swisseph.revjul(JDSet[0], self.calflag) if oyear != tyear or omonth != tmonth or oday != tday: ret, JDSet = swisseph.rise_trans(self.jd - 1.0, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.SET], astrology.SEFLG_SWIEPH) #IC ret, JDIC = swisseph.rise_trans(self.jd, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.IC], astrology.SEFLG_SWIEPH) tyear, tmonth, tday, ttim = swisseph.revjul(JDIC[0], self.calflag) if oyear != tyear or omonth != tmonth or oday != tday: ret, JDIC = swisseph.rise_trans(self.jd - 1.0, i, self.lon, self.lat, self.alt, 0.0, 10.0, RiseSet.Angles[RiseSet.IC], astrology.SEFLG_SWIEPH) #From GMT to Local # JDRise += self.offs year, month, day, hr = swisseph.revjul(JDRise[0], self.calflag) ar.append(hr) # JDMC += self.offs year, month, day, hr = swisseph.revjul(JDMC[0], self.calflag) ar.append(hr) # JDSet += self.offs year, month, day, hr = swisseph.revjul(JDSet[0], self.calflag) ar.append(hr) # JDIC += self.offs year, month, day, hr = swisseph.revjul(JDIC[0], self.calflag) ar.append(hr) self.times.append(ar)
def compute_sun_moon_transitions(self, previous_day_panchangam=None, force_recomputation=False): """ :param previous_day_panchangam: Panchangam for previous day, to avoid unnecessary calculations. (rise_trans calculations can be time consuming.) :param force_recomputation: Boolean indicating if the transitions should be recomputed. (rise_trans calculations can be time consuming.) :return: """ if force_recomputation or self.jd_sunrise is None: if previous_day_panchangam is not None and previous_day_panchangam.jd_next_sunrise is not None: self.jd_sunrise = previous_day_panchangam.jd_next_sunrise else: self.jd_sunrise = swe.rise_trans( jd_start=self.julian_day_start, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=CALC_RISE)[1][0] if force_recomputation or self.jd_sunset is None: self.jd_sunset = swe.rise_trans(jd_start=self.jd_sunrise, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=CALC_SET)[1][0] if force_recomputation or self.jd_previous_sunset is None: if previous_day_panchangam is not None and previous_day_panchangam.jd_sunset is not None: self.jd_previous_sunset = previous_day_panchangam.jd_sunset else: self.jd_previous_sunset = swe.rise_trans( jd_start=self.jd_sunrise - 1, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=CALC_SET)[1][0] if force_recomputation or self.jd_next_sunrise is None: self.jd_next_sunrise = swe.rise_trans(jd_start=self.jd_sunset, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=CALC_RISE)[1][0] if self.jd_sunset == 0.0: logging.error('No sunset was computed!') raise (ValueError( 'No sunset was computed. Perhaps the co-ordinates are beyond the polar circle (most likely a LAT-LONG swap! Please check your inputs.' )) # logging.debug(swe.rise_trans(jd_start=jd_start, body=swe.SUN, lon=city.longitude, # lat=city.latitude, rsmi=CALC_SET)) if force_recomputation or self.jd_moonrise is None: self.jd_moonrise = swe.rise_trans(jd_start=self.jd_sunrise, body=swe.MOON, lon=self.city.longitude, lat=self.city.latitude, rsmi=CALC_RISE)[1][0] if force_recomputation or self.jd_moonset is None: self.jd_moonset = swe.rise_trans(jd_start=self.jd_moonrise, body=swe.MOON, lon=self.city.longitude, lat=self.city.latitude, rsmi=CALC_SET)[1][0] self.tithi_data = temporal.get_angam_data( self.jd_sunrise, self.jd_next_sunrise, temporal.TITHI, ayanamsha_id=self.ayanamsha_id) self.tithi_at_sunrise = self.tithi_data[0][0] self.nakshatram_data = temporal.get_angam_data( self.jd_sunrise, self.jd_next_sunrise, temporal.NAKSHATRAM, ayanamsha_id=self.ayanamsha_id) self.nakshatram_at_sunrise = self.nakshatram_data[0][0] self.yogam_data = temporal.get_angam_data( self.jd_sunrise, self.jd_next_sunrise, temporal.YOGAM, ayanamsha_id=self.ayanamsha_id) self.yogam_at_sunrise = self.yogam_data[0][0] self.karanam_data = temporal.get_angam_data( self.jd_sunrise, self.jd_next_sunrise, temporal.KARANAM, ayanamsha_id=self.ayanamsha_id) self.rashi_data = temporal.get_angam_data( self.jd_sunrise, self.jd_next_sunrise, temporal.RASHI, ayanamsha_id=self.ayanamsha_id)
def lunarbypos(time_zone, year, month, day, location_latitude, location_longitude): end=''; lunar_eclipse = {} now = swe.julday(year, month, day) res = swe.lun_eclipse_when_loc(now, location_longitude, location_latitude) res_how = swe.lun_eclipse_how(res[1][0], location_longitude, location_latitude) duration_umbral = '' if res[1][8] > 0: moon_rise = res[1][8] else: now1 = res[1][0] - 1 # swe.julday(2016, 3, 23) # rsmi=1 rise,2 set rise = swe.rise_trans(now1, 1, location_longitude, location_latitude, rsmi=1) moon_rise = rise[1][0] if res[1][9] > 0: moon_set = res[1][9] else: now1 = res[1][0] # swe.julday(2016, 3, 23) rise = swe.rise_trans(now1, 1, location_longitude, location_latitude, rsmi=2) moon_set = rise[1][0] #print res #print res_how eclipse_total = int('00000100', 2) central = res[0][0] & eclipse_total if central == 4: Type = 'Eclipse Total' Moon_rise = (date_convert(moon_rise) + datetime.timedelta(hours=time_zone)) if moon_rise < res[1][6]: start = (date_convert(res[1][6]) + datetime.timedelta(hours=time_zone)) duration_start = res[1][6] else: duration_start = moon_rise if moon_rise < res[1][2]: print 'Start partial', date_convert(res[1][2]) + datetime.timedelta(hours=time_zone) duration_start_partial = res[1][2] else: duration_start_partial = moon_rise if moon_rise < res[1][4]: print 'Start Total ', date_convert(res[1][4]) + datetime.timedelta(hours=time_zone) duration_start_total = res[1][4] else: duration_start_total = moon_rise maxi = (date_convert(res[1][0]) + datetime.timedelta(hours=time_zone)) if res[1][5] > 0 and moon_set > res[1][5]: print 'End Total ', date_convert(res[1][5]) + datetime.timedelta(hours=time_zone) duration_end_total = res[1][5] else: duration_end_total = moon_set if res[1][3] > 0 and moon_set > res[1][3]: print 'End partial ', date_convert(res[1][3]) + datetime.timedelta(hours=time_zone) duration_end_partial = res[1][3] else: duration_end_partial = moon_set if moon_set > res[1][7] and res[1][7] > 0: end = (date_convert(res[1][7]) + datetime.timedelta(hours=time_zone)) duration_end = res[1][7] else: duration_end = moon_set Moon_set = (date_convert(moon_set) + datetime.timedelta(hours=time_zone)) duration_penumbral = (date_convert(duration_end) - date_convert(duration_start)) duration_umbral = (date_convert(duration_end_partial) - date_convert(duration_start_partial)) print 'Duration Total ', date_convert(duration_end_total) - date_convert(duration_start_total) eclipse_annualar = int('00001000', 2) central = res[0][0] & eclipse_annualar if central == 8: Type = 'Eclipse Annular' eclipse_partial = int('0010000', 2) central = res[0][0] & eclipse_partial if central == 16: Type = 'Eclipse Partial' Moon_rise = (date_convert(moon_rise) + datetime.timedelta(hours=time_zone)) if moon_rise < res[1][6]: start = (date_convert(res[1][6]) + datetime.timedelta(hours=time_zone)) duration_start = res[1][6] else: duration_start = moon_rise if moon_rise < res[1][2]: print 'Start partial', date_convert(res[1][2]) + datetime.timedelta(hours=time_zone) duration_start_partial = res[1][2] else: duration_start_partial = moon_rise maxi = (date_convert(res[1][0]) + datetime.timedelta(hours=time_zone)) if res[1][3] > 0 and moon_set > res[1][3]: print 'End partial ', date_convert(res[1][9]) + datetime.timedelta(hours=time_zone) duration_end_partial = res[1][3] else: duration_end_partial = moon_set if moon_set > res[1][7] and res[1][7] > 0: end = (date_convert(res[1][7]) + datetime.timedelta(hours=time_zone)) duration_end = res[1][7] else: duration_end = moon_set Moon_set = (date_convert(moon_set) + datetime.timedelta(hours=time_zone)) duration_penumbral = (date_convert(duration_end) - date_convert(duration_start)) duration_umbral = (date_convert(duration_end_partial) - date_convert(duration_start_partial)) eclipse_ann_total = int('0100000', 2) central = res[0][0] & eclipse_ann_total if central == 32: Type = 'Eclipse Penumbral' eclipse_ann_total = int('1000000', 2) central = res[0][0] & eclipse_ann_total if central == 64: Type = 'Eclipse Penumbral' Moon_rise = (date_convert(moon_rise) + datetime.timedelta(hours=time_zone)) if moon_rise < res[1][6]: start = (date_convert(res[1][6]) + datetime.timedelta(hours=time_zone)) duration_start = res[1][6] else: duration_start = moon_rise if moon_rise < res[1][2]: print 'Start partial', date_convert(res[1][2]) + datetime.timedelta(hours=time_zone) duration_start_partial = res[1][2] else: duration_start_partial = moon_rise maxi = (date_convert(res[1][0]) + datetime.timedelta(hours=time_zone)) if res[1][3] > 0 and moon_set > res[1][3]: print 'End partial ', date_convert(res[1][9]) + datetime.timedelta(hours=time_zone) duration_end_partial = res[1][3] else: duration_end_partial = moon_set if moon_set > res[1][7] and res[1][7] > 0: end = (date_convert(res[1][7]) + datetime.timedelta(hours=time_zone)) duration_end = res[1][7] else: duration_end = moon_set Moon_set = (date_convert(moon_set) + datetime.timedelta(hours=time_zone)) duration_penumbral = (date_convert(duration_end) - date_convert(duration_start)) #print 'Duration Umbral ', date_convert(duration_end_partial) - date_convert(duration_start_partial) moon_azm = ((res[2][4] + 180) % 360) moon_alt = res[2][5] pos_p = swe.calc_ut(res[1][0], 0) signs = birthchart.natal_planet_signs(pos_p) sun_pos = pos_p[0] sun_zodiac = constants.SIGN_ZODIAC[signs[0]] pos_p = swe.calc_ut(res[1][0], 1) signs = birthchart.natal_planet_signs(pos_p) moon_pos = pos_p[0] moon_zodiac = constants.SIGN_ZODIAC[signs[0]] soros_cycle = int(res_how[1][9]) soros_number = int(res_how[1][10]) magnitude_umbral = res_how[1][0] magnitude_penumbral = res_how[1][1] lunar_eclipse = {'soros_cycle' : soros_cycle, 'moon_rise' : str(Moon_rise), 'moon_set' : str(Moon_set), 'sun_pos' : sun_pos, 'sun_zodiac' : sun_zodiac, 'moon_pos' : moon_pos, 'moon_zodiac' : moon_zodiac, 'start' : str(start), 'max' : str(maxi), 'soros_number' : soros_number, 'magnitude_umbral' : magnitude_umbral, 'end' : str(end), 'Type' : Type, 'magnitude_penumbral' : magnitude_penumbral, 'duration_umbral' : str(duration_umbral), 'duration_penumbral' : str(duration_penumbral), 'moon_alt' : moon_alt, 'moon_azm' : moon_azm} return lunar_eclipse
def main(): city_name = sys.argv[1] latitude = sexastr2deci(sys.argv[2]) longitude = sexastr2deci(sys.argv[3]) tz = sys.argv[4] start_year = int(sys.argv[5]) year = start_year jd = swisseph.julday(year, 1, 1, 0) jd_start = jd if len(sys.argv) == 7: script = sys.argv[6] else: script = 'deva' #Default script is devanagari swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha sun_month_day = jd - get_last_dhanur_transit(jd, latitude, longitude) month_start_after_set = 0 template_file = open('cal_template_compre.tex') template_lines = template_file.readlines() for i in range(0, len(template_lines) - 3): print template_lines[i][:-1] samvatsara_id = (year - 1568) % 60 + 1 #distance from prabhava samvatsara_names = '%s–%s' % (year_names[script][samvatsara_id], year_names[script][(samvatsara_id % 60) + 1]) new_yr = mesha_sankranti[script] + '~(' + year_names[script][ (samvatsara_id % 60) + 1] + '-' + samvatsara[script] + ')' print '\\mbox{}' print '{\\font\\x="Candara" at 60 pt\\x %d\\\\[0.5cm]}' % year print '\\mbox{\\font\\x="Sanskrit 2003:script=deva" at 48 pt\\x %s}\\\\[0.5cm]' % samvatsara_names print '{\\font\\x="Candara" at 48 pt\\x \\uppercase{%s}\\\\[0.5cm]}' % city_name print '\hrule' #INITIALISE VARIABLES jd_sunrise = [None] * 368 jd_sunset = [None] * 368 jd_moonrise = [None] * 368 longitude_moon = [None] * 368 longitude_sun = [None] * 368 longitude_sun_set = [None] * 368 sun_month_id = [None] * 368 sun_month = [None] * 368 sun_month_rise = [None] * 368 moon_month = [None] * 368 month_data = [None] * 368 tithi_data_string = [None] * 368 tithi_sunrise = [None] * 368 nakshatram_data_string = [None] * 368 nakshatram_sunrise = [None] * 368 karanam_data_string = [None] * 368 karanam_sunrise = [None] * 368 yogam_data_string = [None] * 368 yogam_sunrise = [None] * 368 weekday = [None] * 368 sunrise = [None] * 368 sunset = [None] * 368 madhya = [None] * 368 rahu = [None] * 368 yama = [None] * 368 festival_day_list = {} festivals = [''] * 368 weekday_start = swisseph.day_of_week(jd) + 1 #swisseph has Mon = 0, non-intuitively! ################################################## #Compute all parameters -- latitude/longitude etc# ################################################## for d in range(-1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 local_time = pytz.timezone(tz).localize(datetime(y, m, dt, 6, 0, 0)) #checking @ 6am local - can we do any better? tz_off = datetime.utcoffset(local_time).seconds / 3600.0 #compute offset from UTC jd_sunrise[d + 1] = swisseph.rise_trans( jd_start=jd + 1, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] jd_sunset[d + 1] = swisseph.rise_trans( jd_start=jd + 1, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_SET | swisseph.BIT_DISC_CENTER)[1][0] jd_moonrise[d + 1] = swisseph.rise_trans( jd_start=jd + 1, body=swisseph.MOON, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] longitude_sun[d + 1] = swisseph.calc_ut( jd_sunrise[d + 1], swisseph.SUN)[0] - swisseph.get_ayanamsa( jd_sunrise[d + 1]) longitude_moon[d + 1] = swisseph.calc_ut( jd_sunrise[d + 1], swisseph.MOON)[0] - swisseph.get_ayanamsa( jd_sunrise[d + 1]) longitude_sun_set[d + 1] = swisseph.calc_ut( jd_sunset[d + 1], swisseph.SUN)[0] - swisseph.get_ayanamsa( jd_sunset[d + 1]) sun_month_id[d + 1] = int(1 + math.floor(( (longitude_sun_set[d + 1]) % 360) / 30.0)) sun_month[d + 1] = int(1 + math.floor(( (longitude_sun_set[d + 1]) % 360) / 30.0)) sun_month_rise[d + 1] = int(1 + math.floor(( (longitude_sun[d + 1]) % 360) / 30.0)) if (d <= 0): continue t_sunrise = (jd_sunrise[d] - jd) * 24.0 + tz_off t_sunset = (jd_sunset[d] - jd) * 24.0 + tz_off #Solar month calculations if month_start_after_set == 1: sun_month_day = 0 month_start_after_set = 0 if sun_month[d] != sun_month[d + 1]: sun_month_day = sun_month_day + 1 if sun_month[d] != sun_month_rise[d + 1]: month_start_after_set = 1 [_m, sun_month_end_time] = get_angam_data_string( masa_names[script], 30, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [0, 1], script) elif sun_month_rise[d] != sun_month[d]: #mAsa pirappu! #sun moves into next rAsi before sunset -- check rules! sun_month_day = 1 [_m, sun_month_end_time] = get_angam_data_string( masa_names[script], 30, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [0, 1], script) else: sun_month_day = sun_month_day + 1 sun_month_end_time = '' month_data[d] = '\\sunmonth{%s}{%d}{%s}' % (masa_names[script][ sun_month[d]], sun_month_day, sun_month_end_time) #KARADAYAN NOMBU -- easy to check here if sun_month_end_time != '': #month ends today if (sun_month[d] == 12 and sun_month_day == 1) or (sun_month[d] == 11 and sun_month_day != 1): festival_day_list[karadayan_nombu[script]] = [d] #Sunrise/sunset and related stuff (like rahu, yama) [rhs, rms, rss] = deci2sexa( t_sunrise) #rise hour sun, rise minute sun, rise sec sun [shs, sms, sss] = deci2sexa(t_sunset) length_of_day = t_sunset - t_sunrise yamagandam_start = t_sunrise + (1 / 8.0) * ( yamagandam_octets[weekday] - 1) * length_of_day yamagandam_end = yamagandam_start + (1 / 8.0) * length_of_day rahukalam_start = t_sunrise + (1 / 8.0) * (rahukalam_octets[weekday] - 1) * length_of_day rahukalam_end = rahukalam_start + (1 / 8.0) * length_of_day madhyahnikam_start = t_sunrise + (1 / 5.0) * length_of_day sunrise[d] = '%02d:%02d' % (rhs, rms) sunset[d] = '%02d:%02d' % (shs, sms) madhya[d] = print_time(madhyahnikam_start) rahu[d] = '%s--%s' % (print_time(rahukalam_start), print_time(rahukalam_end)) yama[d] = '%s--%s' % (print_time(yamagandam_start), print_time(yamagandam_end)) [tithi_sunrise[d], tithi_data_string[d]] = get_angam_data_string( tithi_names[script], 12, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, -1], script) [nakshatram_sunrise[d], nakshatram_data_string[d]] = get_angam_data_string( nakshatra_names[script], (360.0 / 27.0), jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, 0], script) [karanam_sunrise[d], karanam_data_string[d]] = get_angam_data_string( karanam_names[script], 6, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, -1], script) [yogam_sunrise[d], yogam_data_string[d]] = get_angam_data_string( yogam_names[script], (360.0 / 27.0), jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, 1], script) #ASSIGN MOON MONTHS last_month_change = 1 last_moon_month = None for d in range(1, 367): #Assign moon_month for each day if (tithi_sunrise[d] == 1): for i in range(last_month_change, d): #print '%%#Setting moon_month to sun_month_id, for i=%d:%d to %d' %(last_month_change,d-1,sun_month_id[d]) if (sun_month_id[d] == last_moon_month): moon_month[i] = sun_month_id[d] % 12 + 0.5 else: moon_month[i] = sun_month_id[d] last_month_change = d last_moon_month = sun_month_id[d] elif (tithi_sunrise[d] == 2 and tithi_sunrise[d - 1] == 30): #prathama tithi was never seen @ sunrise for i in range(last_month_change, d): #print '%%@Setting moon_month to sun_month_id, for i=%d:%d to %d (last month = %d)' %(last_month_change,d-1,sun_month_id[d],last_moon_month) if (sun_month_id[d - 1] == last_moon_month): moon_month[i] = sun_month_id[d - 1] % 12 + 0.5 else: moon_month[i] = sun_month_id[d - 1] last_month_change = d last_moon_month = sun_month_id[d - 1] for i in range(last_month_change, 367): moon_month[i] = sun_month_id[last_month_change - 1] + 1 #for d in range(1,367): #jd = jd_start-1+d #[y,m,dt,t] = swisseph.revjul(jd) #print '%%#%02d-%02d-%4d: %3d:%s (sunrise tithi=%d) {%s}' % (dt,m,y,d,moon_month[d],tithi_sunrise[d],tithi_data_string[d]) log_file = open('cal_log_%4d.txt' % year, 'w') for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) log_data = '%02d-%02d-%4d\t[%3d]\tsun_rashi=%8.3f\ttithi=%8.3f\tsun_month=%2d\tmoon_month=%4.1f\n' % ( dt, m, y, d, (longitude_sun_set[d] % 360) / 30.0, get_angam_float(jd_sunrise[d], 12.0, [1, -1]), sun_month[d], moon_month[d]) log_file.write(log_data) #PRINT CALENDAR for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 ################## #Festival details# ################## ###--- MONTHLY VRATAMS ---### #EKADASHI Vratam if tithi_sunrise[d] == 11 or tithi_sunrise[ d] == 12: #One of two consecutive tithis must appear @ sunrise! #check for shukla ekadashi[script] if (tithi_sunrise[d] == 11 and tithi_sunrise[d + 1] == 11): festivals[d + 1] = sarva[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) #moon_month[d] or [d+1]? if moon_month[d + 1] == 4: festivals[d + 1] += '\\\\' + chaturmasya_start[script] if moon_month[d + 1] == 8: festivals[d + 1] += '\\\\' + chaturmasya_end[script] elif (tithi_sunrise[d] == 11 and tithi_sunrise[d + 1] != 11): #Check dashami end time to decide for whether this is sarva[script]/smartha[script] tithi_arunodayam = get_tithi( jd_sunrise[d] - (1 / 15.0) * (jd_sunrise[d] - jd_sunrise[d - 1]) ) #Two muhurtams is 1/15 of day-length if tithi_arunodayam == 10: festivals[d] = smartha[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) festivals[d + 1] = vaishnava[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) if moon_month[d] == 4: festivals[d] += '\\\\' + chaturmasya_start[script] if moon_month[d] == 8: festivals[d] += '\\\\' + chaturmasya_end[script] else: festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) if moon_month[d] == 4: festivals[d] += '\\\\' + chaturmasya_start[script] if moon_month[d] == 8: festivals[d] += '\\\\' + chaturmasya_end[script] elif (tithi_sunrise[d - 1] != 11 and tithi_sunrise[d] == 12): festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) if moon_month[d] == 4: festivals[d] += '\\\\' + chaturmasya_start[script] if moon_month[d] == 8: festivals[d] += '\\\\' + chaturmasya_end[script] if tithi_sunrise[d] == 26 or tithi_sunrise[ d] == 27: #One of two consecutive tithis must appear @ sunrise! #check for krishna ekadashi[script] if (tithi_sunrise[d] == 26 and tithi_sunrise[d + 1] == 26): festivals[d + 1] = sarva[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) #moon_month[d] or [d+1]? elif (tithi_sunrise[d] == 26 and tithi_sunrise[d + 1] != 26): #Check dashami end time to decide for whether this is sarva[script]/smartha[script] tithi_arunodayam = get_tithi( jd_sunrise[d] - (1 / 15.0) * (jd_sunrise[d] - jd_sunrise[d - 1]) ) #Two muhurtams is 1/15 of day-length if tithi_arunodayam == 25: festivals[d] = smartha[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) festivals[d + 1] = vaishnava[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) else: festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) elif (tithi_sunrise[d - 1] != 26 and tithi_sunrise[d] == 27): festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) #PRADOSHA Vratam if tithi_sunrise[d] == 12 or tithi_sunrise[d] == 13: ldiff_set = (swisseph.calc_ut(jd_sunset[d], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d], swisseph.SUN)[0]) % 360 ldiff_set_tmrw = ( swisseph.calc_ut(jd_sunset[d + 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d + 1], swisseph.SUN)[0]) % 360 tithi_sunset = int(1 + math.floor(ldiff_set / 12.0)) tithi_sunset_tmrw = int(1 + math.floor(ldiff_set_tmrw / 12.0)) if tithi_sunset <= 13 and tithi_sunset_tmrw != 13: festivals[d] = pradosham[script] elif tithi_sunset_tmrw == 13: festivals[d + 1] = pradosham[script] if tithi_sunrise[d] == 27 or tithi_sunrise[d] == 28: ldiff_set = (swisseph.calc_ut(jd_sunset[d], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d], swisseph.SUN)[0]) % 360 ldiff_set_tmrw = ( swisseph.calc_ut(jd_sunset[d + 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d + 1], swisseph.SUN)[0]) % 360 tithi_sunset = int(1 + math.floor(ldiff_set / 12.0)) tithi_sunset_tmrw = int(1 + math.floor(ldiff_set_tmrw / 12.0)) if tithi_sunset <= 28 and tithi_sunset_tmrw != 28: festivals[d] = pradosham[script] elif tithi_sunset_tmrw == 28: festivals[d + 1] = pradosham[script] #SANKATAHARA chaturthi[script] if tithi_sunrise[d] == 18 or tithi_sunrise[d] == 19: ldiff_moonrise_yest = ( swisseph.calc_ut(jd_moonrise[d - 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_moonrise[d - 1], swisseph.SUN)[0]) % 360 ldiff_moonrise = ( swisseph.calc_ut(jd_moonrise[d], swisseph.MOON)[0] - swisseph.calc_ut(jd_moonrise[d], swisseph.SUN)[0]) % 360 ldiff_moonrise_tmrw = ( swisseph.calc_ut(jd_moonrise[d + 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_moonrise[d + 1], swisseph.SUN)[0]) % 360 tithi_moonrise_yest = int(1 + math.floor(ldiff_moonrise_yest / 12.0)) tithi_moonrise = int(1 + math.floor(ldiff_moonrise / 12.0)) tithi_moonrise_tmrw = int(1 + math.floor(ldiff_moonrise_tmrw / 12.0)) if tithi_moonrise == 19: if tithi_moonrise_yest != 19: #otherwise yesterday would have already been assigned festivals[d] = chaturthi[script] if moon_month[d] == 5: #shravana krishna chaturthi[script] festivals[d] = maha[script] + festivals[d] elif tithi_moonrise_tmrw == 19: festivals[d + 1] = chaturthi[script] if moon_month[ d] == 5: #moon_month[d] and[d+1] are same, so checking [d] is enough festivals[d + 1] = maha[script] + festivals[d + 1] #SHASHTHI Vratam if tithi_sunrise[d] == 5 or tithi_sunrise[d] == 6: if tithi_sunrise[d] == 6 or (tithi_sunrise[d] == 5 and tithi_sunrise[d + 1] == 7): if tithi_sunrise[ d - 1] != 6: #otherwise yesterday would have already been assigned festivals[d] = shashthi[script] if moon_month[d] == 8: #kArtika krishna shashthi[script] festivals[d] = skanda[script] + festivals[d] elif tithi_sunrise[d + 1] == 6: festivals[d + 1] = shashthi[script] if moon_month[ d] == 8: #moon_month[d] and[d+1] are same, so checking [d] is enough festivals[d + 1] = skanda[script] + festivals[d + 1] ###--- OTHER (MAJOR) FESTIVALS ---### #type of month | month number | type of angam (tithi|nakshatram) | angam number | min_t cut off for considering prev day (without sunrise_angam) as festival date purvaviddha_rules = { akshaya_tritiya[script]: ['moon_month', 2, 'tithi', 3, 0], chitra_purnima[script]: ['sun_month', 1, 'tithi', 15, 0], durgashtami[script]: ['moon_month', 7, 'tithi', 8, 0], mahanavami[script]: ['moon_month', 7, 'tithi', 9, 0], vijayadashami[script]: ['moon_month', 7, 'tithi', 10, 0], dipavali[script]: ['moon_month', 7, 'tithi', 29, 0], shankara_jayanti[script]: ['moon_month', 2, 'tithi', 5, 0], yajur_upakarma[script]: ['moon_month', 5, 'tithi', 15, 0], rg_upakarma[script]: ['moon_month', 5, 'nakshatram', 22, 0], sama_upakarma[script]: ['sun_month', 5, 'nakshatram', 13, 0], rishi_panchami[script]: ['moon_month', 6, 'tithi', 5, 0], ananta_chaturdashi[script]: ['moon_month', 6, 'tithi', 14, 0], mahalaya_paksham[script]: ['moon_month', 6, 'tithi', 16, 0], hanumat_jayanti[script]: ['sun_month', 9, 'tithi', 30, 0], ardra_darshanam[script]: ['sun_month', 9, 'nakshatram', 6, 0], ratha_saptami[script]: ['sun_month', 10, 'tithi', 7, 0], goda_jayanti[script]: ['sun_month', 4, 'nakshatram', 11, 0], adi_krittika[script]: ['sun_month', 4, 'nakshatram', 3, 0], phalguni_uttaram[script]: ['sun_month', 12, 'nakshatram', 12, 4], mahalaya_amavasya[script]: ['moon_month', 6, 'tithi', 30, 0], uma_maheshvara_vratam[script]: ['moon_month', 6, 'tithi', 15, 0] } for x in iter(purvaviddha_rules.keys()): rule = purvaviddha_rules[x] if rule[0] == 'moon_month': if moon_month[d] == rule[1]: if rule[2] == 'tithi': fday = get_festival_day_purvaviddha( rule[3], tithi_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_tithi, rule[4]) elif rule[2] == 'nakshatram': fday = get_festival_day_purvaviddha( rule[3], nakshatram_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_nakshatram, rule[4]) if fday is not None: if festival_day_list.has_key(x): if festival_day_list[x][0] != fday: #Second occurrence of a festival within a Gregorian calendar year festival_day_list[x] = [ festival_day_list[x][0], fday ] else: festival_day_list[x] = [fday] elif rule[0] == 'sun_month': if sun_month[d] == rule[1]: if rule[2] == 'tithi': fday = get_festival_day_purvaviddha( rule[3], tithi_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_tithi, rule[4]) elif rule[2] == 'nakshatram': fday = get_festival_day_purvaviddha( rule[3], nakshatram_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_nakshatram, rule[4]) if fday is not None: if festival_day_list.has_key(x): if festival_day_list[x][0] != fday: #Second occurrence of a festival within a Gregorian calendar year festival_day_list[x] = [ festival_day_list[x][0], fday ] else: festival_day_list[x] = [fday] else: print 'Error; unknown string in rule: %s' % (rule[0]) return #NAVARATRI START if moon_month[d] == 7 and moon_month[d - 1] == 6: festival_day_list[navaratri_start[script]] = [d] #PONGAL/AYANAM if sun_month[d] == 10 and sun_month[d - 1] == 9: festival_day_list[uttarayanam[script]] = [d] if sun_month[d] == 4 and sun_month[d - 1] == 3: festival_day_list[dakshinayanam[script]] = [d] if sun_month[d] == 1 and sun_month[d - 1] == 12: festival_day_list[new_yr] = [d] if moon_month[d] == 1 and moon_month[d - 1] != 1: festival_day_list[yugadi[script]] = [d] #SHRIRAMANAVAMI if moon_month[d] == 1: if tithi_sunrise[d] == 8 or tithi_sunrise[d] == 9: t_11 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (2.0 / 5.0)) #madhyahna1 start t_12 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (3.0 / 5.0)) #madhyahna1 end t_21 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (2.0 / 5.0)) #madhyahna2 start t_22 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (3.0 / 5.0)) #madhyahna2 end if t_11 == 9 or t_12 == 9: if t_21 == 9 or t_22 == 9: festival_day_list[ramanavami[script]] = [d + 1] else: festival_day_list[ramanavami[script]] = [d] #JANMASHTAMI if moon_month[d] == 5: if tithi_sunrise[d] == 22 or tithi_sunrise[d] == 23: t_11 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (7.0 / 15.0)) #nishita1 start t_12 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (8.0 / 15.0)) #nishita1 end #t_11 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(2.0/5.0))#madhyaratri1 start #t_12 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(3.0/5.0))#madhyaratri1 end t_21 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (7.0 / 15.0)) #nishita2 start t_22 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (8.0 / 15.0)) #nishita2 end #t_21 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(2.0/5.0))#madhyaratri2 start #t_22 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(3.0/5.0))#madhyaratri2 end if t_11 == 23 or t_12 == 23: if t_21 == 23 or t_22 == 23: festival_day_list[janmashtami[script]] = [d + 1] else: festival_day_list[janmashtami[script]] = [d] #SHIVARATRI if moon_month[d] == 11: if tithi_sunrise[d] == 28 or tithi_sunrise[d] == 29: t_11 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (7.0 / 15.0)) #nishita1 start t_12 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (8.0 / 15.0)) #nishita1 end t_21 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (7.0 / 15.0)) #nishita2 start t_22 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (8.0 / 15.0)) #nishita2 end if t_11 == 29 or t_12 == 29: if t_21 == 29 or t_22 == 29: festival_day_list[shivaratri[script]] = [d + 1] else: festival_day_list[shivaratri[script]] = [d] #VINAYAKA CHATURTHI if moon_month[d] == 6: if tithi_sunrise[d] == 3 or tithi_sunrise[d] == 4: t_11 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (2.0 / 5.0)) #madhyahna1 start t_12 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (3.0 / 5.0)) #madhyahna1 end t_21 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (2.0 / 5.0)) #madhyahna2 start t_22 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (3.0 / 5.0)) #madhyahna2 end if t_11 == 4 or t_12 == 4: if t_21 == 4 or t_22 == 4: festival_day_list[vchaturthi[script]] = [d + 1] else: festival_day_list[vchaturthi[script]] = [d] #Add saved festivals festival_day_list[gayatri_japam[script]] = [ festival_day_list[yajur_upakarma[script]][0] + 1 ] festival_day_list[varalakshmi_vratam[script]] = [ festival_day_list[yajur_upakarma[script]][0] - ((weekday_start - 1 + festival_day_list[yajur_upakarma[script]][0] - 5) % 7) ] #KARADAYAN_NOMBU for x in iter(festival_day_list.keys()): for j in range(0, len(festival_day_list[x])): if festivals[festival_day_list[x][j]] != '': festivals[festival_day_list[x][j]] += '\\\\' festivals[festival_day_list[x][j]] += x ###--- ECLIPSES ---### ###--- LUNAR ECLIPSES ---### swisseph.set_topo(lon=longitude, lat=latitude, alt=0.0) #Set location jd = jd_start while 1: next_ecl_lun = swisseph.lun_eclipse_when(jd) jd = next_ecl_lun[1][0] + (tz_off / 24.0) jd_ecl_lun_start = next_ecl_lun[1][2] + (tz_off / 24.0) jd_ecl_lun_end = next_ecl_lun[1][3] + (tz_off / 24.0) ecl_y = swisseph.revjul( jd - 1 )[0] # -1 is to not miss an eclipse that occurs after sunset on 31-Dec! if ecl_y != start_year: break else: ecl_lun_start = swisseph.revjul(jd_ecl_lun_start)[3] ecl_lun_end = swisseph.revjul(jd_ecl_lun_end)[3] if (jd_ecl_lun_start - (tz_off / 24.0)) == 0.0 or (jd_ecl_lun_end - (tz_off / 24.0)) == 0.0: jd = jd + 20 #Move towards the next eclipse... at least the next full moon (>=25 days away) continue fday = int(math.floor(jd_ecl_lun_start) - math.floor(jd_start) + 1) #print '%%',jd,fday,jd_sunrise[fday],jd_sunrise[fday-1] if (jd < (jd_sunrise[fday] + tz_off / 24.0)): fday -= 1 if ecl_lun_start < swisseph.revjul(jd_sunrise[fday + 1] + tz_off / 24.0)[3]: ecl_lun_start += 24 #print '%%',jd,fday,jd_sunrise[fday],jd_sunrise[fday-1],ecl_lun_start, ecl_lun_end jd_moonrise_ecl_day = swisseph.rise_trans( jd_start=jd_sunrise[fday], body=swisseph.MOON, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] + (tz_off / 24.0) jd_moonset_ecl_day = swisseph.rise_trans( jd_start=jd_moonrise_ecl_day, body=swisseph.MOON, lon=longitude, lat=latitude, rsmi=swisseph.CALC_SET | swisseph.BIT_DISC_CENTER)[1][0] + (tz_off / 24.0) #if jd_ecl_lun_start<(jd_sunrise[fday]+(tz_off/24.0)): if ecl_lun_end < ecl_lun_start: ecl_lun_end += 24 #print '%%', (jd_ecl_lun_start), (jd_ecl_lun_end), (jd_moonrise_ecl_day), (jd_moonset_ecl_day) #print '%%', swisseph.revjul(jd_ecl_lun_start), swisseph.revjul(jd_ecl_lun_end), swisseph.revjul(jd_moonrise_ecl_day), swisseph.revjul(jd_moonset_ecl_day) if jd_ecl_lun_end < jd_moonrise_ecl_day or jd_ecl_lun_start > jd_moonset_ecl_day: jd = jd + 20 #Move towards the next eclipse... at least the next full moon (>=25 days away) continue lun_ecl_str = chandra_grahanam[script] + '~\\textsf{' + print_time2( ecl_lun_start) + '}{\\RIGHTarrow}\\textsf{' + print_time2( ecl_lun_end) + '}' if festivals[fday] != '': festivals[fday] += '\\\\' festivals[fday] += lun_ecl_str jd = jd + 20 ###--- SOLAR ECLIPSES ---### swisseph.set_topo(lon=longitude, lat=latitude, alt=0.0) #Set location jd = jd_start while 1: next_ecl_sol = swisseph.sol_eclipse_when_loc(julday=jd, lon=longitude, lat=latitude) jd = next_ecl_sol[1][0] + (tz_off / 24.0) jd_ecl_sol_start = next_ecl_sol[1][1] + (tz_off / 24.0) jd_ecl_sol_end = next_ecl_sol[1][4] + (tz_off / 24.0) ecl_y = swisseph.revjul( jd - 1 )[0] # -1 is to not miss an eclipse that occurs after sunset on 31-Dec! if ecl_y != start_year: break else: #print '%%', fday, (jd_ecl_sol_start), (jd_ecl_sol_end), (jd_sunrise[fday]) #print '%%', swisseph.revjul(jd_ecl_sol_start), swisseph.revjul(jd_ecl_sol_end), swisseph.revjul(jd_sunrise[fday]) fday = int(math.floor(jd) - math.floor(jd_start) + 1) if (jd < (jd_sunrise[fday] + tz_off / 24.0)): fday -= 1 #print '%%', fday, (jd_ecl_sol_start), (jd_ecl_sol_end), (jd_sunrise[fday]) #print '%%', swisseph.revjul(jd_ecl_sol_start), swisseph.revjul(jd_ecl_sol_end), swisseph.revjul(jd_sunrise[fday]) ecl_sol_start = swisseph.revjul(jd_ecl_sol_start)[3] ecl_sol_end = swisseph.revjul(jd_ecl_sol_end)[3] if (jd_ecl_sol_start - (tz_off / 24.0)) == 0.0 or ( jd_ecl_sol_end - (tz_off / 24.0) ) == 0.0: # or jd_ecl_end<jd_sunrise[fday] or jd_ecl_start>jd_sunset[fday]: jd = jd + 20 #Move towards the next eclipse... at least the next new moon (>=25 days away) continue if ecl_sol_end < ecl_sol_start: ecl_sol_end += 24 sol_ecl_str = surya_grahanam[script] + '~\\textsf{' + print_time2( ecl_sol_start) + '}{\\RIGHTarrow}\\textsf{' + print_time2( ecl_sol_end) + '}' if festivals[fday] != '': festivals[fday] += '\\\\' festivals[fday] += sol_ecl_str jd = jd + 20 ###--- FESTIVAL ADDITIONS COMPLETE ---### ###--- PRINT LIST OF FESTIVALS (Page 2) ---### if script == 'en': cal = Calendar() print '\\newpage' print '\\centerline {\\LARGE {{%s}}}\\mbox{}\\\\[2cm]' % list_of_festivals[ script] print '\\begin{center}' print '\\begin{minipage}[t]{0.3\\linewidth}' print '\\begin{center}' print '\\begin{tabular}{>{\\sffamily}r>{\\sffamily}r>{\\sffamily}cp{6cm}}' mlast = 1 for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 if festivals[d] != '': if m != mlast: mlast = m #print '\\hline\\\\' print '\\\\' if m == 5 or m == 9: print '\\end{tabular}' print '\\end{center}' print '\\end{minipage}\hspace{1cm}%' print '\\begin{minipage}[t]{0.3\\linewidth}' print '\\begin{center}' print '\\begin{tabular}{>{\\sffamily}r>{\\sffamily}l>{\\sffamily}cp{6cm}}' print '%s & %s & %s & {\\raggedright %s} \\\\' % ( MON[m], dt, WDAY[weekday], festivals[d]) if script == 'en': event = Event() event.add('summary', festivals[d]) event.add('dtstart', datetime(y, m, dt)) event.add('dtend', datetime(y, m, dt)) cal.add_component(event) if m == 12 and dt == 31: break print '\\end{tabular}' print '\\end{center}' print '\\end{minipage}' print '\\end{center}' print '\\clearpage' if script == 'en': cal_fname = '%s-%4d.ics' % (city_name, start_year) cal_file = open(cal_fname, 'w') cal_file.write(cal.as_string()) cal_file.close() #Layout calendar in LATeX format #We use a separate loop here, because of festivals like varalakshmi #vratam, for which we backtrack to the previous friday from yajur #upakarma and change the list of festivals! for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 if dt == 1: if m > 1: if weekday != 0: #Space till Sunday for i in range(weekday, 6): print "{} &" print "\\\\ \hline" print '\end{tabular}' print '\n\n' #Begin tabular print '\\begin{tabular}{|c|c|c|c|c|c|c|}' print '\multicolumn{7}{c}{\Large \\bfseries \sffamily %s %s}\\\\[3mm]' % ( month[m], y) print '\hline' print '\\textbf{\\textsf{SUN}} & \\textbf{\\textsf{MON}} & \\textbf{\\textsf{TUE}} & \\textbf{\\textsf{WED}} & \\textbf{\\textsf{THU}} & \\textbf{\\textsf{FRI}} & \\textbf{\\textsf{SAT}} \\\\ \hline' #print '\\textbf{भानु} & \\textbf{इन्दु} & \\textbf{भौम} & \\textbf{बुध} & \\textbf{गुरु} & \\textbf{भृगु} & \\textbf{स्थिर} \\\\ \hline' #Blanks for previous weekdays for i in range(0, weekday): print "{} &" print '\caldata{\\textcolor{%s}{%s}}{%s{%s}}{\\sundata{%s}{%s}{%s}}{\\tnyk{%s}{%s}{%s}{%s}}{\\rahuyama{%s}{%s}}{%s} ' % ( daycol[weekday], dt, month_data[d], get_chandra_masa(moon_month[d], chandra_masa_names, script), sunrise[d], sunset[d], madhya[d], tithi_data_string[d], nakshatram_data_string[d], yogam_data_string[d], karanam_data_string[d], rahu[d], yama[d], festivals[d]) if weekday == 6: print "\\\\ \hline" else: print "&" if m == 12 and dt == 31: break # For debugging specific dates #if m==4 and dt==10: # break for i in range(weekday + 1, 6): print "{} &" if weekday != 6: print "\\\\ \hline" print '\end{tabular}' print '\n\n' print template_lines[-2][:-1] print template_lines[-1][:-1]
def next_rise(self): if self.observer is None: raise ValueError('Rise/set times require observer longitude and latitude') jd = sweph.rise_trans(self.jd, self.id, self.observer.long, self.observer.lat, rsmi=sweph.CALC_RISE)[1][0] return PlanetEvent('%s rises' % self.name(), jd)
def last_set(self): if self.observer is None: raise ValueError('Rise/set times require observer longitude and latitude') jd = sweph.rise_trans(self.jd-1, self.id, self.observer.long, self.observer.lat, rsmi=2)[1][0] return PlanetEvent('%s sets' % self.name(), jd)
def main(): city_name = sys.argv[1] latitude = sexastr2deci(sys.argv[2]) longitude = sexastr2deci(sys.argv[3]) tz = sys.argv[4] start_year = int(sys.argv[5]) year = start_year jd=swisseph.julday(year,1,1,0) jd_start=jd if len(sys.argv)==7: script = sys.argv[6] else: script = 'deva' #Default script is devanagari swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha sun_month_day = jd-get_last_dhanur_transit(jd,latitude,longitude) month_start_after_set = 0 template_file=open('cal_template_compre.tex') template_lines=template_file.readlines() for i in range(0,len(template_lines)-3): print template_lines[i][:-1] samvatsara_id = (year - 1568)%60 + 1; #distance from prabhava samvatsara_names = '%s–%s' % (year_names[script][samvatsara_id], year_names[script][(samvatsara_id%60)+1]) new_yr=mesha_sankranti[script]+'~('+year_names[script][(samvatsara_id%60)+1]+'-'+samvatsara[script]+')' print '\\mbox{}' print '{\\font\\x="Candara" at 60 pt\\x %d\\\\[0.5cm]}' % year print '\\mbox{\\font\\x="Sanskrit 2003:script=deva" at 48 pt\\x %s}\\\\[0.5cm]' % samvatsara_names print '{\\font\\x="Candara" at 48 pt\\x \\uppercase{%s}\\\\[0.5cm]}' % city_name print '\hrule' #INITIALISE VARIABLES jd_sunrise=[None]*368 jd_sunset=[None]*368 jd_moonrise=[None]*368 longitude_moon=[None]*368 longitude_sun=[None]*368 longitude_sun_set=[None]*368 sun_month_id=[None]*368 sun_month=[None]*368 sun_month_rise=[None]*368 moon_month=[None]*368 month_data=[None]*368 tithi_data_string=[None]*368 tithi_sunrise=[None]*368 nakshatram_data_string=[None]*368 nakshatram_sunrise=[None]*368 karanam_data_string=[None]*368 karanam_sunrise=[None]*368 yogam_data_string=[None]*368 yogam_sunrise=[None]*368 weekday=[None]*368 sunrise=[None]*368 sunset=[None]*368 madhya=[None]*368 rahu=[None]*368 yama=[None]*368 festival_day_list={} festivals=['']*368 weekday_start=swisseph.day_of_week(jd)+1 #swisseph has Mon = 0, non-intuitively! ################################################## #Compute all parameters -- latitude/longitude etc# ################################################## for d in range(-1,367): jd = jd_start-1+d [y,m,dt,t] = swisseph.revjul(jd) weekday = (weekday_start -1 + d)%7 local_time = pytz.timezone(tz).localize(datetime(y, m, dt, 6, 0, 0)) #checking @ 6am local - can we do any better? tz_off=datetime.utcoffset(local_time).seconds/3600.0 #compute offset from UTC jd_sunrise[d+1]=swisseph.rise_trans(jd_start=jd+1,body=swisseph.SUN, lon=longitude,lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0] jd_sunset[d+1]=swisseph.rise_trans(jd_start=jd+1,body=swisseph.SUN, lon=longitude,lat=latitude,rsmi=swisseph.CALC_SET|swisseph.BIT_DISC_CENTER)[1][0] jd_moonrise[d+1]=swisseph.rise_trans(jd_start=jd+1,body=swisseph.MOON, lon=longitude,lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0] longitude_sun[d+1]=swisseph.calc_ut(jd_sunrise[d+1],swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_sunrise[d+1]) longitude_moon[d+1]=swisseph.calc_ut(jd_sunrise[d+1],swisseph.MOON)[0]-swisseph.get_ayanamsa(jd_sunrise[d+1]) longitude_sun_set[d+1]=swisseph.calc_ut(jd_sunset[d+1],swisseph.SUN)[0]-swisseph.get_ayanamsa(jd_sunset[d+1]) sun_month_id[d+1] = int(1+math.floor(((longitude_sun_set[d+1])%360)/30.0)) sun_month[d+1] = int(1+math.floor(((longitude_sun_set[d+1])%360)/30.0)) sun_month_rise[d+1] = int(1+math.floor(((longitude_sun[d+1])%360)/30.0)) if(d<=0): continue t_sunrise=(jd_sunrise[d]-jd)*24.0+tz_off t_sunset=(jd_sunset[d]-jd)*24.0+tz_off #Solar month calculations if month_start_after_set==1: sun_month_day = 0 month_start_after_set = 0 if sun_month[d]!=sun_month[d+1]: sun_month_day = sun_month_day + 1 if sun_month[d]!=sun_month_rise[d+1]: month_start_after_set=1 [_m,sun_month_end_time] = get_angam_data_string(masa_names[script], 30, jd_sunrise[d], jd_sunrise[d+1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d+1], longitude_sun[d+1], [0,1], script) elif sun_month_rise[d]!=sun_month[d]: #mAsa pirappu! #sun moves into next rAsi before sunset -- check rules! sun_month_day = 1 [_m,sun_month_end_time] = get_angam_data_string(masa_names[script], 30, jd_sunrise[d], jd_sunrise[d+1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d+1], longitude_sun[d+1], [0,1], script) else: sun_month_day = sun_month_day + 1 sun_month_end_time = '' month_data[d] = '\\sunmonth{%s}{%d}{%s}' % (masa_names[script][sun_month[d]],sun_month_day,sun_month_end_time) #KARADAYAN NOMBU -- easy to check here if sun_month_end_time !='': #month ends today if (sun_month[d]==12 and sun_month_day==1) or (sun_month[d]==11 and sun_month_day!=1): festival_day_list[karadayan_nombu[script]] = [d] #KOODARA VALLI -- easy to check here if sun_month[d]==9 and sun_month_day==27: festival_day_list[koodaravalli[script]]= [d] #Sunrise/sunset and related stuff (like rahu, yama) [rhs, rms, rss] = deci2sexa(t_sunrise) #rise hour sun, rise minute sun, rise sec sun [shs, sms, sss] = deci2sexa(t_sunset) length_of_day = t_sunset-t_sunrise yamagandam_start = t_sunrise + (1/8.0)*(yamagandam_octets[weekday]-1)*length_of_day yamagandam_end = yamagandam_start + (1/8.0)*length_of_day rahukalam_start = t_sunrise + (1/8.0)*(rahukalam_octets[weekday]-1)*length_of_day rahukalam_end = rahukalam_start + (1/8.0)*length_of_day madhyahnikam_start = t_sunrise + (1/5.0)*length_of_day sunrise[d] = '%02d:%02d' % (rhs,rms) sunset[d] = '%02d:%02d' % (shs,sms) madhya[d] = print_time(madhyahnikam_start) rahu[d] = '%s--%s' % (print_time(rahukalam_start), print_time(rahukalam_end)) yama[d] = '%s--%s' % (print_time(yamagandam_start),print_time(yamagandam_end)) [tithi_sunrise[d],tithi_data_string[d]]=get_angam_data_string(tithi_names[script], 12, jd_sunrise[d], jd_sunrise[d+1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d+1], longitude_sun[d+1], [1,-1], script) [nakshatram_sunrise[d], nakshatram_data_string[d]]=get_angam_data_string(nakshatra_names[script], (360.0/27.0), jd_sunrise[d], jd_sunrise[d+1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d+1], longitude_sun[d+1], [1,0], script) [karanam_sunrise[d],karanam_data_string[d]]=get_angam_data_string(karanam_names[script], 6, jd_sunrise[d], jd_sunrise[d+1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d+1], longitude_sun[d+1], [1,-1], script) [yogam_sunrise[d],yogam_data_string[d]]=get_angam_data_string(yogam_names[script], (360.0/27.0), jd_sunrise[d], jd_sunrise[d+1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d+1], longitude_sun[d+1], [1,1], script) #ASSIGN MOON MONTHS last_month_change = 1 last_moon_month = None for d in range(1,367): #Assign moon_month for each day if(tithi_sunrise[d]==1): for i in range(last_month_change,d): #print '%%#Setting moon_month to sun_month_id, for i=%d:%d to %d' %(last_month_change,d-1,sun_month_id[d]) if (sun_month_id[d]==last_moon_month): moon_month[i] = sun_month_id[d]%12 + 0.5 else: moon_month[i] = sun_month_id[d] last_month_change = d last_moon_month = sun_month_id[d] elif(tithi_sunrise[d]==2 and tithi_sunrise[d-1]==30): #prathama tithi was never seen @ sunrise for i in range(last_month_change,d): #print '%%@Setting moon_month to sun_month_id, for i=%d:%d to %d (last month = %d)' %(last_month_change,d-1,sun_month_id[d],last_moon_month) if (sun_month_id[d-1]==last_moon_month): moon_month[i] = sun_month_id[d-1]%12 + 0.5 else: moon_month[i] = sun_month_id[d-1] last_month_change = d last_moon_month = sun_month_id[d-1] for i in range(last_month_change,367): moon_month[i]=sun_month_id[last_month_change-1]+1 #for d in range(1,367): #jd = jd_start-1+d #[y,m,dt,t] = swisseph.revjul(jd) #print '%%#%02d-%02d-%4d: %3d:%s (sunrise tithi=%d) {%s}' % (dt,m,y,d,moon_month[d],tithi_sunrise[d],tithi_data_string[d]) log_file=open('cal_log_%4d.txt' % year,'w') for d in range(1,367): jd = jd_start-1+d [y,m,dt,t] = swisseph.revjul(jd) log_data = '%02d-%02d-%4d\t[%3d]\tsun_rashi=%8.3f\ttithi=%8.3f\tsun_month=%2d\tmoon_month=%4.1f\n' % (dt,m,y,d,(longitude_sun_set[d]%360)/30.0,get_angam_float(jd_sunrise[d],12.0,[1,-1]),sun_month[d],moon_month[d]) log_file.write(log_data) #PRINT CALENDAR for d in range(1,367): jd = jd_start-1+d [y,m,dt,t] = swisseph.revjul(jd) weekday = (weekday_start -1 + d)%7 ################## #Festival details# ################## ###--- MONTHLY VRATAMS ---### #EKADASHI Vratam if tithi_sunrise[d]==11 or tithi_sunrise[d]==12: #One of two consecutive tithis must appear @ sunrise! #check for shukla ekadashi if (tithi_sunrise[d]==11 and tithi_sunrise[d+1]==11): festivals[d+1]=sarva[script]+'~'+get_ekadashi_name(paksha='shukla',month=moon_month[d],script=script)#moon_month[d] or [d+1]? if moon_month[d+1]==4: festivals[d+1]+='\\\\'+chaturmasya_start[script] if moon_month[d+1]==8: festivals[d+1]+='\\\\'+chaturmasya_end[script] elif (tithi_sunrise[d]==11 and tithi_sunrise[d+1]!=11): #Check dashami end time to decide for whether this is sarva/smartha tithi_arunodayam = get_tithi(jd_sunrise[d]-(1/15.0)*(jd_sunrise[d]-jd_sunrise[d-1])) #Two muhurtams is 1/15 of day-length if tithi_arunodayam==10: festivals[d]=smartha[script]+'~'+get_ekadashi_name(paksha='shukla',month=moon_month[d],script=script) festivals[d+1]=vaishnava[script]+'~'+get_ekadashi_name(paksha='shukla',month=moon_month[d],script=script) if moon_month[d]==4: festivals[d]+='\\\\'+chaturmasya_start[script] if moon_month[d]==8: festivals[d]+='\\\\'+chaturmasya_end[script] else: festivals[d]=sarva[script]+'~'+get_ekadashi_name(paksha='shukla',month=moon_month[d],script=script) if moon_month[d]==4: festivals[d]+='\\\\'+chaturmasya_start[script] if moon_month[d]==8: festivals[d]+='\\\\'+chaturmasya_end[script] elif (tithi_sunrise[d-1]!=11 and tithi_sunrise[d]==12): festivals[d]=sarva[script]+'~'+get_ekadashi_name(paksha='shukla',month=moon_month[d],script=script) if moon_month[d]==4: festivals[d]+='\\\\'+chaturmasya_start[script] if moon_month[d]==8: festivals[d]+='\\\\'+chaturmasya_end[script] if tithi_sunrise[d]==26 or tithi_sunrise[d]==27: #One of two consecutive tithis must appear @ sunrise! #check for krishna ekadashi if (tithi_sunrise[d]==26 and tithi_sunrise[d+1]==26): festivals[d+1]=sarva[script]+'~'+get_ekadashi_name(paksha='krishna',month=moon_month[d],script=script)#moon_month[d] or [d+1]? elif (tithi_sunrise[d]==26 and tithi_sunrise[d+1]!=26): #Check dashami end time to decide for whether this is sarva/smartha tithi_arunodayam = get_tithi(jd_sunrise[d]-(1/15.0)*(jd_sunrise[d]-jd_sunrise[d-1])) #Two muhurtams is 1/15 of day-length if tithi_arunodayam==25: festivals[d]=smartha[script]+'~'+get_ekadashi_name(paksha='krishna',month=moon_month[d],script=script) festivals[d+1]=vaishnava[script]+'~'+get_ekadashi_name(paksha='krishna',month=moon_month[d],script=script) else: festivals[d]=sarva[script]+'~'+get_ekadashi_name(paksha='krishna',month=moon_month[d],script=script) elif (tithi_sunrise[d-1]!=26 and tithi_sunrise[d]==27): festivals[d]=sarva[script]+'~'+get_ekadashi_name(paksha='krishna',month=moon_month[d],script=script) #PRADOSHA Vratam if tithi_sunrise[d]==12 or tithi_sunrise[d]==13: ldiff_set=(swisseph.calc_ut(jd_sunset[d],swisseph.MOON)[0]-swisseph.calc_ut(jd_sunset[d],swisseph.SUN)[0])%360 ldiff_set_tmrw=(swisseph.calc_ut(jd_sunset[d+1],swisseph.MOON)[0]-swisseph.calc_ut(jd_sunset[d+1],swisseph.SUN)[0])%360 tithi_sunset = int(1+math.floor(ldiff_set/12.0)) tithi_sunset_tmrw = int(1+math.floor(ldiff_set_tmrw/12.0)) if tithi_sunset<=13 and tithi_sunset_tmrw!=13: festivals[d]=pradosham[script] elif tithi_sunset_tmrw==13: festivals[d+1]=pradosham[script] if tithi_sunrise[d]==27 or tithi_sunrise[d]==28: ldiff_set=(swisseph.calc_ut(jd_sunset[d],swisseph.MOON)[0]-swisseph.calc_ut(jd_sunset[d],swisseph.SUN)[0])%360 ldiff_set_tmrw=(swisseph.calc_ut(jd_sunset[d+1],swisseph.MOON)[0]-swisseph.calc_ut(jd_sunset[d+1],swisseph.SUN)[0])%360 tithi_sunset = int(1+math.floor(ldiff_set/12.0)) tithi_sunset_tmrw = int(1+math.floor(ldiff_set_tmrw/12.0)) if tithi_sunset<=28 and tithi_sunset_tmrw!=28: festivals[d]=pradosham[script] elif tithi_sunset_tmrw==28: festivals[d+1]=pradosham[script] #SANKATAHARA chaturthi if tithi_sunrise[d]==18 or tithi_sunrise[d]==19: ldiff_moonrise_yest=(swisseph.calc_ut(jd_moonrise[d-1],swisseph.MOON)[0]-swisseph.calc_ut(jd_moonrise[d-1],swisseph.SUN)[0])%360 ldiff_moonrise=(swisseph.calc_ut(jd_moonrise[d],swisseph.MOON)[0]-swisseph.calc_ut(jd_moonrise[d],swisseph.SUN)[0])%360 ldiff_moonrise_tmrw=(swisseph.calc_ut(jd_moonrise[d+1],swisseph.MOON)[0]-swisseph.calc_ut(jd_moonrise[d+1],swisseph.SUN)[0])%360 tithi_moonrise_yest = int(1+math.floor(ldiff_moonrise_yest/12.0)) tithi_moonrise = int(1+math.floor(ldiff_moonrise/12.0)) tithi_moonrise_tmrw = int(1+math.floor(ldiff_moonrise_tmrw/12.0)) if tithi_moonrise==19: if tithi_moonrise_yest!=19:#otherwise yesterday would have already been assigned festivals[d]=chaturthi[script] if moon_month[d]==5:#shravana krishna chaturthi festivals[d]=maha[script]+festivals[d] elif tithi_moonrise_tmrw==19: festivals[d+1]=chaturthi[script] if moon_month[d]==5: #moon_month[d] and[d+1] are same, so checking [d] is enough festivals[d+1]=maha[script]+festivals[d+1] #SHASHTHI Vratam if tithi_sunrise[d]==5 or tithi_sunrise[d]==6: if tithi_sunrise[d]==6 or (tithi_sunrise[d]==5 and tithi_sunrise[d+1]==7): if tithi_sunrise[d-1]!=6:#otherwise yesterday would have already been assigned festivals[d]=shashthi[script] if moon_month[d]==8:#kArtika krishna shashthi festivals[d]=skanda[script]+festivals[d] elif tithi_sunrise[d+1]==6: festivals[d+1]=shashthi[script] if moon_month[d]==8: #moon_month[d] and[d+1] are same, so checking [d] is enough festivals[d+1]=skanda[script]+festivals[d+1] ###--- OTHER (MAJOR) FESTIVALS ---### #type of month | month number | type of angam (tithi|nakshatram) | angam number | min_t cut off for considering prev day (without sunrise_angam) as festival date purvaviddha_rules={akshaya_tritiya[script]:['moon_month',2,'tithi',3,0], chitra_purnima[script]:['sun_month',1,'tithi',15,0], durgashtami[script]:['moon_month',7,'tithi',8,0], mahanavami[script]:['moon_month',7,'tithi',9,0], vijayadashami[script]:['moon_month',7,'tithi',10,0], dipavali[script]:['moon_month',7,'tithi',29,0], shankara_jayanti[script]:['moon_month',2,'tithi',5,0], yajur_upakarma[script]:['moon_month',5,'tithi',15,0], rg_upakarma[script]:['moon_month',5,'nakshatram',22,0], sama_upakarma[script]:['sun_month',5,'nakshatram',13,0], rishi_panchami[script]:['moon_month',6,'tithi',5,0], ananta_chaturdashi[script]:['moon_month',6,'tithi',14,0], mahalaya_paksham[script]:['moon_month',6,'tithi',16,0], hanumat_jayanti[script]:['sun_month',9,'tithi',30,0], ardra_darshanam[script]:['sun_month',9,'nakshatram',6,0], ratha_saptami[script]:['sun_month',10,'tithi',7,0], goda_jayanti[script]:['sun_month',4,'nakshatram',11,0], adi_krittika[script]:['sun_month',4,'nakshatram',3,0], phalguni_uttaram[script]:['sun_month',12,'nakshatram',12,4], mahalaya_amavasya[script]:['moon_month',6,'tithi',30,0], uma_maheshvara_vratam[script]:['moon_month',6,'tithi',15,0]} for x in iter(purvaviddha_rules.keys()): rule=purvaviddha_rules[x] if rule[0]=='moon_month': if moon_month[d]==rule[1]: if rule[2]=='tithi': fday = get_festival_day_purvaviddha(rule[3],tithi_sunrise,d,jd_sunrise[d],jd_sunrise[d+1],get_tithi,rule[4]) elif rule[2]=='nakshatram': fday = get_festival_day_purvaviddha(rule[3],nakshatram_sunrise,d,jd_sunrise[d],jd_sunrise[d+1],get_nakshatram,rule[4]) if fday is not None: if festival_day_list.has_key(x): if festival_day_list[x][0]!=fday: #Second occurrence of a festival within a Gregorian calendar year festival_day_list[x]=[festival_day_list[x][0],fday] else: festival_day_list[x]=[fday] elif rule[0]=='sun_month': if sun_month[d]==rule[1]: if rule[2]=='tithi': fday = get_festival_day_purvaviddha(rule[3],tithi_sunrise,d,jd_sunrise[d],jd_sunrise[d+1],get_tithi,rule[4]) elif rule[2]=='nakshatram': fday = get_festival_day_purvaviddha(rule[3],nakshatram_sunrise,d,jd_sunrise[d],jd_sunrise[d+1],get_nakshatram,rule[4]) if fday is not None: if festival_day_list.has_key(x): if festival_day_list[x][0]!=fday: #Second occurrence of a festival within a Gregorian calendar year festival_day_list[x]=[festival_day_list[x][0],fday] else: festival_day_list[x]=[fday] else: print 'Error; unknown string in rule: %s' % (rule[0]) return #NAVARATRI START if moon_month[d]==7 and moon_month[d-1]==6: festival_day_list[navaratri_start[script]]=[d] #PONGAL/AYANAM if sun_month[d]==10 and sun_month[d-1]==9: festival_day_list[uttarayanam[script]]=[d] if sun_month[d]==4 and sun_month[d-1]==3: festival_day_list[dakshinayanam[script]]=[d] if sun_month[d]==1 and sun_month[d-1]==12: festival_day_list[new_yr]=[d] if moon_month[d]==1 and moon_month[d-1]!=1: festival_day_list[yugadi[script]]=[d] #SHRIRAMANAVAMI if moon_month[d]==1: if tithi_sunrise[d]==8 or tithi_sunrise[d]==9: t_11 = get_tithi(jd_sunrise[d]+(jd_sunset[d]-jd_sunrise[d])*(2.0/5.0))#madhyahna1 start t_12 = get_tithi(jd_sunrise[d]+(jd_sunset[d]-jd_sunrise[d])*(3.0/5.0))#madhyahna1 end t_21 = get_tithi(jd_sunrise[d+1]+(jd_sunset[d+1]-jd_sunrise[d+1])*(2.0/5.0))#madhyahna2 start t_22 = get_tithi(jd_sunrise[d+1]+(jd_sunset[d+1]-jd_sunrise[d+1])*(3.0/5.0))#madhyahna2 end if t_11==9 or t_12==9: if t_21==9 or t_22==9: festival_day_list[ramanavami[script]]=[d+1] else: festival_day_list[ramanavami[script]]=[d] #JANMASHTAMI if moon_month[d]==5: if tithi_sunrise[d]==22 or tithi_sunrise[d]==23: t_11 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(7.0/15.0))#nishita1 start t_12 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(8.0/15.0))#nishita1 end #t_11 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(2.0/5.0))#madhyaratri1 start #t_12 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(3.0/5.0))#madhyaratri1 end t_21 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(7.0/15.0))#nishita2 start t_22 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(8.0/15.0))#nishita2 end #t_21 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(2.0/5.0))#madhyaratri2 start #t_22 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(3.0/5.0))#madhyaratri2 end if t_11==23 or t_12==23: if t_21==23 or t_22==23: festival_day_list[janmashtami[script]]=[d+1] else: festival_day_list[janmashtami[script]]=[d] #SHIVARATRI if moon_month[d]==11: if tithi_sunrise[d]==28 or tithi_sunrise[d]==29: t_11 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(7.0/15.0))#nishita1 start t_12 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(8.0/15.0))#nishita1 end t_21 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(7.0/15.0))#nishita2 start t_22 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(8.0/15.0))#nishita2 end if t_11==29 or t_12==29: if t_21==29 or t_22==29: festival_day_list[shivaratri[script]]=[d+1] else: festival_day_list[shivaratri[script]]=[d] #VINAYAKA CHATURTHI if moon_month[d]==6: if tithi_sunrise[d]==3 or tithi_sunrise[d]==4: t_11 = get_tithi(jd_sunrise[d]+(jd_sunset[d]-jd_sunrise[d])*(2.0/5.0))#madhyahna1 start t_12 = get_tithi(jd_sunrise[d]+(jd_sunset[d]-jd_sunrise[d])*(3.0/5.0))#madhyahna1 end t_21 = get_tithi(jd_sunrise[d+1]+(jd_sunset[d+1]-jd_sunrise[d+1])*(2.0/5.0))#madhyahna2 start t_22 = get_tithi(jd_sunrise[d+1]+(jd_sunset[d+1]-jd_sunrise[d+1])*(3.0/5.0))#madhyahna2 end if t_11==4 or t_12==4: if t_21==4 or t_22==4: festival_day_list[vchaturthi[script]]=[d+1] else: festival_day_list[vchaturthi[script]]=[d] #Add saved festivals festival_day_list[gayatri_japam[script]]=[festival_day_list[yajur_upakarma[script]][0]+1] festival_day_list[varalakshmi_vratam[script]]=[festival_day_list[yajur_upakarma[script]][0]-((weekday_start-1+festival_day_list[yajur_upakarma[script]][0]-5)%7)] for x in iter(festival_day_list.keys()): for j in range(0,len(festival_day_list[x])): if festivals[festival_day_list[x][j]]!='': festivals[festival_day_list[x][j]]+='\\\\' festivals[festival_day_list[x][j]]+=x ###--- ECLIPSES ---### ###--- LUNAR ECLIPSES ---### swisseph.set_topo(lon=longitude,lat=latitude,alt=0.0) #Set location jd = jd_start while 1: next_ecl_lun=swisseph.lun_eclipse_when(jd) jd=next_ecl_lun[1][0]+(tz_off/24.0) jd_ecl_lun_start=next_ecl_lun[1][2]+(tz_off/24.0) jd_ecl_lun_end=next_ecl_lun[1][3]+(tz_off/24.0) ecl_y=swisseph.revjul(jd-1)[0]# -1 is to not miss an eclipse that occurs after sunset on 31-Dec! if ecl_y!=start_year: break else: ecl_lun_start = swisseph.revjul(jd_ecl_lun_start)[3] ecl_lun_end = swisseph.revjul(jd_ecl_lun_end)[3] if (jd_ecl_lun_start-(tz_off/24.0))==0.0 or (jd_ecl_lun_end-(tz_off/24.0))==0.0: jd=jd+20 #Move towards the next eclipse... at least the next full moon (>=25 days away) continue fday=int(math.floor(jd_ecl_lun_start)-math.floor(jd_start)+1) #print '%%',jd,fday,jd_sunrise[fday],jd_sunrise[fday-1] if (jd<(jd_sunrise[fday]+tz_off/24.0)): fday-=1 if ecl_lun_start<swisseph.revjul(jd_sunrise[fday+1]+tz_off/24.0)[3]: ecl_lun_start+=24 #print '%%',jd,fday,jd_sunrise[fday],jd_sunrise[fday-1],ecl_lun_start, ecl_lun_end jd_moonrise_ecl_day=swisseph.rise_trans(jd_start=jd_sunrise[fday],body=swisseph.MOON, lon=longitude,lat=latitude,rsmi=swisseph.CALC_RISE|swisseph.BIT_DISC_CENTER)[1][0]+(tz_off/24.0) jd_moonset_ecl_day=swisseph.rise_trans(jd_start=jd_moonrise_ecl_day,body=swisseph.MOON, lon=longitude,lat=latitude,rsmi=swisseph.CALC_SET|swisseph.BIT_DISC_CENTER)[1][0]+(tz_off/24.0) #if jd_ecl_lun_start<(jd_sunrise[fday]+(tz_off/24.0)): if ecl_lun_end < ecl_lun_start: ecl_lun_end+=24 #print '%%', (jd_ecl_lun_start), (jd_ecl_lun_end), (jd_moonrise_ecl_day), (jd_moonset_ecl_day) #print '%%', swisseph.revjul(jd_ecl_lun_start), swisseph.revjul(jd_ecl_lun_end), swisseph.revjul(jd_moonrise_ecl_day), swisseph.revjul(jd_moonset_ecl_day) if jd_ecl_lun_end<jd_moonrise_ecl_day or jd_ecl_lun_start>jd_moonset_ecl_day: jd=jd+20 #Move towards the next eclipse... at least the next full moon (>=25 days away) continue lun_ecl_str = chandra_grahanam[script]+'~\\textsf{'+print_time2(ecl_lun_start)+'}{\\RIGHTarrow}\\textsf{'+print_time2(ecl_lun_end)+'}' if festivals[fday]!='': festivals[fday]+='\\\\' festivals[fday]+=lun_ecl_str jd=jd+20 ###--- SOLAR ECLIPSES ---### swisseph.set_topo(lon=longitude,lat=latitude,alt=0.0) #Set location jd = jd_start while 1: next_ecl_sol=swisseph.sol_eclipse_when_loc(julday=jd,lon=longitude,lat=latitude) jd=next_ecl_sol[1][0]+(tz_off/24.0) jd_ecl_sol_start=next_ecl_sol[1][1]+(tz_off/24.0) jd_ecl_sol_end=next_ecl_sol[1][4]+(tz_off/24.0) ecl_y=swisseph.revjul(jd-1)[0]# -1 is to not miss an eclipse that occurs after sunset on 31-Dec! if ecl_y!=start_year: break else: #print '%%', fday, (jd_ecl_sol_start), (jd_ecl_sol_end), (jd_sunrise[fday]) #print '%%', swisseph.revjul(jd_ecl_sol_start), swisseph.revjul(jd_ecl_sol_end), swisseph.revjul(jd_sunrise[fday]) fday=int(math.floor(jd)-math.floor(jd_start)+1) if (jd<(jd_sunrise[fday]+tz_off/24.0)): fday-=1 #print '%%', fday, (jd_ecl_sol_start), (jd_ecl_sol_end), (jd_sunrise[fday]) #print '%%', swisseph.revjul(jd_ecl_sol_start), swisseph.revjul(jd_ecl_sol_end), swisseph.revjul(jd_sunrise[fday]) ecl_sol_start = swisseph.revjul(jd_ecl_sol_start)[3] ecl_sol_end = swisseph.revjul(jd_ecl_sol_end)[3] if (jd_ecl_sol_start-(tz_off/24.0))==0.0 or (jd_ecl_sol_end-(tz_off/24.0))==0.0:# or jd_ecl_end<jd_sunrise[fday] or jd_ecl_start>jd_sunset[fday]: jd=jd+20 #Move towards the next eclipse... at least the next new moon (>=25 days away) continue if ecl_sol_end < ecl_sol_start: ecl_sol_end+=24 sol_ecl_str = surya_grahanam[script]+'~\\textsf{'+print_time2(ecl_sol_start)+'}{\\RIGHTarrow}\\textsf{'+print_time2(ecl_sol_end)+'}' if festivals[fday]!='': festivals[fday]+='\\\\' festivals[fday]+=sol_ecl_str jd=jd+20 ###--- FESTIVAL ADDITIONS COMPLETE ---### ###--- PRINT LIST OF FESTIVALS (Page 2) ---### if script=='en': cal = Calendar() print '\\newpage' print '\\centerline {\\LARGE {{%s}}}\\mbox{}\\\\[2cm]' % list_of_festivals[script] print '\\begin{center}' print '\\begin{minipage}[t]{0.3\\linewidth}' print '\\begin{center}' print '\\begin{tabular}{>{\\sffamily}r>{\\sffamily}r>{\\sffamily}cp{6cm}}' mlast=1 for d in range(1,367): jd = jd_start-1+d [y,m,dt,t] = swisseph.revjul(jd) weekday = (weekday_start -1 + d)%7 if festivals[d]!='': if m!=mlast: mlast=m #print '\\hline\\\\' print '\\\\' if m==5 or m==9: print '\\end{tabular}' print '\\end{center}' print '\\end{minipage}\hspace{1cm}%' print '\\begin{minipage}[t]{0.3\\linewidth}' print '\\begin{center}' print '\\begin{tabular}{>{\\sffamily}r>{\\sffamily}l>{\\sffamily}cp{6cm}}' print '%s & %s & %s & {\\raggedright %s} \\\\' % (MON[m],dt,WDAY[weekday],festivals[d]) if script=='en': event = Event() event.add('summary',festivals[d]) event.add('dtstart',datetime(y,m,dt)) event.add('dtend',datetime(y,m,dt)) cal.add_component(event) if m==12 and dt==31: break print '\\end{tabular}' print '\\end{center}' print '\\end{minipage}' print '\\end{center}' print '\\clearpage' if script=='en': cal_fname = '%s-%4d.ics' %(city_name,start_year) cal_file = open(cal_fname,'w') cal_file.write(cal.as_string()) cal_file.close() #Layout calendar in LATeX format #We use a separate loop here, because of festivals like varalakshmi #vratam, for which we backtrack to the previous friday from yajur #upakarma and change the list of festivals! for d in range(1,367): jd = jd_start-1+d [y,m,dt,t] = swisseph.revjul(jd) weekday = (weekday_start -1 + d)%7 if dt==1: if m>1: if weekday!=0: #Space till Sunday for i in range(weekday,6): print "{} &" print "\\\\ \hline" print '\end{tabular}' print '\n\n' #Begin tabular print '\\begin{tabular}{|c|c|c|c|c|c|c|}' print '\multicolumn{7}{c}{\Large \\bfseries \sffamily %s %s}\\\\[3mm]' % (month[m],y) print '\hline' print '\\textbf{\\textsf{SUN}} & \\textbf{\\textsf{MON}} & \\textbf{\\textsf{TUE}} & \\textbf{\\textsf{WED}} & \\textbf{\\textsf{THU}} & \\textbf{\\textsf{FRI}} & \\textbf{\\textsf{SAT}} \\\\ \hline' #print '\\textbf{भानु} & \\textbf{इन्दु} & \\textbf{भौम} & \\textbf{बुध} & \\textbf{गुरु} & \\textbf{भृगु} & \\textbf{स्थिर} \\\\ \hline' #Blanks for previous weekdays for i in range(0,weekday): print "{} &" print '\caldata{\\textcolor{%s}{%s}}{%s{%s}}{\\sundata{%s}{%s}{%s}}{\\tnyk{%s}{%s}{%s}{%s}}{\\rahuyama{%s}{%s}}{%s} ' % (daycol[weekday], dt,month_data[d],get_chandra_masa(moon_month[d],chandra_masa_names,script),sunrise[d],sunset[d],madhya[d],tithi_data_string[d],nakshatram_data_string[d], yogam_data_string[d],karanam_data_string[d],rahu[d],yama[d],festivals[d]) if weekday==6: print "\\\\ \hline" else: print "&" if m==12 and dt==31: break # For debugging specific dates #if m==4 and dt==10: # break for i in range(weekday+1,6): print "{} &" if weekday!=6: print "\\\\ \hline" print '\end{tabular}' print '\n\n' print template_lines[-2][:-1] print template_lines[-1][:-1]
print constants.PLANET_CHARS[aspect_natal_master.loc[x]['planet_a']], constants.ASPECTS[ aspect_natal_master.loc[x]['aspect']], \ constants.PLANET_CHARS[aspect_natal_master.loc[x]['planet_b']] i += 1 #Planetary hours is_birth_time = True lt_zone = 5.5 date_start = datetime.datetime.today() # today's date planetary_hour_sequence = ('saturn', 'jupiter', 'mars', 'sun', 'venus', 'mercury', 'moon') day_sequence = ('moon', 'mars', 'mercury', 'jupiter', 'venus', 'saturn', 'sun') day_sequence_p = (6, 2, 5, 1, 4, 0, 3) #search this date's noon [12 PM] now_julian = swe.julday(date_start.year, date_start.month, date_start.day, 12) planet_rise_jul = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 1) planet_set_jul = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 2) sun_rise_tuple = swe.jdut1_to_utc(planet_rise_jul[1][0],1) sun_rise_list = list(sun_rise_tuple) sun_rise_list[5] = int(sun_rise_list[5]) sun_rise = datetime.datetime(*sun_rise_list[0:6]) + datetime.timedelta(hours=lt_zone) sun_rise_question = sun_rise sun_set_tuple = swe.jdut1_to_utc(planet_set_jul[1][0], 1) sun_set_list = list(sun_set_tuple) sun_set_list[5] = int(sun_set_list[5]) sun_set = datetime.datetime(*sun_set_list[0:6]) + datetime.timedelta(hours=lt_zone) sun_set_question = sun_set # next day sun rise now_julian = swe.julday(date_start.year, date_start.month, date_start.day + 1, 12) planet_rise_jul_next_day = swe.rise_trans(now_julian, 0, city_longitude, city_latitude, 0.0, 0.0, 0.0, 1) sun_rise_tuple_n = swe.jdut1_to_utc(planet_rise_jul_next_day[1][0], 1)
def main(): city_name = sys.argv[1] latitude = sexastr2deci(sys.argv[2]) longitude = sexastr2deci(sys.argv[3]) tz = sys.argv[4] start_year = int(sys.argv[5]) year = start_year jd = swisseph.julday(year, 1, 1, 0) jd_start = jd start_date = datetime(year=year, month=1, day=1, hour=0, minute=0, second=0) day_of_year = 0 swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha sun_month_day = jd - get_last_dhanur_transit(jd, latitude, longitude) #this has to be done in a generic fashion, by scanning for the transit into dhanur of the last year! month_start_after_set = 0 template_file = open('cal_template.tex') template_lines = template_file.readlines() for i in range(0, len(template_lines) - 3): print template_lines[i][:-1] samvatsara_id = (year - 1568) % 60 + 1 #distance from prabhava samvatsara_names = '%s–%s' % (year_names[samvatsara_id], year_names[(samvatsara_id % 60) + 1]) print '\\mbox{}' print '{\\font\\x="Warnock Pro" at 60 pt\\x %d\\\\[0.3cm]}' % year print '\\mbox{\\font\\x="Sanskrit 2003:script=deva" at 48 pt\\x %s}\\\\[0.5cm]' % samvatsara_names print '{\\font\\x="Warnock Pro" at 48 pt\\x \\uppercase{%s}\\\\[0.3cm]}' % city_name print '\hrule' while year <= start_year: day_of_year = day_of_year + 1 [y, m, d, t] = swisseph.revjul(jd) weekday = (swisseph.day_of_week(jd) + 1) % 7 #swisseph has Mon = 0, non-intuitively! local_time = pytz.timezone(tz).localize(datetime( y, m, d, 6, 0, 0)) #checking @ 6am local - can we do any better? tz_off = datetime.utcoffset( local_time).seconds / 3600.0 #compute offset from UTC jd_rise = swisseph.rise_trans(jd_start=jd, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] jd_rise_tmrw = swisseph.rise_trans(jd_start=jd + 1, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] jd_set = swisseph.rise_trans(jd_start=jd, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_SET | swisseph.BIT_DISC_CENTER)[1][0] [_y, _m, _d, t_rise] = swisseph.revjul(jd_rise + tz_off / 24.0) [_y, _m, _d, t_set] = swisseph.revjul(jd_set + tz_off / 24.0) longitude_moon = swisseph.calc_ut( jd_rise, swisseph.MOON)[0] - swisseph.get_ayanamsa(jd_rise) longitude_moon_tmrw = swisseph.calc_ut( jd_rise + 1, swisseph.MOON)[0] - swisseph.get_ayanamsa(jd_rise + 1) longitude_sun = swisseph.calc_ut( jd_rise, swisseph.SUN)[0] - swisseph.get_ayanamsa(jd_rise) longitude_sun_set = swisseph.calc_ut( jd_set, swisseph.SUN)[0] - swisseph.get_ayanamsa(jd_set) sun_month_rise = masa_names[int(1 + math.floor(( (longitude_sun) % 360) / 30.0))] sun_month = masa_names[int(1 + math.floor(( (longitude_sun_set) % 360) / 30.0))] longitude_sun_tmrw = swisseph.calc_ut( jd_rise + 1, swisseph.SUN)[0] - swisseph.get_ayanamsa(jd_rise + 1) sun_month_tmrw = masa_names[int(1 + math.floor(( (longitude_sun_tmrw) % 360) / 30.0))] daily_motion_moon = (longitude_moon_tmrw - longitude_moon) % 360 daily_motion_sun = (longitude_sun_tmrw - longitude_sun) % 360 #Solar month calculations if month_start_after_set == 1: sun_month_day = 0 month_start_after_set = 0 if sun_month_rise != sun_month_tmrw: if sun_month != sun_month_tmrw: month_start_after_set = 1 sun_month_day = sun_month_day + 1 #mAsa pirappu! #sun_month = sun_month_tmrw #sun moves into next rAsi before sunset -- check rules! else: sun_month_day = 1 month_remaining = 30 - (longitude_sun % 30.0) month_end = month_remaining / daily_motion_sun * 24.0 me = deci2sexa(t_rise + month_end) if me[0] >= 24: suff = '(+1)' me[0] = me[0] - 24 else: suff = '\\hspace{2ex}' sun_month_end_time = '{\\textsf{%s} {\\tiny \\RIGHTarrow} %02d:%02d%s}' % ( last_sun_month, me[0], me[1], suff) else: sun_month_day = sun_month_day + 1 sun_month_end_time = '' month_data = '\\sunmonth{%s}{%d}{%s}' % (sun_month, sun_month_day, sun_month_end_time) #print '%%@%f:%d-%d-%d: rise=%s, set=%s, tmrw=%s' %(jd,y,m,d,sun_month_rise,sun_month,sun_month_tmrw) #Compute tithi details tithi = int(1 + math.floor((longitude_moon - longitude_sun) % 360 / 12.0)) tithi_tmrw = int(1 + math.floor( (longitude_moon_tmrw - longitude_sun_tmrw) % 360 / 12.0)) if (tithi_tmrw - tithi) % 30 > 1: #double change tithi_2 = (tithi % 30) + 1 if tithi_2 % 15 != 0: paksha = ('shukla' if tithi_2 < 15 else 'krishna') else: if tithi_2 == 15: paksha = 'fullmoon' elif tithi_2 == 30: paksha = 'newmoon' if tithi_2 % 15 == 0: tithi_str_2 = paksha + tithi_names[tithi_2] else: tithi_str_2 = paksha + tithi_names[tithi_2 % 15] tithi_remaining_2 = 12 + 12 - (( (longitude_moon - longitude_sun) % 360) % 12) tithi_end_2 = tithi_remaining_2 / (daily_motion_moon - daily_motion_sun) * 24.0 tithi_end_str_2 = print_end_time(tithi_end_2, jd_rise_tmrw - jd_rise, t_rise) if tithi_end_str_2 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second tithi cannot be 'all day'! It's ending will reflect in tomorrow's calendar tithi_str_2 = '' tithi_end_str_2 = '' else: tithi_str_2 = '' tithi_end_str_2 = '' if tithi % 15 != 0: paksha = ('shukla' if tithi < 15 else 'krishna') else: if tithi == 15: paksha = 'fullmoon' elif tithi == 30: paksha = 'newmoon' if tithi % 15 == 0: tithi_str = paksha + tithi_names[tithi] else: tithi_str = paksha + tithi_names[tithi % 15] tithi_remaining = 12 - (((longitude_moon - longitude_sun) % 360) % 12) tithi_end = tithi_remaining / (daily_motion_moon - daily_motion_sun) * 24.0 tithi_end_str = print_end_time(tithi_end, jd_rise_tmrw - jd_rise, t_rise) #Compute nakshatram details n_id = int(1 + math.floor((longitude_moon % 360) / (360.0 / 27))) n_id_tmrw = int(1 + math.floor((longitude_moon_tmrw % 360) / (360.0 / 27))) if (n_id_tmrw - n_id) % 27 > 1: #there is a double change nakshatram_str_2 = nakshatra_names[n_id % 27 + 1] nakshatram_remaining_2 = (360.0 / 27) + (360.0 / 27) - ( (longitude_moon % 360) % (360.0 / 27)) nakshatram_end_2 = nakshatram_remaining_2 / daily_motion_moon * 24 nakshatram_end_str_2 = print_end_time(nakshatram_end_2, jd_rise_tmrw - jd_rise, t_rise) if nakshatram_end_str_2 == '\\textsf{अहोरात्रम्}': #needs correction, owing to the fact that we compute longitude every 24h, rather than at next sunrise #the second nakshatram cannot be 'all day'! It's ending will reflect in tomorrow's calendar nakshatram_str_2 = '' nakshatram_end_str_2 = '' else: nakshatram_str_2 = '' nakshatram_end_str_2 = '' nakshatram_str = nakshatra_names[n_id] nakshatram_remaining = (360.0 / 27) - ((longitude_moon % 360) % (360.0 / 27)) nakshatram_end = nakshatram_remaining / daily_motion_moon * 24 nakshatram_end_str = print_end_time(nakshatram_end, jd_rise_tmrw - jd_rise, t_rise) #Sunrise/sunset and related stuff (like rahu, yama) [rh, rm, rs] = deci2sexa(t_rise) #rise_t hour, rise minute [sh, sm, ss] = deci2sexa(t_set) #set_t hour, set minute present_day = start_date + timedelta(days=day_of_year) rise_t = present_day + timedelta(hours=rh, minutes=rm) set_t = present_day + timedelta(hours=sh, minutes=sm) length_of_day = set_t - rise_t yamakandam_start = rise_t + timedelta( seconds=(1 / 8.0) * (yamakandam_octets[weekday] - 1) * length_of_day.seconds) yamakandam_end = yamakandam_start + timedelta(seconds=(1 / 8.0) * length_of_day.seconds) rahukalam_start = rise_t + timedelta(seconds=(1 / 8.0) * (rahukalam_octets[weekday] - 1) * length_of_day.seconds) rahukalam_end = rahukalam_start + timedelta(seconds=(1 / 8.0) * length_of_day.seconds) madhyahnikam_start = rise_t + timedelta(seconds=(1 / 5.0) * length_of_day.seconds) rise = '%02d:%02d' % (rh, rm) set = '%02d:%02d' % (sh, sm) madhya = print_time(madhyahnikam_start) rahu = '%s--%s' % (print_time(rahukalam_start), print_time(rahukalam_end)) yama = '%s--%s' % (print_time(yamakandam_start), print_time(yamakandam_end)) #Layout calendar in LATeX format if d == 1: if m > 1: if weekday != 0: #Space till Sunday for i in range(weekday, 6): print "{} &" print "\\\\ \hline" print '\end{tabular}' print '\n\n' #Begin tabular print '\\begin{tabular}{|c|c|c|c|c|c|c|}' print '\multicolumn{7}{c}{\Large \\bfseries %s %s}\\\\[3mm]' % ( month[m], y) print '\hline' print '\\textbf{SUN} & \\textbf{MON} & \\textbf{TUE} & \\textbf{WED} & \\textbf{THU} & \\textbf{FRI} & \\textbf{SAT} \\\\ \hline' #print '\\textbf{भानु} & \\textbf{इन्दु} & \\textbf{भौम} & \\textbf{बुध} & \\textbf{गुरु} & \\textbf{भृगु} & \\textbf{स्थिर} \\\\ \hline' #Blanks for previous weekdays for i in range(0, weekday): print "{} &" #Create nakshatram data string nEmpty = 0 if nakshatram_end_str_2 != '': nakshatram_data_string = '{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % ( nakshatram_str, nakshatram_end_str, nakshatram_str_2, nakshatram_end_str_2) else: nakshatram_data_string = '{\\textsf{%s} {\\tiny \\RIGHTarrow} %s}' % ( nakshatram_str, nakshatram_end_str) nEmpty = nEmpty + 1 if tithi_end_str_2 != '': tithi_data_string = '{\\textsf{\\%s} {\\tiny \\RIGHTarrow} %s}{\\textsf{\\%s} {\\tiny \\RIGHTarrow} %s}' % ( tithi_str, tithi_end_str, tithi_str_2, tithi_end_str_2) else: tithi_data_string = '{\\textsf{\\%s} {\\tiny \\RIGHTarrow} %s}' % ( tithi_str, tithi_end_str) nEmpty = nEmpty + 1 empty_str = '' for i in range(0, nEmpty): empty_str = empty_str + '{}' print '\caldata{\\textcolor{%s}{%s}}{%s}{\\sundata{%s}{%s}{%s}}%s%s%s{\\textsf{राहु}~%s~~\\textsf{यम}~%s} ' % ( daycol[weekday], d, month_data, rise, set, madhya, tithi_data_string, nakshatram_data_string, empty_str, rahu, yama) if weekday == 6: print "\\\\ \hline" else: print "&" jd = jd + 1 last_sun_month = sun_month if m == 12 and d == 31: year = year + 1 # For debugging specific dates #if m==4 and d==10: # break for i in range(weekday + 1, 6): print "{} &" if weekday != 6: print "\\\\ \hline" print '\end{tabular}' print '\n\n' #print '\\input{%d-%s.tex}' % (year,city_name) print template_lines[-2][:-1] print template_lines[-1][:-1]
def __init__(self, lon, lat, altitude, weekday, jd): self.risetime = None self.settime = None self.hrlen = None self.daytime = None self.weekday = weekday #lon, lat, height, atmpress, celsius #in GMT, searches after jd! ret, risetime = swisseph.rise_trans(jd, astrology.SE_SUN, lon, lat, float(altitude), 0.0, 10.0, astrology.SE_CALC_RISE, astrology.SEFLG_SWIEPH) ret, settime = swisseph.rise_trans(jd, astrology.SE_SUN, lon, lat, float(altitude), 0.0, 10.0, astrology.SE_CALC_SET, astrology.SEFLG_SWIEPH) #swe_rise_trans calculates only forward!! offs = lon * 4.0 / 1440.0 hr = 0 HOURSPERHALFDAY = 12.0 if risetime[0] > settime[0]: # daytime self.daytime = True # print 'daytime'# # Args: float jd_start, int or str body, float lon, float lat, float alt=0.0, float press=0.0, float temp=0.0, int rsmi=0, int flag=FLG_SWIEPH ret, result = swisseph.rise_trans(jd - 1.0, astrology.SE_SUN, lon, lat, float(altitude), 0.0, 10.0, astrology.SE_CALC_RISE, astrology.SEFLG_SWIEPH) #From GMT to Local self.risetime = result[0] + offs self.settime = settime[0] + offs # self.logCalc(settime)# self.hrlen = (self.settime - self.risetime ) / HOURSPERHALFDAY #hrlen(hour-length) is in days for i in range(int(HOURSPERHALFDAY)): if jd + offs < self.risetime + self.hrlen * (i + 1): hr = i break else: # nighttime self.daytime = False # print 'nightime'# # self.logCalc(risetime)# ret, result = swisseph.rise_trans(jd - 1.0, astrology.SE_SUN, lon, lat, float(altitude), 0.0, 10.0, astrology.SE_CALC_SET, astrology.SEFLG_SWIEPH) # self.logCalc(settime)# self.risetime = risetime[0] + offs self.settime = result[0] + offs #Is the local birthtime greater than midnight? If so => decrement day because a planetary day is from sunrise to sunrise if jd + offs > int(jd + offs) + 0.5: self.weekday = util.getPrevDay(self.weekday) self.hrlen = (self.risetime - self.settime) / HOURSPERHALFDAY for i in range(int(HOURSPERHALFDAY)): if jd + offs < self.settime + self.hrlen * (i + 1): hr = i + int(HOURSPERHALFDAY) break self.planetaryhour = PlanetaryHours.PHs[self.weekday][ hr] #planetary day begins from sunrise(not from 0 hour and Planetary hours are not equal!!)