Author Topic: [PJSR] New core Math object methods: Julian Day Number calculations  (Read 7199 times)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Hi all.

The latest build 357 of the core PixInsight application comes with two new methods added to the Math JavaScript object. These methods allow fast and accurate conversions between julian day numbers and complex time representations.

The Julian Day Number (or Julian Day (JD) for short) is a time scale independent time measurement system consisting of a continuous count of days and fractions. The origin of the JD count is -4712 January 1.5. For that instant, we have JD=0.

Traditionally, the Julian Day begins at noon (12 hours). So all dates at 0 hours in any time scale correspond to Julian Day Numbers whose fractions are 0.5.

Our julian day number calculation routines implement original algorithms by Jean Meeus (Meeus, Jean. 1991, Astronomical Algorithms, Willmann-Bell, Inc., ch. 7). However, we have modified original Meeus' algorithms to allow for negative julian day numbers.

In our implementation, the Gregorian Calendar Reform is taken into account. This means that the day following 1582 October 4 (Julian Calendar) is 1582 October 15 (Gregorian Calendar). Refer to the original Meeus' book referenced above for more information about the calendar reform, which is of particular relevance to historical applications.

Of course, our routines follow the astronomical counting of years for B.C. years: the year before year 1 is the year 0, and the year preceding year 0 is year -1.

Static Methods

Number Math.complexTimeToJD( int year, int month, int day[, Number dayFrac=0] )

Returns the Julian Day Number corresponding to the specified time.

year
The year number in the Julian (<= 1582/10/04) or Gregorian Calendar (>= 1582/10/15). Negative years, along with the year zero, are B.C. years.

month
The month number, where 1=January and 12=December. Month numbers outside the nominal [1,12] range are fully supported, including negative months.

day
The integer day number. The nominal range is [1, 28|29|30|31] (the higher bound depending on the date's month, and on whether the date is in a leap year); however, our implementation fully supports arbitrary day numbers, including negative days.

dayFrac
The day fraction. Can be an arbitrary value expressed in days, although the nominal range is [0,1[. To calculate a day fraction from hours, minutes and seconds, use the simple relation:

Code: [Select]
dayFrac = (hour + (minute + seconds/60)/60)/24;

or, equivalently (although with a higher risk of roundoff errors):

Code: [Select]
dayFrac = hour/24 + minute/1440 + seconds/86400;

The returned value will be the Julian Day Number (JD) corresponding to the specified time point. The fractional part of the JD is zero at noon (12 hours), and 0.5 at zero hours.

Array Math.jdToComplexTime( Number jd )

Returns the complex time representation corresponding to a time point expressed as a Julian Day Number.

jd
The Julian Day Number for which the complex time representation is to be obtained.

Returns an array of complex time components: Element at array index 0 is the year, element 1 is the month in the range [1,12], element 2 is the day in the range [1,31], taking into account the number of days in the month (and also if the year is a leap year), and element 3 is the day fraction in the range [0,1[.

To obtain the hour, minute and seconds from the day fraction, one must be careful to avoid rounding problems. This example shows the correct procedure:

Code: [Select]
var T = Math.jdToComplexTime( 2451545.0 );
var year = T[0];
var month = T[1];
var day = T[2];
var dayf = T[3];
var h = 24*dayf; // hours with fraction
var hour = Math.trunc( h ); // integer hour in the range [0,23]
var m = 60*Math.frac( h ); // minutes with fraction
var minute = Math.trunc( m ); // integer minute in the range [0,59]
var seconds = 60*Math.frac( m ); // seconds with fraction


Usage Examples

Using Julian Day Numbers, it is trivial to calculate time intervals in days elapsed between two given time points. It's just a matter of subtracting the two JD values corresponding to the desired time points. For example:

Code: [Select]
var daysElapsed =
Math.complexTimeToJD( 2008, 3, 31.0 ) - Math.complexTimeToJD( 2007, 12, 16.0 );


Time intervals so calculated will be negative if the first time operand precedes the second time operand.

In a similar way, it is very easy to calculate the date that results after elapsing a number of days from a given date:

Code: [Select]
var jd1 = Math.complexTimeToJD( 2007, 12, 16.31 ) + 127;
var newDateAndTime = Math.jdToComplexTime( jd1 );


In the Meeus' book referenced at the beginning of this post you'll find many more interesting and useful calculations that can be made very easily by calculating the JD corresponding to a given date.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline ManoloL

  • PixInsight Addict
  • ***
  • Posts: 220
[PJSR] New core Math object methods: Julian Day Number calculations
« Reply #1 on: 2007 December 16 06:55:40 »
Hola Juan:
Me parece muy bien como disquisición académica.
Pero para que diablos se usan estos cálculos en un programa dedicado al procesamiento de imágenes.
La verdad es que quizás mis miras resulten muy cortas y se me escapen de la mente posibles utilidades, pero el programa no parece destinado a calcular el día de un eclipse, vamos, creo yo, aunque lo mismo también nos esperan sorpresas al respecto.
¡¡¡Queremos más documentación!!!
Saludos.
Saludos.

Manolo L.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
[PJSR] New core Math object methods: Julian Day Number calculations
« Reply #2 on: 2007 December 16 08:43:33 »
Hola ManoloL

Los caminos de PI son ocultos, complejos, variados, y extremadamente sofisticados :lol:

Por supuesto que puedes esperar ver una aplicación de cálculo de efemérides de alta precisión integrada en PI, y ten por seguro que la verás. De hecho, yo mismo tengo un montón de código basado en la DE405, que escribí hace más de cinco años, esperando a que pueda relajarme y tener tiempo para este tipo de cosas, que me encantan, por cierto.

En este momento ya sería perfectamente factible un script o un módulo de cálculo de efemérides, y PI le ofrecería todas las herramientas necesarias para generar gráficos en 2D y 3D.

Aparte de esto, los algoritmos de cálculo del día juliano son fundamentales en muchas áreas, no sólo en astronomía, porque permiten una representación continua del tiempo. Hasta un programa de contabilidad los puede usar  8)
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 988
    • http://www.astrofoto.es/
[PJSR] New core Math object methods: Julian Day Number calculations
« Reply #3 on: 2007 December 16 11:52:57 »
Quote from: "Juan Conejero"
Hasta un programa de contabilidad los puede usar  8)



Es así como vais a llevar la contabilidad en Pleiades Astrophoto??  :lol:


V.