コード例 #1
0
ファイル: ecliptic.py プロジェクト: jparajuli/jyotisha
 def compute_solar_eclipses(self):
   if 'sUrya-grahaNam' not in self.rules_collection.name_to_rule:
     return 
   jd = self.panchaanga.jd_start
   while 1:
     next_eclipse_sol = self.panchaanga.city.get_solar_eclipse_time(jd_start=jd)
     # compute offset from UTC
     jd = next_eclipse_sol[1][0]
     jd_eclipse_solar_start = next_eclipse_sol[1][1]
     jd_eclipse_solar_end = next_eclipse_sol[1][4]
     # -1 is to not miss an eclipse that occurs after sunset on 31-Dec!
     if jd_eclipse_solar_start > self.panchaanga.jd_end + 1:
       break
     else:
       fday = int(floor(jd) - floor(self.daily_panchaangas[0].julian_day_start))
       if (jd < self.daily_panchaangas[fday].jd_sunrise):
         fday -= 1
       if (jd_eclipse_solar_start) == 0.0 or jd_eclipse_solar_end == 0.0:
         # Move towards the next eclipse... at least the next new
         # moon (>=25 days away)
         jd += MIN_DAYS_NEXT_ECLIPSE
         continue
       if abs (Graha.singleton(Graha.SUN).get_longitude(jd_eclipse_solar_end) - Graha.singleton(Graha.RAHU).get_longitude(
           jd_eclipse_solar_end)) < 5:
         grasta = 'rAhugrasta'
       else:
         grasta = 'kEtugrasta'
       solar_eclipse_str = 'sUrya-grahaNaM~(' + grasta + ')'
       if self.daily_panchaangas[fday].date.get_weekday() == 0:
         solar_eclipse_str = '★cUDAmaNi-' + solar_eclipse_str
       fest = FestivalInstance(name=solar_eclipse_str, interval=Interval(jd_start=jd_eclipse_solar_start, jd_end=jd_eclipse_solar_end))
     self.panchaanga.add_festival_instance(festival_instance=fest, date=self.daily_panchaangas[fday].date)
     jd = jd + MIN_DAYS_NEXT_ECLIPSE
コード例 #2
0
ファイル: daily.py プロジェクト: namaljayathunga/jyotisha
    def set_tropical_date_sunset(self, previous_day_panchaanga=None):
        month_transition_jd = None
        if previous_day_panchaanga is not None:
            tropical_date_sunset_day = previous_day_panchaanga.tropical_date_sunset.day + 1
            tropical_date_sunset_month = previous_day_panchaanga.tropical_date_sunset.month

        if previous_day_panchaanga is None or previous_day_panchaanga.tropical_date_sunset.day > 28:
            nd = zodiac.NakshatraDivision(
                jd=self.jd_sunset, ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
            fractional_month = nd.get_fractional_division_for_body(
                body=Graha.singleton(Graha.SUN), anga_type=AngaType.RASHI)
            (month_fraction, _) = modf(fractional_month)
            approx_day = month_fraction * 30
            month_transitions = Graha.singleton(Graha.SUN).get_transits(
                jd_start=self.jd_sunset - approx_day - 5,
                jd_end=self.jd_sunset + 4,
                anga_type=AngaType.RASHI,
                ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
            if month_transitions[
                    -1].jd > self.jd_previous_sunset and month_transitions[
                        -1].jd <= self.jd_sunset:
                tropical_date_sunset_day = 1
                tropical_date_sunset_month = month_transitions[-1].value_2
                month_transition_jd = month_transitions[-1].jd
            else:
                tropical_date_sunset_day = len(
                    self.city.get_sunsets_in_period(
                        jd_start=month_transitions[0].jd,
                        jd_end=self.jd_sunset + 1 / 48.0))
                tropical_date_sunset_month = month_transitions[0].value_2
        self.tropical_date_sunset = time.BasicDateWithTransitions(
            month=tropical_date_sunset_month,
            day=tropical_date_sunset_day,
            month_transition=month_transition_jd)
コード例 #3
0
    def get_anga_float(self, anga_type):
        """Returns the anga/ temporal property. Computed based on lunar and solar longitudes, division of a circle into a certain number of degrees (arc_len).

      Args:
        :param anga_type: One of the pre-defined tuple-valued constants in the panchaanga
        class, such as TITHI, nakshatra, YOGA, KARANA or SIDEREAL_MONTH

      Returns:
        float anga
    """
        if anga_type == AngaType.TITHI:
            # For efficiency - avoid lookups.
            ayanaamsha_id = Ayanamsha.VERNAL_EQUINOX_AT_0
        else:
            ayanaamsha_id = self.ayanaamsha_id

        w_moon = anga_type.weight_moon
        w_sun = anga_type.weight_sun

        lcalc = 0  # computing offset longitudes

        #  Get the lunar longitude, starting at the ayanaamsha point in the ecliptic.
        if w_moon != 0:
            lmoon = Graha.singleton(Graha.MOON).get_longitude(
                self.jd, ayanaamsha_id=ayanaamsha_id)
            lcalc += w_moon * lmoon

        #  Get the solar longitude, starting at the ayanaamsha point in the ecliptic.
        if w_sun != 0:
            lsun = Graha.singleton(Graha.SUN).get_longitude(
                self.jd, ayanaamsha_id=ayanaamsha_id)
            lcalc += w_sun * lsun

        return self.longitude_to_fractional_division(longitude=lcalc,
                                                     anga_type=anga_type)
コード例 #4
0
    def compute_lunar_eclipses(self):
        # Set location
        jd = self.panchaanga.jd_start
        while 1:
            next_eclipse_lun = self.panchaanga.city.get_lunar_eclipse_time(jd)
            jd = next_eclipse_lun[1][0]
            jd_eclipse_lunar_start = next_eclipse_lun[1][2]
            jd_eclipse_lunar_end = next_eclipse_lun[1][3]
            # -1 is to not miss an eclipse that occurs after sunset on 31-Dec!
            if jd_eclipse_lunar_start > self.panchaanga.jd_end:
                break
            else:
                if jd_eclipse_lunar_start == 0.0 or jd_eclipse_lunar_end == 0.0:
                    # 0.0 is returned in case of eclipses when the moon is below the horizon.
                    # Move towards the next eclipse... at least the next full
                    # moon (>=25 days away)
                    jd += MIN_DAYS_NEXT_ECLIPSE
                    continue
                fday = int(
                    floor(jd_eclipse_lunar_start) -
                    floor(self.panchaanga.jd_start) + 1)
                # print '%%', jd, fday, self.date_str_to_panchaanga[fday].jd_sunrise,
                # self.date_str_to_panchaanga[fday-1].jd_sunrise
                if jd < self.daily_panchaangas[fday].jd_sunrise:
                    fday -= 1
                # print '%%', jd, fday, self.date_str_to_panchaanga[fday].jd_sunrise,
                # self.date_str_to_panchaanga[fday-1].jd_sunrise, eclipse_lunar_start,
                # eclipse_lunar_end
                jd_moonrise_eclipse_day = self.panchaanga.city.get_rising_time(
                    julian_day_start=self.daily_panchaangas[fday].jd_sunrise,
                    body=Graha.MOON)

                jd_moonset_eclipse_day = self.panchaanga.city.get_setting_time(
                    julian_day_start=jd_moonrise_eclipse_day, body=Graha.MOON)

                if jd_eclipse_lunar_end < jd_moonrise_eclipse_day or \
                    jd_eclipse_lunar_start > jd_moonset_eclipse_day:
                    # Move towards the next eclipse... at least the next full
                    # moon (>=25 days away)
                    jd += MIN_DAYS_NEXT_ECLIPSE
                    continue

                if Graha.singleton(Graha.MOON).get_longitude(
                        jd_eclipse_lunar_end) < Graha.singleton(
                            Graha.SUN).get_longitude(jd_eclipse_lunar_end):
                    grasta = 'rAhugrasta'
                else:
                    grasta = 'kEtugrasta'

                lunar_eclipse_str = 'candra-grahaNam~(' + grasta + ')'
                if self.daily_panchaangas[fday].date.get_weekday() == 1:
                    lunar_eclipse_str = '★cUDAmaNi-' + lunar_eclipse_str

                self.daily_panchaangas[fday].festival_id_to_instance[
                    lunar_eclipse_str] = (FestivalInstance(
                        name=lunar_eclipse_str,
                        interval=Interval(jd_start=jd_eclipse_lunar_start,
                                          jd_end=jd_eclipse_lunar_end)))
            jd += MIN_DAYS_NEXT_ECLIPSE
コード例 #5
0
def test_longitude_difference():
    numpy.testing.assert_approx_equal(body.longitude_difference(
        jd=2458484.545,
        body1=Graha.singleton(Graha.SUN),
        body2=Graha.singleton(Graha.MARS)),
                                      -79.66,
                                      significant=2)
    numpy.testing.assert_approx_equal(body.longitude_difference(
        jd=2458485.5453,
        body1=Graha.singleton(Graha.SUN),
        body2=Graha.singleton(Graha.MARS)),
                                      -79.31,
                                      significant=2)
コード例 #6
0
ファイル: ecliptic.py プロジェクト: jparajuli/jyotisha
 def set_jupiter_transits(self):
   if 'guru-saGkrAntiH' not in self.rules_collection.name_to_rule:
     return 
   jd_end = self.panchaanga.jd_start + self.panchaanga.duration + 13
   check_window = 400  # Max t between two Jupiter transits is ~396 (checked across 180y)
   # Let's check for transitions in a relatively large window
   # to finalise what is the FINAL transition post retrograde movements
   transits = Graha.singleton(Graha.JUPITER).get_transits(self.panchaanga.jd_start - 13, jd_end + check_window, anga_type=AngaType.RASHI,
                                                          ayanaamsha_id=self.ayanaamsha_id)
   if len(transits) > 0:
     for i, transit in enumerate(transits):
       (jd_transit, rashi1, rashi2) = (transit.jd, transit.value_1, transit.value_2)
       if self.panchaanga.jd_start - 13 < jd_transit < jd_end:
         fday = int(floor(jd_transit) - floor(self.daily_panchaangas[0].julian_day_start))
         fest = TransitionFestivalInstance(name='guru-saGkrAntiH', status_1_hk=names.NAMES['RASHI_NAMES']['sa']['hk'][rashi1], status_2_hk=names.NAMES['RASHI_NAMES']['sa']['hk'][rashi2])
         self.panchaanga.add_festival_instance(festival_instance=fest, date=self.daily_panchaangas[fday].date)
         if (rashi1 % 12 + 1) == rashi2 and ((transits[i + 1].value_1 % 12) + 1) == transits[i + 1].value_2:
           # Considering only non-retrograde transits for pushkara computations
           # logging.debug('Non-retrograde transit; we have a pushkaram!')
           (madhyanha_start, madhyaahna_end) = interval.get_interval(self.daily_panchaangas[fday].jd_sunrise,
                                                                                                  self.daily_panchaangas[fday].jd_sunset, 2, 5).to_tuple()
           if jd_transit < madhyaahna_end:
             fday_pushkara = fday
           else:
             fday_pushkara = fday + 1
           self.panchaanga.add_festival(
             fest_id='%s-Adi-puSkara-ArambhaH' % names.NAMES['PUSHKARA_NAMES']['sa']['hk'][rashi2], date=self.daily_panchaangas[fday_pushkara].date)
           self.panchaanga.add_festival(
             fest_id='%s-Adi-puSkara-samApanam' % names.NAMES['PUSHKARA_NAMES']['sa']['hk'][rashi2], date=self.daily_panchaangas[fday_pushkara].date + 11)
           self.panchaanga.add_festival(
             fest_id='%s-antya-puSkara-samApanam' % names.NAMES['PUSHKARA_NAMES']['sa']['hk'][rashi1], date=self.daily_panchaangas[fday_pushkara].date - 1)
           self.panchaanga.add_festival(
             fest_id='%s-antya-puSkara-ArambhaH' % names.NAMES['PUSHKARA_NAMES']['sa']['hk'][rashi1], date=self.daily_panchaangas[fday_pushkara].date - 12)
コード例 #7
0
 def get_setting_time(self, julian_day_start, body):
   from jyotisha.panchaanga.temporal.body import Graha
   graha = Graha.singleton(body)
   # rise_trans expects UT time
   return swe.rise_trans(
     jd_start=julian_day_start, body=graha._get_swisseph_id(),
     lon=self.longitude, lat=self.latitude,
     rsmi=CALC_SET)[1][0]
コード例 #8
0
def test_graha_get_next_raashi_transit():
    from jyotisha.panchaanga.temporal.zodiac import Ayanamsha
    from jyotisha.panchaanga.temporal.zodiac import AngaType
    assert Graha.singleton(Graha.JUPITER).get_transits(
        jd_start=2457755,
        jd_end=2458120,
        anga_type=AngaType.RASHI,
        ayanaamsha_id=Ayanamsha.CHITRA_AT_180) == [
            Transit(body=Graha.JUPITER,
                    jd=2458008.4510242934,
                    anga_type=AngaType.RASHI.name,
                    value_1=6,
                    value_2=7)
        ]
    assert Graha.singleton(Graha.SUN).get_transits(
        jd_start=2458162.545722,
        jd_end=2458177.545722,
        anga_type=AngaType.RASHI,
        ayanaamsha_id=Ayanamsha.CHITRA_AT_180) == []
コード例 #9
0
 def get(self, body_name, anga_type_str, timezone, year, month, day, hour,
         minute, second):
     jd = Timezone(timezone).local_time_to_julian_day(
         Date(year, month, day, hour, minute, second))
     nd = NakshatraDivision(jd=jd, ayanaamsha_id=Ayanamsha.CHITRA_AT_180)
     body = Graha(body_name=body_name)
     anga_type = AngaType.NAKSHATRA
     if anga_type_str == AngaType.RASHI.name:
         anga_type = AngaType.RASHI
     division = nd.get_fractional_division_for_body(body=body,
                                                    anga_type=anga_type)
     logging.info(division)
     return str(division)
コード例 #10
0
ファイル: daily.py プロジェクト: namaljayathunga/jyotisha
    def set_mauDhyas(self):
        sun = Graha.singleton(body_name=Graha.SUN)
        mauDhyas = {}
        amauDhyas = {}

        for graha_id in [
                Graha.MERCURY, Graha.VENUS, Graha.MARS, Graha.JUPITER,
                Graha.SATURN
        ]:
            graha = Graha.singleton(body_name=graha_id)
            gap = self.computation_system.graha_lopa_measures.graha_id_to_lopa_measure.get(
                graha_id, None)

            if self.day_has_conjunction(body1=sun, body2=graha, gap=gap):
                mauDhyas[graha_id] = [
                    body.longitude_difference(jd=self.jd_sunrise,
                                              body1=sun,
                                              body2=graha),
                    body.longitude_difference(jd=self.jd_next_sunrise,
                                              body1=sun,
                                              body2=graha)
                ]
            else:
                amauDhyas[graha_id] = [
                    body.longitude_difference(jd=self.jd_sunrise,
                                              body1=sun,
                                              body2=graha),
                    body.longitude_difference(jd=self.jd_next_sunrise,
                                              body1=sun,
                                              body2=graha)
                ]

        if len(mauDhyas) > 0:
            self.mauDhyas = mauDhyas
        if len(amauDhyas) > 0:
            self.amauDhyas = amauDhyas
コード例 #11
0
 def get(self, timezone, year, month, day, hour, minute, second, body):
     from jyotisha import zodiac
     jd = Timezone(timezone).local_time_to_julian_day(
         Date(year, month, day, hour, minute, second))
     from jyotisha.panchaanga import temporal
     transits = Graha.singleton(body).get_transits(
         jd_start=jd,
         jd_end=jd + 100,
         anga_type=AngaType.RASHI,
         ayanaamsha_id=Ayanamsha.CHITRA_AT_180)
     # logging.debug(transits)
     transits_local = [
         (Timezone(timezone).julian_day_to_local_time(transit.jd),
          transit.value_1, transit.value_2) for transit in transits
     ]
     return str(transits_local)
コード例 #12
0
ファイル: ecliptic.py プロジェクト: jparajuli/jyotisha
  def compute_conjunctions(self, Graha1, Graha2, delta=0.0):
    # Compute the time of conjunction between Graha1 and Graha2
    GRAHA_NAMES = {Graha.SUN: 'sUryaH', Graha.MOON: 'candraH', Graha.JUPITER: 'guruH',
        Graha.VENUS: 'zukraH', Graha.MERCURY: 'budhaH', Graha.MARS: 'aGgArakaH', 
        Graha.SATURN: 'zanaizcaraH', Graha.RAHU: 'rAhuH'}
    if delta == 0.0:
      try:
        t = brentq(lambda jd: Graha.singleton(Graha1).get_longitude(jd) - Graha.singleton(Graha2).get_longitude(jd),
                 self.panchaanga.jd_start, self.panchaanga.jd_end)
      except ValueError:
        t = None
        logging.error('Not able to bracket!')
        
      if t is not None and self.panchaanga.jd_start < t < self.panchaanga.jd_end:
        fday = [self.daily_panchaangas[i].jd_sunrise < t < self.daily_panchaangas[i + 1].jd_sunrise for i in range(self.panchaanga.duration)].index(True)
        fest = FestivalInstance(name='graha-yuddhaH (%s–%s)' % (GRAHA_NAMES[Graha1], GRAHA_NAMES[Graha2]), interval=Interval(jd_start=None, jd_end=t))
        self.panchaanga.add_festival_instance(festival_instance=fest, date=self.daily_panchaangas[fday].date)
    else:
      # mauDhya / combustion with some degrees assigned
      try:
        t_start = brentq(lambda jd: Graha.singleton(Graha1).get_longitude(jd) - Graha.singleton(Graha2).get_longitude(jd) - delta,
                 self.panchaanga.jd_start, self.panchaanga.jd_end)
      except ValueError:
        t_start = None
        logging.error('Not able to bracket!')

      try:
        t_end = brentq(lambda jd: Graha.singleton(Graha1).get_longitude(jd) - Graha.singleton(Graha2).get_longitude(jd) + delta,
                 self.panchaanga.jd_start, self.panchaanga.jd_end)
      except ValueError:
        t_end = None
        logging.error('Not able to bracket!')

      if t_start is not None and self.panchaanga.jd_start < t_start < self.panchaanga.jd_end:
        fday = [self.daily_panchaangas[i].jd_sunrise < t_start < self.daily_panchaangas[i + 1].jd_sunrise for i in range(self.panchaanga.duration)].index(True)
        fest = FestivalInstance(name='%s–mauDhya' % GRAHA_NAMES[Graha1], interval=Interval(jd_start=t_start, jd_end=None))
        self.panchaanga.add_festival_instance(festival_instance=fest, date=self.daily_panchaangas[fday].date)

      if t_end is not None and self.panchaanga.jd_start < t_end < self.panchaanga.jd_end:
        fday = [self.daily_panchaangas[i].jd_sunrise < t_end < self.daily_panchaangas[i + 1].jd_sunrise for i in range(self.panchaanga.duration)].index(True)
        fest = FestivalInstance(name='%s–mauDhya' % GRAHA_NAMES[Graha1], interval=Interval(jd_start=None, jd_end=t_end))
        self.panchaanga.add_festival_instance(festival_instance=fest, date=self.daily_panchaangas[fday].date)
コード例 #13
0
ファイル: tithi_festival.py プロジェクト: jparajuli/jyotisha
    def assign_chaturthi_vratam(self):
        if "vikaTa-mahAgaNapati_saGkaTahara-caturthI-vratam" not in self.rules_collection.name_to_rule:
            return
        for d in range(
                self.panchaanga.duration_prior_padding,
                self.panchaanga.duration +
                self.panchaanga.duration_prior_padding):
            # SANKATAHARA chaturthi
            if self.daily_panchaangas[
                    d].sunrise_day_angas.tithi_at_sunrise.index == 18 or self.daily_panchaangas[
                        d].sunrise_day_angas.tithi_at_sunrise.index == 19:
                day_panchaanga = self.daily_panchaangas[d]
                ldiff_moonrise_yest = (
                    Graha.singleton(Graha.MOON).get_longitude(
                        self.daily_panchaangas[d - 1].jd_moonrise) -
                    Graha.singleton(Graha.SUN).get_longitude(
                        self.daily_panchaangas[d - 1].jd_moonrise)) % 360
                ldiff_moonrise = (Graha.singleton(Graha.MOON).get_longitude(
                    day_panchaanga.jd_moonrise) -
                                  Graha.singleton(Graha.SUN).get_longitude(
                                      day_panchaanga.jd_moonrise)) % 360
                ldiff_moonrise_tmrw = (
                    Graha.singleton(Graha.MOON).get_longitude(
                        self.daily_panchaangas[d + 1].jd_moonrise) -
                    Graha.singleton(Graha.SUN).get_longitude(
                        self.daily_panchaangas[d + 1].jd_moonrise)) % 360
                tithi_moonrise_yest = int(1 +
                                          floor(ldiff_moonrise_yest / 12.0))
                tithi_moonrise = int(1 + floor(ldiff_moonrise / 12.0))
                tithi_moonrise_tmrw = int(1 +
                                          floor(ldiff_moonrise_tmrw / 12.0))

                _m = day_panchaanga.lunar_month_sunrise.index
                if floor(_m) != _m:
                    _m = 13  # Adhika masa
                chaturthi_name = names.NAMES['SANKATAHARA_CHATURTHI_NAMES'][
                    'sa']['hk'][_m] + '-mahAgaNapati_'

                if tithi_moonrise == 19:
                    # otherwise yesterday would have already been assigned
                    if tithi_moonrise_yest != 19:
                        chaturthi_name = '%s%s' % (
                            'aGgArakI~' if day_panchaanga.date.get_weekday()
                            == 2 else '', chaturthi_name)
                        fest = FestivalInstance(
                            name=chaturthi_name +
                            'saGkaTahara-caturthI-vratam',
                            interval=day_panchaanga.get_interval(
                                interval_id="full_day"))
                        self.panchaanga.add_festival_instance(
                            festival_instance=fest, date=day_panchaanga.date)
                        # shravana krishna chaturthi
                        if day_panchaanga.lunar_month_sunrise.index == 5:
                            chaturthi_name = '%s%s' % (
                                'aGgArakI~' if
                                day_panchaanga.date.get_weekday() == 2 else '',
                                chaturthi_name)
                            fest = FestivalInstance(
                                name=chaturthi_name +
                                'mahAsaGkaTahara-caturthI-vratam',
                                interval=day_panchaanga.get_interval(
                                    interval_id="full_day"))
                            self.panchaanga.add_festival_instance(
                                festival_instance=fest,
                                date=day_panchaanga.date)
                elif tithi_moonrise_tmrw == 19:
                    chaturthi_name = '%s%s' % (
                        'aGgArakI~' if self.daily_panchaangas[d + 1].date.
                        get_weekday() == 2 else '', chaturthi_name)
                    fest = FestivalInstance(
                        name=chaturthi_name + 'saGkaTahara-caturthI-vratam',
                        interval=day_panchaanga.get_interval(
                            interval_id="full_day"))
                    self.panchaanga.add_festival_instance(
                        festival_instance=fest,
                        date=self.daily_panchaangas[d + 1].date)
                    # self.date_str_to_panchaanga[d].lunar_month_sunrise and[d + 1] are same, so checking [d] is enough
                    if day_panchaanga.lunar_month_sunrise.index == 5:
                        chaturthi_name = '%s%s' % (
                            'aGgArakI~' if day_panchaanga.date.get_weekday()
                            == 2 else '', chaturthi_name)
                        fest = FestivalInstance(
                            name=chaturthi_name +
                            'mahAsaGkaTahara-caturthI-vratam',
                            interval=day_panchaanga.get_interval(
                                interval_id="full_day"))
                        self.panchaanga.add_festival_instance(
                            festival_instance=fest,
                            date=self.daily_panchaangas[d + 1].date)
                else:
                    if tithi_moonrise_yest != 19:
                        if tithi_moonrise == 18 and tithi_moonrise_tmrw == 20:
                            # No vyApti on either day -- pick parA, i.e. next day.
                            chaturthi_name = '%s%s' % (
                                'aGgArakI~' if self.daily_panchaangas[
                                    d + 1].date.get_weekday() == 2 else '',
                                chaturthi_name)
                            fest = FestivalInstance(
                                name=chaturthi_name +
                                'saGkaTahara-caturthI-vratam',
                                interval=day_panchaanga.get_interval(
                                    interval_id="full_day"))
                            self.panchaanga.add_festival_instance(
                                festival_instance=fest,
                                date=self.daily_panchaangas[d + 1].date)
                            # shravana krishna chaturthi
                            if day_panchaanga.lunar_month_sunrise.index == 5:
                                chaturthi_name = '%s%s' % (
                                    'aGgArakI~' if self.daily_panchaangas[
                                        d + 1].date.get_weekday() == 2 else '',
                                    chaturthi_name)
                                fest = FestivalInstance(
                                    name=chaturthi_name +
                                    'mahAsaGkaTahara-caturthI-vratam',
                                    interval=day_panchaanga.get_interval(
                                        interval_id="full_day"))
                                self.panchaanga.add_festival_instance(
                                    festival_instance=fest,
                                    date=self.daily_panchaangas[d + 1].date)
コード例 #14
0
    def compute_lunar_eclipses(self):
        # Set location
        jd = self.panchaanga.jd_start
        while 1:
            next_eclipse_lun = self.panchaanga.city.get_lunar_eclipse_time(jd)
            [y, m, dt, t] = time.jd_to_utc_gregorian(
                next_eclipse_lun[1][0]).to_date_fractional_hour_tuple()
            local_time = tz(self.panchaanga.city.timezone).localize(
                datetime(y, m, dt, 6, 0, 0))
            # checking @ 6am local - can we do any better? This is crucial,
            # since DST changes before 6 am
            tz_off = (datetime.utcoffset(local_time).days * 86400 +
                      datetime.utcoffset(local_time).seconds) / 3600.0
            # compute offset from UTC
            jd = next_eclipse_lun[1][0] + (tz_off / 24.0)
            jd_eclipse_lunar_start = next_eclipse_lun[1][2] + (tz_off / 24.0)
            jd_eclipse_lunar_end = next_eclipse_lun[1][3] + (tz_off / 24.0)
            # -1 is to not miss an eclipse that occurs after sunset on 31-Dec!
            if jd_eclipse_lunar_start > self.panchaanga.jd_end:
                break
            else:
                if (jd_eclipse_lunar_start - (tz_off / 24.0)) == 0.0 or \
                    (jd_eclipse_lunar_end - (tz_off / 24.0)) == 0.0:
                    # Move towards the next eclipse... at least the next full
                    # moon (>=25 days away)
                    jd += MIN_DAYS_NEXT_ECLIPSE
                    continue
                fday = int(
                    floor(jd_eclipse_lunar_start) -
                    floor(self.panchaanga.jd_start) + 1)
                # print '%%', jd, fday, self.date_str_to_panchaanga[fday].jd_sunrise,
                # self.date_str_to_panchaanga[fday-1].jd_sunrise
                if (jd <
                    (self.daily_panchaangas[fday].jd_sunrise + tz_off / 24.0)):
                    fday -= 1
                # print '%%', jd, fday, self.date_str_to_panchaanga[fday].jd_sunrise,
                # self.date_str_to_panchaanga[fday-1].jd_sunrise, eclipse_lunar_start,
                # eclipse_lunar_end
                jd_moonrise_eclipse_day = self.panchaanga.city.get_rising_time(
                    julian_day_start=self.daily_panchaangas[fday].jd_sunrise,
                    body=Graha.MOON) + (tz_off / 24.0)

                jd_moonset_eclipse_day = self.panchaanga.city.get_rising_time(
                    julian_day_start=jd_moonrise_eclipse_day,
                    body=Graha.MOON) + (tz_off / 24.0)

                if jd_eclipse_lunar_end < jd_moonrise_eclipse_day or \
                    jd_eclipse_lunar_start > jd_moonset_eclipse_day:
                    # Move towards the next eclipse... at least the next full
                    # moon (>=25 days away)
                    jd += MIN_DAYS_NEXT_ECLIPSE
                    continue

                if Graha.singleton(Graha.MOON).get_longitude(
                        jd_eclipse_lunar_end) < Graha.singleton(
                            Graha.SUN).get_longitude(jd_eclipse_lunar_end):
                    grasta = 'rAhugrasta'
                else:
                    grasta = 'kEtugrasta'

                lunar_eclipse_str = 'candra-grahaNam~(' + grasta + ')'
                if self.daily_panchaangas[fday].date.get_weekday() == 1:
                    lunar_eclipse_str = '★cUDAmaNi-' + lunar_eclipse_str

                self.daily_panchaangas[fday].festival_id_to_instance[
                    lunar_eclipse_str] = (FestivalInstance(
                        name=lunar_eclipse_str,
                        interval=Interval(jd_start=jd_eclipse_lunar_start,
                                          jd_end=jd_eclipse_lunar_end)))
            jd += MIN_DAYS_NEXT_ECLIPSE
コード例 #15
0
def test_graha_get_longitude():
    assert Graha.singleton(
        Graha.SUN).get_longitude(jd=2458434.083333251) == 229.12286985575702
コード例 #16
0
    def assign_chaturthi_vratam(self):
        for d in range(self.panchaanga.duration_prior_padding,
                       self.panchaanga.duration + 1):
            [y, m, dt,
             t] = time.jd_to_utc_gregorian(self.panchaanga.jd_start + d -
                                           1).to_date_fractional_hour_tuple()

            # SANKATAHARA chaturthi
            if self.daily_panchaangas[
                    d].sunrise_day_angas.tithi_at_sunrise.index == 18 or self.daily_panchaangas[
                        d].sunrise_day_angas.tithi_at_sunrise.index == 19:
                ldiff_moonrise_yest = (
                    Graha.singleton(Graha.MOON).get_longitude(
                        self.daily_panchaangas[d - 1].jd_moonrise) -
                    Graha.singleton(Graha.SUN).get_longitude(
                        self.daily_panchaangas[d - 1].jd_moonrise)) % 360
                ldiff_moonrise = (Graha.singleton(Graha.MOON).get_longitude(
                    self.daily_panchaangas[d].jd_moonrise) - Graha.singleton(
                        Graha.SUN).get_longitude(
                            self.daily_panchaangas[d].jd_moonrise)) % 360
                ldiff_moonrise_tmrw = (
                    Graha.singleton(Graha.MOON).get_longitude(
                        self.daily_panchaangas[d + 1].jd_moonrise) -
                    Graha.singleton(Graha.SUN).get_longitude(
                        self.daily_panchaangas[d + 1].jd_moonrise)) % 360
                tithi_moonrise_yest = int(1 +
                                          floor(ldiff_moonrise_yest / 12.0))
                tithi_moonrise = int(1 + floor(ldiff_moonrise / 12.0))
                tithi_moonrise_tmrw = int(1 +
                                          floor(ldiff_moonrise_tmrw / 12.0))

                _m = self.daily_panchaangas[d].lunar_month_sunrise.index
                if floor(_m) != _m:
                    _m = 13  # Adhika masa
                chaturthi_name = names.NAMES['SANKATAHARA_CHATURTHI_NAMES'][
                    'hk'][_m] + '-mahAgaNapati '

                if tithi_moonrise == 19:
                    # otherwise yesterday would have already been assigned
                    if tithi_moonrise_yest != 19:
                        chaturthi_name = '%s%s' % (
                            'aGgArakI~' if self.daily_panchaangas[d].date.
                            get_weekday() == 2 else '', chaturthi_name)
                        fest = FestivalInstance(name=chaturthi_name +
                                                'saGkaTahara-caturthI-vratam')
                        self.daily_panchaangas[d].festival_id_to_instance[
                            fest.name] = fest
                        # shravana krishna chaturthi
                        if self.daily_panchaangas[
                                d].lunar_month_sunrise.index == 5:
                            chaturthi_name = '%s%s' % (
                                'aGgArakI~' if self.daily_panchaangas[d].date.
                                get_weekday() == 2 else '', chaturthi_name)
                            fest = FestivalInstance(
                                name=chaturthi_name +
                                'mahAsaGkaTahara-caturthI-vratam')
                            self.daily_panchaangas[d].festival_id_to_instance[
                                fest.name] = fest
                elif tithi_moonrise_tmrw == 19:
                    chaturthi_name = '%s%s' % (
                        'aGgArakI~' if self.daily_panchaangas[d + 1].date.
                        get_weekday() == 2 else '', chaturthi_name)
                    fest = FestivalInstance(name=chaturthi_name +
                                            'saGkaTahara-caturthI-vratam')
                    self.daily_panchaangas[d + 1].festival_id_to_instance[
                        fest.name] = fest
                    # self.date_str_to_panchaanga[d].lunar_month_sunrise and[d + 1] are same, so checking [d] is enough
                    if self.daily_panchaangas[
                            d].lunar_month_sunrise.index == 5:
                        chaturthi_name = '%s%s' % (
                            'aGgArakI~' if self.daily_panchaangas[d].date.
                            get_weekday() == 2 else '', chaturthi_name)
                        fest = FestivalInstance(
                            name=chaturthi_name +
                            'mahAsaGkaTahara-caturthI-vratam')
                        self.daily_panchaangas[d + 1].festival_id_to_instance[
                            fest.name] = fest
                else:
                    if tithi_moonrise_yest != 19:
                        if tithi_moonrise == 18 and tithi_moonrise_tmrw == 20:
                            # No vyApti on either day -- pick parA, i.e. next day.
                            chaturthi_name = '%s%s' % (
                                'aGgArakI~' if self.daily_panchaangas[
                                    d + 1].date.get_weekday() == 2 else '',
                                chaturthi_name)
                            fest = FestivalInstance(
                                name=chaturthi_name +
                                'saGkaTahara-caturthI-vratam')
                            self.daily_panchaangas[d +
                                                   1].festival_id_to_instance[
                                                       fest.name] = fest
                            # shravana krishna chaturthi
                            if self.daily_panchaangas[
                                    d].lunar_month_sunrise.index == 5:
                                chaturthi_name = '%s%s' % (
                                    'aGgArakI~' if self.daily_panchaangas[
                                        d + 1].date.get_weekday() == 2 else '',
                                    chaturthi_name)
                                fest = FestivalInstance(
                                    name=chaturthi_name +
                                    'mahAsaGkaTahara-caturthI-vratam')
                                self.daily_panchaangas[
                                    d + 1].festival_id_to_instance[
                                        fest.name] = fest