Giter Club home page Giter Club logo

sun-position-spa-php's Introduction

Sun-Position-SPA-php

SPA Sun Position Calc Library for PHP

Build Status Coverage Status Maintainability Test Coverage Codacy Badge Codacy Badge

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

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

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

C Source code for Solar Position Algorithm (SPA)

http://www.nrel.gov/midc/spa/

Requirements

  • PHP 7.2
  • PHP 7.3
  • PHP 7.4

Composer install

composer require abbadon1334/sun-position-spa-php

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() :

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

  • Earth heliocentric longitude (degrees)
  • 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)
  • Observer hour angle (degrees)
  • H´° topocentric hour angle (degrees)
  • ξ° equatorial horizontal parallax of the sun (degrees)
  • 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)
  • 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


$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)

sun-position-spa-php's People

Contributors

abbadon1334 avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sun-position-spa-php's Issues

ObserverTimezone is necessary?

Hi,

I don't have any experience in solar calculations.

I got confused a bit:
Based on the example, we need to set the following arguments:

  • setObserverPosition
  • setObserverDate
  • setObserverTime

As their name implies, these are local dates and local times of the observer.

Then why do I need to give the ObserverTimezone?

Furthermore, how can I calculate the timezone from a LatLong coordinate for those exotic places close to the date line, where some island belongs to different timezone as they have these zigzag timezone border?

Even further, I believe the observer's local time with the lat/long coordinates is the most accurate, because with those it is easier and more precise to calculate the Earth's UTC time, and then we can have the Observer sunset, rather than the timezone sunset.

The point is, how can I calculate the Sun position without Timezone information?
(I don't need to know the local sunset, or anything else, I need only the Sun azimuth and alt)

Can anyone shed some light on that?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Unsupported composer value

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Detected dependencies

composer
composer.json
  • php >=7.2
  • phpmd/phpmd 2.9.0
  • phpstan/phpstan 0.12.11
  • phpunit/phpunit *
  • squizlabs/php_codesniffer 3.5.6
  • symfony/yaml ~2.1|~3.0|~4.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.