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 years_diff(y1, m1, d1, h1 , y2, m2, d2, h2): swe.set_ephe_path(ephe_path) jd1 = swe.julday(y1,m1,d1,h1) jd2 = swe.julday(y2,m2,d2,h2) jd = jd1 + swe._years_diff(jd1, jd2) #jd = jd1 + ( (jd2-jd1) / 365.248193724 ) y, mth, d, h, m, s = swe._revjul(jd, swe.GREG_CAL) return datetime.datetime(y,mth,d,h,m,s)
def years_diff(y1, m1, d1, h1, y2, m2, d2, h2): swe.set_ephe_path(ephe_path) jd1 = swe.julday(y1, m1, d1, h1) jd2 = swe.julday(y2, m2, d2, h2) jd = jd1 + swe._years_diff(jd1, jd2) #jd = jd1 + ( (jd2-jd1) / 365.248193724 ) y, mth, d, h, m, s = swe._revjul(jd, swe.GREG_CAL) return datetime.datetime(y, mth, d, h, m, s)
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 navamsa_tests(): print(sys._getframe().f_code.co_name) jd = swe.julday(2015, 9, 25, 13 + 29/60. + 13/3600.) nv = navamsa(jd, bangalore) expected = [[0, 11], [1, 5], [4, 1], [2, 2], [5, 4], [3, 10], [6, 4], [10, 11], [9, 5], [7, 10], [8, 10]] assert(nv == expected)
def natal_chart_calc(t_zone, b_offset, b_date, t_birth_hour, t_birth_min, b_latitude, b_longitude, is_time, h_type): date_year_birth = int(b_date.strftime("%Y")) date_month_birth = int(b_date.strftime("%m")) date_day_birth = int(b_date.strftime("%d")) # print 'naren', date_year_birth, date_month_birth, date_day_birth, t_birth_hour, t_birth_min, t_zone, b_offset,\ # (t_birth_hour + (t_birth_min / 60.)) - (t_zone + b_offset) now_julian = swe.julday(date_year_birth, date_month_birth, date_day_birth, (t_birth_hour + (t_birth_min / 60.)) - (t_zone + b_offset)) # print now_julian l_birthchart = len(constants.BIRTH_PLANETS) bchart_pos = np.zeros(l_birthchart + 2) bchart_speed = np.zeros(l_birthchart) for i in range(l_birthchart): pos_p = swe.calc_ut(now_julian, constants.BIRTH_PLANETS[i]) bchart_pos[i] = pos_p[0] bchart_speed[i] = pos_p[3] if is_time: house_array = (swe.houses(now_julian, b_latitude, b_longitude, h_type)) bchart_pos[i + 1] = house_array[1][0] bchart_pos[i + 2] = house_array[1][1] else: bchart_pos[i + 1] = 0 bchart_pos[i + 2] = 0 return bchart_pos, bchart_speed
def get_jd(self): """ Calculates julian day from the utc time.""" utc = self.get_utc() time_utc = utc.hour + utc.minute / 60 self.time = self.hours + self.minuts / 60 self.j_day = float(swe.julday(utc.year, utc.month, utc.day, time_utc)) return self.j_day
def _swisseph(t, ipl): t = t[0] jd = swe.julday(t.year,t.month,t.day,t.hour+t.minute/60) rslt = swe.calc_ut(jd, ipl , swe.FLG_EQUATORIAL | swe.FLG_SWIEPH | swe.FLG_SPEED) if ipl == 1: #Moon rm = swe.calc_ut(jd, ipl , swe.FLG_EQUATORIAL | swe.FLG_SWIEPH | swe.FLG_SPEED |swe.FLG_TRUEPOS | swe.FLG_RADIANS) sinhp = EARTH_RADIUS / rm[2] / AUNIT moondist=asin(sinhp) / DEGTORAD *3600 return rslt[0], rslt[1], moondist return rslt[0], rslt[1], rslt[2]
def year_buckets(self, dates): zero_date = swe.julday(1900, 1, 1) buckets = collections.defaultdict(list) for date in dates: diff = (date - zero_date) / (self.args.match_by_years * DAYS_IN_YEAR) if diff < 0: bucket = -(int(-diff) + 1) else: bucket = int(diff) buckets[bucket].append(date) return buckets
def calc_chart(date): year = date.year month = date.month day = date.day hour = date.hour + date.minute/60 julday = swe.julday(year, month, day, hour) dic = {} for planet_index in range(10): n = planets[planet_index] d = swe.calc_ut(julday, planet_index)[0] s = calc_sign(d) dic[n.lower()] = d return dic
def get_dates(path: Path, args: argparse.Namespace): """ :param path: a csv file, assumed to contain a date in the last column of each row. The date should be in the form yyyy-mm-dd. We assume there is no time information, so we set the time to a random number of hours between 0 and 24. :return: an array of "Julian" (actually Gregorian) day values, one for each date in the file. """ dates = [] keep_first_days = args.keep_first_days min_year = args.min_year max_year = args.max_year flatten = args.flatten_by_day default_to_noon = args.default_to_noon date_years = collections.defaultdict(list) max_day = [None, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # reject all February 29 with path.open() as inp: for row in csv.reader(inp): try: day = row[-1] y, m, d = [int(n) for n in day.split("-")] if y < min_year or y > max_year: continue # year outside the range we want if m <= 0 or d <= 0 or m > 12 or d > max_day[m]: continue # invalid month or day value if (m, d) == (2, 29) and (flatten or not is_leap_year(y)): continue # don't want Feb 29 if flattening, or if it's not a leap year if d == 1 and keep_first_days < 2 and (m == 1 or keep_first_days == 0): continue # first day of month; discard if January (if keep_first_days == 1) or always (if 2) date_years[(m, d)].append(y) except IndexError: # not all rows may be of the expected format pass if flatten: counts = [len(lst) for lst in date_years.values()] min_count = min(counts) else: min_count = 0 for (m, d), y_list in date_years.items(): if flatten: shuffle(y_list) y_list = y_list[:min_count] for y in y_list: hour = 12.0 if default_to_noon else 24.0 * random() dates.append(swe.julday(y, m, d, hour)) if flatten: print( f"# Equalizing by day of year reduces count from {sum(counts)} to " f"{len(date_years)}*{min_count}={len(dates)} for {path}") return np.array(dates)
def _swisseph(t, ipl): t = t[0] jd = swe.julday(t.year, t.month, t.day, t.hour + t.minute / 60) rslt = swe.calc_ut( jd, ipl, swe.FLG_EQUATORIAL | swe.FLG_SWIEPH | swe.FLG_SPEED) if ipl == 1: #Moon rm = swe.calc_ut( jd, ipl, swe.FLG_EQUATORIAL | swe.FLG_SWIEPH | swe.FLG_SPEED | swe.FLG_TRUEPOS | swe.FLG_RADIANS) sinhp = EARTH_RADIUS / rm[2] / AUNIT moondist = asin(sinhp) / DEGTORAD * 3600 return rslt[0], rslt[1], moondist return rslt[0], rslt[1], rslt[2]
def ephemeris_calc(t_zone, b_date, t_birth_hour, t_birth_min): date_year_birth = int(b_date.strftime("%Y")) date_month_birth = int(b_date.strftime("%m")) date_day_birth = int(b_date.strftime("%d")) now_julian = swe.julday(date_year_birth, date_month_birth, date_day_birth, (t_birth_hour + (t_birth_min / 60.)) - t_zone) len_ephemeris = len(constants.EPHEMERIS_PLANETS) ephemeris_pos = np.zeros(len_ephemeris) ephemeris_speed = np.zeros(len_ephemeris) for i in range(len_ephemeris): pos_p = swe.calc_ut(now_julian, constants.EPHEMERIS_PLANETS[i]) ephemeris_pos[i] = pos_p[0] ephemeris_speed[i] = pos_p[3] return ephemeris_pos, ephemeris_speed
def day_buckets(self, dates): zero_date = swe.julday(1900, 1, 1) buckets = collections.defaultdict(list) if self.args.match_by_days == 1: # Recover the calendar day for extra accuracy for date in dates: _, m, d, _ = swe.revjul(date) bucket = (m, d) buckets[bucket].append(date) else: for date in dates: year_fraction = (date - zero_date) / DAYS_IN_YEAR + 1000 year_fraction -= int(year_fraction) bucket = int(year_fraction * DAYS_IN_YEAR / self.args.match_by_days) buckets[bucket].append(date) return buckets
def local_asc_mc(sun_rise1, sun_set1, sun_rise_n1, b_latitude, b_longitude, h_type, t_zone, b_offset): date_year_birth = sun_rise1.year date_month_birth = sun_rise1.month date_day_birth = sun_rise1.day date_hour_birth = sun_rise1.hour date_min_birth = sun_rise1.minute day_diff = (sun_set1 - sun_rise1) / 12 day_diff1 = (sun_rise_n1 - sun_set1) / 12 day_divided = 24 + 1 # 60 * 24 /20 extra for storing start of next day, 24 planetary hours in a day l_asc_mc = np.zeros(day_divided * 2) j = -1 # print sun_rise1,sun_set1, sun_rise_n1 for i in range(day_divided): # print i, date_year_birth, date_month_birth, date_day_birth, date_hour_birth, date_min_birth, day_diff now_julian = swe.julday( date_year_birth, date_month_birth, date_day_birth, (date_hour_birth + date_min_birth / 60.) - (t_zone - b_offset)) house_array = (swe.houses(now_julian, b_latitude, b_longitude, h_type)) j += 1 l_asc_mc[j] = house_array[1][0] j += 1 l_asc_mc[j] = house_array[1][1] if i < 12: sun_rise1 += day_diff date_year_birth = sun_rise1.year date_month_birth = sun_rise1.month date_day_birth = sun_rise1.day date_hour_birth = sun_rise1.hour date_min_birth = sun_rise1.minute else: sun_set1 += day_diff1 date_year_birth = sun_set1.year date_month_birth = sun_set1.month date_day_birth = sun_set1.day date_hour_birth = sun_set1.hour date_min_birth = sun_set1.minute day_diff = day_diff1 return l_asc_mc
def generate_chart(config, input_data): input_time = dateutil.parser.parse(input_data["chart"]['date']) intermediate = {} intermediate['jul_day_UT'] = swe.julday(input_time.year, input_time.month, input_time.day, compute_hour(input_time)) intermediate['geo_loc'] = swe.set_topo( float(input_data['chart']['longitude']), float(input_data['chart']['latitude']), float(input_data['chart']['altitude'])) intermediate['iflag'] = calculate_iflag(input_data) output = {} output['input'] = input_data output['intermediate'] = intermediate output = calculate_planets(input_data, intermediate, output, config) output = calculate_main_chart(input_data, intermediate, output) output = calculate_planets_in_houses(output) return output
def local_asc_mc(sun_rise1, sun_set1, sun_rise_n1, b_latitude, b_longitude, h_type, t_zone, b_offset): date_year_birth = sun_rise1.year date_month_birth = sun_rise1.month date_day_birth = sun_rise1.day date_hour_birth = sun_rise1.hour date_min_birth = sun_rise1.minute day_diff = (sun_set1 - sun_rise1) / 12 day_diff1 = (sun_rise_n1 - sun_set1) / 12 day_divided = 24 + 1 # 60 * 24 /20 extra for storing start of next day, 24 planetary hours in a day l_asc_mc = np.zeros(day_divided * 2) j = -1 # print sun_rise1,sun_set1, sun_rise_n1 for i in range(day_divided): # print i, date_year_birth, date_month_birth, date_day_birth, date_hour_birth, date_min_birth, day_diff now_julian = swe.julday(date_year_birth, date_month_birth, date_day_birth, (date_hour_birth + date_min_birth / 60.) - (t_zone - b_offset)) house_array = (swe.houses(now_julian, b_latitude, b_longitude, h_type)) j += 1 l_asc_mc[j] = house_array[1][0] j += 1 l_asc_mc[j] = house_array[1][1] if i < 12: sun_rise1 += day_diff date_year_birth = sun_rise1.year date_month_birth = sun_rise1.month date_day_birth = sun_rise1.day date_hour_birth = sun_rise1.hour date_min_birth = sun_rise1.minute else: sun_set1 += day_diff1 date_year_birth = sun_set1.year date_month_birth = sun_set1.month date_day_birth = sun_set1.day date_hour_birth = sun_set1.hour date_min_birth = sun_set1.minute day_diff = day_diff1 return l_asc_mc
def calc_planets(): Planet = namedtuple('Planet', ['name', 'angle', 'sign']) planet_names = ['Sol', 'Lua', 'Mercurio', 'Venus', 'Marte', 'Jupiter','Saturno', 'Urano', 'Netuno' ,'Plutao'] signs = ['Aries', 'Touro', 'Gemeos', 'Cancer', 'Leao', 'Virgem', 'Libra', 'Escorpiao', 'Sagitario', 'Capricornio', 'Aquario', 'Peixes'] d = datetime.utcnow() t = list(d.timetuple()[:5]) t[3] += t[4]/60.0 t = t[:4] j = swe.julday(*t) result = {} result['date'] = d planets = [] for i in range(10): a = swe.calc_ut(j,i)[0] s = signs[int(a/30)] d = {} d['index'] = i d['name'] = planet_names[i] d['angle'] = a d['sign'] = s planets.append(d) result['planets'] = planets return jsonify(result=result)
def convert_to_julian(self, date: datetime): """ Convert date from Gregorian to Julian calendar. :param date: Date represented as datetime object. :type date: datetime :param daylightsaving: Flag if hour needs day light saving adjust. :rtype: int """ # Transform to UTC timezone. date = date.astimezone(pytz.timezone('UTC')) # Aggregate hours, mins, secs as required by swisseph. aggregate_time = date.hour + (date.minute / 60.0) + (date.second / 3600.0) self.time = aggregate_time # Set calendar type to use based on time options. calflag = astrology.SE_GREG_CAL # Convert date to Julian Day. julian_date = swisseph.julday(date.year, date.month, date.day, aggregate_time, calflag) return julian_date
('L','e'), ('P','f') ) sn = 9*[0] old='' date1 = '1979-01-01' date2 = '2030-01-01' startdate = datetime.datetime.strptime(date1, '%Y-%m-%d') enddate = datetime.datetime.strptime(date2, '%Y-%m-%d') step = datetime.timedelta(days=1) while startdate <= enddate: out = '' y,m,d = startdate.year, startdate.month, startdate.day j = s.julday(y, m, d, 12) for n, b in enumerate(planets): ra = (s.calc_ut(j, b))[0] sn[n] = int(ra//30.) p = sn[3]*1728+sn[8]*144+sn[6]*12+sn[5] q = sn[4]*1728+sn[7]*144+sn[2]*12+sn[0] p = "{0:x}".format(p) q = "{0:x}".format(q) if len(p) < 4: p = (4-len(p)) * '0' + p if len(q) < 4: q = (4-len(q)) * '0' + q for xx,yy in r: p = p.replace(yy,xx) q = q.replace(yy,xx) dmer = sn[1] - sn[0]
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 julday(d): j = swe.julday(d.year, d.month, d.day, d.hour + d.minute/60.0) return j
def lunar(time_zone, year, month, day, location_latitude, location_longitude): # ###lunar eclipses lunar_eclipse = {} now = swe.julday(year, month, day) res = swe.lun_eclipse_when(now) res_how = swe.lun_eclipse_how(res[1][0], 139.7, 35.68) #print res #print res_how eclip_time = swe.revjul(res[1][0]) # utc # print len(res[1]),res[0],res[1],eclip_time,bin(res[0][0]) ecl_central_or_not = '' duration_penumbral = '' ecl_central = int('00000001', 2) central = res[0][0] & ecl_central if central == 1: ecl_central_or_not = 'Eclipse Central' ecl_noncentral = int('00000010', 2) central = res[0][0] & ecl_noncentral if central == 2: ecl_central_or_not = 'Eclipse Non Central' eclipse_total = int('00000100', 2) central = res[0][0] & eclipse_total if central == 4: Type = 'Eclipse Total' start = (date_convert(res[1][6]) + datetime.timedelta(hours=time_zone)) #print 'Start partial', date_convert(res[1][2]) + datetime.timedelta(hours=time_zone) #print 'Start Total ', date_convert(res[1][4]) + datetime.timedelta(hours=time_zone) maxi = (date_convert(res[1][0]) + datetime.timedelta(hours=time_zone)) #print 'End Total ', date_convert(res[1][5]) + datetime.timedelta(hours=time_zone) #print 'End partial ', date_convert(res[1][3]) + datetime.timedelta(hours=time_zone) end = (date_convert(res[1][7]) + datetime.timedelta(hours=time_zone)) duration_penumbral = (date_convert(res[1][7]) - date_convert(res[1][6])) duration_umbral = (date_convert(res[1][3]) - date_convert(res[1][2])) #print 'Total ', date_convert(res[1][5]) - date_convert(res[1][4]) 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' start = (date_convert(res[1][6]) + datetime.timedelta(hours=time_zone)) #print 'Start partial', date_convert(res[1][2]) + datetime.timedelta(hours=time_zone) maxi = (date_convert(res[1][0]) + datetime.timedelta(hours=time_zone)) #print 'End partial ', date_convert(res[1][3]) + datetime.timedelta(hours=time_zone) end = (date_convert(res[1][7]) + datetime.timedelta(hours=time_zone)) duration_penumbral = (date_convert(res[1][7]) - date_convert(res[1][6])) duration_umbral = (date_convert(res[1][3]) - date_convert(res[1][2])) 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' start = (date_convert(res[1][6]) + datetime.timedelta(hours=time_zone)) maxi = (date_convert(res[1][0]) + datetime.timedelta(hours=time_zone)) end = (date_convert(res[1][7]) + datetime.timedelta(hours=time_zone)) duration_umbral = (date_convert(res[1][7]) - date_convert(res[1][6])) 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] 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]] lunar_eclipse = {'ecl_central_or_not' : ecl_central_or_not, 'soros_cycle' : soros_cycle, '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)} return lunar_eclipse
assert(len(x) == len(y)) total = 0 for i in range(len(x)): numer = 1 denom = 1 for j in range(len(x)): if j != i: numer *= (ya - y[j]) denom *= (y[i] - y[j]) total += numer * x[i] / denom return total # Julian Day number as on (year, month, day) at 00:00 UTC gregorian_to_jd = lambda date: swe.julday(date.year, date.month, date.day, 0.0) jd_to_gregorian = lambda jd: swe.revjul(jd, swe.GREG_CAL) # returns (y, m, d, h, min, s) def local_time_to_jdut1(year, month, day, hour = 0, minutes = 0, seconds = 0, timezone = 0.0): """Converts local time to JD(UT1)""" y, m, d, h, mnt, s = swe.utc_time_zone(year, month, day, hour, minutes, seconds, timezone) # BUG in pyswisseph: replace 0 by s jd_et, jd_ut1 = swe.utc_to_jd(y, m, d, h, mnt, 0, flag = swe.GREG_CAL) return jd_ut1 def nakshatra_pada(longitude): """Gives nakshatra (1..27) and paada (1..4) in which given longitude lies""" # 27 nakshatras span 360° one_star = (360 / 27) # = 13°20' # Each nakshatra has 4 padas, so 27 x 4 = 108 padas in 360° one_pada = (360 / 108) # = 3°20'
def date_convert(jul_number): temp = swe.revjul(jul_number) year = temp[0] month = temp[1] day = temp[2] min_temp, hour = math.modf(temp[3]) sec_temp, min = math.modf(min_temp * 60) sub_sec, sec = math.modf(sec_temp * 60) return datetime.datetime(year, month, day, int(hour), int(min), int(sec)) # ###lunar eclipses print 'When next Lunar Eclipse' print '------------------------' now = swe.julday(2016, 3, 23) time_zone = 0 # we have to look up time zone from lat/long res = swe.lun_eclipse_when(now) res_how = swe.lun_eclipse_how(res[1][0], 139.7, 35.68) print res print res_how eclip_time = swe.revjul(res[1][0]) # utc # print len(res[1]),res[0],res[1],eclip_time,bin(res[0][0]) ecl_central = int('00000001', 2) central = res[0][0] & ecl_central if central == 1: print 'Eclipse Central' ecl_noncentral = int('00000010', 2) central = res[0][0] & ecl_noncentral if central == 2: print 'Eclipse Non Central'
# 9 12 - # 10 1 - # 7 12 - # First two numbers are the signs for each planet: 1 = Aries,..., 12 = Pisces # "+ - - -" -> The Sun matches, everything else not so much. import sys import swisseph as s y1,m1,d1,y2,m2,d2 = [int(x) for x in sys.argv[1:]] print(y1,m1,d1,y2,m2,d2) for b in s.SUN, s.MERCURY, s.VENUS, s.MARS: j = s.julday(y1, m1, d1, 12) ra = (s.calc_ut(j, b))[0] x1 = int(ra//30.)+1 j = s.julday(y2, m2, d2, 12) ra = (s.calc_ut(j, b))[0] x2 = int(ra//30.)+1 d = x2-x1 if d < 0: d += 12 if d in (0,2,4,6,8,10): f = "+" else: f = "-" print(x1, x2, f)
for x in xx[0]: 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)
#YYYY = 1956 #MM = 4 #DD = 14 #hh = 9 #mm = 35 #Lezione 7 Es. 20 Bologna (+44°30', Est 11°21'), 22 Febbraio 1940, 11h 20m TU. giorno = datetime.datetime.now().date() ora = datetime.datetime.now().time() YYYY = giorno.year MM = giorno.month DD = giorno.day hh = ora.hour mm = ora.minute ut = hh + mm/60 jut = swe.julday( YYYY, MM, DD, ut, swe.GREG_CAL) house_nums = (10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9) #print(house_nums) ###### Luogo ################################ # Alessandria 44°54′48″N 8°37′12″E 95m #top_long = 44.916; top_lat = 8.616; top_elev = 95; # Milano 45°27′50.98″N 9°11′25.21″E 122m #top_lat = 45.464; top_long = 9.19; top_elev = 122; # Bologna (+44°30', Est 11°21') top_lat = 44.5; top_long = 11.35; top_elev = 54; swe.set_topo(top_long, top_lat, top_elev) ## CASE ##########################################
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]
#!/usr/bin/python # Print current Coleco Zodiac date codes # (needs Python 3 and PySwissEph) # 2016-02-29 import datetime import swisseph as s planets = (s.SUN, s.MERCURY, s.VENUS, s.MARS, s.JUPITER, s.SATURN, s.URANUS, s.NEPTUNE, s.PLUTO, s.MOON) r = (('A', 'a'), ('D', 'b'), ('E', 'c'), ('J', 'd'), ('L', 'e'), ('P', 'f')) sn = 10 * [0] n = datetime.datetime.utcnow() j = s.julday(n.year, n.month, n.day, n.hour + n.minute / 60.) for n, b in enumerate(planets): ra = (s.calc_ut(j, b))[0] sn[n] = int(ra // 30.) ##################################################################### p = sn[3] * 1728 + sn[8] * 144 + sn[6] * 12 + sn[5] q = sn[4] * 1728 + sn[7] * 144 + sn[2] * 12 + sn[0] p = "{0:x}".format(p) q = "{0:x}".format(q) if len(p) < 4: p = (4 - len(p)) * ' ' + p if len(q) < 4: q = (4 - len(q)) * '0' + q for xx, yy in r: p = p.replace(yy, xx)
URANUS = swe.URANUS NEPTUNE = swe.NEPTUNE # 'jd' can be any time: ex, 2015-09-19 14:20 UTC # today = swe.julday(2015, 9, 19, 14 + 20./60) def planet_position(jd, place, planet): """Computes instantaneous planet position """ jd_ut = jd - place.timezone / 24. if planet != swe.KETU: nirayana_long = sidereal_longitude(jd_ut, planet) else: # Ketu nirayana_long = ketu(sidereal_longitude(jd_ut, swe.RAHU)) return nirayana_long if __name__ == "__main__": print("starting...") # hyderabad = Place(17.383, 78.484, +5.5) # today = swe.julday(2020, 3, 10, 18 + 00./60) # planet_pos = planetary_positions(today, hyderabad) # for planet in planet_pos: # print(planet) hyderabad = Place(17.383, 78.484, +5.5) jd = swe.julday(2020, 3, 15, 12 + 00. / 60) print(jd) position = planet_position(jd, hyderabad, JUPITER) print(position)
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 __init__(self,year,month,day,hour,geolon,geolat,altitude,planets,zodiac,openastrocfg,houses_override=None): #ephemeris path (default "/usr/share/swisseph:/usr/local/share/swisseph") #swe.set_ephe_path(ephe_path) #basic location self.jul_day_UT=swe.julday(year,month,day,hour) self.geo_loc = swe.set_topo(geolon,geolat,altitude) #output variables self.planets_sign = list(range(len(planets))) self.planets_degree = list(range(len(planets))) self.planets_degree_ut = list(range(len(planets))) self.planets_info_string = list(range(len(planets))) self.planets_retrograde = list(range(len(planets))) #iflag """ #define SEFLG_JPLEPH 1L // use JPL ephemeris #define SEFLG_SWIEPH 2L // use SWISSEPH ephemeris, default #define SEFLG_MOSEPH 4L // use Moshier ephemeris #define SEFLG_HELCTR 8L // return heliocentric position #define SEFLG_TRUEPOS 16L // return true positions, not apparent #define SEFLG_J2000 32L // no precession, i.e. give J2000 equinox #define SEFLG_NONUT 64L // no nutation, i.e. mean equinox of date #define SEFLG_SPEED3 128L // speed from 3 positions (do not use it, SEFLG_SPEED is // faster and preciser.) #define SEFLG_SPEED 256L // high precision speed (analyt. comp.) #define SEFLG_NOGDEFL 512L // turn off gravitational deflection #define SEFLG_NOABERR 1024L // turn off 'annual' aberration of light #define SEFLG_EQUATORIAL 2048L // equatorial positions are wanted #define SEFLG_XYZ 4096L // cartesian, not polar, coordinates #define SEFLG_RADIANS 8192L // coordinates in radians, not degrees #define SEFLG_BARYCTR 16384L // barycentric positions #define SEFLG_TOPOCTR (32*1024L) // topocentric positions #define SEFLG_SIDEREAL (64*1024L) // sidereal positions """ #check for apparent geocentric (default), true geocentric, topocentric or heliocentric iflag=swe.FLG_SWIEPH+swe.FLG_SPEED if(openastrocfg['postype']=="truegeo"): iflag += swe.FLG_TRUEPOS elif(openastrocfg['postype']=="topo"): iflag += swe.FLG_TOPOCTR elif(openastrocfg['postype']=="helio"): iflag += swe.FLG_HELCTR #sidereal if(openastrocfg['zodiactype']=="sidereal"): iflag += swe.FLG_SIDEREAL mode="SIDM_"+openastrocfg['siderealmode'] swe.set_sid_mode(getattr(swe,mode.encode("ascii"))) #compute a planet (longitude,latitude,distance,long.speed,lat.speed,speed) for i in range(23): ret_flag = swe.calc_ut(self.jul_day_UT,i,iflag) for x in range(len(zodiac)): deg_low=float(x*30) deg_high=float((x+1)*30) if ret_flag[0] >= deg_low: if ret_flag[0] <= deg_high: self.planets_sign[i]=x self.planets_degree[i] = ret_flag[0] - deg_low self.planets_degree_ut[i] = ret_flag[0] #if latitude speed is negative, there is retrograde if ret_flag[3] < 0: self.planets_retrograde[i] = True else: self.planets_retrograde[i] = False #available house systems: """ hsys= ‘P’ Placidus ‘K’ Koch ‘O’ Porphyrius ‘R’ Regiomontanus ‘C’ Campanus ‘A’ or ‘E’ Equal (cusp 1 is Ascendant) ‘V’ Vehlow equal (Asc. in middle of house 1) ‘X’ axial rotation system ‘H’ azimuthal or horizontal system ‘T’ Polich/Page (“topocentric” system) ‘B’ Alcabitus ‘G’ Gauquelin sectors ‘M’ Morinus """ #houses calculation (hsys=P for Placidus) #check for polar circle latitude < -66 > 66 if houses_override: self.jul_day_UT = swe.julday(houses_override[0],houses_override[1],houses_override[2],houses_override[3]) if geolat > 66.0: geolat = 66.0 print("polar circle override for houses, using 66 degrees") elif geolat < -66.0: geolat = -66.0 print("polar circle override for houses, using -66 degrees") #sidereal houses if(openastrocfg['zodiactype']=="sidereal"): sh = swe.houses_ex(self.jul_day_UT,geolat,geolon,openastrocfg['houses_system'].encode("ascii"),swe.FLG_SIDEREAL) else: sh = swe.houses(self.jul_day_UT,geolat,geolon,openastrocfg['houses_system'].encode("ascii")) self.houses_degree_ut = list(sh[0]) self.houses_degree = list(range(len(self.houses_degree_ut))) self.houses_sign = list(range(len(self.houses_degree_ut))) for i in range(12): for x in range(len(zodiac)): deg_low=float(x*30) deg_high=float((x+1)*30) if self.houses_degree_ut[i] >= deg_low: if self.houses_degree_ut[i] <= deg_high: self.houses_sign[i]=x self.houses_degree[i] = self.houses_degree_ut[i] - deg_low #compute additional points and angles #list index 23 is asc, 24 is Mc, 25 is Dsc, 26 is Ic self.planets_degree_ut[23] = self.houses_degree_ut[0] self.planets_degree_ut[24] = self.houses_degree_ut[9] self.planets_degree_ut[25] = self.houses_degree_ut[6] self.planets_degree_ut[26] = self.houses_degree_ut[3] #arabic parts sun,moon,asc = self.planets_degree_ut[0],self.planets_degree_ut[1],self.planets_degree_ut[23] dsc,venus = self.planets_degree_ut[25],self.planets_degree_ut[3] #list index 27 is day pars self.planets_degree_ut[27] = asc + (moon - sun) #list index 28 is night pars self.planets_degree_ut[28] = asc + (sun - moon) #list index 29 is South Node self.planets_degree_ut[29] = self.planets_degree_ut[10] - 180.0 #list index 30 is marriage pars self.planets_degree_ut[30] = (asc+dsc)-venus #if planet degrees is greater than 360 substract 360 or below 0 add 360 for i in range(23,31): if self.planets_degree_ut[i] > 360.0: self.planets_degree_ut[i] = self.planets_degree_ut[i] - 360.0 elif self.planets_degree_ut[i] < 0.0: self.planets_degree_ut[i] = self.planets_degree_ut[i] + 360.0 #get zodiac sign for x in range(12): deg_low=float(x*30.0) deg_high=float((x+1.0)*30.0) if self.planets_degree_ut[i] >= deg_low: if self.planets_degree_ut[i] <= deg_high: self.planets_sign[i]=x self.planets_degree[i] = self.planets_degree_ut[i] - deg_low self.planets_retrograde[i] = False #close swiss ephemeris swe.close()
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 if __name__ == '__main__': loc_origin = (50.1109, 8.6821) loc_dest = (28.6139, 77.2090) t_start = swe.julday(2017,7,26,20.25) t_end = swe.julday(2017,7,27,4) compute_flight_sunrise_sunsets(loc_origin, loc_dest, t_start, t_end)
def getinfo(lat=0.0, lon=0.0, year=1970, month=1, day=1, time=0.0, hsys='E', display=range(23)): swe.set_ephe_path('ephe') julday = swe.julday(year, month, day, time) geo = swe.set_topo(lon, lat, 0) houses, ascmc = swe.houses(julday, lat, lon, hsys) for body in range(25): if str(body) in display: if body == 23: result = swe.calc_ut(julday, 10) degree_ut = sanitize(result[0] + 180); retrograde = bool(result[3] > 0) elif body == 24: result = swe.calc_ut(julday, 11) degree_ut = sanitize(result[0] + 180); retrograde = bool(result[3] > 0) else: result = swe.calc_ut(julday, body) degree_ut = result[0]; retrograde = bool(result[3] < 0) for sign in range(12): deg_low = float(sign * 30) deg_high = float((sign + 1) * 30) if (degree_ut >= deg_low and degree_ut <= deg_high): cibody = { "id" : body, "name" : bnames[body], "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, "degree_ut" : degree_ut, "retrograde" : retrograde } cibodies.append(cibody) for index, degree_ut in enumerate(houses): for sign in range(12): deg_low = float(sign * 30) deg_high = float((sign + 1) * 30) if (degree_ut >= deg_low and degree_ut <= deg_high): cihouse = { "id" : index + 1, "number" : hnames[index], "name" : "House", "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, "degree_ut" : degree_ut } cihouses.append(cihouse) for index, degree_ut in enumerate(ascmc): for sign in range(12): deg_low = float(sign * 30) deg_high = float((sign + 1) * 30) if (degree_ut >= deg_low and degree_ut <= deg_high): ciascmc = { "id" : index + 1, "name" : anames[index], "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, "degree_ut" : degree_ut } ciascmcs.append(ciascmc) for body1 in cibodies: deg1 = body1["degree_ut"] - ciascmcs[0]["degree_ut"] + 180 for body2 in cibodies: deg2 = body2["degree_ut"] - ciascmcs[0]["degree_ut"] + 180 test_aspect(body1, body2, deg1, deg2, 180, 10, "Opposition") test_aspect(body1, body2, deg1, deg2, 150, 2, "Quincunx") test_aspect(body1, body2, deg1, deg2, 120, 8, "Trine") test_aspect(body1, body2, deg1, deg2, 90, 6, "Square") test_aspect(body1, body2, deg1, deg2, 60, 4, "Sextile") test_aspect(body1, body2, deg1, deg2, 30, 1, "Semi-sextile") test_aspect(body1, body2, deg1, deg2, 0, 10, "Conjunction") swe.close() cibodies.sort(cmp_bodies) old_deg = -1000. dist = 0 for body in cibodies: deg = body["degree_ut"] - ciascmcs[0]["degree_ut"] + 180 dist = dist + 1 if math.fabs(old_deg - deg) < 5 else 0 body["dist"] = dist old_deg = deg ciresults = { "bodies" : cibodies, "houses" : cihouses, "ascmcs" : ciascmcs, "aspects" : ciaspects, } return ciresults
month = int (get['month'].value) day = int (get['day'].value) time = float(get['time'].value) hsys = str (get['hsys'].value) display = str (get['display'].value) swe.set_ephe_path('ephe') # Thanks to openastro.org for this algorythm solaryearsecs = 31556925.51 # 365 days, 5 hours, 48 minutes, 45.51 seconds #print("localToSolar: from %s to %s" %(year,newyear)) h,m,s = decHour(time) dt_original = datetime.datetime(year,month,day,h,m,s) dt_new = datetime.datetime(newyear,month,day,h,m,s) result1 = swe.calc_ut(swe.julday(year,month,day,time), 0) #print("localToSolar: first sun %s" % (result1[0]) ) result2 = swe.calc_ut(swe.julday(newyear,month,day,time), 0) #print("localToSolar: second sun %s" % (result2[0]) ) sundiff = result1[0] - result2[0] #print("localToSolar: sundiff %s" %(sundiff)) sundelta = ( sundiff / 360.0 ) * solaryearsecs #print("localToSolar: sundelta %s" % (sundelta)) dt_delta = datetime.timedelta(seconds=int(sundelta)) dt_new = dt_new + dt_delta result2 = swe.calc_ut(swe.julday(dt_new.year,dt_new.month,dt_new.day,decHourJoin(dt_new.hour,dt_new.minute,dt_new.second)), 0) #print("localToSolar: new sun %s" % (result2[0])) #get precise step = 0.000011408 # 1 seconds in degrees sundiff = result1[0] - result2[0]
def calculateNearestEclipse(ecplanet, chrt, year, month, day, hour, minute=0, second=0): out = [] time = hour + minute / 60.0 + second / 3600.0 tjd = swisseph.julday(year, month, day, time, astrology.SE_GREG_CAL) # Calculate the global eclipse nearest to the specified date if ecplanet == 'sun': retflag = swisseph.sol_eclipse_when_glob( tjd, astrology.SEFLG_SWIEPH, astrology.SE_ECL_ALLTYPES_SOLAR, True) planet_id = astrology.SE_SUN elif ecplanet == 'moon': retflag = swisseph.lun_eclipse_when(tjd, astrology.SEFLG_SWIEPH, astrology.SE_ECL_ALLTYPES_LUNAR, True) planet_id = astrology.SE_MOON else: print('No valid eclipse ecplanet input at calculateNearestEclipse\n') exit(1) # Get date and eclipse type ejd = retflag[1][0] eclflag = retflag[0][0] # Convert julian to gregorian date eyear, emonth, eday, ejtime = swisseph.revjul(ejd, astrology.SE_GREG_CAL) ehour, eminute, esecond = util.decToDeg(ejtime) if (eclflag & astrology.SE_ECL_TOTAL): ecltype = 'total' elif (eclflag & astrology.SE_ECL_ANNULAR): ecltype = 'annular' elif (eclflag & astrology.SE_ECL_ANNULAR_TOTAL): ecltype = 'anntotal' elif (eclflag & astrology.SE_ECL_PARTIAL): ecltype = 'partial' elif (eclflag & astrology.SE_ECL_PENUMBRAL): ecltype = 'penumbral' else: ecltype = '' ecldate = 'GMT: %s - %s - %d-%d-%d %d:%d:%d' % ( ecplanet, ecltype, eyear, emonth, eday, ehour, eminute, esecond) # Calculate the sun position for GMT if eclipses_cache.has_key(ecldate): lon = eclipses_cache[ecldate] else: day_time = chart.event.DateTime(eyear, emonth, eday, ehour, eminute, esecond, False, 0, 0, False, 0, 0, 0, chrt.place) day_chart = chart.Chart(chrt.name, chrt.male, day_time, chrt.place, chrt.htype, chrt.notes, chrt.options) lon = day_chart.planets.planets[planet_id].data[planets.Planet.LONG] eclipses_cache[ecldate] = lon # add to out buffer out.append("%.2f\t%s\t" % (lon, ecltype)) # send out sys.stdout.write(''.join(out))
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 if __name__ == '__main__': tz_off = 5.5 jd = swe.julday(2017, 1, 1, 0) - (tz_off / 24) lat = 13.08784 lon = 80.27847 for i in range(366): print(revjul(jd + i + tz_off / 24), compute_lagna_data(jd + i, lat, lon, tz_off))
def __init__(self, year, month, day, hour, geolon, geolat, altitude, planets, zodiac, openastrocfg, houses_override=None): #ephemeris path (default "/usr/share/swisseph:/usr/local/share/swisseph") #swe.set_ephe_path(ephe_path) #basic location self.jul_day_UT = swe.julday(year, month, day, hour) self.geo_loc = swe.set_topo(geolon, geolat, altitude) #output variables self.planets_sign = list(range(len(planets))) self.planets_degree = list(range(len(planets))) self.planets_degree_ut = list(range(len(planets))) self.planets_info_string = list(range(len(planets))) self.planets_retrograde = list(range(len(planets))) #iflag """ #define SEFLG_JPLEPH 1L // use JPL ephemeris #define SEFLG_SWIEPH 2L // use SWISSEPH ephemeris, default #define SEFLG_MOSEPH 4L // use Moshier ephemeris #define SEFLG_HELCTR 8L // return heliocentric position #define SEFLG_TRUEPOS 16L // return true positions, not apparent #define SEFLG_J2000 32L // no precession, i.e. give J2000 equinox #define SEFLG_NONUT 64L // no nutation, i.e. mean equinox of date #define SEFLG_SPEED3 128L // speed from 3 positions (do not use it, SEFLG_SPEED is // faster and preciser.) #define SEFLG_SPEED 256L // high precision speed (analyt. comp.) #define SEFLG_NOGDEFL 512L // turn off gravitational deflection #define SEFLG_NOABERR 1024L // turn off 'annual' aberration of light #define SEFLG_EQUATORIAL 2048L // equatorial positions are wanted #define SEFLG_XYZ 4096L // cartesian, not polar, coordinates #define SEFLG_RADIANS 8192L // coordinates in radians, not degrees #define SEFLG_BARYCTR 16384L // barycentric positions #define SEFLG_TOPOCTR (32*1024L) // topocentric positions #define SEFLG_SIDEREAL (64*1024L) // sidereal positions """ #check for apparent geocentric (default), true geocentric, topocentric or heliocentric iflag = swe.FLG_SWIEPH + swe.FLG_SPEED if (openastrocfg['postype'] == "truegeo"): iflag += swe.FLG_TRUEPOS elif (openastrocfg['postype'] == "topo"): iflag += swe.FLG_TOPOCTR elif (openastrocfg['postype'] == "helio"): iflag += swe.FLG_HELCTR #sidereal if (openastrocfg['zodiactype'] == "sidereal"): iflag += swe.FLG_SIDEREAL mode = "SIDM_" + openastrocfg['siderealmode'] swe.set_sid_mode(getattr(swe, mode.encode("ascii"))) #compute a planet (longitude,latitude,distance,long.speed,lat.speed,speed) for i in range(23): ret_flag = swe.calc_ut(self.jul_day_UT, i, iflag) for x in range(len(zodiac)): deg_low = float(x * 30) deg_high = float((x + 1) * 30) if ret_flag[0] >= deg_low: if ret_flag[0] <= deg_high: self.planets_sign[i] = x self.planets_degree[i] = ret_flag[0] - deg_low self.planets_degree_ut[i] = ret_flag[0] #if latitude speed is negative, there is retrograde if ret_flag[3] < 0: self.planets_retrograde[i] = True else: self.planets_retrograde[i] = False #available house systems: """ hsys= ‘P’ Placidus ‘K’ Koch ‘O’ Porphyrius ‘R’ Regiomontanus ‘C’ Campanus ‘A’ or ‘E’ Equal (cusp 1 is Ascendant) ‘V’ Vehlow equal (Asc. in middle of house 1) ‘X’ axial rotation system ‘H’ azimuthal or horizontal system ‘T’ Polich/Page (“topocentric” system) ‘B’ Alcabitus ‘G’ Gauquelin sectors ‘M’ Morinus """ #houses calculation (hsys=P for Placidus) #check for polar circle latitude < -66 > 66 if houses_override: self.jul_day_UT = swe.julday(houses_override[0], houses_override[1], houses_override[2], houses_override[3]) if geolat > 66.0: geolat = 66.0 print("polar circle override for houses, using 66 degrees") elif geolat < -66.0: geolat = -66.0 print("polar circle override for houses, using -66 degrees") #sidereal houses if (openastrocfg['zodiactype'] == "sidereal"): sh = swe.houses_ex(self.jul_day_UT, geolat, geolon, openastrocfg['houses_system'].encode("ascii"), swe.FLG_SIDEREAL) else: sh = swe.houses(self.jul_day_UT, geolat, geolon, openastrocfg['houses_system'].encode("ascii")) self.houses_degree_ut = list(sh[0]) self.houses_degree = list(range(len(self.houses_degree_ut))) self.houses_sign = list(range(len(self.houses_degree_ut))) for i in range(12): for x in range(len(zodiac)): deg_low = float(x * 30) deg_high = float((x + 1) * 30) if self.houses_degree_ut[i] >= deg_low: if self.houses_degree_ut[i] <= deg_high: self.houses_sign[i] = x self.houses_degree[ i] = self.houses_degree_ut[i] - deg_low #compute additional points and angles #list index 23 is asc, 24 is Mc, 25 is Dsc, 26 is Ic self.planets_degree_ut[23] = self.houses_degree_ut[0] self.planets_degree_ut[24] = self.houses_degree_ut[9] self.planets_degree_ut[25] = self.houses_degree_ut[6] self.planets_degree_ut[26] = self.houses_degree_ut[3] #arabic parts sun, moon, asc = self.planets_degree_ut[0], self.planets_degree_ut[ 1], self.planets_degree_ut[23] dsc, venus = self.planets_degree_ut[25], self.planets_degree_ut[3] #list index 27 is day pars self.planets_degree_ut[27] = asc + (moon - sun) #list index 28 is night pars self.planets_degree_ut[28] = asc + (sun - moon) #list index 29 is South Node self.planets_degree_ut[29] = self.planets_degree_ut[10] - 180.0 #list index 30 is marriage pars self.planets_degree_ut[30] = (asc + dsc) - venus #if planet degrees is greater than 360 substract 360 or below 0 add 360 for i in range(23, 31): if self.planets_degree_ut[i] > 360.0: self.planets_degree_ut[i] = self.planets_degree_ut[i] - 360.0 elif self.planets_degree_ut[i] < 0.0: self.planets_degree_ut[i] = self.planets_degree_ut[i] + 360.0 #get zodiac sign for x in range(12): deg_low = float(x * 30.0) deg_high = float((x + 1.0) * 30.0) if self.planets_degree_ut[i] >= deg_low: if self.planets_degree_ut[i] <= deg_high: self.planets_sign[i] = x self.planets_degree[ i] = self.planets_degree_ut[i] - deg_low self.planets_retrograde[i] = False #close swiss ephemeris swe.close()
def julday(self): d = self.chart.datetime_utc return swe.julday(d.year, d.month, d.day, d.hour + d.minute / 60.0)
sn = 9*[0] old='' n = datetime.datetime.utcnow() date1 = "%4u-%02u-%02u" % (n.year, n.month, n.day) startdate = datetime.datetime.strptime(date1, '%Y-%m-%d') enddate = startdate + datetime.timedelta(days=10) step = datetime.timedelta(hours=1) while startdate <= enddate: out = '' y,m,d = startdate.year, startdate.month, startdate.day hh,mm = startdate.hour, startdate.minute j = s.julday(y, m, d, hh) for n, b in enumerate(planets): ra = (s.calc_ut(j, b))[0] sn[n] = int(ra//30.) p = sn[3]*1728+sn[8]*144+sn[6]*12+sn[5] q = sn[4]*1728+sn[7]*144+sn[2]*12+sn[0] p = "{0:x}".format(p) q = "{0:x}".format(q) if len(p) < 4: p = (4-len(p)) * '0' + p if len(q) < 4: q = (4-len(q)) * '0' + q for xx,yy in r: p = p.replace(yy,xx) q = q.replace(yy,xx) dmer = sn[1] - sn[0]
def ascendant_tests(): print(sys._getframe().f_code.co_name) jd = swe.julday(2015, 9, 24, 23 + 38/60.) assert(ascendant(jd, bangalore) == [2, [4, 37, 10], [5, 4]]) jd = swe.julday(2015, 9, 25, 13 + 29/60. + 13/3600.) assert(ascendant(jd, bangalore) == [8, [20, 23, 31], [20, 3]])
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]
a = Almanac() a.compute(datetime.now(timezone.utc)) print(a.tithi) for t in tithi_list: print(f'requesting for {t.__str__()}') a.get_next_thiti(t) a.get_dates_on_day(VARAM.TUE, DateRange(date(2020, 4, 1), date(2020, 4, 30))) # from flatlib.datetime import Datetime # from flatlib.geopos import GeoPos # import flatlib.const as const # from flatlib.chart import Chart # now = Datetime('2009/07/15', '05:30') # pos = GeoPos(13.0827, 80.2707) # chennai now = swe.julday(2019, 8, 26, .5, swe.GREG_CAL) ts = skyfield.api.load.timescale() planets = skyfield.api.load('de421.bsp') # for k in range(0,39): # swe.set_sid_mode(k) # ayanamsa = swe.get_ayanamsa(now) # print(swe.get_ayanamsa_name(k),ayanamsa) swe.set_sid_mode(swe.SIDM_LAHIRI) # chart = Chart(now, pos, hsys=const.HOUSES_EQUAL) # sun = chart.getObject(const.SUN) # moon = chart.getObject(const.MOON) chennai = skyfield.api.Topos('13.0827 N', '80.2707 E') t0 = ts.utc(2019, 4, 14) t1 = ts.utc(2020, 4, 14)
def datetime_to_julian(date): utc = date.utctimetuple() total_hour = utc.tm_hour*1.0+utc.tm_min/60.0+utc.tm_sec/3600.0 day = swisseph.julday(utc.tm_year, utc.tm_mon, utc.tm_mday, hour=total_hour) swisseph.close() return day
def calc(self, lat=0.0, lon=0.0, i_date=DEFAULT_DATE, hsys='P'): year = i_date.year month = i_date.month day = i_date.day time = dechourjoin(i_date.hour, i_date.minute, i_date.second) julday = swe.julday(year, month, day, time) geo = swe.set_topo(lat, lon, 0) houses, ascmc = swe.houses(julday, lat, lon, hsys) #print houses for i, body in enumerate(bnames): #日月水金火木土天海冥北交 result = swe.calc_ut(julday, bnames_se[body]) degree_ut = result[0]; #和春分点的夹角 retrograde = bool(result[3] < 0) #是否逆行 for sign in range(12): #行星在12星座的什么位置 deg_low = float(sign * 30) deg_high = float((sign + 1) * 30) if (degree_ut >= deg_low and degree_ut <= deg_high): cibody = { "id" : bnames_se[body], "name" : body, "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, #相对星座头部的夹角 "degree_ut" : degree_ut, #和春分点的夹角 "retrograde" : retrograde } #是否逆行 self.cibodies.append(cibody) for index, degree_ut in enumerate(houses): #十二宫的位置 for sign in range(12): deg_low = float(sign * 30) deg_high = float((sign + 1) * 30) if (degree_ut >= deg_low and degree_ut <= deg_high): cihouse = { "id" : index + 1, "name" : "House", "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, "degree_ut" : degree_ut } self.cihouses.append(cihouse) for index in range(2): #上升点和天顶 degree_ut = ascmc[index] for sign in range(12): deg_low = float(sign * 30) deg_high = float((sign + 1) * 30) if (degree_ut >= deg_low and degree_ut <= deg_high): ciascmc = { "id" : index + 1, "name" : anames[index], "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, "degree_ut" : degree_ut } self.ciascmcs.append(ciascmc) cibody = { "id" : anames[index], "name" : anames[index], "sign" : sign, "sign_name" : snames[sign], "degree" : degree_ut - deg_low, "degree_ut" : degree_ut, "retrograde" : None } self.cibodies.append(cibody) swe.close() ciresults = { "bodies" : self.cibodies, "houses" : self.cihouses, "ascmcs" : self.ciascmcs } return ciresults
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 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
import swisseph as swe #swe.set_ephe_path('/usr/share/ephe') # set path to ephemeris files now = swe.julday(2007,3,3) # get Julian day number res = swe.lun_eclipse_when(now) # find next lunar eclipse (from now on) ecltime = swe.revjul(res[1][0]) # get date UTC print (ecltime)
import cmath import collections import csv import math import sys from pathlib import Path from random import random, shuffle from typing import Tuple, List, Dict, Optional import numpy as np import swisseph as swe import roc_sd from roc_estimates import ROC_SD DAYS_IN_YEAR = (swe.julday(2300, 1, 1) - swe.julday(1900, 1, 1)) / 400 swe.set_ephe_path("/home/dmc/astrolog/astephem") SUN = 0 MERCURY = 2 VENUS = 3 """ For each "planet" we're going to consider, we record its index in SwissEph, its full name, a unique two-letter identifier, and its orbital period in years. (Astrologers use the term "planet" to include not only true astronomical planets but all bodies of interest in the solar system, including the Sun, Moon, asteroids and other things too small to be planets). """ PLANET_DATA = [ (0, "Sun", "Su", 1.0), (1, "Moon", "Mo", 0.074),
total = 0 for i in range(len(x)): numer = 1 denom = 1 for j in range(len(x)): if j != i: numer *= (ya - y[j]) denom *= (y[i] - y[j]) total += numer * x[i] / denom return total # Julian Day number as on (year, month, day) at 00:00 UTC gregorian_to_jd = lambda date: swe.julday(date.year, date.month, date.day, 0.0) jd_to_gregorian = lambda jd: swe.revjul(jd, swe.GREG_CAL ) # returns (y, m, d, h, min, s) def solar_longitude(jd): """Solar longitude at given instant (julian day) jd""" data = swe.calc_ut(jd, swe.SUN, flag=swe.FLG_SWIEPH) return data[0] # in degrees def lunar_longitude(jd): """Lunar longitude at given instant (julian day) jd""" data = swe.calc_ut(jd, swe.MOON, flag=swe.FLG_SWIEPH) return data[0] # in degrees
print "week day", weekday #arrondir l'heure? if not heure_dete(month, day): print "winter hour" uthour = hour - 1 else: uthour = hour - 2 print "summer hour" divine_year = reduc_theo(hour, 2) uthour = uthour + 2 #print "uthour",uthour current_jul_day_UT = swe.julday(year, month, day, uthour, gregflag) ret_flag_sun = swe.calc_ut(current_jul_day_UT, 0, gregflag) longitude_sun = ret_flag_sun[0] print "Sun", longitude_sun zodiaque = int(longitude_sun // 30) + 1 print "zodiaque", zodiaque ret_flag_moon = swe.calc_ut(current_jul_day_UT, 1, gregflag) longitude_moon = ret_flag_moon[0] print "moon", longitude_moon cusp = range(13) cusp = swe.houses(current_jul_day_UT, geolat, geolon, "P") #print cusp[0] longitude_asc = cusp[0][0]
def calc_julday(self, datetime_utc): j = swe.julday(datetime_utc.year, datetime_utc.month, datetime_utc.day, datetime_utc.hour + datetime_utc.minute / 60.0) return j
def date_convert(jul_number): temp = swe.revjul(jul_number) year = temp[0] month = temp[1] day = temp[2] min_temp, hour = math.modf(temp[3]) sec_temp, min = math.modf(min_temp * 60) sub_sec, sec = math.modf(sec_temp * 60) return datetime.datetime(year, month, day, int(hour), int(min), int(sec)) print 'Next Solar Eclipse global' print '------------------------' now = swe.julday(2017, 8, 1) time_zone = -0 # we have to look up time zone from lat/long for i in range(1): res_global = swe.sol_eclipse_when_glob(now) print 'global', res_global t_start = res_global[1][0] lat_long = swe.sol_eclipse_where(t_start) print 'where', lat_long longitude = lat_long[1][0] latitude = lat_long[1][1] res_how = swe.sol_eclipse_how(res_global[1][0], longitude, latitude) print 'how', res_how ecl_central = True ecl_central_mask = int('00000001', 2) ecl_type = res_how[0][0] & ecl_central_mask
#!/usr/bin/python # Print approx. hours until next Moon sign # (needs PySwissEph) # 2014-07-08 import datetime import swisseph as s n = datetime.datetime.utcnow() j = s.julday(n.year, n.month, n.day, n.hour + n.minute / 60.) j2 = j ra = (s.calc_ut(j, s.MOON))[0] next_ra = 30.*(1+(ra//30.)) diff = 100 for it in range(15): ra = (s.calc_ut(j2, s.MOON))[0] if next_ra == 360 and ra < 25: h = -ra else: h = next_ra - ra diff = 27.321582/360. * h if abs(diff*24*60*60) < 1: break j2 += diff h = 24 * (j2-j) def plur(x):
month = int(get['month'].value) day = int(get['day'].value) time = float(get['time'].value) hsys = str(get['hsys'].value) display = str(get['display'].value) swe.set_ephe_path('ephe') # Thanks to openastro.org for this algorythm solaryearsecs = 31556925.51 # 365 days, 5 hours, 48 minutes, 45.51 seconds #print("localToSolar: from %s to %s" %(year,newyear)) h, m, s = decHour(time) dt_original = datetime.datetime(year, month, day, h, m, s) dt_new = datetime.datetime(newyear, month, day, h, m, s) result1 = swe.calc_ut(swe.julday(year, month, day, time), 0) #print("localToSolar: first sun %s" % (result1[0]) ) result2 = swe.calc_ut(swe.julday(newyear, month, day, time), 0) #print("localToSolar: second sun %s" % (result2[0]) ) sundiff = result1[0] - result2[0] #print("localToSolar: sundiff %s" %(sundiff)) sundelta = (sundiff / 360.0) * solaryearsecs #print("localToSolar: sundelta %s" % (sundelta)) dt_delta = datetime.timedelta(seconds=int(sundelta)) dt_new = dt_new + dt_delta result2 = swe.calc_ut( swe.julday(dt_new.year, dt_new.month, dt_new.day, decHourJoin(dt_new.hour, dt_new.minute, dt_new.second)), 0) #print("localToSolar: new sun %s" % (result2[0])) #get precise