The Sentience

The Sentience
Showing posts with label lunar calendars. Show all posts
Showing posts with label lunar calendars. Show all posts

Monday, July 11, 2011

The Hindu Calendar

Introduction
Hindu Calendars are by far the nearest approaches to the actual machinery of astronomical phenomena governing life on our planet. (Hashim Amir Ali)

The are more than 30 variations of the calendars used in India, the best known of which is the classical Hindu Calendar Surya Siddhanta which is said to have been revealed to Asura Maya the Assyrian at the end of the last Golden Age (2,163,154 BCE). The Hindu lunisolar calendar is similar to the Chinese calendar, but varies in terms of application of fixed ancient methods to approximate true sun and true moon, based on sidereal year. Hindu longitudes are sidereal, having their origin near Piscium, the 6th brightest star in Pisces. However, having sidereal longitudes doesn't really affect the calculations. The calendar is lunisolar in the sense that it uses lunar months to approximate the sidereal year. The epoch used for Hindu calendars dates to January 23, -3101 in the Gregorian Calendar. The era in the Indian calendar is called the Vikram Era, or the Vikram Samvat, which began in 57 BCE.

There are two types of Hindu Lunisolar Calendars:
  • Amanta - one which is based on new moon ending of the lunar month
  • Parimanta - the other is based on full moon ending of the lunar month
I would be designing the Amanta Lunisolar Calendar for KCalendarSystem.

The Month
The amanta month runs from new moon to the next new moon. Each amanta month and hence the lunar year are expressed in integral number of civil days. The lunar month is either 29 or 30 civil days long but always comprises of 30 lunar days. In general, the month is named after the solar month in which the moment of its defining initial new moon falls. The month is divided into two halves, the sudi and the vadi. The sudi half is also known as the sukla paksha or the bright half-month, covering the time period from new moon to the next full moon. The vadi half, also known as the krishna paksha or the dark half-month, covers the period from the full moon to the next new moon.

There are twelve months in Hindu lunar Calendar:

  1. Chaitra (चैत्र, चैत)
  2. Vaishakh (वैशाख, बैसाख)
  3. Jyeshtha(ज्येष्ठ, जेठ)
  4. Ashadha (आषाढ, आषाढ़)
  5. Shravana (श्रावण, सावन)
  6. Bhadrapada (भाद्रपद, भादो)
  7. Ashwin (आश्विन)
  8. Kartik (कार्तिक)
  9. Margashirsha (मार्गशीर्ष, अगहन)
  10. Paush (पौष)
  11. Magh (माघ)
  12. Phalgun (फाल्गुन)
Leap Months
The lunar calendar year is shorter than the solar sidereal year and hence leap months are occasionally added at intervals to keep the lunar calendar and the solar calendar in sync. When a solar month completely covers a lunar month, that is when there are two new moons (one falling at the beginning and the other falling at the end of the solar month), the lunar month that begins at the first new moon is treated as a leap month and is prefixed with the title adhika. An adhika month generally occurs at average intervals of 2 years 8.4 months.

Missing Months
Very rarely, the lunar month can completely cover a solar month, i.e, there is no new moon falling in that solar month and hence no lunar month naming after it. This missing month is called the kshaya or decayed month. When a kshaya month occurs in a lunar year, there will always be two adhika months (one before and on after the kshaya month).

Days
In the Hindu calendar, the day starts with local sunrise. It is allotted five properties, called angas. They are:
  • the tithi (one of 30 divisions of a synodic month) active at sunrise
  • the vaasara, vaar (ravi-vaar, som-vaar, etc.) or weekday
  • the nakshatra (one of 27 divisions of the celestial ecliptic) in which the moon resides at sunrise
  • the yoga (one of 27 divisions based on theecliptic longitude of the sun and moon) active at sunrise
  • the karana (divisions based on tithis) active at sunrise.
Together these are called the panchangas.

Vaar refers to the days of the week and bear striking similarities with the names of the week in many western cultures:

No.↓

Sanskrit name of
the weekday
Celestial object
1

Ravi vaar रविवार Sun
2

Soma vaar सोमवार Moon
3

Mangala vaar मंगलवार Mars
4

Budha vaar बुधवार Mercury
5

Guru vaar गुरुवार
or
Bruhaspati vaar बृहस्पतिवार
Jupiter
6

Shukra vaar शुक्रवार Venus
7

Shani vāsara शनिवार Saturn

Day numbers are determined by the tithi, the time required by the longitude of the moon to increase by 12 degrees over the longitude of the Sun. Sometimes we call it a lunar day. There are 29 or 30 days in a lunar month. Each day is assigned the number of the tithi in effect at sunrise,. However, days are not always counted serially from 1 to 29 or 30. To understand why, it is important to note the fact that the value of a tithi varies from 19.48 hours to 26.78 hours. A short tithi, may begin after sunrise and end before the next sunrise. In this case, a number is omitted from the day count and hence we have skipped a kshaya day. Similarly, a longer tithi may span two sunrises, i.e., there is no tithi ending in that day. Then a day number is carried over to the second day and is treated as a leap day, suffixed by the term adhika.

Thursday, June 23, 2011

Observational Islamic Lunar Calendar

After coding the astro library, the next step was to implement the astronomical calculations in the Islamic Calendar. The arithmetical Islamic Calendar had already been defined in the KCalendarSystem API, to implement the astronomical calculations, functions like dateToJulianDay() and julianDayToDate() had to be modified.

The header file for defining the observational Islamic Lunar calendar is kcalendarsystemislamiclunar.h. It defines two classes:

KCalendarSystemIslamicLunar
Class definition in the public domain, publicly inherited from KCalendarSystem. It re-implements the virtual functions defined in the KCalendarSystem class. The re-implemented functions are defined in the public domain of the class.

virtual QString calendarType() const
Returns the calendar system type.

virtual QDate epoch() const
Returns a QDate holding the epoch of the calendar system. Islamic epoch is defined on 16th July 622 AD, which is Julian Day 1949440.

virtual QDate earliestValidDate() const
Returns the earliest date valid in this calendar system implementation, i.e. the epoch of the calendar system as the Islamic calendar is not proleptic.

virtual QDate latestValidDate() const
Returns the latest date valid in this calendar system implementation, i.e. 29th December 9999.

virtual bool isValid(int year, int month, int day) const
Returns whether a given date is valid in this calendar system.

virtual bool isValid(const QDate &date) const
Returns whether a given date is valid in this calendar system.

virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.

virtual bool isLeapYear(const QDate &date) const
Returns whether a given year(taken from the QDate) is a leap year.

virtual QString monthName(int month, int year, MonthNameFormat format = LongName) const
Gets specific calendar type month name for a given month number If an invalid month is specified, QString() is returned.

virtual QString monthName(const QDate &date, MonthNameFormat format = LongName) const
Gets specific calendar type month name for a given date.

virtual QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const
Gets specific calendar type week day name. If an invalid week day is specified, QString() is returned.

virtual QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const
Gets specific calendar type week day name.

virtual int weekDayOfPray() const
Returns the weekday of pray for this calendar system, i.e. Friday.

virtual bool isLunar() const
Returns whether the calendar is lunar.

virtual bool isLunisolar() const
Returns whether the calendar is lunisolar.
virtual bool isSolar() const
Returns whether the calendar is solar.

virtual bool isProleptic() const
Returns whether the calendar is proleptic, i.e, supports dates before the epoch.

KCalendarSystemIslamicLunarPrivate
Class definition in the private domain, publicy inherited from KCalendarSystemPrivate. It re-implements the virtual functions defined in the KCalendarSystem class. The re-implemented functions are defined in the public domain of the class.

virtual KLocale::CalendarSystem calendarSystem() const
Returns the calendar type.

virtual void loadDefaultEraList()
Loads the era supported by this calendar system.

virtual int monthsInYear(int year) const
Returns the number of months in the year used by this calendar system.

virtual int daysInMonth(int year, int month) const
Returns the number of days in a month used by this calendar system.

virtual int daysInYear(int year) const
Returns the number of days in a year used by this calendar system.

virtual int daysInWeek() const
Returns the number of days in a week used by this calendar system.

virtual bool isLeapYear(int year) const
Checks whether a year is a leap year or not.

virtual bool hasLeapMonths() const
Returns true is this calendar system has leap months. The Islamic calendar doesn't have leap months.

virtual bool hasYearZero() const
Returns true is this calendar system uses year 0. The Islamic calendar doesn't have a year 0.

virtual int maxDaysInWeek() const
Returns the maximum number of days in a week in this calendar system, i.e, 7.

virtual int maxMonthsInYear() const
Returns the maximum number of months in a year in this calendar system, i.e. 12.

virtual int earliestValidYear() const
Returns the earliest valid year in this calendar system, i.e., year 1.

virtual int latestValidYear() const
Returns the latest valid year in this calendar system, i.e., year 9999.

virtual QString monthName(int month, int year, Locale::DateTimeComponentFormat format, bool possessive) const
Gets specific calendar type month name for a given month number If an invalid month is specified, QString() is returned.

virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const
Gets specific calendar type weekday name for a given month number If an invalid weekday is specified, QString() is returned.

Astronomical Implementation
Re-implementations of the functions dateToJulianDay() and julianDayToDate() using the functions defined in the Astro Library.

bool julianDayToDate(int jd, int &year, int &month, int &day) const
Gets the date in this calendar system from the Julian day. The astro library function visibleCrescentBefore() is used to get the Julian day when the visible crescent was observed on or before the jd. The number of months elapsed since the Islamic epoch are then calculated and are used to get the year and month:
  • Year = elapsedMonths/12 + 1
  • Month = elapsedMonths%12 + 1
  • Day = jd - day returned by visiblecrescentbefore() +1
The function returns false if it encounters an invalid date at any point during the calculations, otherwise it returns true.

bool dateToJulianDay(int &jd, int year, int month, int day) const
Gets the Julian day number corresponding to a given date in this calendar system. The astro library function visibleCrescentBefore() is used to get the Julian day when the visible crescent was observed on or before a particular date. The date passed as an argument to the visibleCrescentBefore() function is calculated as:
  • Islamic epoch + the number of days elapsed since the start of the calendar to median of the current month
The Julian day is then calculated by adding to the value returned by the visibleCrescentBefore() function with the aforementioned argument.

The function returns false if it encounters an invalid date at any point during the calculations, otherwise it returns true.

The calculations for implementing the Islamic Lunar Calendar have been derived from the public domain Lisp code/Mathematical functions of Calendrical Calculations by Edward M. Reingold on the Illinois Institute of Technology website.

Wednesday, June 22, 2011

Astro Library

While I was programming the astronomical functions, I had to reconsider some function definitions to match the compatibility with the KCalendarSystem API. The function definitions and their functionality are mentioned in the following post:

astro.h
Astronomical functions require the geographical latitude and longitude for most of their calculations. KDECore does not have any sort of data functionality that would use the geographical latitude and longitude. The only reliable way to get this data is to ask the user to input it while defining the KDE locale (as in KStars, etc). I am yet to talk regarding the feasibility of this feature with my mentor, John Layt, and then decide upon the method to proceed further on this. Until then, I have defined a structure in the header file and would be using this structure as an argument to member functions requiring geographical latitude and longitude. The main reason of using a structure over an enum was due to the fact that I can define the data type in the structure and wouldn't require static casting of data while handling the calculations of latitude and longitude.

static double zoneFromLongitude(struct AstroLocale locale) Calculates the time zone from a given locale (latitude and longitude) and returns it in degrees.

double universalFromLocal(double localTime, struct AstroLocale locale)
Returns the Universal Time from the Local time by at the given locale.

double localFromUniversal(double universalTime, struct AstroLocale locale)
Returns the Local Time from Universal Time.

double standardFromUniversal(double universalTime)
Returns the Standard Time from Universal Time.

double universalFromStandard(double standardTime)
Returns the Universal Time from Standard Time.

double standardFromLocal(double localTime, struct AstroLocale locale) Returns Standard Time from Local Time.

double localFromStandard(double standardTime, struct AstroLocale locale) Returns Local Time from Standard Time.

double ephemerisCorrection(double time)
Returns the corrections based on the astronomical ephemeris, which computes the secondary realizations based on lunar observations and the Cesium atomic clock.

double dynamicalFromUniversal(double time)
Returns the Dynamical(or Ephemeris) Time from Universal Time by applying the Ephemeris Correction to it.

double universalFromDynamical(double time)
Returns Universal Time from Dynamical Time.

double julianCenturies(double time)
Returns the Julian Centuries since January 1, 2000 12:00PM.

double obliquity(double time)
Computes the obliquity of the ecliptic.

double equationOfTime(double time)
Calculates the difference between the apparent solar time and the mean solar time. The equation of time results from the two superposed astronomical causes of the obliquity of the ecliptic and the eccentricity of Earth's orbit which causes a non-uniformity in the apparent daily motion of the Sun relative to the stars.

double apparentFromLocal(double localTime, struct AstroLocale locale)
Returns Apparent Time(calculation of time based on the position of the sun) from Local Time.

double localFromApparent(double apparentTime, struct AstroLocale locale)
Returns Local Time from Apparent Time.

double siderealFromMoment(double time)
Returns the sidereal time from the current moment considering the precession of equinoxes.

double declination(double time, double eclipticLatitude, double eclipticLongitude) double rightAscension(double time, double eclipticLatitude, double eclipticLongitude)
These functions compute the polar coordinates in degrees, from equatorial coordinates.

int roundOff(double value)
Rounds off the double value to integer value

astrosolar.h
Contains functions based on the astronomy of the Sun. As of now, the features required for implementing the Islamic Calendar have been specified in this header file. Other functions/features would be appended later on as per the need of other calendars.

double aberration(double time)
Returns the value in degrees considering the effect of the movement of the Sun to about 20.47 seconds of the arc during the time its light is en route to the Earth.

double nutation(double time)
Returns the value in degrees, compensates for the small irregularity due to the precession of equinoxes.

double solarLongitude(double time)
Returns the equatorial longitude of the Sun.

double solarAnomaly(double time)
Computes solar anomaly observed in the celestial sphere.

double sineOffset(double time, struct AstroLocale locale, double angleDepression)
Computes the offset of the sine of the angle of depression of the Sun at the time of twilight.

double approxTimeOfTwilight(double time, struct AstroLocale locale, double angleDepression, bool early)
Returns an approximate time at which twilight would occur.

double timeOfTwilight(double approxTime, struct AstroLocale locale, double angleDepression, bool early)
Returns the precise time (precision of up to 30seconds) at which the twilight would occur.

double dawn(int time, struct AstroLocale locale, double angleDepression)
Returns the time at which dawn is observed.

double dusk(int time, struct AstroLocale locale, double angleDepression)
Returns the time at which dusk is observed.

double estimatePriorSolarLongitude(double longitude, double time)
This function has an important role to play in implementing astronomical solar calendars, as it determines a particular solar longitude on or before the given date. The solar longitude can correspondingly help to find the day of the New Year as per the astronomical calendar.

astrolunar.h
Contains functions based on the astronomy of the Moon. The Islamic Calendar is a lunar calendar which is based on the sightings of the crescent and observations of the moon. The lunar crescent visibility criteria defined by S.K. Shaukat has been used to derive the astronomical implementation of the calendar.

double nthNewMoon(int n)
Returns the date on which the nth new moon would be observed.

double meanLunarLongitude(double time)
Computes the mean lunar longitude (without considering the effects contributed by the other heavenly bodies in the Celestial Sphere); it returns the value in degrees. The moon is assumed to revolve around the Earth in a circle while calculating the mean lunar longitude.

double lunarElongation(double time)
Returns lunar elongation, i.e., the angular distance of the moon, east of the sun.

double lunarAnomaly(double time)
Computes lunar anomaly.

double moonNode(double time)
Computes the angle of orbital nodes of the moon, i.e. the points where the orbit of the moon crosses the ecliptic.

double lunarLongitude(double time)
Calculates the lunar longitude considering the effects of the Sun, Jupiter, Venus, precession of equinoxes, flattening of the Earth at the poles and the corrections imposed on the mean lunar longitude to make it compatible with the elliptical orbit of the Moon around the earth.

double lunarLatitude(double time)
Calculates the latitude of the moon, considering the effects of Jupiter, flattening of Earth near the poles, and a few other complex factors as derived from Cassini's Law.

double lunarPhase(double time)
Returns the phase of the moon in degrees.

double lunarDistance(double time)
Returns the distance of the moon from the Earth at a given time.

double lunarParallax(double time, struct AstroLocale locale)
Calculates the lunar parallax at a given time as seen from a locale.

double lunarAltitude(double time, struct AstroLocale locale)
Calculates the geocentric lunar altitude in degrees, at a given time as seen from a locale.

double lunarAltitudeTopocentric(double time, struct AstroLocale locale)
Calculates the topocentric lunar altitude at a given time as seen from a locale.

bool lunarCrescentVisibility(int time, struct AstroLocale locale)
Returns whether the lunar crescent is visible from the locale at a given time.

int visibleCrescentBefore(int time, struct AstroLocale locale)
Calculates the date of the same month on which the crescent was visible before the given time, it, therefore, returns the date on which the lunar crescent had just met its visibility criteria.

double newMoonBefore(double time)
Returns the moment of a New Moon occurrence before the given time

double newMoonOnOrAfter(double time)
Returns the moment of a New Moon occurrence at or after the given time

The astronomical functions have been translated/derived from the publicly available Lisp Code of Calendrical Calculations by Edward M. Reingold on the Illinois Institute of Technology website.