jyotisham / jyotisha

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

How to print a list of festivals given a single (or set of) toml file? #64

Closed karthikraman closed 3 years ago

karthikraman commented 3 years ago

Give write_events_ics.py has been (rightly) phased out, what is the recommended way to get a list of festivals for a calendar year for a specified list of toml files? (these are not necessary festivals, so not on adyatithi, but could be birthdays/wedding days etc. specified by a festival rule)

Please share your thoughts @vvasuki ...

vvasuki commented 3 years ago

Why not just print panchaanga.festival_id_to_days? What does this have to do with the deleted file? If ICS is needed, could use ics.compute_calendar

karthikraman commented 3 years ago

This would be a custom set of TOML files, not in the repo. I don't seem to find how to supply a custom set of TOML files to the festivalAPplier... The deleted file would take as input a json file with (arbitrary) festivals and generate an ICS.

vvasuki commented 3 years ago

This would be a custom set of TOML files, not in the repo. I don't seem to find how to supply a custom set of TOML files to the festivalAPplier... The deleted file would take as input a json file with (arbitrary) festivals and generate an ICS.

Consider this code snippet from jyotisha/panchaanga/writer/generation_project/common_ics.py :

  computation_system = ComputationSystem.SOLSTICE_POST_DARK_10_ADHIKA__CHITRA_180
  computation_system.options.fest_repos = [RulesRepo(name="gRhya/general")]
  tropical_panchaanga = annual.get_panchaanga_for_shaka_year(city=city, year=year, computation_system=computation_system, allow_precomputed=False)

See how I am generating the panchaanga using ONLY "gRhya/general" repo. You will do something analogous with the following changes:

Second part above is untested - but should work.

karthikraman commented 3 years ago
import os
import jyotisha
from jyotisha.panchaanga import spatio_temporal
from jyotisha.panchaanga.spatio_temporal import annual
from jyotisha.panchaanga.temporal import ComputationSystem
from jyotisha.panchaanga.temporal.festival.rules import RulesRepo
from jyotisha.panchaanga.writer import ics

def dump_common(year, city):
  elim_tags = ["AdiShankaraHistory", "AmavasyaDays", "AndhraTempleFestivals", "AzhwarJayanti", "BengalFestivals", "ChandraDarshanam", "Combinations", "CommonFestivals", "CommonFestivalsTamilnadu", "DanamDays", "Dashamahavidya", "Dashavataram", "DevataPuja", "DeviPuja", "Eclipses", "EkadashiVratam", "KalpadiDays", "KanchiAradhanaDays", "KeralaTempleFestivals", "LessCommonFestivals", "MahapurushaEvents", "ManvadiDays", "MonthWeekdayFestivals", "MonthlyFestivals", "MonthlyShraddhaDays", "MonthlyVratam", "Navaratri", "NayanarGurupujai", "NorthIndiaTempleFestivals", "OdishaTempleFestivals", "OtherAvataram", "OtherAvatarams", "OtherJayantis", "PradoshaVratam", "PuranaEvents", "PurnimaDays", "Pushkara", "RareDays", "SankataharaChaturthiVratam", "Sankranti", "ShannavatiTarpanaDays", "ShashthiVratam", "ShraddhaDays", "SpecialDays", "SpecialPeriodEnd", "SpecialPeriodStart", "SpecialPuja", "SpecialSnanam", "SpecialVratam", "SringeriAradhanaDays", "SringeriFestivals", "SunSankranti", "TamilFestivals", "TamilnaduTempleFestivals", "UttarPradeshTempleFestivals", "VratamEnd", "VratamStart", "Yugadi", "YugadiDays"]
  computation_system = ComputationSystem.DEFAULT
  computation_system.options.fest_tags_excluded = elim_tags
  # computation_system.options.fest_tags_included = None
  computation_system.options.fest_repos = [RulesRepo(name="private/")]
  panchaanga = annual.get_panchaanga_for_civil_year(city=city, year=year, computation_system=computation_system)
  ics_calendar = ics.compute_calendar(panchaanga)
  output_file = os.path.join(city.name, '%d.ics' % (year))
  ics.write_to_file(ics_calendar, output_file)

if __name__ == '__main__':
  Chennai = spatio_temporal.City.get_city_from_db("Chennai")
  dump_common(year=2021, city=Chennai)

This generates a file with several events, even though I have eliminated every possible tag.

karthikraman commented 3 years ago

It also doesn't seem to pick up the files inside "private/"

vvasuki commented 3 years ago

It also doesn't seem to pick up the files inside "private/"

That's because you haven't passed the path parameter - please look at the constructor definition.

This generates a file with several events, even though I have eliminated every possible tag.

Filtering based on computation_system.options.fest_tags_excluded is not implemented. (I'm hoping it will be mostly obviated due to repo-list-passing functionality.) Further, non-rule-based (ie dynamic) festival assignment is yet to be eliminated/ filtered out (or turned into rule-based computations) - hence the junk (which bothers me as well).

vvasuki commented 3 years ago

Filtering based on computation_system.options.fest_tags_excluded is not implemented. (I'm hoping it will be mostly obviated due to repo-list-passing functionality.) Further, non-rule-based (ie dynamic) festival assignment is yet to be eliminated/ filtered out (or turned into rule-based computations) - hence the junk (which bothers me as well).

This should be fixed now.

karthikraman commented 3 years ago

Got this to work finally. However, festivals get saved with the JSON. If I have to just create an ICS for newly added rules, without re-computing the panchaanga, is it possible as of now?

vvasuki commented 3 years ago

Got this to work finally. However, festivals get saved with the JSON. If I have to just create an ICS for newly added rules, without re-computing the panchaanga, is it possible as of now?

No. The current idea is that festivals ought to be recomputed every time the panchaanga is loaded (because rule-set may have changed in the meantime). They're just stored in JSON for reference, debugging and other ancillary (client side) use

karthikraman commented 3 years ago

Perhaps I can use _reset_festivals(), change fest repos and then update_festivals()?

vvasuki commented 3 years ago

update_festivals

First statement of update_festival_details is self._reset_festivals() :-)