Example #1
0
    def get_month_sunrise(self, daily_panchaanga):
        """ Assigns Lunar months to days in the period
        
    :return: 
    """
        solstice_tropical_month_span = zodiac.get_previous_solstice(
            jd=daily_panchaanga.jd_sunrise)
        solstice_lunar_month = SolsticePostDark10AdhikaAssigner._get_solstice_lunar_month(
            solstice_tropical_month_span=solstice_tropical_month_span)
        is_solstice_lunar_month_adhika = str(
            solstice_lunar_month.index).endswith(".5")
        if is_solstice_lunar_month_adhika:
            lunar_month = self._month_from_previous_jd_month(
                jd=daily_panchaanga.jd_sunrise,
                prev_jd=solstice_tropical_month_span.jd_start,
                prev_jd_month=solstice_lunar_month)
            return lunar_month
        else:
            # At this point, we're sure that there was no previous postDark10 solstice.
            # Are we in a lunar month containing solstice?
            tropical_month = zodiac.get_tropical_month(
                jd=daily_panchaanga.jd_sunrise)
            if tropical_month.index in [3, 9]:
                anga_span_finder = AngaSpanFinder.get_cached(
                    ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0,
                    anga_type=AngaType.SIDEREAL_MONTH)
                solstice_tropical_month_span = anga_span_finder.find(
                    jd1=daily_panchaanga.jd_sunrise,
                    jd2=daily_panchaanga.jd_sunrise + 32,
                    target_anga_id=daily_panchaanga.tropical_date_sunset.month
                    + 1)
                span_finder = AngaSpanFinder.get_cached(
                    anga_type=AngaType.TITHI,
                    ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
                tithi_1_jds = span_finder.get_spans_in_period(
                    jd_start=daily_panchaanga.jd_sunrise,
                    jd_end=solstice_tropical_month_span.jd_start,
                    target_anga_id=1)
                if len(tithi_1_jds) == 0:
                    solstice_lunar_month = SolsticePostDark10AdhikaAssigner._get_solstice_lunar_month(
                        solstice_tropical_month_span=
                        solstice_tropical_month_span)
                    return solstice_lunar_month

            # The default case.
            lunar_month = self._month_from_previous_jd_month(
                jd=daily_panchaanga.jd_sunrise,
                prev_jd=solstice_tropical_month_span.jd_start,
                prev_jd_month=solstice_lunar_month)
            return lunar_month
Example #2
0
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
Example #3
0
def test_get_tithis_in_period():
  span_finder = AngaSpanFinder.get_cached(anga_type=AngaType.TITHI, ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
  spans = span_finder.get_spans_in_period(jd_start=time.ist_timezone.local_time_to_julian_day(Date(year=2020, month=1, day=1)), jd_end=time.ist_timezone.local_time_to_julian_day(Date(year=2020, month=6, day=30)), target_anga_id=30)
  jds = [x.jd_start for x in spans]
  numpy.testing.assert_array_almost_equal(jds, [2458872.36655025,
                                                         2458902.0647052005,
                                                         2458931.792117506,
                                                         2458961.5055956016,
                                                         2458991.1712410315,
                                                         2459020.765607745], decimal=3)
Example #4
0
def test_get_anga_span_solar_month():
  from jyotisha.panchaanga.temporal import time
  span_finder = AngaSpanFinder.get_cached(anga_type=AngaType.SIDEREAL_MONTH, ayanaamsha_id=Ayanamsha.CHITRA_AT_180)

  numpy.testing.assert_array_almost_equal(span_finder.find(jd1=2458222.0333434483-32, jd2=2458222.0333434483 + 4, target_anga_id=12,).to_tuple(), (2458192.24785228, 2458222.6026552585), decimal=3)

  jd2 = time.ist_timezone.local_time_to_julian_day(time.Date(2020, 4, 16))
  assert span_finder.find(jd1=jd2-32, jd2=jd2, target_anga_id=1).to_tuple() == (2458953.109659805, None)

  assert span_finder.find(jd1=2458133.0189002366-32, jd2=2458133.0189002366, target_anga_id=10).to_tuple() == (2458132.8291680976, None)
Example #5
0
 def _month_from_previous_jd_month(cls, jd, prev_jd, prev_jd_month):
     span_finder = AngaSpanFinder.get_cached(
         anga_type=AngaType.TITHI,
         ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
     tithi_1_jds = span_finder.get_spans_in_period(jd_start=prev_jd,
                                                   jd_end=jd,
                                                   target_anga_id=1)
     is_prev_month_adhika = str(prev_jd_month.index).endswith(".5")
     if is_prev_month_adhika:
         lunar_month = prev_jd_month + max(0, len(tithi_1_jds) - 0.5)
     else:
         lunar_month = prev_jd_month + len(tithi_1_jds)
     return lunar_month
Example #6
0
def test_get_anga_span_tithi():
    span_finder = AngaSpanFinder.get_cached(
        anga_type=AngaType.TITHI, ayanaamsha_id=Ayanamsha.CHITRA_AT_180)

    assert span_finder.find(
        jd1=2458102.5, jd2=2458108.5,
        target_anga_id=30).to_tuple() == (2458104.6663699686,
                                          2458105.771125107)

    assert span_finder.find(
        jd1=2444959.54042, jd2=2444963.54076,
        target_anga_id=27).to_tuple() == (2444960.4924699212,
                                          2444961.599213224)
Example #7
0
def test_get_yogas_in_period():
    span_finder = AngaSpanFinder.get_cached(
        anga_type=AngaType.KARANA, ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
    spans = span_finder.get_spans_in_period(
        jd_start=time.ist_timezone.local_time_to_julian_day(
            Date(year=2020, month=1, day=1)),
        jd_end=time.ist_timezone.local_time_to_julian_day(
            Date(year=2020, month=6, day=30)),
        target_anga_id=15)
    jds = [x.jd_start for x in spans]
    numpy.testing.assert_array_almost_equal(jds, [
        2458851.146, 2458881.029, 2458910.808, 2458940.431, 2458969.882,
        2458999.185, 2459028.392
    ],
                                            decimal=3)
Example #8
0
def test_get_karanas_in_period():
    span_finder = AngaSpanFinder.get_cached(
        anga_type=AngaType.KARANA, ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0)
    spans = span_finder.get_spans_in_period(
        jd_start=time.ist_timezone.local_time_to_julian_day(
            Date(year=2020, month=1, day=1)),
        jd_end=time.ist_timezone.local_time_to_julian_day(
            Date(year=2020, month=6, day=30)),
        target_anga_id=30)
    jds = [x.jd_start for x in spans]
    numpy.testing.assert_array_almost_equal(jds, [
        2458858.845, 2458888.379, 2458917.821, 2458947.19, 2458976.52,
        2459005.852
    ],
                                            decimal=3)
Example #9
0
    def get_month_sunrise(self, daily_panchaanga):
        """ Assigns Lunar months to days in the period
        
    :return: 
    """
        next_tithi_30_span = AngaSpanFinder.get_cached(
            anga_type=AngaType.TITHI,
            ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0).get_spans_in_period(
                jd_start=daily_panchaanga.jd_sunrise,
                jd_end=daily_panchaanga.jd_sunrise + 35,
                target_anga_id=30)[0]

        tropical_solar_month_span = self._get_previous_post_dark_10_tropical_solar_month_span(
            jd=next_tithi_30_span.jd_end)
        if tropical_solar_month_span.jd_start >= daily_panchaanga.jd_sunrise:
            return tropical_solar_month_span.anga + 0.5
        else:
            return self._month_from_previous_jd_month_provisional(
                jd=daily_panchaanga.jd_sunrise,
                prev_jd=tropical_solar_month_span.jd_start,
                prev_jd_month=tropical_solar_month_span.anga + 0.5)
Example #10
0
    def compute_sun_moon_transitions(self,
                                     previous_day_panchaanga=None,
                                     force_recomputation=False):
        """

    :param previous_day_panchaanga: Panchangam for previous day, to avoid unnecessary calculations. (rise_trans calculations can be time consuming.)
    :param force_recomputation: Boolean indicating if the transitions should be recomputed. (rise_trans calculations can be time consuming.)
    :return:
    """
        if force_recomputation or self.jd_sunrise is None:
            if previous_day_panchaanga is not None and previous_day_panchaanga.jd_next_sunrise is not None:
                self.jd_sunrise = previous_day_panchaanga.jd_next_sunrise
            else:
                self.jd_sunrise = self.city.get_rising_time(
                    julian_day_start=self.julian_day_start, body=Graha.SUN)
        if force_recomputation or self.jd_sunset is None:
            self.jd_sunset = self.city.get_setting_time(
                julian_day_start=self.jd_sunrise, body=Graha.SUN)
        if force_recomputation or self.jd_previous_sunset is None:
            if previous_day_panchaanga is not None and previous_day_panchaanga.jd_sunset is not None:
                self.jd_previous_sunset = previous_day_panchaanga.jd_sunset
            else:
                self.jd_previous_sunset = self.city.get_setting_time(
                    julian_day_start=self.jd_sunrise - 1, body=Graha.SUN)
        if force_recomputation or self.jd_next_sunrise is None:
            self.jd_next_sunrise = self.city.get_rising_time(
                julian_day_start=self.jd_sunset, body=Graha.SUN)
        if self.jd_sunset == 0.0:
            logging.error('No sunset was computed!')
            raise (ValueError(
                'No sunset was computed. Perhaps the co-ordinates are beyond the polar circle (most likely a LAT-LONG swap! Please check your inputs.'
            ))

        if force_recomputation or self.jd_moonrise is None:
            self.jd_moonrise = self.city.get_rising_time(
                julian_day_start=self.jd_sunrise, body=Graha.MOON)
        if force_recomputation or self.jd_moonset is None:
            self.jd_moonset = self.city.get_setting_time(
                julian_day_start=self.jd_sunrise, body=Graha.MOON)

        if force_recomputation or self.sunrise_day_angas is None:
            self.sunrise_day_angas = DayAngas()
            # Deliberately passing ASHVINI_STARTING_0 below since it is cheapest. Tithi is independent of ayanAmsha.
            self.sunrise_day_angas.tithis_with_ends = AngaSpanFinder.get_cached(
                ayanaamsha_id=Ayanamsha.ASHVINI_STARTING_0,
                anga_type=zodiac.AngaType.TITHI).get_all_angas_in_period(
                    jd1=self.jd_sunrise, jd2=self.jd_next_sunrise)
            self.sunrise_day_angas.tithi_at_sunrise = self.sunrise_day_angas.tithis_with_ends[
                0].anga

            self.sunrise_day_angas.nakshatras_with_ends = AngaSpanFinder.get_cached(
                ayanaamsha_id=self.computation_system.ayanaamsha_id,
                anga_type=zodiac.AngaType.NAKSHATRA).get_all_angas_in_period(
                    jd1=self.jd_sunrise, jd2=self.jd_next_sunrise)
            self.sunrise_day_angas.nakshatra_at_sunrise = self.sunrise_day_angas.nakshatras_with_ends[
                0].anga

            self.sunrise_day_angas.yogas_with_ends = AngaSpanFinder.get_cached(
                ayanaamsha_id=self.computation_system.ayanaamsha_id,
                anga_type=zodiac.AngaType.YOGA).get_all_angas_in_period(
                    jd1=self.jd_sunrise, jd2=self.jd_next_sunrise)
            self.sunrise_day_angas.yoga_at_sunrise = self.sunrise_day_angas.yogas_with_ends[
                0].anga

            self.sunrise_day_angas.karanas_with_ends = AngaSpanFinder.get_cached(
                ayanaamsha_id=self.computation_system.ayanaamsha_id,
                anga_type=zodiac.AngaType.KARANA).get_all_angas_in_period(
                    jd1=self.jd_sunrise, jd2=self.jd_next_sunrise)

            self.sunrise_day_angas.raashis_with_ends = AngaSpanFinder.get_cached(
                ayanaamsha_id=self.computation_system.ayanaamsha_id,
                anga_type=zodiac.AngaType.RASHI).get_all_angas_in_period(
                    jd1=self.jd_sunrise, jd2=self.jd_next_sunrise)
            self.sunrise_day_angas.solar_nakshatras_with_ends = AngaSpanFinder.get_cached(
                ayanaamsha_id=self.computation_system.ayanaamsha_id,
                anga_type=zodiac.AngaType.SOLAR_NAKSH).get_all_angas_in_period(
                    jd1=self.jd_sunrise, jd2=self.jd_next_sunrise)
Example #11
0
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