Where is the Sun?
In a previous article I wrote that I am using my Raspberry PI as status screen showing the weather among things, but I wanted to make the widget that shows the current weather a bit more interesting. Instead of having the background black (for nights) and white (for days) I want to have a better approximation of the lightness of the sky. In order to be able to do this, I need to know: Where the Sun in the sky is? (In Britain, of course that would be: Where in the sky is the Sun behind the clouds.)
With PHP's date_sun_info() function you can easily calculate when the Sun rises and sets, but it's not useful to determine how far above or under the horizon the Sun is. For that, I needed to implement a little bit more maths. I found an excellent tutorial online that explains the formulas that are used to calculate the position of the Sun. The trigonometry and maths go beyond me at the moment though!
I've implemented some of those functions in a simple library, called "astro". You can find it on GitHub at https://github.com/derickr/astro. Right now, it doesn't implement a lot more than just the position of the Sun, but I am intending to implement the rest of the algorithms too.
Of course, just a C-library of some maths isn't very useful if your language of choice is PHP, so I also implemented a tiny PHP extension wrapping the astro library. It's called solarsystem and available on GitHub as well. There is only an earth_sunpos() function so far, but again, I am intending to extend on that.
In order to make use of it, you'll have to run:
git clone git://github.com/derickr/php-solarsystem.git cd php-solarsystem git submodule init git submodule update phpize ./configure make make install
Then you can either add extension=solarsystem.so to php.ini, or run scripts with php -dextension=solarsystem.so yourscript.php. In the tests/ directory of the Git checkout you can find a script called sun-position.php. If we examine that, we will see that for four cities (Johannesburg, London, Longyearbyen and Oslo) we calculate the position of the Sun for every 15 minutes during January 14th, 2013. The main function there is earth_sunpos() which takes a Unix timestamp, as well as the latitude and the longitude of the location for which we want to calculate the Sun's position.
The script produces CSV, that I redirect into a file:
php -dextension=solarsystem.so sun-position.php > sunpos.csv
I then opened this file in LibreOffice and made a pretty graph out of it:
For Longyearbyen (yellow line) it shows that the Sun never rises as it always stays below the horizon. It also shows that the highest point over the horizon is different for London and Oslo—mostly because they are 10° apart horizontally. For London, you can also see that sunrise happens around 08:00 and sunset around 16:20.
The position over the horizon, combined with the weather forecast allows me to calculate the likely lightness of the sky. But that will have to wait to a future blog post.
Life Line
Updated an estate_agent office
My First Lapwing!
I went to the London Wetland Centre yesterday, for a day out in nature.
While hiding in a hide, this chap and a friend showed up starting to forage for grubs.
#BirdPhotography #BirdsOfMastodon #Photography #Birds #London #Nature
Created a waste_basket; Updated a cafe and a restaurant; Confirmed an estate_agent office
@bennuttall Are you at the Crucible this year again?
I walked 9.7km in 5h29m12s
Updated a gate
Staring Contest with a Squirrel
On my walk on the weekend, I sat down on a tree branch of a tree that had fallen over some time ago. Just listening to the birds.
Then after hearing rustling in the foliage above me, I looked up, and saw this chap staring at me.
I walked 3.0km in 41m38s
I walked 1.1km in 12m20s
Bluebell Carpet
I had a lovely walk on Hampstead Heath yesterday, finding all the nooks and crannies away from the busy paths.
This field of bluebells under the colourful tree was a stand-out quiet spot.
I walked 2.3km in 21m51s
Fix paths
Created a memorial
Created a bench
@Edent Seems like my Android stopped sending coordinates to @openbenches as well, which is surprising as I haven't updated anything as far as I'm aware. Could it be a problem with the reader in your side after the latest changes and the addition of the warning?
I walked 5.8km in 2h15m45s
I walked 1.7km in 17m46s
I walked 4.8km in 1h39m40s
Add the new Queen Elizabeth II garden.
Updated a bench and a crossing; Deleted 2 kerbs
Created 3 gates and a waste_basket
Created 6 benches
Created a bench; Updated 4 benches
Created 2 benches and a bicycle_parking; Updated a telephone and a waste_basket
I walked 10.3km in 2h34m24s




Shortlink
This article has a short URL available: https://drck.me/where-sun-a22