def test_orinda_ca_dst_2019(): city = City('Orinda', '37:51:38', '-122:10:59', 'America/Los_Angeles') panchangam = annual.get_panchangam(city=city, year=2019, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_TRUE_CITRA, compute_lagnams=False) # March 10 is the 69th day of the year (70th in leap years) in the Gregorian calendar. # Sunrise on that day is around 7:27 AM according to Google, which is JD 2458553.14375 according to https://ssd.jpl.nasa.gov/tc.cgi#top . # We use the index 70 below as the annual panchanga object seems to use the index d + 1. assert panchangam.jd_sunrise[ 70] == 2458554.104348237 # 2019-Mar-10 07:30:15.68
def test_adhika_maasa_computations_2018(): city = City('Chennai', "13:05:24", "80:16:12", "Asia/Calcutta") panchangam_2018 = jyotisha.panchangam.spatio_temporal.annual.Panchangam( city=city, year=2018, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_LAHIRI, compute_lagnams=False) panchangam_2018.assignLunarMonths() expected_lunar_months_2018 = [2] + [2.5] * 29 + [3] * 30 + [4] assert expected_lunar_months_2018 == panchangam_2018.lunar_month[135:196] return True
def test_adhika_maasa_computations_2009(): city = City('Chennai', "13:05:24", "80:16:12", "Asia/Calcutta") panchangam_2009 = jyotisha.panchangam.spatio_temporal.annual.Panchangam( city=city, year=2009, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_LAHIRI, compute_lagnams=False) panchangam_2009.assignLunarMonths() expected_lunar_months_2009 = [7] + [8] * 29 + [9] * 30 + [10] * 15 assert expected_lunar_months_2009 == panchangam_2009.lunar_month[291:366] return True
def test_adhika_maasa_computations_2010(): city = City('Chennai', "13:05:24", "80:16:12", "Asia/Calcutta") panchangam_2010 = annual.Panchangam(city=city, year=2010, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_LAHIRI, compute_lagnams=False) panchangam_2010.assignLunarMonths() expected_lunar_months_2010 = [10] * 15 + [11] * 30 + [12] * 29 + [ 1 ] * 30 + [1.5] * 30 + [2] * 29 + [3] assert expected_lunar_months_2010 == panchangam_2010.lunar_month[1:165] return True
def test_tb_muhuurta_mtv(): city = City.from_address_and_timezone('Cupertino, CA', "America/Los_Angeles") from jyotisha.panchangam.spatio_temporal import daily panchangam = daily.Panchangam.from_date(city=city, year=2018, month=11, day=11) panchangam.compute_tb_muhuurtas() assert len(panchangam.tb_muhuurtas) == 15 assert panchangam.tb_muhuurtas[0].jd_start == panchangam.jd_sunrise for muhurta in panchangam.tb_muhuurtas: logging.info(muhurta.to_localized_string())
def test_jd_from_local_time(): city = City.from_address_and_timezone('Cupertino, CA', "America/Los_Angeles") jd = city.local_time_to_julian_day(year=2018, month=11, day=11, hours=6, minutes=0, seconds=0) import numpy.testing numpy.testing.assert_approx_equal(actual=jd, desired=2458433.750000, significant=7)
def get(self, latitude, longitude, year): args = self.get_parser.parse_args() city = City("", latitude, longitude, args['timezone']) panchangam = scripts.get_panchangam(city=city, year=int(year), script=args['encoding']) panchangam.compute_festivals() panchangam.assign_relative_festivals() panchangam.compute_solar_eclipses() panchangam.compute_lunar_eclipses() panchangam.computeTransits() return panchangam.to_json_map()
def test_panchanga_chennai(): panchangam_expected_chennai_18 = JsonObject.read_from_file( filename=os.path.join(TEST_DATA_PATH, 'Chennai-2018.json')) city = City('Chennai', "13:05:24", "80:16:12", "Asia/Calcutta") panchangam = jyotisha.panchangam.spatio_temporal.annual.Panchangam( city=city, year=2018, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_LAHIRI, compute_lagnams=False) if str(panchangam) != str(panchangam_expected_chennai_18): panchangam.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Chennai-2018-actual.json.local')) assert str(panchangam) == str(panchangam_expected_chennai_18)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) if len(sys.argv) == 7: script = sys.argv[6] else: script = sanscript.IAST # Default script is IAST for writing calendar city = City(city_name, latitude, longitude, tz) panchangam = scripts.get_panchangam(city=city, year=year, script=script) panchangam.add_details() ics_calendar = compute_calendar(panchangam) write_to_file(ics_calendar, '%s-%d-%s.ics' % (city_name, year, script))
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) if len(sys.argv) == 7: script = sys.argv[6] else: script = sanscript.IAST # Default script is IAST for writing calendar city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam(city=city, year=year, script=script) ics_calendar = compute_calendar(panchangam) output_file = os.path.expanduser('%s/%s-%d-%s.ics' % ("~/Documents", city.name, year, script)) write_to_file(ics_calendar, output_file)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) script = sanscript.DEVANAGARI # Default script is devanagari if len(sys.argv) == 7: script = sys.argv[6] # logging.debug(script) city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam(city=city, year=year, script=script) panchangam.script = script # Force script panchangam.update_festival_details() monthly_template_file = open(os.path.join(CODE_ROOT, 'panchangam/data/templates/monthly_cal_template.tex')) writeMonthlyTeX(panchangam, monthly_template_file)
def test_panchanga_chennai_18(): panchangam_expected_chennai_18 = JsonObject.read_from_file( filename=os.path.join(TEST_DATA_PATH, 'Chennai-2018.json')) city = City('Chennai', "13:05:24", "80:16:12", "Asia/Calcutta") panchangam = annual.Panchangam(city=city, year=2018, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_LAHIRI, compute_lagnams=False) if panchangam.__str__(floating_point_precision=4 ) != panchangam_expected_chennai_18.__str__( floating_point_precision=4): panchangam.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Chennai-2018-actual.json.local'), floating_point_precision=4) panchangam_expected_chennai_18.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Chennai-2018-expected.json.local'), floating_point_precision=4) assert str(panchangam) == str(panchangam_expected_chennai_18)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) compute_lagnams = False # Default script = sanscript.DEVANAGARI # Default script is devanagari fmt = 'hh:mm' lagnasuff = '' if len(sys.argv) == 9: compute_lagnams = True lagnasuff = '-lagna' fmt = sys.argv[7] script = sys.argv[6] elif len(sys.argv) == 8: script = sys.argv[6] fmt = sys.argv[7] compute_lagnams = False elif len(sys.argv) == 7: script = sys.argv[6] compute_lagnams = False city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam( city=city, year=year, script=script, fmt=fmt, compute_lagnams=compute_lagnams) panchangam.script = script # Force script irrespective of what was obtained from saved file panchangam.fmt = fmt # Force fmt panchangam.update_festival_details() city_name_en = jyotisha.custom_transliteration.romanise( jyotisha.custom_transliteration.tr(city.name, sanscript.IAST)).title() output_file = os.path.expanduser( '%s/%s-%d-%s-daily%s.md' % ("../txt/daily", city_name_en, year, script, lagnasuff)) writeDailyText(panchangam, compute_lagnams, open(output_file, 'w'))
def main(): [json_file, city_name, latitude, longitude, tz] = sys.argv[1:6] if not os.path.isfile(json_file): raise IOError('File %s not found!' % json_file) year = int(sys.argv[6]) if len(sys.argv) == 8: script = sys.argv[7] else: script = 'iast' # Default script is IAST for writing calendar city = City(city_name, latitude, longitude, tz) panchangam = scripts.get_panchangam(city=city, year=year, script=script) # panchangam.add_details() compute_events(panchangam, json_file) cal_file_name = '%s-%s-%s' % (city_name, year, os.path.basename(json_file).replace('.json', '.ics')) computeIcsCalendar(panchangam, cal_file_name) print('Wrote ICS file to %s' % cal_file_name)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] start_date = sys.argv[5] end_date = sys.argv[6] compute_lagnams = False # Default script = sanscript.DEVANAGARI # Default script is devanagari fmt = 'hh:mm' if len(sys.argv) == 10: compute_lagnams = True fmt = sys.argv[8] script = sys.argv[7] elif len(sys.argv) == 9: script = sys.argv[7] fmt = sys.argv[8] compute_lagnams = False elif len(sys.argv) == 8: script = sys.argv[7] compute_lagnams = False city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.periodical.get_panchangam( city=city, start_date=start_date, end_date=end_date, script=script, fmt=fmt, compute_lagnams=compute_lagnams, ayanamsha_id=swe.SIDM_TRUE_CITRA) panchangam.script = script # Force script irrespective of what was obtained from saved file panchangam.fmt = fmt # Force fmt panchangam.update_festival_details() daily_template_file = open( os.path.join(CODE_ROOT, 'panchangam/data/templates/daily_cal_template.tex')) writeDailyTeX(panchangam, daily_template_file, compute_lagnams)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) compute_lagnams = False # Default script = sanscript.DEVANAGARI # Default script is devanagari fmt = 'hh:mm' if len(sys.argv) == 9: compute_lagnams = True fmt = sys.argv[7] script = sys.argv[6] elif len(sys.argv) == 8: script = sys.argv[6] fmt = sys.argv[7] compute_lagnams = False elif len(sys.argv) == 7: script = sys.argv[6] compute_lagnams = False city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam( city=city, year=year, script=script, fmt=fmt, compute_lagnams=compute_lagnams) panchangam.script = script # Force script irrespective of what was obtained from saved file panchangam.fmt = fmt # Force fmt panchangam.update_festival_details() ics_calendar = writeDailyICS(panchangam, compute_lagnams) city_name_en = jyotisha.custom_transliteration.romanise( jyotisha.custom_transliteration.tr(city.name, sanscript.IAST)).title() output_file = os.path.expanduser( '%s/%s-%d-%s-daily.ics' % ("../ics/daily", city_name_en, year, script)) write_to_file(ics_calendar, output_file) print('Output ICS written to %s' % output_file, file=sys.stderr)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) script = sanscript.DEVANAGARI # Default script is devanagari if len(sys.argv) == 7: script = sys.argv[6] logging.debug(script) city = City(city_name, latitude, longitude, tz) panchangam = scripts.get_panchangam(city=city, year=year, script=script) panchangam.compute_festivals() panchangam.assign_relative_festivals() panchangam.compute_solar_eclipses() panchangam.compute_lunar_eclipses() panchangam.computeTransits() monthly_template_file = open(os.path.join(CODE_ROOT, 'panchangam/data/templates/monthly_cal_template.tex')) writeMonthlyTeX(panchangam, monthly_template_file)
def test_panchanga_orinda(): panchangam_expected_orinda_19 = JsonObject.read_from_file( filename=os.path.join(TEST_DATA_PATH, 'Orinda-2019.json')) city = City('Orinda', '37:51:38', '-122:10:59', 'America/Los_Angeles') panchangam = annual.Panchangam(city=city, year=2019, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_LAHIRI, compute_lagnams=False) if panchangam.__str__(floating_point_precision=4 ) != panchangam_expected_orinda_19.__str__( floating_point_precision=4): panchangam.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Orinda-2019-actual.json.local'), floating_point_precision=4) panchangam_expected_orinda_19.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Orinda-2019-expected.json.local'), floating_point_precision=4) assert panchangam.__str__( floating_point_precision=4) == panchangam_expected_orinda_19.__str__( floating_point_precision=4)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) if len(sys.argv) == 8: all_tags = False else: all_tags = True # Default assume detailed ICS with all tags if len(sys.argv) >= 7: script = sys.argv[6] else: script = sanscript.IAST # Default script is IAST for writing calendar city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam(city=city, year=year, script=script) panchangam.script = script # Force script panchangam.update_festival_details() ics_calendar = compute_calendar(panchangam, all_tags) output_file = os.path.expanduser('%s/%s-%d-%s.ics' % ("~/Documents", city.name, year, script)) write_to_file(ics_calendar, output_file)
def main(): [city_name, latitude, longitude, tz] = sys.argv[1:5] year = int(sys.argv[5]) compute_lagnams = False # Default script = sanscript.DEVANAGARI # Default script is devanagari fmt = 'hh:mm' if len(sys.argv) == 9: compute_lagnams = True fmt = sys.argv[7] script = sys.argv[6] elif len(sys.argv) == 8: script = sys.argv[6] fmt = sys.argv[7] compute_lagnams = False elif len(sys.argv) == 7: script = sys.argv[6] compute_lagnams = False city = City(city_name, latitude, longitude, tz) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam( city=city, year=year, script=script, fmt=fmt, compute_lagnams=compute_lagnams) panchangam.script = script # Force script irrespective of what was obtained from saved file panchangam.fmt = fmt # Force fmt panchangam.update_festival_details() ics_calendar = writeDailyICS(panchangam, compute_lagnams) output_file = os.path.expanduser('%s/%s-%d-%s-daily.ics' % ("~/Documents", city.name, year, script)) write_to_file(ics_calendar, output_file)
def test_panchanga_chennai_19(): panchangam_expected_chennai_19 = JsonObject.read_from_file( filename=os.path.join(TEST_DATA_PATH, 'Chennai-2019.json')) panchangam_expected_chennai_19.update_festival_details() city = City('Chennai', "13:05:24", "80:16:12", "Asia/Calcutta") panchangam = annual.get_panchangam(city=city, year=2019, script=sanscript.DEVANAGARI, ayanamsha_id=swe.SIDM_TRUE_CITRA, compute_lagnams=False, allow_precomputed=False) if panchangam.__str__(floating_point_precision=4 ) != panchangam_expected_chennai_19.__str__( floating_point_precision=4): panchangam.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Chennai-2019-actual.json.local'), floating_point_precision=4) panchangam_expected_chennai_19.dump_to_file(filename=os.path.join( TEST_DATA_PATH, 'Chennai-2019-expected.json.local'), floating_point_precision=4) assert panchangam.__str__( floating_point_precision=4) == panchangam_expected_chennai_19.__str__( floating_point_precision=4)
temporal.get_kaalas(self.jd_sunset, self.jd_next_sunrise, 1, 15), 'rAtri yAma 1': temporal.get_kaalas(self.jd_sunset, self.jd_next_sunrise, 1, 4), 'zayana': temporal.get_kaalas(self.jd_sunset, self.jd_next_sunrise, 3, 8), 'dinAnta': temporal.get_kaalas(self.jd_sunset, self.jd_next_sunrise, 5, 8), 'rahu': temporal.get_kaalas(self.jd_sunrise, self.jd_sunset, RAHUKALA_OCTETS[self.weekday], 8), 'yama': temporal.get_kaalas(self.jd_sunrise, self.jd_sunset, YAMAGANDA_OCTETS[self.weekday], 8), 'gulika': temporal.get_kaalas(self.jd_sunrise, self.jd_sunset, GULIKAKALA_OCTETS[self.weekday], 8) } return self.kaalas # Essential for depickling to work. common.update_json_class_index(sys.modules[__name__]) # logging.debug(common.json_class_index) if __name__ == '__main__': panchangam = DailyPanchanga.from_city_and_julian_day(city=City( 'Chennai', '13:05:24', '80:16:12', 'Asia/Calcutta'), julian_day=2457023.27) panchangam.compute_tb_muhuurtas() logging.debug(str(panchangam))
def test_get_timezone_offset_hours_from_date(): city = City.from_address_and_timezone('Cupertino, CA', "America/Los_Angeles") offset = city.get_timezone_offset_hours_from_jd(2458447.000000) assert offset == -8
jd_masa_transit = brentq(get_angam_float, self.jd_sunrise - 34, self.jd_sunset, args=(SOLAR_MONTH, -target, self.ayanamsha_id, False)) jd_next_sunset = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] jd_next_sunrise = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] if jd_next_sunset > jd_next_sunrise: # Masa begins after sunset and before sunrise # Therefore Masa 1 is on the day when the sun rises next solar_month_day = floor(self.jd_sunset - jd_next_sunrise) + 1 else: # Masa has started before sunset solar_month_day = round(self.jd_sunset - jd_next_sunset) + 1 self.solar_month_day = solar_month_day # Essential for depickling to work. common.update_json_class_index(sys.modules[__name__]) logging.debug(common.json_class_index) if __name__ == '__main__': panchangam = Panchangam(city=City('Chennai', '13:05:24', '80:16:12', 'Asia/Calcutta'), julian_day=2457023.27) panchangam.compute_tb_muhuurtas() logging.debug(str(panchangam))
rsmi=swe.CALC_SET | swe.BIT_DISC_CENTER)[1][0] jd_next_sunrise = swe.rise_trans(jd_start=jd_masa_transit, body=swe.SUN, lon=self.city.longitude, lat=self.city.latitude, rsmi=swe.CALC_RISE | swe.BIT_DISC_CENTER)[1][0] if jd_next_sunset > jd_next_sunrise: # Masa begins after sunset and before sunrise # Therefore Masa 1 is on the day when the sun rises next solar_month_day = floor(self.jd_sunset - jd_next_sunrise) + 1 else: # Masa has started before sunset solar_month_day = round(self.jd_sunset - jd_next_sunset) + 1 self.solar_month_day = solar_month_day # Essential for depickling to work. common.update_json_class_index(sys.modules[__name__]) logging.debug(common.json_class_index) if __name__ == '__main__': panchangam = Panchangam(city=City('Chennai', '13:05:24', '80:16:12', 'Asia/Calcutta'), julian_day=2457023.27) panchangam.compute_tb_muhuurtas() logging.debug(str(panchangam))
import logging import swisseph as swe from jyotisha.panchangam import temporal from jyotisha.panchangam.spatio_temporal import City city = City.from_address_and_timezone(address="Mountain View, CA", timezone_str="America/Los_Angeles") time = city.local_time_to_julian_day(year=2019, month=1, day=21, hours=18, minutes=32, seconds=0) logging.info(time) temporal.print_angas_x_ayanamshas(jd=time)
def test_sunrise_mtv(): city = City.from_address_and_timezone('Cupertino, CA', "America/Los_Angeles") panchangam = daily.DailyPanchanga(city=city, year=2018, month=11, day=11) panchangam.compute_sun_moon_transitions() numpy.testing.assert_approx_equal(panchangam.jd_sunrise, 2458434.11)
def get(self, latitude, longitude, year): args = self.get_parser.parse_args() city = City("", latitude, longitude, args['timezone']) panchangam = jyotisha.panchangam.spatio_temporal.annual.get_panchangam(city=city, year=int(year), script=args['encoding']) return panchangam.to_json_map()
def get(self, latitude, longitude, year, month, day): args = self.get_parser.parse_args() city = City("", latitude, longitude, args['timezone']) panchangam = jyotisha.panchangam.spatio_temporal.daily.DailyPanchanga(city=city, year=int(year), month=int(month), day=int(day)) return panchangam.get_kaalas_local_time(format=args['format'])
if data[d]: for id, end_jd in data[d]: anga_name = NAMES[anga_entity['names']][panchangam.script][id] if end_jd is None: anga_collector.append({'name': anga_name}) else: anga_end = temporal.Time( 24 * (end_jd - jd)).toString(format=panchangam.fmt) anga_collector.append({'name': anga_name, 'end': anga_end}) return anga_collector # generate panchangam place = get_places()[args.city] city = City(place['name'], place['lat'], place['lon'], place['tz']) panchangam = spatio_temporal.annual.get_panchangam( city=city, year=args.year, compute_lagnams=args.lagna, script="iast", precomputed_json_dir="./data/jyotisha") panchangam.get_kaalas() samvatsara_id = (panchangam.year - 1568) % 60 + 1 # distance from prabhava samvatsara_names = '%s–%s' % ( NAMES['SAMVATSARA_NAMES'][panchangam.script][samvatsara_id], NAMES['SAMVATSARA_NAMES'][panchangam.script][(samvatsara_id % 60) + 1]) output_collector = {}