Example #1
0
 def get_name(self, script="hk"):
     name_dict = NAME_TO_TYPE[self.anga_type_id].names_dict
     if self.anga_type_id == AngaType.SIDEREAL_MONTH.name:
         return names.get_chandra_masa(month=self.index, script=script)
     elif name_dict is not None:
         return name_dict[script][self.index]
     else:
         return None
Example #2
0
 def get_month_str(self, month_type, script):
     if month_type == RulesRepo.SIDEREAL_SOLAR_MONTH_DIR:
         return names.NAMES['RASHI_NAMES']['sa'][script][
             self.solar_sidereal_date_sunset.month]
     elif month_type == RulesRepo.LUNAR_MONTH_DIR:
         return names.get_chandra_masa(month=self.lunar_month_sunrise.index,
                                       script=script)
     elif month_type == RulesRepo.TROPICAL_MONTH_DIR:
         return names.NAMES['RTU_MASA_NAMES_SHORT']['sa'][script][
             self.tropical_date_sunset.month]
     elif month_type == RulesRepo.ISLAMIC_MONTH_DIR:
         islamic_date = self.date.to_islamic_date()
         return names.NAMES["ARAB_MONTH_NAMES"]["ar"][islamic_date.month -
                                                      1]
     elif month_type == RulesRepo.GREGORIAN_MONTH_DIR:
         return names.month_map[self.date.month]
Example #3
0
    def assign_solar_sidereal_amaavaasyaa(self):
        if 'sidereal_solar_month_amAvAsyA' not in self.rules_collection.name_to_rule:
            return
        if 'sidereal_solar_month_amAvAsyA' not in self.panchaanga.festival_id_to_days:
            logging.error('Must compute amAvAsyA before coming here!')
            return
        ama_days = self.panchaanga.festival_id_to_days[
            'sidereal_solar_month_amAvAsyA']
        for ama_day in ama_days:
            d = int(ama_day - self.daily_panchaangas[0].date)
            day_panchaanga = self.daily_panchaangas[d]
            # Get Name
            if day_panchaanga.lunar_month_sunrise.index == 6:
                pref = '(%s) mahAlaya ' % (names.get_chandra_masa(
                    day_panchaanga.lunar_month_sunrise.index,
                    'hk',
                    visarga=False))
            elif day_panchaanga.solar_sidereal_date_sunset.month == 4:
                pref = '%s (karkaTa) ' % (names.get_chandra_masa(
                    day_panchaanga.lunar_month_sunrise.index,
                    'hk',
                    visarga=False))
            elif day_panchaanga.solar_sidereal_date_sunset.month == 10:
                pref = 'mauni (%s/makara) ' % (names.get_chandra_masa(
                    day_panchaanga.lunar_month_sunrise.index,
                    'hk',
                    visarga=False))
            else:
                pref = names.get_chandra_masa(
                    day_panchaanga.lunar_month_sunrise.index,
                    'hk',
                    visarga=False) + '-'

            apraahna_interval = day_panchaanga.get_interval("अपराह्णः")
            ama_nakshatra_today = [
                y for y in apraahna_interval.get_boundary_angas(
                    anga_type=AngaType.NAKSHATRA,
                    ayanaamsha_id=self.ayanaamsha_id).to_tuple()
            ]
            suff = ''
            # Assign
            if 23 in ama_nakshatra_today and day_panchaanga.lunar_month_sunrise.index == 10:
                suff = ' (alabhyam–zraviSThA)'
            elif 24 in ama_nakshatra_today and day_panchaanga.lunar_month_sunrise.index == 10:
                suff = ' (alabhyam–zatabhiSak)'
            elif ama_nakshatra_today[0] in [15, 16, 17, 6, 7, 8, 23, 24, 25]:
                suff = ' (alabhyam–%s)' % names.NAMES['NAKSHATRA_NAMES']['sa'][
                    'hk'][ama_nakshatra_today[0]]
            elif ama_nakshatra_today[1] in [15, 16, 17, 6, 7, 8, 23, 24, 25]:
                suff = ' (alabhyam–%s)' % names.NAMES['NAKSHATRA_NAMES']['sa'][
                    'hk'][ama_nakshatra_today[1]]
            if day_panchaanga.date.get_weekday() in [1, 2, 4]:
                if suff == '':
                    suff = ' (alabhyam–puSkalA)'
                else:
                    suff = suff.replace(')', ', puSkalA)')
            self.panchaanga.add_festival(fest_id=pref + 'amAvAsyA' + suff,
                                         date=day_panchaanga.date)

        self.panchaanga.delete_festival(
            fest_id='sidereal_solar_month_amAvAsyA')
Example #4
0
def write_monthly_tex(panchaanga, time_format="hh:mm", languages=None, scripts=None):
  """Write out the panchaanga TeX using a specified template
  """
  if scripts is None:
    scripts = [sanscript.DEVANAGARI]
  day_colours = {0: 'blue', 1: 'blue', 2: 'blue',
                 3: 'blue', 4: 'blue', 5: 'blue', 6: 'blue'}

  if languages is None:
    languages = ["sa"]

  monthly_template_file = open(os.path.join(os.path.dirname(__file__), 'templates/monthly_cal_template.tex'))

  template_lines = monthly_template_file.readlines()
  for i in range(0, len(template_lines) - 3):
    print(template_lines[i][:-1])

  samvatsara_id = (panchaanga.year - 1568) % 60 + 1  # distance from prabhava
  samvatsara_names = '%s–%s' % (names.NAMES['SAMVATSARA_NAMES']['sa'][scripts[0]][samvatsara_id],
                                names.NAMES['SAMVATSARA_NAMES']['sa'][scripts[0]][(samvatsara_id % 60) + 1])

  print('\\mbox{}')
  print('{\\sffamily\\fontsize{60}{25}\\selectfont %d\\\\[0.5cm]}' % panchaanga.year)
  print('\\mbox{\\font\\x="Siddhanta:language=deva" at 48 pt\\x %s}\\\\[0.5cm]' %
        samvatsara_names)
  print('\\mbox{\\font\\x="Siddhanta:language=deva" at 32 pt\\x %s } %%'
        % jyotisha.custom_transliteration.tr('kali', scripts[0]))
  print('{\\sffamily\\fontsize{32}{25}\\selectfont %d–%d\\\\[0.5cm]}'
        % (panchaanga.year + 3100, panchaanga.year + 3101))
  print('{\\sffamily\\fontsize{48}{25}\\selectfont \\uppercase{%s}\\\\[0.2cm]}' %
        panchaanga.city.name)
  print('{\\sffamily\\fontsize{16}{25}\\selectfont {%s}\\\\[0.5cm]}' %
        jyotisha.custom_transliteration.print_lat_lon(panchaanga.city.latitude, panchaanga.city.longitude))
  print('\\hrule')

  print('\\newpage')
  print('\\centering')
  print('\\centerline{\\LARGE {{%s}}}' % jyotisha.custom_transliteration.tr('mAsAntara-vizESAH', scripts[0]))
  print('\\begin{multicols*}{3}')
  print('\\TrickSupertabularIntoMulticols')
  print('\\begin{supertabular}' +
        '{>{\\sffamily}r>{\\sffamily}r>{\\sffamily}c>{\\hangindent=2ex}p{8cm}}')

  mlast = 1
  daily_panchaangas = panchaanga.daily_panchaangas_sorted()
  for d in range(panchaanga.duration_prior_padding, jyotisha.panchaanga.temporal.MAX_SZ - 1):
    [y, m, dt, t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d - 1).to_date_fractional_hour_tuple()
    daily_panchaanga = daily_panchaangas[d]

    rules_collection = rules.RulesCollection.get_cached(
      repos_tuple=tuple(panchaanga.computation_system.festival_options.repos), julian_handling=panchaanga.computation_system.festival_options.julian_handling)
    fest_details_dict = rules_collection.name_to_rule

    if len(daily_panchaanga.festival_id_to_instance) != 0:
      if m != mlast:
        mlast = m
        print('\\\\')

      print('%s & %s & %s & {\\raggedright %s} \\\\' %
            (names.month_map[m], dt, names.weekday_short_map[daily_panchaanga.date.get_weekday()],
             '\\\\'.join([f.tex_code(languages=languages, scripts=scripts, timezone=panchaanga.city.timezone, fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date)
                          for f in sorted(daily_panchaanga.festival_id_to_instance.values())])))

    if m == 12 and dt == 31:
      break

  print('\\end{supertabular}')
  print('\\end{multicols*}')
  print('\\renewcommand{\\tamil}[1]{%')
  print('{\\fontspec[Scale=0.9,FakeStretch=0.9]{Noto Sans Tamil}\\fontsize{7}{12}\\selectfont #1}}')

  # print('\\clearpage')

  month_text = ''
  W6D1 = W6D2 = ''
  for d in range(panchaanga.duration_prior_padding, jyotisha.panchaanga.temporal.MAX_SZ - 1):
    [y, m, dt, t] = time.jd_to_utc_gregorian(panchaanga.jd_start + d - 1).to_date_fractional_hour_tuple()

    # checking @ 6am local - can we do any better?
    local_time = tz(panchaanga.city.timezone).localize(datetime(y, m, dt, 6, 0, 0))
    # compute offset from UTC in hours
    tz_off = (datetime.utcoffset(local_time).days * 86400 +
              datetime.utcoffset(local_time).seconds) / 3600.0

    # What is the jd at 00:00 local time today?
    jd = daily_panchaanga.julian_day_start

    if dt == 1:
      currWeek = 1
      if m > 1:
        month_text = month_text.replace('W6D1', W6D1)
        month_text = month_text.replace('W6D2', W6D2)
        print(month_text)
        month_text = W6D1 = W6D2 = ''
        if currWeek < 6:
          if daily_panchaanga.date.get_weekday() != 0:  # Space till Sunday
            for i in range(daily_panchaanga.date.get_weekday(), 6):
              print("\\mbox{}  & %% %d" % currWeek)
            print("\\\\ \\hline")
        print('\\end{tabular}')
        print('\n\n')

      # Begin tabular
      print('\\begin{tabular}{|c|c|c|c|c|c|c|}')
      print('\\multicolumn{7}{c}{\\Large \\bfseries \\sffamily %s %s}\\\\[3mm]' % (
        names.month_map[m], y))
      print('\\hline')
      WDAY_NAMES = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
      print(' & '.join(['\\textbf{\\textsf{%s}}' %
                        _day for _day in WDAY_NAMES]) + ' \\\\ \\hline')

      # Blanks for previous weekdays
      for i in range(0, daily_panchaanga.date.get_weekday()):
        if i == 0:
          month_text += '\n' + ("{W6D1}  &")
        elif i == 1:
          month_text += '\n' + ("{W6D2}  &")
        else:
          month_text += '\n' + ("{}  &")

    tithi_data_str = day_details.get_tithi_data_str(daily_panchaanga, scripts, time_format)

    nakshatra_data_str = day_details.get_nakshatra_data_str(daily_panchaanga, scripts, time_format)

    yoga_data_str = day_details.get_yoga_data_str(daily_panchaanga, scripts, time_format)

    karana_data_str = day_details.get_karaNa_data_str(daily_panchaanga, scripts, time_format)


    sunrise = Hour(24 * (daily_panchaanga.jd_sunrise - jd)).to_string(
      format=time_format)
    sunset = Hour(24 * (daily_panchaanga.jd_sunset - jd)).to_string(format=time_format)
    saangava = Hour(24 * (daily_panchaanga.day_length_based_periods.fifteen_fold_division.saangava.jd_start - jd)).to_string(
      format=time_format)
    rahu = '%s--%s' % (
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.raahu.jd_start - jd)).to_string(
        format=time_format),
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.raahu.jd_end - jd)).to_string(
        format=time_format))
    yama = '%s--%s' % (
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.yama.jd_start - jd)).to_string(
        format=time_format),
      Hour(24 * (daily_panchaanga.day_length_based_periods.eight_fold_division.yama.jd_end - jd)).to_string(
        format=time_format))

    if daily_panchaanga.solar_sidereal_date_sunset.month_transition is None:
      month_end_str = ''
    else:
      _m = daily_panchaangas[d - 1].solar_sidereal_date_sunset.month
      if daily_panchaanga.solar_sidereal_date_sunset.month_transition >= daily_panchaangas[d + 1].jd_sunrise:
        month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}\\textsf{%s}}' % (
          names.NAMES['RASHI_NAMES']['sa'][scripts[0]][_m], Hour(
            24 * (daily_panchaanga.solar_sidereal_date_sunset.month_transition - daily_panchaangas[d + 1].julian_day_start)).to_string(format=time_format))
      else:
        month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}\\textsf{%s}}' % (
          names.NAMES['RASHI_NAMES']['sa'][scripts[0]][_m], Hour(
            24 * (daily_panchaanga.solar_sidereal_date_sunset.month_transition - daily_panchaanga.julian_day_start)).to_string(format=time_format))

    month_data = '\\sunmonth{%s}{%d}{%s}' % (
      names.NAMES['RASHI_NAMES']['sa'][scripts[0]][daily_panchaanga.solar_sidereal_date_sunset.month], daily_panchaanga.solar_sidereal_date_sunset.day,
      month_end_str)

    if currWeek < 6:
      month_text += '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                            (day_colours[daily_panchaanga.date.get_weekday()], dt, month_data,
                             names.get_chandra_masa(daily_panchaanga.lunar_month_sunrise, scripts[0])))
      month_text += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' % (sunrise, sunset, saangava))
      month_text += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' % (tithi_data_str, nakshatra_data_str,
                                                                        yoga_data_str, karana_data_str))
      month_text += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

      # Using set as an ugly workaround since we may have sometimes assigned the same
      # festival to the same day again!
      month_text += '\n' + ('{%s}' % '\\eventsep '.join(
        [f.tex_code(languages=languages, scripts=scripts, timezone=panchaanga.city.timezone, fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date) for f in
         sorted(daily_panchaanga.festival_id_to_instance.values())]))
    else:
      if daily_panchaanga.date.get_weekday() == 0:
        W6D1 = '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                       (day_colours[daily_panchaanga.date.get_weekday()], dt, month_data,
                        names.get_chandra_masa(daily_panchaanga.lunar_month_sunrise,scripts[0])))
        W6D1 += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' % (sunrise, sunset, saangava))
        W6D1 += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' % (tithi_data_str, nakshatra_data_str,
                                                                    yoga_data_str, karana_data_str))
        W6D1 += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

        # Using set as an ugly workaround since we may have sometimes assigned the same
        # festival to the same day again!
        W6D1 += '\n' + ('{%s}' % '\\eventsep '.join(
          [f.tex_code(languages=languages, scripts=scripts, timezone=Timezone(panchaanga.city.timezone), fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date) for f in sorted(daily_panchaanga.festival_id_to_instance.values())]))
      elif daily_panchaanga.date.get_weekday() == 1:
        W6D2 = '\n' + ('\\caldata{\\textcolor{%s}{%s}}{%s{%s}}%%' %
                       (day_colours[daily_panchaanga.date.get_weekday()], dt, month_data,
                        names.get_chandra_masa(daily_panchaanga.lunar_month_sunrise,scripts[0])))
        W6D2 += '\n' + ('{\\sundata{%s}{%s}{%s}}%%' % (sunrise, sunset, saangava))
        W6D2 += '\n' + ('{\\tnyk{%s}%%\n{%s}%%\n{%s}%%\n{%s}}%%' % (tithi_data_str, nakshatra_data_str,
                                                                    yoga_data_str, karana_data_str))
        W6D2 += '\n' + ('{\\rahuyama{%s}{%s}}%%' % (rahu, yama))

        # Using set as an ugly workaround since we may have sometimes assigned the same
        # festival to the same day again!
        W6D2 += '\n' + ('{%s}' % '\\eventsep '.join(
          [f.tex_code(languages=languages, scripts=scripts, timezone=panchaanga.city.timezone, fest_details_dict=fest_details_dict, reference_date=daily_panchaanga.date) for f in sorted(daily_panchaanga.festival_id_to_instance.values())]))
      else:
        # Cannot be here, since we cannot have more than 2 days in week 6 of any month!
        pass

    if daily_panchaanga.date.get_weekday() == 6:
      month_text += '\n' + ("\\\\ \\hline %%END OF WEEK %d" % (currWeek))
      currWeek += 1
    else:
      if currWeek < 6:
        month_text += '\n' + ("&")

    if m == 12 and dt == 31:
      break

  month_text = month_text.replace('W6D1', W6D1)
  month_text = month_text.replace('W6D2', W6D2)
  print(month_text)

  if currWeek < 6:
    for i in range(daily_panchaanga.date.get_weekday() + 1, 6):
      print("{}  &")
    if daily_panchaanga.date.get_weekday() != 6:
      print("\\\\ \\hline")
  print('\\end{tabular}')
  print('\n\n')

  print(template_lines[-2][:-1])
  print(template_lines[-1][:-1])
def emit(panchaanga,
         time_format="hh:mm",
         languages=None,
         scripts=None,
         output_stream=None):
    """Write out the panchaanga TeX using a specified template
  """
    # day_colours = {0: 'blue', 1: 'blue', 2: 'blue',
    #                3: 'blue', 4: 'blue', 5: 'blue', 6: 'blue'}
    compute_lagnams = panchaanga.computation_system.festival_options.set_lagnas
    if scripts is None:
        scripts = [sanscript.DEVANAGARI]
    if languages is None:
        languages = ["sa"]

    template_file = open(
        os.path.join(os.path.dirname(__file__),
                     'templates/daily_cal_template.tex'))

    template_lines = template_file.readlines()
    for i in range(len(template_lines)):
        print(template_lines[i][:-1], file=output_stream)

    year = panchaanga.start_date.year
    logging.debug(year)

    samvatsara_id = (year - 1568) % 60 + 1  # distance from prabhava
    samvatsara_names = (
        names.NAMES['SAMVATSARA_NAMES']['sa'][scripts[0]][samvatsara_id],
        names.NAMES['SAMVATSARA_NAMES']['sa'][scripts[0]][(samvatsara_id % 60)
                                                          + 1])

    yname = samvatsara_names[0]  # Assign year name until Mesha Sankranti

    set_top_content(output_stream, panchaanga, samvatsara_names, scripts, year)

    daily_panchaangas = panchaanga.daily_panchaangas_sorted()
    for d, daily_panchaanga in enumerate(daily_panchaangas):
        if daily_panchaanga.date < panchaanga.start_date or daily_panchaanga.date > panchaanga.end_date:
            continue
        [y, m, dt] = [
            daily_panchaanga.date.year, daily_panchaanga.date.month,
            daily_panchaanga.date.day
        ]

        # checking @ 6am local - can we do any better?
        local_time = tz(panchaanga.city.timezone).localize(
            datetime(y, m, dt, 6, 0, 0))
        # compute offset from UTC in hours
        tz_off = (datetime.utcoffset(local_time).days * 86400 +
                  datetime.utcoffset(local_time).seconds) / 3600.0

        tithi_data_str = get_tithi_data_str(daily_panchaanga, scripts,
                                            time_format)

        nakshatra_data_str = get_nakshatra_data_str(daily_panchaanga, scripts,
                                                    time_format)

        rashi_data_str = get_raashi_data_str(daily_panchaanga, scripts,
                                             time_format)

        lagna_data_str = get_lagna_data_str(
            daily_panchaanga, scripts, time_format) if compute_lagnams else ''

        yoga_data_str = get_yoga_data_str(daily_panchaanga, scripts,
                                          time_format)

        karana_data_str = get_karaNa_data_str(daily_panchaanga, scripts,
                                              time_format)

        gulika, rahu, yama, raatri_gulika, raatri_yama = get_raahu_yama_gulika_strings(
            daily_panchaanga, time_format)

        if daily_panchaanga.solar_sidereal_date_sunset.month == 1:
            # Flip the year name for the remaining days
            yname = samvatsara_names[1]

        # Assign samvatsara, ayana, rtu #
        sar_data = '{%s}{%s}{%s}' % (yname, names.NAMES['AYANA_NAMES']['sa'][
            scripts[0]][daily_panchaanga.solar_sidereal_date_sunset.
                        month], names.NAMES['RTU_NAMES']['sa'][scripts[0]][
                            daily_panchaanga.solar_sidereal_date_sunset.month])

        if daily_panchaanga.solar_sidereal_date_sunset.month_transition is None:
            month_end_str = ''
        else:
            _m = daily_panchaangas[d - 1].solar_sidereal_date_sunset.month
            if daily_panchaanga.solar_sidereal_date_sunset.month_transition >= daily_panchaangas[
                    d + 1].jd_sunrise:
                month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}{%s}}' % (
                    names.NAMES['RASHI_NAMES']['sa'][scripts[0]][_m],
                    time.Hour(
                        24 *
                        (daily_panchaanga.solar_sidereal_date_sunset.
                         month_transition -
                         daily_panchaangas[d + 1].julian_day_start)).to_string(
                             format=time_format))
            else:
                month_end_str = '\\mbox{%s{\\tiny\\RIGHTarrow}{%s}}' % (
                    names.NAMES['RASHI_NAMES']['sa'][scripts[0]][_m],
                    time.Hour(24 *
                              (daily_panchaanga.solar_sidereal_date_sunset.
                               month_transition -
                               daily_panchaanga.julian_day_start)).to_string(
                                   format=time_format))

        month_data = '\\sunmonth{%s}{%d}{%s}' % (
            names.NAMES['RASHI_NAMES']['sa'][scripts[0]][
                daily_panchaanga.solar_sidereal_date_sunset.month],
            daily_panchaanga.solar_sidereal_date_sunset.day, month_end_str)

        print('\\caldata{%s}{%s}{%s{%s}{%s}{%s}%s}' %
              (names.month_map[m].upper(), dt, month_data,
               names.get_chandra_masa(
                   daily_panchaanga.lunar_month_sunrise.index,
                   scripts[0]), names.NAMES['RTU_NAMES']['sa'][scripts[0]][int(
                       ceil(daily_panchaanga.lunar_month_sunrise.index))],
               names.NAMES['VARA_NAMES']['sa'][scripts[0]][
                   daily_panchaanga.date.get_weekday()], sar_data),
              file=output_stream)

        stream_sun_moon_rise_data(daily_panchaanga, output_stream, time_format)

        stream_daylength_based_periods(daily_panchaanga, output_stream,
                                       time_format)

        print('{\\tnykdata{%s}%%\n{%s}{%s}%%\n{%s}%%\n{%s}{%s}\n}' %
              (tithi_data_str, nakshatra_data_str, rashi_data_str,
               yoga_data_str, karana_data_str, lagna_data_str),
              file=output_stream)

        print_festivals_to_stream(daily_panchaanga, output_stream, panchaanga,
                                  languages, scripts)

        print('{%s} ' %
              names.weekday_short_map[daily_panchaanga.date.get_weekday()],
              file=output_stream)
        print('\\cfoot{\\rygdata{%s}{%s}{%s}}' % (rahu, yama, gulika),
              file=output_stream)

        if m == 12 and dt == 31:
            break

    print('\\end{document}', file=output_stream)