def get_panchaanga_for_given_dates( city, start_date, end_date, precomputed_json_dir="~/Documents/jyotisha", computation_system: ComputationSystem = None, allow_precomputed=True): fname = os.path.expanduser('%s/%s__%s-%s__%s.json' % (precomputed_json_dir, city.name, start_date, end_date, computation_system)) if os.path.isfile(fname) and allow_precomputed: fn = lambda: get_panchaanga_for_given_dates( city=city, start_date=start_date, end_date=end_date, precomputed_json_dir=precomputed_json_dir, computation_system=computation_system, allow_precomputed=False) panchaanga = load_panchaanga(fname=fname, fallback_fn=fn) return panchaanga else: logging.info( 'No precomputed data available or allowed. Computing panchaanga...\n' ) panchaanga = periodical.Panchaanga( city=city, start_date=start_date, end_date=end_date, computation_system=computation_system) logging.info('Writing computed panchaanga to %s...\n' % fname) panchaanga.dump_to_file(filename=fname) return panchaanga
def get_panchaanga_for_shaka_year(city, year, precomputed_json_dir="~/Documents/jyotisha", computation_system: ComputationSystem = None, allow_precomputed=True): fname = os.path.expanduser( '%s/%s__shaka_%s__%s.json' % (precomputed_json_dir, city.name, year, computation_system)) if os.path.isfile(fname) and allow_precomputed: fn = lambda: get_panchaanga_for_shaka_year( city=city, year=year, precomputed_json_dir=precomputed_json_dir, computation_system=computation_system, allow_precomputed=False) panchaanga = load_panchaanga(fname=fname, fallback_fn=fn) # Fest repos to be used might have changed in this call. panchaanga.computation_system = computation_system panchaanga.update_festival_details() return panchaanga else: logging.info( 'No precomputed data available. Computing panchaanga...\n') SHAKA_CIVIL_ERA_DIFF = 78 start_year_civil = year + era.get_year_0_offset(era_id=era.ERA_SHAKA) anga_span_finder = AngaSpanFinder.get_cached( ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0, anga_type=AngaType.SIDEREAL_MONTH) start_equinox = anga_span_finder.find(jd1=time.utc_gregorian_to_jd( Date(year=start_year_civil, month=3, day=1)), jd2=time.utc_gregorian_to_jd( Date(year=start_year_civil, month=5, day=1)), target_anga_id=1) end_equinox = anga_span_finder.find(jd1=time.utc_gregorian_to_jd( Date(year=start_year_civil + 1, month=3, day=1)), jd2=time.utc_gregorian_to_jd( Date(year=start_year_civil + 1, month=5, day=1)), target_anga_id=1) tz = Timezone(city.timezone) panchaanga = periodical.Panchaanga( city=city, start_date=tz.julian_day_to_local_time( julian_day=start_equinox.jd_start), end_date=tz.julian_day_to_local_time( julian_day=end_equinox.jd_start), computation_system=computation_system) panchaanga.year = year # Festival data may be updated more frequently and a precomputed panchaanga may go out of sync. Hence we keep this method separate. logging.info('Writing computed panchaanga to %s...\n' % fname) try: panchaanga.dump_to_file(filename=fname) except EnvironmentError: logging.warning("Not able to save.") logging.error(traceback.format_exc()) return panchaanga
def get_panchaanga_for_civil_year(city, year, precomputed_json_dir="~/Documents/jyotisha", computation_system: ComputationSystem = None, allow_precomputed=True): fname = os.path.expanduser( '%s/%s__gregorian_%s__%s.json' % (precomputed_json_dir, city.name, year, computation_system)) if os.path.isfile(fname) and allow_precomputed: fn = lambda: get_panchaanga_for_civil_year( city=city, year=year, precomputed_json_dir=precomputed_json_dir, computation_system=computation_system, allow_precomputed=False) panchaanga = load_panchaanga(fname=fname, fallback_fn=fn) return panchaanga else: logging.info( 'No precomputed data available. Computing panchaanga...\n') panchaanga = periodical.Panchaanga( city=city, start_date='%d-01-01' % year, end_date='%d-12-31' % year, computation_system=computation_system) panchaanga.year = year logging.info('Writing computed panchaanga to %s...\n' % fname) panchaanga.dump_to_file(filename=fname) return panchaanga
def test_daily_solar_viSukkaNi(): computation_system = ComputationSystem.DEFAULT panchaanga = periodical.Panchaanga(city=chennai, start_date=Date(2018, 4, 14), end_date=Date(2018, 4, 15), computation_system=computation_system) assert "viSukkan2i" not in panchaanga.date_str_to_panchaanga[Date(2018, 4, 14).get_date_str()].festival_id_to_instance assert "viSukkan2i" in panchaanga.date_str_to_panchaanga[Date(2018, 4, 15).get_date_str()].festival_id_to_instance.keys()
def get_panchaanga_for_civil_year(city, year, precomputed_json_dir="~/Documents/jyotisha", computation_system: ComputationSystem = None, allow_precomputed=True): fname = os.path.expanduser('%s/%s-%s.json' % (precomputed_json_dir, city.name, year)) if os.path.isfile(fname) and allow_precomputed: fn = lambda: get_panchaanga_for_civil_year( city=city, year=year, precomputed_json_dir=precomputed_json_dir, computation_system=computation_system, allow_precomputed=False) return load_panchaanga(fname=fname, fallback_fn=fn) else: logging.info( 'No precomputed data available. Computing panchaanga...\n') panchaanga = periodical.Panchaanga( city=city, start_date='%d-01-01' % year, end_date='%d-12-31' % year, computation_system=computation_system) panchaanga.year = year logging.info('Writing computed panchaanga to %s...\n' % fname) panchaanga.dump_to_file(filename=fname) # Save without festival details # Festival data may be updated more frequently and a precomputed panchaanga may go out of sync. Hence we keep this method separate. panchaanga.update_festival_details() return panchaanga
def test_periodic_solar_mUDavaN_muLukku(): computation_system = ComputationSystem.DEFAULT panchaanga = periodical.Panchaanga(city=chennai, start_date=Date(2018, 11, 14), end_date=Date(2018, 11, 20), computation_system=computation_system) assert "muDavan2 muzhukku" in panchaanga.date_str_to_panchaanga[Date( 2018, 11, 17).get_date_str()].festival_id_to_instance assert "muDavan2 muzhukku" not in panchaanga.date_str_to_panchaanga[Date( 2018, 11, 18).get_date_str()].festival_id_to_instance
def test_orinda_ca_dst_2019(): city = City('Orinda', '37:51:38', '-122:10:59', 'America/Los_Angeles') panchaanga = periodical.Panchaanga(city=city, start_date=Date(2019, 1, 1), end_date=Date(2019, 5, 1)) # 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 panchaanga object seems to use the index d + 1. assert round( panchaanga.daily_panchaangas_sorted()[panchaanga.duration_prior_padding + 69].jd_sunrise, ndigits=4) == round(2458554.104348237, ndigits=4) # 2019-Mar-10 07:30:15.68
def get_panchaanga_for_kali_year(city, year, precomputed_json_dir="~/Documents/jyotisha", computation_system: ComputationSystem = None, allow_precomputed=True, recompute_festivals=True): year = int(year) fname = os.path.expanduser( '%s/%s__kali_%s__%s.json' % (precomputed_json_dir, city.name, year, computation_system)) if os.path.isfile(fname) and allow_precomputed: fn = lambda: get_panchaanga_for_kali_year( city=city, year=year, precomputed_json_dir=precomputed_json_dir, computation_system=computation_system, allow_precomputed=False) panchaanga = load_panchaanga(fname=fname, fallback_fn=fn) # Fest repos to be used might have changed in this call. panchaanga.computation_system = computation_system if recompute_festivals: panchaanga.update_festival_details() return panchaanga else: logging.info( 'No precomputed data available or allowed. Computing panchaanga...\n' ) start_year_civil = year - era.get_year_0_offset(era_id=era.ERA_KALI) anga_span_finder = AngaSpanFinder.get_cached( ayanaamsha_id=Ayanamsha.CHITRA_AT_180, anga_type=AngaType.SIDEREAL_MONTH) start_mesha = anga_span_finder.find(jd1=time.utc_gregorian_to_jd( Date(year=start_year_civil, month=3, day=1)), jd2=time.utc_gregorian_to_jd( Date(year=start_year_civil, month=5, day=1)), target_anga_id=1) jd_next_sunset_start_mesha = city.get_setting_time( julian_day_start=start_mesha.jd_start, body=Graha.SUN) end_mina = anga_span_finder.find(jd1=time.utc_gregorian_to_jd( Date(year=start_year_civil + 1, month=3, day=1)), jd2=time.utc_gregorian_to_jd( Date(year=start_year_civil + 1, month=5, day=1)), target_anga_id=1) jd_preceding_sunset_end_mina = city.get_setting_time( julian_day_start=end_mina.jd_start - 1, body=Graha.SUN) tz = Timezone(city.timezone) panchaanga = periodical.Panchaanga( city=city, start_date=tz.julian_day_to_local_time( julian_day=jd_next_sunset_start_mesha), end_date=tz.julian_day_to_local_time( julian_day=jd_preceding_sunset_end_mina), computation_system=computation_system) panchaanga.year = year # Festival data may be updated more frequently and a precomputed panchaanga may go out of sync. Hence we keep this method separate. logging.info('Writing computed panchaanga to %s...\n' % fname) try: panchaanga.dump_to_file(filename=fname) except EnvironmentError: logging.warning("Not able to save.") logging.error(traceback.format_exc()) return panchaanga