def _setup_swisseph(self): """Prepare swisseph for calculations.""" f = self._filter # ephemeris type if f._ephe_type == 'swiss': swe.set_ephe_path(f._ephe_path) elif f._ephe_type == 'jpl': swe.set_jpl_file(f._ephe_path) # sidereal mode if f._sid_mode > -1: swe.set_sid_mode(f._sid_mode, f._sid_t0, f._sid_ayan_t0) # situation if f._xcentric == 'topo': swe.set_topo(float(self._longitude), float(self._latitude), self._altitude)
def __init__(self, name, male, time, place, htype, notes, options, full=True, proftype=0, nolat=False): self.name = name self.male = male self.time = time self.place = place self.htype = htype self.notes = notes self.options = options self.full = full self.proftype = proftype self.nolat = nolat d = swisseph.deltat(time.jd) self.obl = swisseph.calc(time.jd+d, astrology.SE_ECL_NUT, 0) # true obliquity of the ecliptic # mean #nutation in long #nutation in obl swisseph.set_topo(place.lon, place.lat, place.altitude) self.create()
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 Setup_eph(self, lat, long, side=1): swe.set_topo(lat, long) swe.set_sid_mode(side)
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 ########################################## # Ascensione retta mediocelo ARMC = (swe.sidtime(jut)+(top_long/15))*15; #print( "\nARMC") #print(ARMC) # Ascensioni oblique delle case (corrispondono alle ascensioni rette, in quanto si misurano sull'equatore case_aoch = [ARMC] case_aoch_gm = [] for i in range(1,12): case_aoch.append((case_aoch[i-1] + 30)%360) for i in range(1,12): case_aoch_gm.append(decdeg2dm(case_aoch[i],"dm")) print( "\nAOCH case dalla 10°")
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 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
def main(): city_name = sys.argv[1] latitude = sexastr2deci(sys.argv[2]) longitude = sexastr2deci(sys.argv[3]) tz = sys.argv[4] start_year = int(sys.argv[5]) year = start_year jd = swisseph.julday(year, 1, 1, 0) jd_start = jd if len(sys.argv) == 7: script = sys.argv[6] else: script = 'deva' #Default script is devanagari swisseph.set_sid_mode(swisseph.SIDM_LAHIRI) #Force Lahiri Ayanamsha sun_month_day = jd - get_last_dhanur_transit(jd, latitude, longitude) month_start_after_set = 0 template_file = open('cal_template_compre.tex') template_lines = template_file.readlines() for i in range(0, len(template_lines) - 3): print template_lines[i][:-1] samvatsara_id = (year - 1568) % 60 + 1 #distance from prabhava samvatsara_names = '%s–%s' % (year_names[script][samvatsara_id], year_names[script][(samvatsara_id % 60) + 1]) new_yr = mesha_sankranti[script] + '~(' + year_names[script][ (samvatsara_id % 60) + 1] + '-' + samvatsara[script] + ')' print '\\mbox{}' print '{\\font\\x="Candara" at 60 pt\\x %d\\\\[0.5cm]}' % year print '\\mbox{\\font\\x="Sanskrit 2003:script=deva" at 48 pt\\x %s}\\\\[0.5cm]' % samvatsara_names print '{\\font\\x="Candara" at 48 pt\\x \\uppercase{%s}\\\\[0.5cm]}' % city_name print '\hrule' #INITIALISE VARIABLES jd_sunrise = [None] * 368 jd_sunset = [None] * 368 jd_moonrise = [None] * 368 longitude_moon = [None] * 368 longitude_sun = [None] * 368 longitude_sun_set = [None] * 368 sun_month_id = [None] * 368 sun_month = [None] * 368 sun_month_rise = [None] * 368 moon_month = [None] * 368 month_data = [None] * 368 tithi_data_string = [None] * 368 tithi_sunrise = [None] * 368 nakshatram_data_string = [None] * 368 nakshatram_sunrise = [None] * 368 karanam_data_string = [None] * 368 karanam_sunrise = [None] * 368 yogam_data_string = [None] * 368 yogam_sunrise = [None] * 368 weekday = [None] * 368 sunrise = [None] * 368 sunset = [None] * 368 madhya = [None] * 368 rahu = [None] * 368 yama = [None] * 368 festival_day_list = {} festivals = [''] * 368 weekday_start = swisseph.day_of_week(jd) + 1 #swisseph has Mon = 0, non-intuitively! ################################################## #Compute all parameters -- latitude/longitude etc# ################################################## for d in range(-1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 local_time = pytz.timezone(tz).localize(datetime(y, m, dt, 6, 0, 0)) #checking @ 6am local - can we do any better? tz_off = datetime.utcoffset(local_time).seconds / 3600.0 #compute offset from UTC jd_sunrise[d + 1] = swisseph.rise_trans( jd_start=jd + 1, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] jd_sunset[d + 1] = swisseph.rise_trans( jd_start=jd + 1, body=swisseph.SUN, lon=longitude, lat=latitude, rsmi=swisseph.CALC_SET | swisseph.BIT_DISC_CENTER)[1][0] jd_moonrise[d + 1] = swisseph.rise_trans( jd_start=jd + 1, body=swisseph.MOON, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] longitude_sun[d + 1] = swisseph.calc_ut( jd_sunrise[d + 1], swisseph.SUN)[0] - swisseph.get_ayanamsa( jd_sunrise[d + 1]) longitude_moon[d + 1] = swisseph.calc_ut( jd_sunrise[d + 1], swisseph.MOON)[0] - swisseph.get_ayanamsa( jd_sunrise[d + 1]) longitude_sun_set[d + 1] = swisseph.calc_ut( jd_sunset[d + 1], swisseph.SUN)[0] - swisseph.get_ayanamsa( jd_sunset[d + 1]) sun_month_id[d + 1] = int(1 + math.floor(( (longitude_sun_set[d + 1]) % 360) / 30.0)) sun_month[d + 1] = int(1 + math.floor(( (longitude_sun_set[d + 1]) % 360) / 30.0)) sun_month_rise[d + 1] = int(1 + math.floor(( (longitude_sun[d + 1]) % 360) / 30.0)) if (d <= 0): continue t_sunrise = (jd_sunrise[d] - jd) * 24.0 + tz_off t_sunset = (jd_sunset[d] - jd) * 24.0 + tz_off #Solar month calculations if month_start_after_set == 1: sun_month_day = 0 month_start_after_set = 0 if sun_month[d] != sun_month[d + 1]: sun_month_day = sun_month_day + 1 if sun_month[d] != sun_month_rise[d + 1]: month_start_after_set = 1 [_m, sun_month_end_time] = get_angam_data_string( masa_names[script], 30, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [0, 1], script) elif sun_month_rise[d] != sun_month[d]: #mAsa pirappu! #sun moves into next rAsi before sunset -- check rules! sun_month_day = 1 [_m, sun_month_end_time] = get_angam_data_string( masa_names[script], 30, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [0, 1], script) else: sun_month_day = sun_month_day + 1 sun_month_end_time = '' month_data[d] = '\\sunmonth{%s}{%d}{%s}' % (masa_names[script][ sun_month[d]], sun_month_day, sun_month_end_time) #KARADAYAN NOMBU -- easy to check here if sun_month_end_time != '': #month ends today if (sun_month[d] == 12 and sun_month_day == 1) or (sun_month[d] == 11 and sun_month_day != 1): festival_day_list[karadayan_nombu[script]] = [d] #Sunrise/sunset and related stuff (like rahu, yama) [rhs, rms, rss] = deci2sexa( t_sunrise) #rise hour sun, rise minute sun, rise sec sun [shs, sms, sss] = deci2sexa(t_sunset) length_of_day = t_sunset - t_sunrise yamagandam_start = t_sunrise + (1 / 8.0) * ( yamagandam_octets[weekday] - 1) * length_of_day yamagandam_end = yamagandam_start + (1 / 8.0) * length_of_day rahukalam_start = t_sunrise + (1 / 8.0) * (rahukalam_octets[weekday] - 1) * length_of_day rahukalam_end = rahukalam_start + (1 / 8.0) * length_of_day madhyahnikam_start = t_sunrise + (1 / 5.0) * length_of_day sunrise[d] = '%02d:%02d' % (rhs, rms) sunset[d] = '%02d:%02d' % (shs, sms) madhya[d] = print_time(madhyahnikam_start) rahu[d] = '%s--%s' % (print_time(rahukalam_start), print_time(rahukalam_end)) yama[d] = '%s--%s' % (print_time(yamagandam_start), print_time(yamagandam_end)) [tithi_sunrise[d], tithi_data_string[d]] = get_angam_data_string( tithi_names[script], 12, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, -1], script) [nakshatram_sunrise[d], nakshatram_data_string[d]] = get_angam_data_string( nakshatra_names[script], (360.0 / 27.0), jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, 0], script) [karanam_sunrise[d], karanam_data_string[d]] = get_angam_data_string( karanam_names[script], 6, jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, -1], script) [yogam_sunrise[d], yogam_data_string[d]] = get_angam_data_string( yogam_names[script], (360.0 / 27.0), jd_sunrise[d], jd_sunrise[d + 1], t_sunrise, longitude_moon[d], longitude_sun[d], longitude_moon[d + 1], longitude_sun[d + 1], [1, 1], script) #ASSIGN MOON MONTHS last_month_change = 1 last_moon_month = None for d in range(1, 367): #Assign moon_month for each day if (tithi_sunrise[d] == 1): for i in range(last_month_change, d): #print '%%#Setting moon_month to sun_month_id, for i=%d:%d to %d' %(last_month_change,d-1,sun_month_id[d]) if (sun_month_id[d] == last_moon_month): moon_month[i] = sun_month_id[d] % 12 + 0.5 else: moon_month[i] = sun_month_id[d] last_month_change = d last_moon_month = sun_month_id[d] elif (tithi_sunrise[d] == 2 and tithi_sunrise[d - 1] == 30): #prathama tithi was never seen @ sunrise for i in range(last_month_change, d): #print '%%@Setting moon_month to sun_month_id, for i=%d:%d to %d (last month = %d)' %(last_month_change,d-1,sun_month_id[d],last_moon_month) if (sun_month_id[d - 1] == last_moon_month): moon_month[i] = sun_month_id[d - 1] % 12 + 0.5 else: moon_month[i] = sun_month_id[d - 1] last_month_change = d last_moon_month = sun_month_id[d - 1] for i in range(last_month_change, 367): moon_month[i] = sun_month_id[last_month_change - 1] + 1 #for d in range(1,367): #jd = jd_start-1+d #[y,m,dt,t] = swisseph.revjul(jd) #print '%%#%02d-%02d-%4d: %3d:%s (sunrise tithi=%d) {%s}' % (dt,m,y,d,moon_month[d],tithi_sunrise[d],tithi_data_string[d]) log_file = open('cal_log_%4d.txt' % year, 'w') for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) log_data = '%02d-%02d-%4d\t[%3d]\tsun_rashi=%8.3f\ttithi=%8.3f\tsun_month=%2d\tmoon_month=%4.1f\n' % ( dt, m, y, d, (longitude_sun_set[d] % 360) / 30.0, get_angam_float(jd_sunrise[d], 12.0, [1, -1]), sun_month[d], moon_month[d]) log_file.write(log_data) #PRINT CALENDAR for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 ################## #Festival details# ################## ###--- MONTHLY VRATAMS ---### #EKADASHI Vratam if tithi_sunrise[d] == 11 or tithi_sunrise[ d] == 12: #One of two consecutive tithis must appear @ sunrise! #check for shukla ekadashi[script] if (tithi_sunrise[d] == 11 and tithi_sunrise[d + 1] == 11): festivals[d + 1] = sarva[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) #moon_month[d] or [d+1]? if moon_month[d + 1] == 4: festivals[d + 1] += '\\\\' + chaturmasya_start[script] if moon_month[d + 1] == 8: festivals[d + 1] += '\\\\' + chaturmasya_end[script] elif (tithi_sunrise[d] == 11 and tithi_sunrise[d + 1] != 11): #Check dashami end time to decide for whether this is sarva[script]/smartha[script] tithi_arunodayam = get_tithi( jd_sunrise[d] - (1 / 15.0) * (jd_sunrise[d] - jd_sunrise[d - 1]) ) #Two muhurtams is 1/15 of day-length if tithi_arunodayam == 10: festivals[d] = smartha[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) festivals[d + 1] = vaishnava[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) if moon_month[d] == 4: festivals[d] += '\\\\' + chaturmasya_start[script] if moon_month[d] == 8: festivals[d] += '\\\\' + chaturmasya_end[script] else: festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) if moon_month[d] == 4: festivals[d] += '\\\\' + chaturmasya_start[script] if moon_month[d] == 8: festivals[d] += '\\\\' + chaturmasya_end[script] elif (tithi_sunrise[d - 1] != 11 and tithi_sunrise[d] == 12): festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='shukla', month=moon_month[d], script=script) if moon_month[d] == 4: festivals[d] += '\\\\' + chaturmasya_start[script] if moon_month[d] == 8: festivals[d] += '\\\\' + chaturmasya_end[script] if tithi_sunrise[d] == 26 or tithi_sunrise[ d] == 27: #One of two consecutive tithis must appear @ sunrise! #check for krishna ekadashi[script] if (tithi_sunrise[d] == 26 and tithi_sunrise[d + 1] == 26): festivals[d + 1] = sarva[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) #moon_month[d] or [d+1]? elif (tithi_sunrise[d] == 26 and tithi_sunrise[d + 1] != 26): #Check dashami end time to decide for whether this is sarva[script]/smartha[script] tithi_arunodayam = get_tithi( jd_sunrise[d] - (1 / 15.0) * (jd_sunrise[d] - jd_sunrise[d - 1]) ) #Two muhurtams is 1/15 of day-length if tithi_arunodayam == 25: festivals[d] = smartha[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) festivals[d + 1] = vaishnava[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) else: festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) elif (tithi_sunrise[d - 1] != 26 and tithi_sunrise[d] == 27): festivals[d] = sarva[script] + '~' + get_ekadashi_name( paksha='krishna', month=moon_month[d], script=script) #PRADOSHA Vratam if tithi_sunrise[d] == 12 or tithi_sunrise[d] == 13: ldiff_set = (swisseph.calc_ut(jd_sunset[d], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d], swisseph.SUN)[0]) % 360 ldiff_set_tmrw = ( swisseph.calc_ut(jd_sunset[d + 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d + 1], swisseph.SUN)[0]) % 360 tithi_sunset = int(1 + math.floor(ldiff_set / 12.0)) tithi_sunset_tmrw = int(1 + math.floor(ldiff_set_tmrw / 12.0)) if tithi_sunset <= 13 and tithi_sunset_tmrw != 13: festivals[d] = pradosham[script] elif tithi_sunset_tmrw == 13: festivals[d + 1] = pradosham[script] if tithi_sunrise[d] == 27 or tithi_sunrise[d] == 28: ldiff_set = (swisseph.calc_ut(jd_sunset[d], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d], swisseph.SUN)[0]) % 360 ldiff_set_tmrw = ( swisseph.calc_ut(jd_sunset[d + 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_sunset[d + 1], swisseph.SUN)[0]) % 360 tithi_sunset = int(1 + math.floor(ldiff_set / 12.0)) tithi_sunset_tmrw = int(1 + math.floor(ldiff_set_tmrw / 12.0)) if tithi_sunset <= 28 and tithi_sunset_tmrw != 28: festivals[d] = pradosham[script] elif tithi_sunset_tmrw == 28: festivals[d + 1] = pradosham[script] #SANKATAHARA chaturthi[script] if tithi_sunrise[d] == 18 or tithi_sunrise[d] == 19: ldiff_moonrise_yest = ( swisseph.calc_ut(jd_moonrise[d - 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_moonrise[d - 1], swisseph.SUN)[0]) % 360 ldiff_moonrise = ( swisseph.calc_ut(jd_moonrise[d], swisseph.MOON)[0] - swisseph.calc_ut(jd_moonrise[d], swisseph.SUN)[0]) % 360 ldiff_moonrise_tmrw = ( swisseph.calc_ut(jd_moonrise[d + 1], swisseph.MOON)[0] - swisseph.calc_ut(jd_moonrise[d + 1], swisseph.SUN)[0]) % 360 tithi_moonrise_yest = int(1 + math.floor(ldiff_moonrise_yest / 12.0)) tithi_moonrise = int(1 + math.floor(ldiff_moonrise / 12.0)) tithi_moonrise_tmrw = int(1 + math.floor(ldiff_moonrise_tmrw / 12.0)) if tithi_moonrise == 19: if tithi_moonrise_yest != 19: #otherwise yesterday would have already been assigned festivals[d] = chaturthi[script] if moon_month[d] == 5: #shravana krishna chaturthi[script] festivals[d] = maha[script] + festivals[d] elif tithi_moonrise_tmrw == 19: festivals[d + 1] = chaturthi[script] if moon_month[ d] == 5: #moon_month[d] and[d+1] are same, so checking [d] is enough festivals[d + 1] = maha[script] + festivals[d + 1] #SHASHTHI Vratam if tithi_sunrise[d] == 5 or tithi_sunrise[d] == 6: if tithi_sunrise[d] == 6 or (tithi_sunrise[d] == 5 and tithi_sunrise[d + 1] == 7): if tithi_sunrise[ d - 1] != 6: #otherwise yesterday would have already been assigned festivals[d] = shashthi[script] if moon_month[d] == 8: #kArtika krishna shashthi[script] festivals[d] = skanda[script] + festivals[d] elif tithi_sunrise[d + 1] == 6: festivals[d + 1] = shashthi[script] if moon_month[ d] == 8: #moon_month[d] and[d+1] are same, so checking [d] is enough festivals[d + 1] = skanda[script] + festivals[d + 1] ###--- OTHER (MAJOR) FESTIVALS ---### #type of month | month number | type of angam (tithi|nakshatram) | angam number | min_t cut off for considering prev day (without sunrise_angam) as festival date purvaviddha_rules = { akshaya_tritiya[script]: ['moon_month', 2, 'tithi', 3, 0], chitra_purnima[script]: ['sun_month', 1, 'tithi', 15, 0], durgashtami[script]: ['moon_month', 7, 'tithi', 8, 0], mahanavami[script]: ['moon_month', 7, 'tithi', 9, 0], vijayadashami[script]: ['moon_month', 7, 'tithi', 10, 0], dipavali[script]: ['moon_month', 7, 'tithi', 29, 0], shankara_jayanti[script]: ['moon_month', 2, 'tithi', 5, 0], yajur_upakarma[script]: ['moon_month', 5, 'tithi', 15, 0], rg_upakarma[script]: ['moon_month', 5, 'nakshatram', 22, 0], sama_upakarma[script]: ['sun_month', 5, 'nakshatram', 13, 0], rishi_panchami[script]: ['moon_month', 6, 'tithi', 5, 0], ananta_chaturdashi[script]: ['moon_month', 6, 'tithi', 14, 0], mahalaya_paksham[script]: ['moon_month', 6, 'tithi', 16, 0], hanumat_jayanti[script]: ['sun_month', 9, 'tithi', 30, 0], ardra_darshanam[script]: ['sun_month', 9, 'nakshatram', 6, 0], ratha_saptami[script]: ['sun_month', 10, 'tithi', 7, 0], goda_jayanti[script]: ['sun_month', 4, 'nakshatram', 11, 0], adi_krittika[script]: ['sun_month', 4, 'nakshatram', 3, 0], phalguni_uttaram[script]: ['sun_month', 12, 'nakshatram', 12, 4], mahalaya_amavasya[script]: ['moon_month', 6, 'tithi', 30, 0], uma_maheshvara_vratam[script]: ['moon_month', 6, 'tithi', 15, 0] } for x in iter(purvaviddha_rules.keys()): rule = purvaviddha_rules[x] if rule[0] == 'moon_month': if moon_month[d] == rule[1]: if rule[2] == 'tithi': fday = get_festival_day_purvaviddha( rule[3], tithi_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_tithi, rule[4]) elif rule[2] == 'nakshatram': fday = get_festival_day_purvaviddha( rule[3], nakshatram_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_nakshatram, rule[4]) if fday is not None: if festival_day_list.has_key(x): if festival_day_list[x][0] != fday: #Second occurrence of a festival within a Gregorian calendar year festival_day_list[x] = [ festival_day_list[x][0], fday ] else: festival_day_list[x] = [fday] elif rule[0] == 'sun_month': if sun_month[d] == rule[1]: if rule[2] == 'tithi': fday = get_festival_day_purvaviddha( rule[3], tithi_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_tithi, rule[4]) elif rule[2] == 'nakshatram': fday = get_festival_day_purvaviddha( rule[3], nakshatram_sunrise, d, jd_sunrise[d], jd_sunrise[d + 1], get_nakshatram, rule[4]) if fday is not None: if festival_day_list.has_key(x): if festival_day_list[x][0] != fday: #Second occurrence of a festival within a Gregorian calendar year festival_day_list[x] = [ festival_day_list[x][0], fday ] else: festival_day_list[x] = [fday] else: print 'Error; unknown string in rule: %s' % (rule[0]) return #NAVARATRI START if moon_month[d] == 7 and moon_month[d - 1] == 6: festival_day_list[navaratri_start[script]] = [d] #PONGAL/AYANAM if sun_month[d] == 10 and sun_month[d - 1] == 9: festival_day_list[uttarayanam[script]] = [d] if sun_month[d] == 4 and sun_month[d - 1] == 3: festival_day_list[dakshinayanam[script]] = [d] if sun_month[d] == 1 and sun_month[d - 1] == 12: festival_day_list[new_yr] = [d] if moon_month[d] == 1 and moon_month[d - 1] != 1: festival_day_list[yugadi[script]] = [d] #SHRIRAMANAVAMI if moon_month[d] == 1: if tithi_sunrise[d] == 8 or tithi_sunrise[d] == 9: t_11 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (2.0 / 5.0)) #madhyahna1 start t_12 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (3.0 / 5.0)) #madhyahna1 end t_21 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (2.0 / 5.0)) #madhyahna2 start t_22 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (3.0 / 5.0)) #madhyahna2 end if t_11 == 9 or t_12 == 9: if t_21 == 9 or t_22 == 9: festival_day_list[ramanavami[script]] = [d + 1] else: festival_day_list[ramanavami[script]] = [d] #JANMASHTAMI if moon_month[d] == 5: if tithi_sunrise[d] == 22 or tithi_sunrise[d] == 23: t_11 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (7.0 / 15.0)) #nishita1 start t_12 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (8.0 / 15.0)) #nishita1 end #t_11 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(2.0/5.0))#madhyaratri1 start #t_12 = get_tithi(jd_sunset[d]+(jd_sunrise[d+1]-jd_sunset[d])*(3.0/5.0))#madhyaratri1 end t_21 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (7.0 / 15.0)) #nishita2 start t_22 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (8.0 / 15.0)) #nishita2 end #t_21 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(2.0/5.0))#madhyaratri2 start #t_22 = get_tithi(jd_sunset[d+1]+(jd_sunrise[d+2]-jd_sunset[d+1])*(3.0/5.0))#madhyaratri2 end if t_11 == 23 or t_12 == 23: if t_21 == 23 or t_22 == 23: festival_day_list[janmashtami[script]] = [d + 1] else: festival_day_list[janmashtami[script]] = [d] #SHIVARATRI if moon_month[d] == 11: if tithi_sunrise[d] == 28 or tithi_sunrise[d] == 29: t_11 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (7.0 / 15.0)) #nishita1 start t_12 = get_tithi(jd_sunset[d] + (jd_sunrise[d + 1] - jd_sunset[d]) * (8.0 / 15.0)) #nishita1 end t_21 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (7.0 / 15.0)) #nishita2 start t_22 = get_tithi(jd_sunset[d + 1] + (jd_sunrise[d + 2] - jd_sunset[d + 1]) * (8.0 / 15.0)) #nishita2 end if t_11 == 29 or t_12 == 29: if t_21 == 29 or t_22 == 29: festival_day_list[shivaratri[script]] = [d + 1] else: festival_day_list[shivaratri[script]] = [d] #VINAYAKA CHATURTHI if moon_month[d] == 6: if tithi_sunrise[d] == 3 or tithi_sunrise[d] == 4: t_11 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (2.0 / 5.0)) #madhyahna1 start t_12 = get_tithi(jd_sunrise[d] + (jd_sunset[d] - jd_sunrise[d]) * (3.0 / 5.0)) #madhyahna1 end t_21 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (2.0 / 5.0)) #madhyahna2 start t_22 = get_tithi(jd_sunrise[d + 1] + (jd_sunset[d + 1] - jd_sunrise[d + 1]) * (3.0 / 5.0)) #madhyahna2 end if t_11 == 4 or t_12 == 4: if t_21 == 4 or t_22 == 4: festival_day_list[vchaturthi[script]] = [d + 1] else: festival_day_list[vchaturthi[script]] = [d] #Add saved festivals festival_day_list[gayatri_japam[script]] = [ festival_day_list[yajur_upakarma[script]][0] + 1 ] festival_day_list[varalakshmi_vratam[script]] = [ festival_day_list[yajur_upakarma[script]][0] - ((weekday_start - 1 + festival_day_list[yajur_upakarma[script]][0] - 5) % 7) ] #KARADAYAN_NOMBU for x in iter(festival_day_list.keys()): for j in range(0, len(festival_day_list[x])): if festivals[festival_day_list[x][j]] != '': festivals[festival_day_list[x][j]] += '\\\\' festivals[festival_day_list[x][j]] += x ###--- ECLIPSES ---### ###--- LUNAR ECLIPSES ---### swisseph.set_topo(lon=longitude, lat=latitude, alt=0.0) #Set location jd = jd_start while 1: next_ecl_lun = swisseph.lun_eclipse_when(jd) jd = next_ecl_lun[1][0] + (tz_off / 24.0) jd_ecl_lun_start = next_ecl_lun[1][2] + (tz_off / 24.0) jd_ecl_lun_end = next_ecl_lun[1][3] + (tz_off / 24.0) ecl_y = swisseph.revjul( jd - 1 )[0] # -1 is to not miss an eclipse that occurs after sunset on 31-Dec! if ecl_y != start_year: break else: ecl_lun_start = swisseph.revjul(jd_ecl_lun_start)[3] ecl_lun_end = swisseph.revjul(jd_ecl_lun_end)[3] if (jd_ecl_lun_start - (tz_off / 24.0)) == 0.0 or (jd_ecl_lun_end - (tz_off / 24.0)) == 0.0: jd = jd + 20 #Move towards the next eclipse... at least the next full moon (>=25 days away) continue fday = int(math.floor(jd_ecl_lun_start) - math.floor(jd_start) + 1) #print '%%',jd,fday,jd_sunrise[fday],jd_sunrise[fday-1] if (jd < (jd_sunrise[fday] + tz_off / 24.0)): fday -= 1 if ecl_lun_start < swisseph.revjul(jd_sunrise[fday + 1] + tz_off / 24.0)[3]: ecl_lun_start += 24 #print '%%',jd,fday,jd_sunrise[fday],jd_sunrise[fday-1],ecl_lun_start, ecl_lun_end jd_moonrise_ecl_day = swisseph.rise_trans( jd_start=jd_sunrise[fday], body=swisseph.MOON, lon=longitude, lat=latitude, rsmi=swisseph.CALC_RISE | swisseph.BIT_DISC_CENTER)[1][0] + (tz_off / 24.0) jd_moonset_ecl_day = swisseph.rise_trans( jd_start=jd_moonrise_ecl_day, body=swisseph.MOON, lon=longitude, lat=latitude, rsmi=swisseph.CALC_SET | swisseph.BIT_DISC_CENTER)[1][0] + (tz_off / 24.0) #if jd_ecl_lun_start<(jd_sunrise[fday]+(tz_off/24.0)): if ecl_lun_end < ecl_lun_start: ecl_lun_end += 24 #print '%%', (jd_ecl_lun_start), (jd_ecl_lun_end), (jd_moonrise_ecl_day), (jd_moonset_ecl_day) #print '%%', swisseph.revjul(jd_ecl_lun_start), swisseph.revjul(jd_ecl_lun_end), swisseph.revjul(jd_moonrise_ecl_day), swisseph.revjul(jd_moonset_ecl_day) if jd_ecl_lun_end < jd_moonrise_ecl_day or jd_ecl_lun_start > jd_moonset_ecl_day: jd = jd + 20 #Move towards the next eclipse... at least the next full moon (>=25 days away) continue lun_ecl_str = chandra_grahanam[script] + '~\\textsf{' + print_time2( ecl_lun_start) + '}{\\RIGHTarrow}\\textsf{' + print_time2( ecl_lun_end) + '}' if festivals[fday] != '': festivals[fday] += '\\\\' festivals[fday] += lun_ecl_str jd = jd + 20 ###--- SOLAR ECLIPSES ---### swisseph.set_topo(lon=longitude, lat=latitude, alt=0.0) #Set location jd = jd_start while 1: next_ecl_sol = swisseph.sol_eclipse_when_loc(julday=jd, lon=longitude, lat=latitude) jd = next_ecl_sol[1][0] + (tz_off / 24.0) jd_ecl_sol_start = next_ecl_sol[1][1] + (tz_off / 24.0) jd_ecl_sol_end = next_ecl_sol[1][4] + (tz_off / 24.0) ecl_y = swisseph.revjul( jd - 1 )[0] # -1 is to not miss an eclipse that occurs after sunset on 31-Dec! if ecl_y != start_year: break else: #print '%%', fday, (jd_ecl_sol_start), (jd_ecl_sol_end), (jd_sunrise[fday]) #print '%%', swisseph.revjul(jd_ecl_sol_start), swisseph.revjul(jd_ecl_sol_end), swisseph.revjul(jd_sunrise[fday]) fday = int(math.floor(jd) - math.floor(jd_start) + 1) if (jd < (jd_sunrise[fday] + tz_off / 24.0)): fday -= 1 #print '%%', fday, (jd_ecl_sol_start), (jd_ecl_sol_end), (jd_sunrise[fday]) #print '%%', swisseph.revjul(jd_ecl_sol_start), swisseph.revjul(jd_ecl_sol_end), swisseph.revjul(jd_sunrise[fday]) ecl_sol_start = swisseph.revjul(jd_ecl_sol_start)[3] ecl_sol_end = swisseph.revjul(jd_ecl_sol_end)[3] if (jd_ecl_sol_start - (tz_off / 24.0)) == 0.0 or ( jd_ecl_sol_end - (tz_off / 24.0) ) == 0.0: # or jd_ecl_end<jd_sunrise[fday] or jd_ecl_start>jd_sunset[fday]: jd = jd + 20 #Move towards the next eclipse... at least the next new moon (>=25 days away) continue if ecl_sol_end < ecl_sol_start: ecl_sol_end += 24 sol_ecl_str = surya_grahanam[script] + '~\\textsf{' + print_time2( ecl_sol_start) + '}{\\RIGHTarrow}\\textsf{' + print_time2( ecl_sol_end) + '}' if festivals[fday] != '': festivals[fday] += '\\\\' festivals[fday] += sol_ecl_str jd = jd + 20 ###--- FESTIVAL ADDITIONS COMPLETE ---### ###--- PRINT LIST OF FESTIVALS (Page 2) ---### if script == 'en': cal = Calendar() print '\\newpage' print '\\centerline {\\LARGE {{%s}}}\\mbox{}\\\\[2cm]' % list_of_festivals[ script] print '\\begin{center}' print '\\begin{minipage}[t]{0.3\\linewidth}' print '\\begin{center}' print '\\begin{tabular}{>{\\sffamily}r>{\\sffamily}r>{\\sffamily}cp{6cm}}' mlast = 1 for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 if festivals[d] != '': if m != mlast: mlast = m #print '\\hline\\\\' print '\\\\' if m == 5 or m == 9: print '\\end{tabular}' print '\\end{center}' print '\\end{minipage}\hspace{1cm}%' print '\\begin{minipage}[t]{0.3\\linewidth}' print '\\begin{center}' print '\\begin{tabular}{>{\\sffamily}r>{\\sffamily}l>{\\sffamily}cp{6cm}}' print '%s & %s & %s & {\\raggedright %s} \\\\' % ( MON[m], dt, WDAY[weekday], festivals[d]) if script == 'en': event = Event() event.add('summary', festivals[d]) event.add('dtstart', datetime(y, m, dt)) event.add('dtend', datetime(y, m, dt)) cal.add_component(event) if m == 12 and dt == 31: break print '\\end{tabular}' print '\\end{center}' print '\\end{minipage}' print '\\end{center}' print '\\clearpage' if script == 'en': cal_fname = '%s-%4d.ics' % (city_name, start_year) cal_file = open(cal_fname, 'w') cal_file.write(cal.as_string()) cal_file.close() #Layout calendar in LATeX format #We use a separate loop here, because of festivals like varalakshmi #vratam, for which we backtrack to the previous friday from yajur #upakarma and change the list of festivals! for d in range(1, 367): jd = jd_start - 1 + d [y, m, dt, t] = swisseph.revjul(jd) weekday = (weekday_start - 1 + d) % 7 if dt == 1: if m > 1: if weekday != 0: #Space till Sunday for i in range(weekday, 6): print "{} &" print "\\\\ \hline" print '\end{tabular}' print '\n\n' #Begin tabular print '\\begin{tabular}{|c|c|c|c|c|c|c|}' print '\multicolumn{7}{c}{\Large \\bfseries \sffamily %s %s}\\\\[3mm]' % ( month[m], y) print '\hline' print '\\textbf{\\textsf{SUN}} & \\textbf{\\textsf{MON}} & \\textbf{\\textsf{TUE}} & \\textbf{\\textsf{WED}} & \\textbf{\\textsf{THU}} & \\textbf{\\textsf{FRI}} & \\textbf{\\textsf{SAT}} \\\\ \hline' #print '\\textbf{भानु} & \\textbf{इन्दु} & \\textbf{भौम} & \\textbf{बुध} & \\textbf{गुरु} & \\textbf{भृगु} & \\textbf{स्थिर} \\\\ \hline' #Blanks for previous weekdays for i in range(0, weekday): print "{} &" print '\caldata{\\textcolor{%s}{%s}}{%s{%s}}{\\sundata{%s}{%s}{%s}}{\\tnyk{%s}{%s}{%s}{%s}}{\\rahuyama{%s}{%s}}{%s} ' % ( daycol[weekday], dt, month_data[d], get_chandra_masa(moon_month[d], chandra_masa_names, script), sunrise[d], sunset[d], madhya[d], tithi_data_string[d], nakshatram_data_string[d], yogam_data_string[d], karanam_data_string[d], rahu[d], yama[d], festivals[d]) if weekday == 6: print "\\\\ \hline" else: print "&" if m == 12 and dt == 31: break # For debugging specific dates #if m==4 and dt==10: # break for i in range(weekday + 1, 6): print "{} &" if weekday != 6: print "\\\\ \hline" print '\end{tabular}' print '\n\n' print template_lines[-2][:-1] print template_lines[-1][:-1]
def __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 __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 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]
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 ########################################## # Ascensione retta mediocelo ARMC = (swe.sidtime(jut) + (top_long / 15)) * 15 #print( "\nARMC") #print(ARMC) # Ascensioni oblique delle case (corrispondono alle ascensioni rette, in quanto si misurano sull'equatore case_aoch = [ARMC] case_aoch_gm = [] for i in range(1, 12): case_aoch.append((case_aoch[i - 1] + 30) % 360) for i in range(1, 12): case_aoch_gm.append(decdeg2dm(case_aoch[i], "dm")) print("\nAOCH case dalla 10°")
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
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)) #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]) #arabic parts sun, moon, asc = self.planets_degree_ut[0], self.planets_degree_ut[ 1], self.houses_degree_ut[0] dsc, venus = self.houses_degree_ut[6], self.planets_degree_ut[3] #offset offset = moon - sun #if planet degrees is greater than 360 substract 360 or below 0 add 360 for i in range(len(self.houses_degree_ut)): #add offset #self.houses_degree_ut[i] += offset if self.houses_degree_ut[i] > 360.0: self.houses_degree_ut[i] = self.houses_degree_ut[i] - 360.0 elif self.houses_degree_ut[i] < 0.0: self.houses_degree_ut[i] = self.houses_degree_ut[i] + 360.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 #mean apogee bm = self.planets_degree_ut[12] #mean north node mn = self.planets_degree_ut[10] #perigee lunaire moyen pl = self.planets_degree_ut[22] #perigee solaire moyen #define SE_NODBIT_MEAN 1 #define SE_NODBIT_OSCU 2 #define SE_NODBIT_OSCU_BAR 4 #define SE_NODBIT_FOPOINT 256 #Return: 4 tuples of 6 float (asc, des, per, aph) ps = swe.nod_aps_ut(self.jul_day_UT, 0, swe.NODBIT_MEAN, iflag) pl = swe.nod_aps_ut(self.jul_day_UT, 1, swe.NODBIT_MEAN, iflag) ps = ps[2][0] pl = pl[2][0] #print mn #print sun #print ps #print moon #print pl c = 1.517 * math.sin(2 * math.radians(sun - mn)) c += -0.163 * math.sin(math.radians(sun - ps)) c += -0.128 * math.sin(2 * math.radians(moon - sun)) c += 0.120 * math.sin(2 * math.radians(moon - mn)) c += 0.107 * math.sin(2 * math.radians(pl - mn)) c += 0.063 * math.sin(math.radians(3 * sun - ps - 2 * mn)) c += 0.040 * math.sin(math.radians(moon + pl - 2 * sun)) c += -0.040 * math.sin(math.radians(moon + pl - 2 * mn)) c += 0.027 * math.sin(math.radians(moon - pl)) c += -0.027 * math.sin(math.radians(sun + ps - 2 * mn)) c += 0.015 * math.sin(2 * math.radians(sun - pl)) c += -0.013 * math.sin(math.radians(moon + 2 * mn - pl - 2 * sun)) c += -0.013 * math.sin(math.radians(moon - 2 * mn - pl + 2 * sun)) c += -0.007 * math.sin(math.radians(2 * moon + pl - 3 * sun)) c += 0.005 * math.sin(math.radians(3 * moon - pl - 2 * mn)) c += -0.005 * math.sin(math.radians(3 * moon - pl - 2 * sun)) #print c sbm = sun - bm if sbm < 0: sbm += 360 if sbm > 180.0: sbm -= 180 print("sun %s black moon %s sun-bm %s=%s" % (sun, bm, sun - bm, sbm)) q = 12.333 if sbm < 60.0: print('sbm<60') c = q * math.sin(1.5 * math.radians(sbm)) elif sbm > 120.0: print('sbm>120') c = q * math.cos(1.5 * math.radians(sbm)) else: print('sbm 60-120') c = -q * math.cos(3.0 * math.radians(sbm)) true_lilith = c def true_lilith_calc(sun, lilith): deg = sun - lilith q = 12.333 if deg < 0.0: deg += 360.0 if deg > 180.0: deg -= 180.0 if deg < 60.0: return q * math.sin(1.5 * math.radians(deg) ) - 1.892 * math.sin(3 * math.radians(deg)) elif deg > 120.0: return q * math.cos(1.5 * math.radians(deg) ) + 1.892 * math.sin(3 * math.radians(deg)) elif deg < 100.0: return -q * math.cos( 3.0 * math.radians(deg)) + 0.821 * math.cos( 4.5 * math.radians(deg)) else: return -q * math.cos(3.0 * math.radians(deg)) def true_lilith_calc2(sun, lilith): deg = sun - lilith q = 12.333 if deg < 0.0: deg += 360.0 if deg > 180.0: deg -= 180.0 if deg < 60.0: return q * math.sin(1.5 * math.radians(deg)) elif deg > 120.0: return q * math.cos(1.5 * math.radians(deg)) else: return -q * math.cos(3.0 * math.radians(deg)) true_lilith = true_lilith_calc2(sun, bm) #print c """ if sbm < 60.0: print 'sbm 0-60' c= q * math.sin(1.5*math.radians(sbm)) - 0.0917 elif sbm >= 60.0 and sbm < 120.0: print 'sbm 60-120' c= -q * math.cos(3*math.radians(sbm)) - 0.0917 elif sbm >= 120.0 and sbm < 240.0: print 'sbm 120-240' c= q * math.cos(1.5*math.radians(sbm)) - 0.0917 elif sbm >= 240.0 and sbm < 300.0: print 'sbm 240-300' c= q * math.cos(3*math.radians(sbm)) - 0.0917 else: print 'sbm 300-360' c= -q * math.sin(1.5*math.radians(sbm)) - 0.0917 """ c += -0.117 * math.sin(math.radians(sun - ps)) #print c #c+= x * -0.163 * math.sin(math.radians(sun-ps)) #c+= x * -0.128 * math.sin(2*math.radians(moon-sun)) #c+= x * 0.120 * math.sin(2*math.radians(moon-bm)) #c+= x * 0.107 * math.sin(2*math.radians(pl-bm)) #c+= x * 0.063 * math.sin(math.radians(3*sun-ps-2*bm)) #c+= x * 0.040 * math.sin(math.radians(moon+pl-2*sun)) #c+= x * -0.040 * math.sin(math.radians(moon+pl-2*bm)) #c+= x * 0.027 * math.sin(math.radians(moon-pl)) #c+= x * -0.027 * math.sin(math.radians(sun+ps-2*bm)) #c+= x * 0.015 * math.sin(2*math.radians(sun-pl)) #c+= x * -0.013 * math.sin(math.radians(moon+2*bm-pl-2*sun)) #c+= x * -0.013 * math.sin(math.radians(moon-2*bm-pl+2*sun)) #c+= x * -0.007 * math.sin(math.radians(2*moon+pl-3*sun)) #c+= x * 0.005 * math.sin(math.radians(3*moon-pl-2*bm)) #c+= x * -0.005 * math.sin(math.radians(3*moon-pl-2*sun)) #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] #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 #list index 31 is black sun self.planets_degree_ut[31] = swe.nod_aps_ut(self.jul_day_UT, 0, swe.NODBIT_MEAN, swe.FLG_SWIEPH)[3][0] #list index 32 is vulcanus self.planets_degree_ut[32] = 31.1 + (self.jul_day_UT - 2425246.5) * 0.00150579 #list index 33 is persephone self.planets_degree_ut[33] = 240.0 + (self.jul_day_UT - 2425246.5) * 0.002737829 #list index 34 is true lilith (own calculation) self.planets_degree_ut[34] = self.planets_degree_ut[12] + true_lilith #swiss ephemeris version of true lilith #self.planets_degree_ut[34] = swe.nod_aps_ut(self.jul_day_UT,1,swe.NODBIT_OSCU,swe.FLG_SWIEPH)[3][0] #adjust list index 32 and 33 for i in range(23, 35): while (self.planets_degree_ut[i] < 0): self.planets_degree_ut[i] += 360.0 while (self.planets_degree_ut[i] > 360.0): 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 #lunar phase, anti-clockwise degrees between sun and moon ddeg = moon - sun if ddeg < 0: ddeg += 360.0 step = 360.0 / 28.0 print(moon, sun, ddeg) for x in range(28): low = x * step high = (x + 1) * step if ddeg >= low and ddeg < high: mphase = x + 1 sunstep = [ 0, 30, 40, 50, 60, 70, 80, 90, 120, 130, 140, 150, 160, 170, 180, 210, 220, 230, 240, 250, 260, 270, 300, 310, 320, 330, 340, 350 ] for x in range(len(sunstep)): low = sunstep[x] if x is 27: high = 360 else: high = sunstep[x + 1] if ddeg >= low and ddeg < high: sphase = x + 1 self.lunar_phase = { "degrees": ddeg, "moon_phase": mphase, "sun_phase": sphase } #close swiss ephemeris swe.close()