flatangle / flatlib

Python library for Traditional Astrology
MIT License
296 stars 105 forks source link

Vedic sunset/sunrise? #74

Closed velkyvont closed 2 years ago

velkyvont commented 2 years ago

I try to use the functions nextSunrise, nextSunset, lastSunrise, lastSunset. I noticed that the data differs from my astrology software Maitreya8.

For example for 2022/04/07,

Charleston = GeoPos (32.861389, -79.903611)
CharlestonTZ = pytz.timezone('US/Eastern')

I get:

lastSunrise<2022/04/07 06:59:35 -04:00:00>
lastSunset<2022/04/07 19:44:20 -04:00:00>
nextSunrise<2022/04/08 06:58:19 -04:00:00>
nextSunset<2022/04/08 19:45:03 -04:00:00>

however Maireya8 shows me: 2022-04-07 Sunrise: 07:02:43 Sunset: 19:40:09 2022-04-08 Sunrise: 07:01:28 Sunset: 19:40:51

That's quite a big difference.

So I found swisseph manual which states:

The astronomical sunrise is defined as the time when the upper limb of the solar disk is seen appearing at the horizon. The astronomical sunset is defined as the moment the upper limb of the solar disk disappears below the horizon.

The function swe_rise_trans() by default follows this definition of astronomical sunrises and sunsets. Also, astronomical almanacs and newspapers publish astronomical sunrises and sunset according to this definition.

Hindu astrology and Hindu calendars use a different definition of sunrise and sunset. They consider the Sun as rising or setting, when the center of the solar disk is exactly at the horizon. In addition, the Hindu method ignores atmospheric refraction. Moreover, the geocentric rather than topocentric position is used and the small ecliptic latitude of the Sun is ignored.

In order to calculate correct Hindu rising and setting times, the flags SE_BIT_NO_REFRACTION and SE_BIT_DISC_CENTER must be added (or'ed) to the parameter rsmi. From Swiss Ephemeris version 2.06 on, a flag SE_BIT_HINDU_RISING is supported. It includes the flags SE_BIT_NO_REFRACTION, SE_BIT_DISC_CENTER and SE_BIT_GEOCTR_NO_ECL_LAT.

So I tried the following code:

print (Datetime.fromJD(swe.rise_trans(swe.julday(2022, 4, 7), swe.SUN, self.data.lat, self.data.long, 0, 0, 0, swe.CALC_RISE, swe.BIT_DISC_CENTER)[1][0], "-04:00"))
print (Datetime.fromJD(swe.rise_trans(swe.julday(2022, 4, 7), swe.SUN, self.data.lat, self.data.long, 0, 0, 0, swe.CALC_SET, swe.BIT_DISC_CENTER)[1][0], "-04:00"))

But what I'm getting is very crazy data:

<2022/04/08 02:24:39 -04:00:00>
<2022/04/07 09:24:09 -04:00:00>

Any idea what I'm doing wrong here?

Thanks for any help!

velkyvont commented 2 years ago

I just made it work! I use the following version - which is probably too cumbersome but at least it works.

sunrise = Datetime.fromJD(swe.rise_trans(jd_start=swe.julday(int(self.date.strftime("%Y")), int(self.date.strftime("%m")), int(self.date.strftime("%d"))), body=swe.SUN, lon=self.long, lat=self.lat, rsmi=swe.CALC_RISE | swe.BIT_HINDU_RISING)[1][0], offsetformated)