def yoga(jd, place):
    """Yoga at given jd and place.
     1 = Vishkambha, 2 = Priti, ..., 27 = Vaidhrti
  """
    swe.set_sid_mode(swe.SIDM_LAHIRI)
    # 1. Find time of sunrise
    lat, lon, tz = place
    rise = sunrise(jd, place)[0] - tz / 24.  # Sunrise at UT 00:00

    # 2. Find the Nirayana longitudes and add them
    lunar_long = (lunar_longitude(rise) - swe.get_ayanamsa_ut(rise)) % 360
    solar_long = (solar_longitude(rise) - swe.get_ayanamsa_ut(rise)) % 360
    total = (lunar_long + solar_long) % 360
    # There are 27 Yogas spanning 360 degrees
    yog = ceil(total * 27 / 360)

    # 3. Find how many longitudes is there left to be swept
    degrees_left = yog * (360 / 27) - total

    # 3. Compute longitudinal sums at intervals of 0.25 days from sunrise
    offsets = [0.25, 0.5, 0.75, 1.0]
    lunar_long_diff = [
        (lunar_longitude(rise + t) - lunar_longitude(rise)) % 360
        for t in offsets
    ]
    solar_long_diff = [
        (solar_longitude(rise + t) - solar_longitude(rise)) % 360
        for t in offsets
    ]
    total_motion = [
        moon + sun for (moon, sun) in zip(lunar_long_diff, solar_long_diff)
    ]

    # 4. Find end time by 4-point inverse Lagrange interpolation
    y = total_motion
    x = offsets
    # compute fraction of day (after sunrise) needed to traverse 'degrees_left'
    approx_end = inverse_lagrange(x, y, degrees_left)
    ends = (rise + approx_end - jd) * 24 + tz
    answer = [int(yog), to_dms(ends)]

    # 5. Check for skipped yoga
    lunar_long_tmrw = (lunar_longitude(rise + 1) -
                       swe.get_ayanamsa_ut(rise + 1)) % 360
    solar_long_tmrw = (solar_longitude(rise + 1) -
                       swe.get_ayanamsa_ut(rise + 1)) % 360
    total_tmrw = (lunar_long_tmrw + solar_long_tmrw) % 360
    tomorrow = ceil(total_tmrw * 27 / 360)
    isSkipped = (tomorrow - yog) % 27 > 1
    if isSkipped:
        # interpolate again with same (x,y)
        leap_yog = yog + 1
        degrees_left = leap_yog * (360 / 27) - total
        approx_end = inverse_lagrange(x, y, degrees_left)
        ends = (rise + approx_end - jd) * 24 + tz
        answer += [int(leap_yog), to_dms(ends)]

    return answer
Example #2
0
def yoga(jd, place):
  """Yoga at given jd and place.
     1 = Vishkambha, 2 = Priti, ..., 27 = Vaidhrti
  """
  swe.set_sid_mode(swe.SIDM_LAHIRI)
  # 1. Find time of sunrise
  lat, lon, tz = place
  rise = sunrise(jd, place)[0] - tz / 24.  # Sunrise at UT 00:00

  # 2. Find the Nirayana longitudes and add them
  lunar_long = (lunar_longitude(rise) - swe.get_ayanamsa_ut(rise)) % 360
  solar_long = (solar_longitude(rise) - swe.get_ayanamsa_ut(rise)) % 360
  total = (lunar_long + solar_long) % 360
  # There are 27 Yogas spanning 360 degrees
  yog = ceil(total * 27 / 360)

  # 3. Find how many longitudes is there left to be swept
  degrees_left = yog * (360 / 27) - total

  # 3. Compute longitudinal sums at intervals of 0.25 days from sunrise
  offsets = [0.25, 0.5, 0.75, 1.0]
  lunar_long_diff = [ (lunar_longitude(rise + t) - lunar_longitude(rise)) % 360 for t in offsets ]
  solar_long_diff = [ (solar_longitude(rise + t) - solar_longitude(rise)) % 360 for t in offsets ]
  total_motion = [ moon + sun for (moon, sun) in zip(lunar_long_diff, solar_long_diff) ]

  # 4. Find end time by 4-point inverse Lagrange interpolation
  y = total_motion
  x = offsets
  # compute fraction of day (after sunrise) needed to traverse 'degrees_left'
  approx_end = inverse_lagrange(x, y, degrees_left)
  ends = (rise + approx_end - jd) * 24 + tz
  answer = [int(yog), to_dms(ends)]

  # 5. Check for skipped yoga
  lunar_long_tmrw = (lunar_longitude(rise + 1) - swe.get_ayanamsa_ut(rise + 1)) % 360
  solar_long_tmrw = (solar_longitude(rise + 1) - swe.get_ayanamsa_ut(rise + 1)) % 360
  total_tmrw = (lunar_long_tmrw + solar_long_tmrw) % 360
  tomorrow = ceil(total_tmrw * 27 / 360)
  isSkipped = (tomorrow - yog) % 27 > 1
  if isSkipped:
    # interpolate again with same (x,y)
    leap_yog = yog + 1
    degrees_left = leap_yog * (360 / 27) - total
    approx_end = inverse_lagrange(x, y, degrees_left)
    ends = (rise + approx_end - jd) * 24 + tz
    answer += [int(leap_yog), to_dms(ends)]

  return answer
def raasi(jd):
    """Zodiac of given jd. 1 = Mesha, ... 12 = Meena"""
    swe.set_sid_mode(swe.SIDM_LAHIRI)
    s = solar_longitude(jd)
    solar_nirayana = (solar_longitude(jd) - swe.get_ayanamsa_ut(jd)) % 360
    # 12 rasis occupy 360 degrees, so each one is 30 degrees
    return ceil(solar_nirayana / 30.)
def nakshatra(jd, place):
    """Current nakshatra as of julian day (jd)
     1 = Asvini, 2 = Bharani, ..., 27 = Revati
  """
    swe.set_sid_mode(swe.SIDM_LAHIRI)
    # 1. Find time of sunrise
    lat, lon, tz = place
    rise = sunrise(jd, place)[0] - tz / 24.  # Sunrise at UT 00:00

    # Swiss Ephemeris always gives Sayana. So subtract ayanamsa to get Nirayana
    offsets = [0.0, 0.25, 0.5, 0.75, 1.0]
    longitudes = [(lunar_longitude(rise + t) - swe.get_ayanamsa_ut(rise)) % 360
                  for t in offsets]

    # 2. Today's nakshatra is when offset = 0
    # There are 27 Nakshatras spanning 360 degrees
    nak = ceil(longitudes[0] * 27 / 360)

    # 3. Find end time by 5-point inverse Lagrange interpolation
    y = unwrap_angles(longitudes)
    x = offsets
    approx_end = inverse_lagrange(x, y, nak * 360 / 27)
    ends = (rise - jd + approx_end) * 24 + tz
    answer = [int(nak), to_dms(ends)]

    # 4. Check for skipped nakshatra
    nak_tmrw = ceil(longitudes[-1] * 27 / 360)
    isSkipped = (nak_tmrw - nak) % 27 > 1
    if isSkipped:
        leap_nak = nak + 1
        approx_end = inverse_lagrange(offsets, longitudes, leap_nak * 360 / 27)
        ends = (rise - jd + approx_end) * 24 + tz
        answer += [int(leap_nak), to_dms(ends)]

    return answer
Example #5
0
def raasi(jd):
  """Zodiac of given jd. 1 = Mesha, ... 12 = Meena"""
  swe.set_sid_mode(swe.SIDM_LAHIRI)
  s = solar_longitude(jd)
  solar_nirayana = (solar_longitude(jd) - swe.get_ayanamsa_ut(jd)) % 360
  # 12 rasis occupy 360 degrees, so each one is 30 degrees
  return ceil(solar_nirayana / 30.)
Example #6
0
def nakshatra(jd, place):
  """Current nakshatra as of julian day (jd)
     1 = Asvini, 2 = Bharani, ..., 27 = Revati
  """
  swe.set_sid_mode(swe.SIDM_LAHIRI)
  # 1. Find time of sunrise
  lat, lon, tz = place
  rise = sunrise(jd, place)[0] - tz / 24.  # Sunrise at UT 00:00
   
  # Swiss Ephemeris always gives Sayana. So subtract ayanamsa to get Nirayana
  offsets = [0.0, 0.25, 0.5, 0.75, 1.0]
  longitudes = [ (lunar_longitude(rise + t) - swe.get_ayanamsa_ut(rise)) % 360 for t in offsets]

  # 2. Today's nakshatra is when offset = 0
  # There are 27 Nakshatras spanning 360 degrees
  nak = ceil(longitudes[0] * 27 / 360)
  
  # 3. Find end time by 5-point inverse Lagrange interpolation
  y = unwrap_angles(longitudes)
  x = offsets
  approx_end = inverse_lagrange(x, y, nak * 360 / 27)
  ends = (rise - jd + approx_end) * 24 + tz
  answer = [int(nak), to_dms(ends)]

  # 4. Check for skipped nakshatra
  nak_tmrw = ceil(longitudes[-1] * 27 / 360)
  isSkipped = (nak_tmrw - nak) % 27 > 1
  if isSkipped:
    leap_nak = nak + 1
    approx_end = inverse_lagrange(offsets, longitudes, leap_nak * 360 / 27)
    ends = (rise - jd + approx_end) * 24 + tz
    answer += [int(leap_nak), to_dms(ends)]

  return answer
Example #7
0
    def get_lagna_float(self, jd, offset=0, debug=False):
        """Returns the angam

          Args:
            :param jd: The Julian Day at which the lagnam is to be computed
            :param offset: Used by internal functions for bracketing
            :param debug

          Returns:
            float lagna
        """
        swe.set_sid_mode(self.ayanamsha_id)
        lcalc = swe.houses_ex(
            jd, self.city.latitude,
            self.city.longitude)[1][0] - swe.get_ayanamsa_ut(jd)
        lcalc = lcalc % 360

        if offset == 0:
            return lcalc / 30

        else:
            if debug:
                logging.debug(debug)
                logging.debug(('offset:', offset))
                logging.debug(('lcalc/30', lcalc / 30))
                logging.debug(('lcalc/30 + offset = ', lcalc / 30 + offset))

            # The max expected value is somewhere between 2 and -2, with bracketing

            if (lcalc / 30 + offset) >= 3:
                return (lcalc / 30) + offset - 12
            elif (lcalc / 30 + offset) <= -3:
                return (lcalc / 30)
            else:
                return (lcalc / 30) + offset
Example #8
0
def elapsed_year(jd):
  swe.set_sid_mode(swe.SIDM_LAHIRI)
  ahar = ahargana(jd)
  mean_sidereal_year = 365.25636
  solar_long = (solar_longitude(jd) - swe.get_ayanamsa_ut(jd)) % 360
  kali = round(ahar / mean_sidereal_year -  solar_long / 360)
  saka = kali - 3179
  vikrama = saka + 135
  return kali, saka
Example #9
0
 def get_offset(self, jd):
     if self.ayanaamsha_id == Ayanamsha.VERNAL_EQUINOX_AT_0:
         return 0
     elif self.ayanaamsha_id == Ayanamsha.CHITRA_AT_180:
         # TODO: The below fails due to https://github.com/astrorigin/pyswisseph/issues/35
         from jyotisha.panchaanga.temporal import body
         return body.get_star_longitude(star="Spica", jd=jd) - 180
     elif self.ayanaamsha_id == Ayanamsha.ASHVINI_STARTING_0:
         return 0
     elif self.ayanaamsha_id == Ayanamsha.RASHTRIYA_PANCHANGA_NAKSHATRA_TRACKING:
         swe.set_sid_mode(swe.SIDM_LAHIRI)
         return swe.get_ayanamsa_ut(jd)
     raise Exception("Bad ayanamsha_id")
Example #10
0
def get_lagna_float(jd, lat, lon, offset=0, ayanamsha_id=swe.SIDM_LAHIRI, debug=False):
  """Returns the angam

    Args:
      :param jd: The Julian Day at which the lagnam is to be computed
      :param lat: Latitude of the place where the lagnam is to be computed
      :param lon: Longitude of the place where the lagnam is to be computed
      :param offset: Used by internal functions for bracketing
      :param ayanamsha_id
      :param debug

    Returns:
      float lagna

    Examples:
      >>> get_lagna_float(2444961.7125,13.08784, 80.27847)
      10.353595502472984
  """
  swe.set_sid_mode(ayanamsha_id)
  lcalc = swe.houses_ex(jd, lat, lon)[1][0] - swe.get_ayanamsa_ut(jd)
  lcalc = lcalc % 360

  if offset == 0:
    return lcalc / 30

  else:
    if (debug):
      print('offset:', offset)
      print('lcalc/30', lcalc / 30)
      print('lcalc/30 + offset = ', lcalc / 30 + offset)

    # The max expected value is somewhere between 2 and -2, with bracketing

    if (lcalc / 30 + offset) >= 3:
      return (lcalc / 30) + offset - 12
    elif (lcalc / 30 + offset) <= -3:
      return (lcalc / 30)
    else:
      return (lcalc / 30) + offset
Example #11
0
def compute_lagna_float(jd, lat=13.08784, lon=80.27847, offset=0, debug=False):
    swe.set_sid_mode(swe.SIDM_LAHIRI)  # Force Lahiri Ayanamsha
    lcalc = swe.houses_ex(jd, lat, lon)[1][0] - swe.get_ayanamsa_ut(jd)
    lcalc = lcalc % 360

    if offset == 0:
        return lcalc / 30

    else:
        if (debug):
            print('offset:', offset)
            print('lcalc/30', lcalc / 30)
            print('lcalc/30 + offset = ', lcalc / 30 + offset)

        # The max expected value is somewhere between 2 and -2, with bracketing

        if (lcalc / 30 + offset) >= 3:
            return (lcalc / 30) + offset - 12
        elif (lcalc / 30 + offset) <= -3:
            return (lcalc / 30)
        else:
            return (lcalc / 30) + offset
Example #12
0
    def GetAyanamsa(self, Bday_accurate):

        ayan = swe.get_ayanamsa_ut(self.Bday_accurate[1])

        print("Ayanamsa = ", self.prnt(self.decdeg2dms(ayan)))
Example #13
0
def html_data(chart):
    """Return a html string for output of chart data.

    :type chart: Chart
    """

    # ### chart data ###
    # name
    fmt = unicode(tr('<b>%(name)s:</b> %(val)s<br/>'))
    try:
        txt = fmt % {
            'name': tr('Name'),
            'val': chart._name}
    except UnicodeDecodeError:
        txt += fmt % {
            'name': tr('Name'),
            'val': chart._name.decode(_encoding)}
    # date
    fmt = unicode(tr('<b>%(date)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'date': tr('Date'),
        'val': chart._datetime.date().isoformat()}
    # time
    fmt = unicode(tr('<b>%(time)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'time': tr('Time'),
        'val': chart._datetime.time().isoformat()}
    # calendar
    fmt = unicode(tr('<b>%(calendar)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'calendar': tr('Calendar'),
        'val': chart._calendar.capitalize()}
    # location
    fmt = unicode(tr('<b>%(location)s:</b> %(val)s<br/>'))
    try:
        txt += fmt % {
            'location': tr('Location'),
            'val': chart._location}
    except UnicodeDecodeError:
        txt += fmt % {
            'location': tr('Location'),
            'val': chart._location.decode(_encoding)}
    # latitude
    fmt = unicode(tr('<b>%(latitude)s:</b> %(dg).2d%(deg)s %(dr)s %(mn).2d%(min)s %(sc).2d%(sec)s<br/>',
        'Geo latitude display'))
    txt += fmt % {
        'latitude': tr('Latitude'),
        'dg': chart._latitude.degrees,
        'deg': tr('\xb0', 'Degrees'),
        'dr': chart._latitude.direction,
        'mn': chart._latitude.minutes,
        'min': tr("'", 'Minutes'),
        'sc': chart._latitude.seconds,
        'sec': tr('"', 'Seconds')}
    # longitude
    fmt = unicode(tr('<b>%(longitude)s:</b> %(dg).3d%(deg)s %(dr)s %(mn).2d%(min)s %(sc).2d%(sec)s<br/>',
        'Geo longitude display'))
    txt += fmt % {
        'longitude': tr('Longitude'),
        'dg': chart._longitude.degrees,
        'deg': tr('\xb0', 'Degrees'),
        'dr': chart._longitude.direction,
        'mn': chart._longitude.minutes,
        'min': tr("'", 'Minutes'),
        'sc': chart._longitude.seconds,
        'sec': tr('"', 'Seconds')}
    # altitude
    fmt = unicode(tr('<b>%(altitude)s:</b> %(val)s m.<br/>'))
    txt += fmt % {
        'altitude': tr('Altitude'),
        'val': str(chart._altitude)}
    # country
    fmt = unicode(tr('<b>%(country)s:</b> %(val)s<br/>'))
    try:
        txt += fmt % {
            'country': tr('Country'),
            'val': chart._country}
    except UnicodeDecodeError:
        txt += fmt % {
            'country': tr('Country'),
            'val': chart._country.decode(_encoding)}
    # zoneinfo
    zoneinfo = chart._zoneinfo if chart._zoneinfo not in (None, '') else tr('-', 'No zoneinfo')
    fmt = unicode(tr('<b>%(zoneinfo)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'zoneinfo': tr('Zoneinfo'),
        'val': zoneinfo}
    # timezone
    timezone = chart._timezone if chart._timezone != None else tr('-', 'No timezone')
    fmt = unicode(tr('<b>%(timezone)s:</b> %(tzname)s<br/>'))
    txt += fmt % {
        'timezone': tr('Timezone'),
        'tzname': str(timezone)
        }
    # utcoffset
    utcoffset = chart.utcoffset if chart.utcoffset != None else tr('?', 'No utcoffset')
    dst = tr('yes', 'dst') if chart.dst == True else tr('no', 'dst')
    fmt = unicode(tr('<b>%(utcoffset)s:</b> %(offset)s  <b>%(dst)s:</b> %(bool)s<br/>'))
    txt += fmt % {
        'utcoffset': tr('Utc offset'),
        'offset': utcoffset,
        'dst': tr('Dst'),
        'bool': dst}
    # comment
    if chart._comment != '':
        if cfg.use_docutils:
            cmt = publish_parts(chart._comment, writer_name='html')['html_body']
        else:
            cmt = chart._comment
    else:
        cmt = unicode(tr('-', 'No comment'))
    fmt = unicode(tr('<b>%(comment)s:</b> %(cmt)s<br/>'))
    try:
        txt += fmt % {
            'comment': tr('Comment'),
            'cmt': cmt}
    except UnicodeDecodeError:
        txt += fmt % {
            'comment': tr('Comment'),
            'cmt': cmt.decode(_encoding)}
    # keywords
    fmt = unicode(tr('<b>%(keywords)s:</b>'))
    txt += fmt % {
        'keywords': tr('Keywords')}
    if len(chart._keywords) == 0:
        txt += tr(' -', 'No keywords')
    else:
        kw = list()
        fmt = unicode(tr(' %(key)s:%(word)s'))
        for k, v in chart._keywords.items():
            try:
                kw.append(fmt % {
                    'key': k,
                    'word': v})
            except UnicodeDecodeError:
                kw.append(fmt % {
                    'key': k.decode(_encoding),
                    'word': v.decode(_encoding)})
        txt += unicode(tr('; ', 'Keywords delimiter')).join(kw)

    # ### more data ###
    txt += '<hr/>'
    # ephemeris type
    fmt = unicode(tr('%(ephem)s %(info)s<br/>'))
    if chart.filter._ephe_type == 'swiss':
        txt += fmt % {
            'ephem': tr('Swiss Ephemeris'),
            'info': swe.version}
    elif chart.filter._ephe_type == 'jpl':
        txt += fmt % {
            'ephem': tr('Jet Propulsion Lab.'),
            'info': chart.filter._ephe_path}
    else:
        txt += unicode(tr('%(moshier)s<br/>')) % {
            'moshier': tr('Moshier Ephemeris')}
    # zodiac type
    if chart.filter._sid_mode == -1: ## tropical
        txt += unicode(tr('%(tropical)s, ')) % {
            'tropical': tr('Tropical')}
    elif chart.filter._sid_mode < 255: ## ayanamsa
        txt += unicode(tr('%(ayanamsaname)s (%(ayanamsaut)s), ')) % {
            'ayanamsaname': swe.get_ayanamsa_name(chart.filter._sid_mode),
            'ayanamsaut': swe.get_ayanamsa_ut(chart.julday)}
    elif chart.filter._sid_mode == 255: ## user-defined ayanamsa
        txt += unicode(tr('%(ayan)s (%(ayant0)s, %(t0)s), ')) % {
            'ayan': tr('Ayanamsa'),
            'ayant0': chart.filter._sid_ayan_t0,
            't0': chart.filter._sid_t0}
    else:
        raise ValueError('Invalid sid mode %s.' % chart.filter._sid_mode)
    # xcentric
    fmt = unicode(tr('%(situation)s<br/>', 'geo,topo,helio,bary'))
    if chart.filter._xcentric == 'geo':
        txt += fmt % {'situation': tr('Geocentric')}
    elif chart.filter._xcentric == 'topo':
        txt += fmt % {'situation': tr('Topocentric')}
    elif chart.filter._xcentric == 'helio':
        txt += fmt % {'situation': tr('Heliocentric')}
    elif chart.filter._xcentric == 'bary':
        txt += fmt % {'situation': tr('Barycentric')}
    else:
        raise ValueError('Invalid xcentric %s.' % chart.filter._xcentric)
    # julian day
    txt += unicode(tr('%(julday)s: %(jd)s<br/>')) % {
        'julday': tr('Julian day'),
        'jd': chart.julday}
    # local mean time
    try:
        lmtime = chart.local_mean_datetime
        y, mth, d, h, m, s = lmtime.timetuple()[:6]
        fmt = unicode(tr('%(local_mean_time)s: %(year).4d-%(month).2d-%(day).2d %(hour).2d:%(minute).2d:%(second).2d<br/>'))
        txt += fmt % {
            'local_mean_time': tr('Local mean time'),
            'year': y,
            'month': mth,
            'day': d,
            'hour': h,
            'minute': m,
            'second': s
            }
    except ValueError: ## no timezone set
        pass
    # local sidereal time
    try:
        lsidt = chart.local_sidtime
        h, mn, sc = lsidt.hour, lsidt.minute, lsidt.second
        fmt = unicode(tr('%(sidtime)s: %(h).2d:%(mn).2d:%(sc).2d<br/>'))
        txt += fmt % {
            'sidtime': tr('Sidereal time'),
            'h': h,
            'mn': mn,
            'sc': sc}
    except ValueError: ## no timezone set
        pass
    # obliquity
    dg, sn, mn, sc = swe._degsplit(chart.ecl_nut[0])
    fmt = unicode(tr('%(obliquity)s: %(dg).2d%(deg)s %(mn).2d%(min)s %(sc).2d%(sec)s<br/>'))
    txt += fmt % {
        'obliquity': tr('Obliquity'),
        'dg': dg,
        'deg': tr('\xb0', 'Degrees'),
        'mn': mn,
        'min': tr("'", 'Minutes'),
        'sc': sc,
        'sec': tr('"', 'Seconds')}
    # nutation
    nutlon = swe.split_deg(chart.ecl_nut[2], 0)
    nutobl = swe.split_deg(chart.ecl_nut[3], 0)
    fmt = unicode(tr('%(nutation)s (%(longitude)s): %(nutlonsn)s%(nutlondg)d%(deg)s %(nutlonmn)d%(min)s %(nutlonsc)d%(sec)s<br/>%(nutation)s (%(obliquity)s): %(nutoblsn)s%(nutobldg)d%(deg)s %(nutoblmn)d%(min)s %(nutoblsc)d%(sec)s<br/>'))
    txt += fmt % {
        'nutation': tr('Nutation'),
        'longitude': tr('lon.'),
        'nutlonsn': '+' if nutlon[4] > 0 else '-',
        'nutlondg': nutlon[0],
        'nutlonmn': nutlon[1],
        'nutlonsc': nutlon[2],
        'obliquity': tr('obl.'),
        'nutoblsn': '+' if nutobl[4] > 0 else '-',
        'nutobldg': nutobl[0],
        'nutoblmn': nutobl[1],
        'nutoblsc': nutobl[2],
        'deg': tr('\xb0', 'Degrees'),
        'min': tr("'", 'Minutes'),
        'sec': tr('"', 'Seconds')
        }
    # delta T
    fmt = unicode(tr('%(deltat)s: %(val)s<hr/>'))
    txt += fmt % {
        'deltat': tr('Delta T'),
        'val': swe.deltat(chart.julday)*86400} ## ?

    return txt
Example #14
0
def disabled_test_swe_ayanaamsha_api():
  import swisseph as swe
  swe.set_sid_mode(swe.SIDM_LAHIRI)
  # city = City.from_address_and_timezone('Cupertino, CA', "America/Los_Angeles")
  # jd = city.local_time_to_julian_day(year=2018, month=11, day=11, hours=6, minutes=0, seconds=0)
  assert swe.get_ayanamsa_ut(2458434.083333251) == 24.120535828308334
Example #15
0
def html_data(chart):
    """Return a html string for output of chart data.

    :type chart: Chart
    """

    # ### chart data ###
    # name
    fmt = unicode(tr('<b>%(name)s:</b> %(val)s<br/>'))
    try:
        txt = fmt % {'name': tr('Name'), 'val': chart._name}
    except UnicodeDecodeError:
        txt += fmt % {'name': tr('Name'), 'val': chart._name.decode(_encoding)}
    # date
    fmt = unicode(tr('<b>%(date)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'date': tr('Date'),
        'val': chart._datetime.date().isoformat()
    }
    # time
    fmt = unicode(tr('<b>%(time)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'time': tr('Time'),
        'val': chart._datetime.time().isoformat()
    }
    # calendar
    fmt = unicode(tr('<b>%(calendar)s:</b> %(val)s<br/>'))
    txt += fmt % {
        'calendar': tr('Calendar'),
        'val': chart._calendar.capitalize()
    }
    # location
    fmt = unicode(tr('<b>%(location)s:</b> %(val)s<br/>'))
    try:
        txt += fmt % {'location': tr('Location'), 'val': chart._location}
    except UnicodeDecodeError:
        txt += fmt % {
            'location': tr('Location'),
            'val': chart._location.decode(_encoding)
        }
    # latitude
    fmt = unicode(
        tr(
            '<b>%(latitude)s:</b> %(dg).2d%(deg)s %(dr)s %(mn).2d%(min)s %(sc).2d%(sec)s<br/>',
            'Geo latitude display'))
    txt += fmt % {
        'latitude': tr('Latitude'),
        'dg': chart._latitude.degrees,
        'deg': tr('\xb0', 'Degrees'),
        'dr': chart._latitude.direction,
        'mn': chart._latitude.minutes,
        'min': tr("'", 'Minutes'),
        'sc': chart._latitude.seconds,
        'sec': tr('"', 'Seconds')
    }
    # longitude
    fmt = unicode(
        tr(
            '<b>%(longitude)s:</b> %(dg).3d%(deg)s %(dr)s %(mn).2d%(min)s %(sc).2d%(sec)s<br/>',
            'Geo longitude display'))
    txt += fmt % {
        'longitude': tr('Longitude'),
        'dg': chart._longitude.degrees,
        'deg': tr('\xb0', 'Degrees'),
        'dr': chart._longitude.direction,
        'mn': chart._longitude.minutes,
        'min': tr("'", 'Minutes'),
        'sc': chart._longitude.seconds,
        'sec': tr('"', 'Seconds')
    }
    # altitude
    fmt = unicode(tr('<b>%(altitude)s:</b> %(val)s m.<br/>'))
    txt += fmt % {'altitude': tr('Altitude'), 'val': str(chart._altitude)}
    # country
    fmt = unicode(tr('<b>%(country)s:</b> %(val)s<br/>'))
    try:
        txt += fmt % {'country': tr('Country'), 'val': chart._country}
    except UnicodeDecodeError:
        txt += fmt % {
            'country': tr('Country'),
            'val': chart._country.decode(_encoding)
        }
    # zoneinfo
    zoneinfo = chart._zoneinfo if chart._zoneinfo not in (None, '') else tr(
        '-', 'No zoneinfo')
    fmt = unicode(tr('<b>%(zoneinfo)s:</b> %(val)s<br/>'))
    txt += fmt % {'zoneinfo': tr('Zoneinfo'), 'val': zoneinfo}
    # timezone
    timezone = chart._timezone if chart._timezone != None else tr(
        '-', 'No timezone')
    fmt = unicode(tr('<b>%(timezone)s:</b> %(tzname)s<br/>'))
    txt += fmt % {'timezone': tr('Timezone'), 'tzname': str(timezone)}
    # utcoffset
    utcoffset = chart.utcoffset if chart.utcoffset != None else tr(
        '?', 'No utcoffset')
    dst = tr('yes', 'dst') if chart.dst == True else tr('no', 'dst')
    fmt = unicode(
        tr('<b>%(utcoffset)s:</b> %(offset)s  <b>%(dst)s:</b> %(bool)s<br/>'))
    txt += fmt % {
        'utcoffset': tr('Utc offset'),
        'offset': utcoffset,
        'dst': tr('Dst'),
        'bool': dst
    }
    # comment
    if chart._comment != '':
        if cfg.use_docutils:
            cmt = publish_parts(chart._comment,
                                writer_name='html')['html_body']
        else:
            cmt = chart._comment
    else:
        cmt = unicode(tr('-', 'No comment'))
    fmt = unicode(tr('<b>%(comment)s:</b> %(cmt)s<br/>'))
    try:
        txt += fmt % {'comment': tr('Comment'), 'cmt': cmt}
    except UnicodeDecodeError:
        txt += fmt % {'comment': tr('Comment'), 'cmt': cmt.decode(_encoding)}
    # keywords
    fmt = unicode(tr('<b>%(keywords)s:</b>'))
    txt += fmt % {'keywords': tr('Keywords')}
    if len(chart._keywords) == 0:
        txt += tr(' -', 'No keywords')
    else:
        kw = list()
        fmt = unicode(tr(' %(key)s:%(word)s'))
        for k, v in chart._keywords.items():
            try:
                kw.append(fmt % {'key': k, 'word': v})
            except UnicodeDecodeError:
                kw.append(fmt % {
                    'key': k.decode(_encoding),
                    'word': v.decode(_encoding)
                })
        txt += unicode(tr('; ', 'Keywords delimiter')).join(kw)

    # ### more data ###
    txt += '<hr/>'
    # ephemeris type
    fmt = unicode(tr('%(ephem)s %(info)s<br/>'))
    if chart.filter._ephe_type == 'swiss':
        txt += fmt % {'ephem': tr('Swiss Ephemeris'), 'info': swe.version}
    elif chart.filter._ephe_type == 'jpl':
        txt += fmt % {
            'ephem': tr('Jet Propulsion Lab.'),
            'info': chart.filter._ephe_path
        }
    else:
        txt += unicode(tr('%(moshier)s<br/>')) % {
            'moshier': tr('Moshier Ephemeris')
        }
    # zodiac type
    if chart.filter._sid_mode == -1:  ## tropical
        txt += unicode(tr('%(tropical)s, ')) % {'tropical': tr('Tropical')}
    elif chart.filter._sid_mode < 255:  ## ayanamsa
        txt += unicode(tr('%(ayanamsaname)s (%(ayanamsaut)s), ')) % {
            'ayanamsaname': swe.get_ayanamsa_name(chart.filter._sid_mode),
            'ayanamsaut': swe.get_ayanamsa_ut(chart.julday)
        }
    elif chart.filter._sid_mode == 255:  ## user-defined ayanamsa
        txt += unicode(tr('%(ayan)s (%(ayant0)s, %(t0)s), ')) % {
            'ayan': tr('Ayanamsa'),
            'ayant0': chart.filter._sid_ayan_t0,
            't0': chart.filter._sid_t0
        }
    else:
        raise ValueError('Invalid sid mode %s.' % chart.filter._sid_mode)
    # xcentric
    fmt = unicode(tr('%(situation)s<br/>', 'geo,topo,helio,bary'))
    if chart.filter._xcentric == 'geo':
        txt += fmt % {'situation': tr('Geocentric')}
    elif chart.filter._xcentric == 'topo':
        txt += fmt % {'situation': tr('Topocentric')}
    elif chart.filter._xcentric == 'helio':
        txt += fmt % {'situation': tr('Heliocentric')}
    elif chart.filter._xcentric == 'bary':
        txt += fmt % {'situation': tr('Barycentric')}
    else:
        raise ValueError('Invalid xcentric %s.' % chart.filter._xcentric)
    # julian day
    txt += unicode(tr('%(julday)s: %(jd)s<br/>')) % {
        'julday': tr('Julian day'),
        'jd': chart.julday
    }
    # local mean time
    try:
        lmtime = chart.local_mean_datetime
        y, mth, d, h, m, s = lmtime.timetuple()[:6]
        fmt = unicode(
            tr('%(local_mean_time)s: %(year).4d-%(month).2d-%(day).2d %(hour).2d:%(minute).2d:%(second).2d<br/>'
               ))
        txt += fmt % {
            'local_mean_time': tr('Local mean time'),
            'year': y,
            'month': mth,
            'day': d,
            'hour': h,
            'minute': m,
            'second': s
        }
    except ValueError:  ## no timezone set
        pass
    # local sidereal time
    try:
        lsidt = chart.local_sidtime
        h, mn, sc = lsidt.hour, lsidt.minute, lsidt.second
        fmt = unicode(tr('%(sidtime)s: %(h).2d:%(mn).2d:%(sc).2d<br/>'))
        txt += fmt % {
            'sidtime': tr('Sidereal time'),
            'h': h,
            'mn': mn,
            'sc': sc
        }
    except ValueError:  ## no timezone set
        pass
    # obliquity
    dg, sn, mn, sc = swe._degsplit(chart.ecl_nut[0])
    fmt = unicode(
        tr('%(obliquity)s: %(dg).2d%(deg)s %(mn).2d%(min)s %(sc).2d%(sec)s<br/>'
           ))
    txt += fmt % {
        'obliquity': tr('Obliquity'),
        'dg': dg,
        'deg': tr('\xb0', 'Degrees'),
        'mn': mn,
        'min': tr("'", 'Minutes'),
        'sc': sc,
        'sec': tr('"', 'Seconds')
    }
    # nutation
    nutlon = swe.split_deg(chart.ecl_nut[2], 0)
    nutobl = swe.split_deg(chart.ecl_nut[3], 0)
    fmt = unicode(
        tr('%(nutation)s (%(longitude)s): %(nutlonsn)s%(nutlondg)d%(deg)s %(nutlonmn)d%(min)s %(nutlonsc)d%(sec)s<br/>%(nutation)s (%(obliquity)s): %(nutoblsn)s%(nutobldg)d%(deg)s %(nutoblmn)d%(min)s %(nutoblsc)d%(sec)s<br/>'
           ))
    txt += fmt % {
        'nutation': tr('Nutation'),
        'longitude': tr('lon.'),
        'nutlonsn': '+' if nutlon[4] > 0 else '-',
        'nutlondg': nutlon[0],
        'nutlonmn': nutlon[1],
        'nutlonsc': nutlon[2],
        'obliquity': tr('obl.'),
        'nutoblsn': '+' if nutobl[4] > 0 else '-',
        'nutobldg': nutobl[0],
        'nutoblmn': nutobl[1],
        'nutoblsc': nutobl[2],
        'deg': tr('\xb0', 'Degrees'),
        'min': tr("'", 'Minutes'),
        'sec': tr('"', 'Seconds')
    }
    # delta T
    fmt = unicode(tr('%(deltat)s: %(val)s<hr/>'))
    txt += fmt % {
        'deltat': tr('Delta T'),
        'val': swe.deltat(chart.julday) * 86400
    }  ## ?

    return txt
Example #16
0
    def create(self):
        hflag = 0
        fsflag = 0
        pflag = astrology.SEFLG_SWIEPH+astrology.SEFLG_SPEED
        astflag = astrology.SEFLG_SWIEPH
        self.ayanamsha = 0.0
        if self.options.ayanamsha != 0:
            swisseph.set_sid_mode(self.options.ayanamsha-1, 0, 0)
            self.ayanamsha = swisseph.get_ayanamsa_ut(self.time.jd)

        if self.options.topocentric:
            pflag += astrology.SEFLG_TOPOCTR

        self.houses = houses.Houses(
            self.time.jd,
            hflag,
            self.place.lat,
            self.place.lon,
            self.options.hsys,
            self.obl[0],
            self.options.ayanamsha,
            self.ayanamsha)

        self.raequasc, declequasc, dist = swisseph.cotrans(
            self.houses.ascmc[houses.Houses.EQUASC], 0.0, 1.0, -self.obl[0])
        self.planets = planets.Planets(
            self.time.jd,
            self.options.meannode,
            pflag,
            self.place.lat,
            self.houses.ascmc2,
            self.raequasc,
            self.nolat,
            self.obl[0])

        self.abovehorizonwithorb = self.isAboveHorizonWithOrb()

        abovehor = self.planets.planets[astrology.SE_SUN].abovehorizon
        if self.options.usedaynightorb:
            abovehor = self.abovehorizonwithorb

        self.fortune = fortune.Fortune(
            self.options.lotoffortune,
            self.houses.ascmc2,
            self.raequasc,
            self.planets,
            self.obl[0],
            self.place.lat,
            abovehor)

# ###########################################
# Roberto change  V 7.3.0
        self.firdaria = None
# ###########################################
        self.munfortune = None
        self.parts = None
        self.fixstars = None
        self.midpoints = None
        self.riseset = None
        self.zodpars = None
        self.antiscia = None
        self.antzodpars = None
        self.cpd = None
        self.cpd2 = None
        self.syzygy = None
        self.almutens = None
        mdsun = self.planets.planets[astrology.SE_SUN].speculums[0][planets.Planet.MD]
        sasun = self.planets.planets[astrology.SE_SUN].speculums[0][planets.Planet.SA]
        if self.full:
            # ###########################################
            # Roberto change  V 7.3.0
            self.firdaria = firdaria.Firdaria(
                self.time.origyear,
                self.time.origmonth,
                self.time.origday,
                self.options,
                self.abovehorizonwithorb)
# ###########################################
            self.munfortune = munfortune.MundaneFortune(
                self.houses.ascmc2, self.planets, self.obl[0], self.place.lat)
            self.syzygy = syzygy.Syzygy(self)
            self.parts = arabicparts.ArabicParts(
                self.options.arabicparts,
                self.houses.ascmc,
                self.planets,
                self.houses,
                self.houses.cusps,
                self.fortune,
                self.syzygy,
                self.options)
            self.fixstars = fixstars.FixStars(
                self.time.jd, fsflag, self.options.fixstars, self.obl[0])
            self.midpoints = midpoints.MidPoints(self.planets)
            self.riseset = riseset.RiseSet(
                self.time.jd,
                self.time.cal,
                self.place.lon,
                self.place.lat,
                self.place.altitude,
                self.planets)
            self.zodpars = zodpars.ZodPars(self.planets, self.obl[0])
            self.antiscia = antiscia.Antiscia(
                self.planets.planets,
                self.houses.ascmc,
                self.fortune.fortune,
                self.obl[0],
                self.options.ayanamsha,
                self.ayanamsha)
            self.antzodpars = antzodpars.AntZodPars(
                self.antiscia.plantiscia, self.antiscia.plcontraant, self.obl[0])
            self.almutens = almutens.Almutens(self)
            if self.options.pdcustomer:
                self.cpd = customerpd.CustomerPD(
                    self.options.pdcustomerlon[0],
                    self.options.pdcustomerlon[1],
                    self.options.pdcustomerlon[2],
                    self.options.pdcustomerlat[0],
                    self.options.pdcustomerlat[1],
                    self.options.pdcustomerlat[2],
                    self.options.pdcustomersouthern,
                    self.place.lat,
                    self.houses.ascmc2,
                    self.obl[0],
                    self.raequasc)
            if self.options.pdcustomer2:
                self.cpd2 = customerpd.CustomerPD(
                    self.options.pdcustomer2lon[0],
                    self.options.pdcustomer2lon[1],
                    self.options.pdcustomer2lon[2],
                    self.options.pdcustomer2lat[0],
                    self.options.pdcustomer2lat[1],
                    self.options.pdcustomer2lat[2],
                    self.options.pdcustomer2southern,
                    self.place.lat,
                    self.houses.ascmc2,
                    self.obl[0],
                    self.raequasc)

        swisseph.close()

        self.calcAspMatrix()

        if self.fixstars is not None:
            self.calcFixStarAspMatrix()