jyotisham / jyotisha

Python tools for the astronomical / astrological vedAnga of Hindus
MIT License
88 stars 52 forks source link

Computing select festivals #98

Closed karthikraman closed 3 years ago

karthikraman commented 3 years ago
if __name__ == '__main__':
    city = spatio_temporal.City.get_city_from_db("Chennai")
    computation_system = ComputationSystem.MULTI_NEW_MOON_SIDEREAL_MONTH_ADHIKA__CHITRA_180
    computation_system.festival_options = FestivalOptions(fest_repos = [RulesRepo("devatA/pitR/")])

    panchaanga = annual.get_panchaanga_for_kali_year(city=city, year=year, computation_system=computation_system)
    panchaanga.computation_system.festival_options = FestivalOptions(fest_repos = [RulesRepo("devatA/pitR/")])
    solar.SolarFestivalAssigner(panchaanga=panchaanga).assign_pitr_dina()
    tithi_festival.TithiFestivalAssigner(panchaanga=panchaanga).assign_solar_sidereal_amaavaasyaa()
    tithi_festival.TithiFestivalAssigner(panchaanga=panchaanga).assign_amaavaasya_soma()
    tithi_festival.TithiFestivalAssigner(panchaanga=panchaanga).assign_amaavaasya_vyatiipaata()
    panchaanga.update_festival_details()

    # OUTPUT TEXT
    rules_collection = rules.RulesCollection.get_cached(
      repos_tuple=tuple(panchaanga.computation_system.festival_options.repos),
      julian_handling=panchaanga.computation_system.festival_options.julian_handling)

    for dp in panchaanga.daily_panchaangas_sorted():
        for f in (dp.festival_id_to_instance.values()):
            fest_name = f.get_best_transliterated_name(languages=["sa"], scripts=["devanagari"], fest_details_dict=rules_collection.name_to_rule)["text"].replace("~", " ")
            print('%s\t%s\t%s' % (dp.date.get_date_str(), weekday_short_map[dp.date.get_weekday()], fest_name))

    #WRITE OUT ICS
    ics_calendar = ics.compute_calendar(panchaanga, festivals_only=True)
    output_file = os.path.join(city.name, '%d.ics' % (year))
    ics.write_to_file(ics_calendar, output_file)

What am I doing wrong in the above snippet of code? The solar & tithi_festivals don't show up... Something very obvious I must've missed :)

vvasuki commented 3 years ago

Not clear from just looking at the code - no escaping breakpoints and debugging this time it seems :-)

karthikraman commented 3 years ago

The following lines don't have any effect it seems:

tithi_festival.TithiFestivalAssigner(panchaanga=panchaanga).assign_solar_sidereal_amaavaasyaa()
tithi_festival.TithiFestivalAssigner(panchaanga=panchaanga).assign_amaavaasya_soma()
tithi_festival.TithiFestivalAssigner(panchaanga=panchaanga).assign_amaavaasya_vyatiipaata()
panchaanga.update_festival_details()

Am I missing some assignment or something?

vvasuki commented 3 years ago

update_festival_details

Thought to mention it earlier, but didn't (thinking that you'll notice it while running the debugger anyway) - first line of update_festival_details is self._reset_festivals(), which makes all prior lines useless. Simplest thing is to run the code line by line in debug mode and inspect the state of variables (I use Intellij Idea Ultimate with PyCharm - quite good. Since you're an academic, you can get a free educational license).