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_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