PHPackages                             abbadon1334/sun-position-spa-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. abbadon1334/sun-position-spa-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

abbadon1334/sun-position-spa-php
================================

solar data calculation and sun position

2.0.0(6y ago)850.6k↓13.9%4[2 issues](https://github.com/abbadon1334/sun-position-spa-php/issues)[9 PRs](https://github.com/abbadon1334/sun-position-spa-php/pulls)MITPHPPHP &gt;=7.2

Since May 7Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/abbadon1334/sun-position-spa-php)[ Packagist](https://packagist.org/packages/abbadon1334/sun-position-spa-php)[ RSS](/packages/abbadon1334-sun-position-spa-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (13)Used By (0)

Sun-Position-SPA-php
====================

[](#sun-position-spa-php)

SPA Sun Position Calc Library for PHP

[![Build Status](https://camo.githubusercontent.com/eb4dd258d88344a1806d3adaf6c55e842bb78e7e0a65d9c208b7a72863fd0d24/68747470733a2f2f7472617669732d63692e6f72672f61626261646f6e313333342f73756e2d706f736974696f6e2d7370612d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/abbadon1334/sun-position-spa-php)[![Coverage Status](https://camo.githubusercontent.com/80b64b082dd8b27ba85a493c5fcfab5785389bd5ff4a169b2b8dd8d78189df81/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f61626261646f6e313333342f73756e2d706f736974696f6e2d7370612d7068702f62616467652e7376673f6272616e63683d757067726164652d746f2d756e69742d38)](https://coveralls.io/github/abbadon1334/sun-position-spa-php?branch=upgrade-to-unit-8)[![Maintainability](https://camo.githubusercontent.com/cf94cadbb3e3fdc693f452ff28c6db9596cce5b4e2088bd98b5045b85b458ab7/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66653063383530353362343334653239363235342f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/abbadon1334/sun-position-spa-php/maintainability)[![Test Coverage](https://camo.githubusercontent.com/bf7cc78cdec2c9bf5ae9316f8dc1dde65ee39bb5deb67add33f1bbf73bf1e527/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66653063383530353362343334653239363235342f746573745f636f766572616765)](https://codeclimate.com/github/abbadon1334/sun-position-spa-php/test_coverage)[![Codacy Badge](https://camo.githubusercontent.com/db276b16d47e902d8760723ddde21443be5c97f5562855978dd175dd06f624c7/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6133383938353434303835613435623039376130386366303162666633313331)](https://www.codacy.com/app/abbadon1334/sun-position-spa-php?utm_source=github.com&utm_medium=referral&utm_content=abbadon1334/sun-position-spa-php&utm_campaign=Badge_Grade)[![Codacy Badge](https://camo.githubusercontent.com/2cf6029dd1e2366f8395068c8a3528191c3ce5115c1d3898eeaad6da734b9fdf/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f436f7665726167652f6133383938353434303835613435623039376130386366303162666633313331)](https://www.codacy.com/app/abbadon1334/sun-position-spa-php?utm_source=github.com&utm_medium=referral&utm_content=abbadon1334/sun-position-spa-php&utm_campaign=Badge_Coverage)

This library is based on the work of Ibrahim Reda and Afshin Andreas (SPA) Solar Position Algorithm for Solar Radiation Applications ( 2008 National Renewable Energy Laboratory )

Abstract from the original study
--------------------------------

[](#abstract-from-the-original-study)

There have been many published articles describing solar position algorithms for solar radiation applications. The best uncertainty achieved in most of these articles is greater than ±0.01 / in calculating the solar zenith and azimuth angles. For some, the algorithm is valid for a limited number of years varying from 15 years to a hundred years. This report is a step by step procedure for implementing an algorithm to calculate the solar zenith and azimuth angles in the period from the year -2000 to 6000, with uncertainties of ±0.0003°

### PHPUNIT TEST

[](#phpunit-test)

Library test data vs Table A.4 of the original study

### C Source code for Solar Position Algorithm (SPA)

[](#c-source-code-for-solar-position-algorithm-spa)

### Requirements

[](#requirements)

- PHP 7.2
- PHP 7.3
- PHP 7.4

### Composer install

[](#composer-install)

```
composer require abbadon1334/sun-position-spa-php

```

### Simple Usage

[](#simple-usage)

```
$SD = new SolarData\SolarData();

/* ARGS : observer latitude, observer longitude, observer altitude */
$SD->setObserverPosition(39.742476,-105.1786,1830.14);

/* ARGS : Observer Date : Year, Month, Day */
$SD->setObserverDate(2003, 10, 17);

/* ARGS : Observer Time : Hours, Minutes, Seconds */
$SD->setObserverTime(12, 30,30);

/* ARGS : difference in seconds between the Earth rotation time and the Terrestrial Time (TT) */
$SD->setDeltaTime(67);
/* ARGS : Observer Timezone */
$SD->setObserverTimezone(-7);

/* ARGS : Observer mean pressure in Millibar */
$SD->object->setObserverAtmosphericPressure(820);

/* ARGS : Observer mean temperature in Celsius */
$SD->object->setObserverAtmosphericTemperature(11.0);

/* calculate sun position */
$SunPosition = $SD->calculate();

```

#### Available attributes after calculate() :

[](#available-attributes-after-calculate-)

*I know this attributes names are not so ortodox.**Formulas that are present in the original document are really complex and using the same name for variables is a big aid for debugging*

- `L°` Earth heliocentric longitude (degrees)
- `B°` Earth heliocentric latitude (degrees)
- `R` Earth radius vector, R (in Astronomical Units, AU)
- `Θ°` geocentric longitude (degrees)
- `β°` geocentric longitude (degrees)
- `X` nutation in longitude and obliquity
- `ε°` true obliquity of the ecliptic (degrees)
- `Δτ` aberration correction (degrees)
- `λ°` apparent sun longitude (degrees)
- `ν°` apparent sidereal time at Greenwich (degrees)
- `ν0°` apparent mean sidereal time at Greenwich (degrees)
- `α°` geocentric sun right ascension (degrees)
- `α´°` topocentric sun right ascension (degrees)
- `δ°` geocentric sun declination (degrees)
- `δ´°` topocentric sun declination (degrees)
- `H°` Observer hour angle (degrees)
- `H´°` topocentric hour angle (degrees)
- `ξ°` equatorial horizontal parallax of the sun (degrees)
- `Z°` topocentric zenith angle (degrees)
- `Γ°` topocentric astronomers azimuth angle (degrees)
- `Φ°` topocentric azimuth angle, M for navigators and solar radiation users (in degrees)
- `e0°` topocentric elevation angle without atmospheric refraction (in degrees)
- `e°` topocentric elevation angle (in degrees)
- `Eot` Equation Of Time

*Example to get angle H° - Observer hour angle (degrees)*

```
$SD = new SolarData\SolarData();

/* ARGS : observer latitude, observer longitude, observer altitude */
$SD->setObserverPosition(39.742476,-105.1786,1830.14);

/* ARGS : Observer Date : Year, Month, Day */
$SD->setObserverDate(2003, 10, 17);

/* ARGS : Observer Time : Hours, Minutes, Seconds */
$SD->setObserverTime(12, 30,30);

/* ARGS : difference in seconds between the Earth rotation time and the Terrestrial Time (TT) */
$SD->setDeltaTime(67);
/* ARGS : Observer Timezone */
$SD->setObserverTimezone(-7);

/* ARGS : Observer mean pressure in Millibar */
$SD->object->setObserverAtmosphericPressure(820);

/* ARGS : Observer mean temperature in Celsius */
$SD->object->setObserverAtmosphericTemperature(11.0);

/* calculate sun position */
$SunPosition = $SD->calculate();

```

to get H° Observer hour angle (degrees)

```
echo $SunPosition->H°;

```

\*Example to get fraction day for sunrise - transit - sunset \*

```

$SD = new SolarData\SolarData();

/* ARGS : observer latitude, observer longitude, observer altitude */
$SD->setObserverPosition(39.742476,-105.1786,1830.14);

/* ARGS : Observer Date : Year, Month, Day */
$SD->setObserverDate(2003, 10, 17);

/* ARGS : Observer Time : Hours, Minutes, Seconds */
$SD->setObserverTime(12, 30,30);

/* ARGS : difference in seconds between the Earth rotation time and the Terrestrial Time (TT) */
$SD->setDeltaTime(67);
/* ARGS : Observer Timezone */
$SD->setObserverTimezone(-7);

/* ARGS : Observer mean pressure in Millibar */
$SD->object->setObserverAtmosphericPressure(820);

/* ARGS : Observer mean temperature in Celsius */
$SD->object->setObserverAtmosphericTemperature(11.0);

/* calculate sun position and calculate sun rise transit set angles
ARGS : true = call ->calculate()
*/
$SunPosition = $SD->calculateSunRiseTransitSet(true);

$SunRiseDayFraction = $SunPosition->DayFractionSunrise;
$TransitDayFraction = $SunPosition->DayFractionTransit;
$SunsetDayFraction  = $SunPosition->DayFractionSunset;

```

### Get Sun Incidence Angle

[](#get-sun-incidence-angle)

```

$SD = new SolarData\SolarData();

/* ARGS : observer latitude, observer longitude, observer altitude */
$SD->setObserverPosition(39.742476,-105.1786,1830.14);

/* ARGS : Observer Date : Year, Month, Day */
$SD->setObserverDate(2003, 10, 17);

/* ARGS : Observer Time : Hours, Minutes, Seconds */
$SD->setObserverTime(12, 30,30);

/* ARGS : difference in seconds between the Earth rotation time and the Terrestrial Time (TT) */
$SD->setDeltaTime(67);
/* ARGS : Observer Timezone */
$SD->setObserverTimezone(-7);

/* ARGS : Observer mean pressure in Millibar */
$SD->object->setObserverAtmosphericPressure(820);

/* ARGS : Observer mean temperature in Celsius */
$SD->object->setObserverAtmosphericTemperature(11.0);

```

- no need of calling calculate \*

```
/* ARGS : tilt angle from horizontal plane, rotation angle from real south  */
$Surface2SunAngleOfIncidence = $SD->getSurfaceIncidenceAngle(30,-10)

```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 81.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~396 days

Total

3

Last Release

2506d ago

Major Versions

1.1 → 2.0.02019-07-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/54f3bc6465a0f20b47cc7cd7bfe00f607bf80b9de41d5d35fa6740f4b6b3f6c9?d=identicon)[abbadon1334](/maintainers/abbadon1334)

---

Top Contributors

[![abbadon1334](https://avatars.githubusercontent.com/u/5801824?v=4)](https://github.com/abbadon1334 "abbadon1334 (49 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (11 commits)")

---

Tags

algorithmazimuth-anglesdegreeslongitudephpsiderealsolar-position-algorithmssolar-radiation-applicationsspa

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/abbadon1334-sun-position-spa-php/health.svg)

```
[![Health](https://phpackages.com/badges/abbadon1334-sun-position-spa-php/health.svg)](https://phpackages.com/packages/abbadon1334-sun-position-spa-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
