Astrotools is a general purpose PHP library for astronomy.
- Requirements
- Installation
- Features
- Why not use PHP's calendar extension?
- Usage Examples
- Todo
- References
- PHP >= 7.0
- bcmath extension
It's possible to use the 0.0.x branch of Astrotools with PHP 5.4 - 5.6. For details see the next section.
composer require mjaschen/astrotools
If you need to use Astrotools with PHP 5.4, 5.5, or 5.6, just require version 0.0.2:
composer require mjaschen/astrotools:0.0.2
Please keep in mind, that the 0.0.x branch is no longer maintained and won't get any updates.
- Julian day calculation (forward/reverse)
- Sidereal time calculation (GMST, local sidereal time)
- Date of Easter calculation
- Time helper
Some of the implemented features (e.g. calculation of Julian day or Date of Easter) are already provided by PHP's calendar extension.
These functions come with some problems, e. g. easter_date()
can only calculate the Date of Easter for the timerange of unix timestamps (1970 January 1 to somewhere around 2037/2038).
use Astrotools\Time\JulianDay;
$timestamp = new \DateTime('2015-02-25 12:01:36', new \DateTimeZone('Europe/Berlin'));
$jd = new JulianDay($timestamp);
echo $jd->getValue();
The code above produces the output shown below:
2457078.9594444
use Astrotools\Time\JulianDay;
$jd = new JulianDay();
$jd->setValue(2451545.0);
var_dump($jd->getDateTime());
The code above produces the output shown below:
class DateTime#10 (3) {
public $date =>
string(26) "2000-01-01 12:00:00.000000"
public $timezone_type =>
int(3)
public $timezone =>
string(3) "UTC"
}
use Astrotools\Time\SiderealTime;
$dt = new \DateTime('2007-12-25 00:00:00', new \DateTimeZone('UTC'));
$st = new SiderealTime($dt);
echo $st->getSiderealTime();
The code above produces the output shown below:
6.2086583333
Local sidereal time for Berlin, Germany (longitude = 13.5 degrees east):
use Astrotools\Time\SiderealTime;
$dt = new \DateTime('2007-12-25 20:00:00', new \DateTimeZone('UTC'));
$st = new SiderealTime($dt);
echo $st->getLocalSiderealTime(13.5);
The code above produces the output shown below:
3.1634161794
use Astrotools\Helper\Time;
$time = new Time(6, 42, 23.1337);
echo $time->getValue();
The code above produces the output shown below:
6.7064260278
use Astrotools\Helper\Time;
$time = new Time(6.7064260278);
printf('%02d:%02d:%02.4f', $time->getHour(), $time->getMinute(), $time->getSecond());
The code above produces the output shown below:
06:42:23.1337
use Astrotools\Helper\Time;
$time = new Time(6, 42, 23.1337);
echo $time->getHourAngle() . PHP_EOL;
$time->setHourAngle(275);
echo $time->getValue();
The code above produces the output shown below:
100.596390417
18.333333333333
use Astrotools\Time\DateOfEaster;
$doe = new DateOfEaster(2000);
echo $doe->getDate()->format('Y-m-d');
The code above produces the output shown below:
2000-04-23
There exist multiple methods to get the value of ΔT for a given (decimal) year. One can lookup the value in tables and interpolate it for the wanted date or calculate it using polynomial expressions.
Astrotools currently provides the calculation of ΔT with polynomial expressions. Reasonably accurate values are provided for the timespan between the years -500 and 2150.
<?php
use Astrotools\Time\DeltaT\PolynomialExpression;
$deltaT = new PolynomialExpression();
echo $deltaT->getDeltaT(2016.125);
The code above produces the output shown below:
69.568218578125
- Support for microseconds in Julian day calculation
- Implement ΔT determination by table lookups
- Julian day formula - Astronomical Applications Department of the U.S. Naval Observatory
- Julian Date Converter - Astronomical Applications Department of the U.S. Naval Observatory
- Julian day - Wikipedia
- ΔT
- Astronomical Algorithms, Jean Meuss, 1998, ISBN 978-0943396613
- Polynomial Expressions For Delta T (ΔT)