Web App to plot Sunrise / Sunset times
Justin Pearson, 2015-08-05
Summary
Here is a function that plots the time of day of the sunrise and sunset at a given location:
The sunrise and sunset times are pretty constant near the equator:
The sunrise and sunset times vary farther from the equator:
In the following extreme high-latitude case, you get so much sunlight during the Summer that the yellow filling doesn’t work quite right:
CloudDeploy to make it a web app
First we make a FormFunction -- this does not cost any Cloud Credits to execute.
Here is a screenshot of what happens when you call form[] :
Fill it out and Submit:
Deploy it to the Wolfram Cloud:
(Here I pass in the CloudObject that I want to write to, so that it doesn’t create a new one each time. Omit the CloudObject in the call to CloudDeploy if it’s your first time deploying it.)
How it works
The heavy-lifting functions are Sunrise and Sunset:
Calling these functions with a list of dates yields an EventSeries:
An EventSeries has {time,value} pairs. In this case, the times are AbsoluteTimes of each of the days:
... and the values are the corresponding sunrise times:
Here are the {time,value} pairs themselves:
To plot the EventSeries, the values have to be something that’s sensible to plot. How about the number of hours from midnight?
Here is a function to do that:
Test it on 6:30am, 6.5 hours after midnight:
Test it on 8:45pm:
Since the values are just numbers, you can plot the EventSeries’s path:
Now do it across many days
Here are the days for which we’ll compute sunrise/set times:
Compute the sunrise and sunset times for each day, at a particular location:
Here is a slick way of combining two EventSeries and applying a function to combine values with the same corresponding times:
The result is a EventSeries whose values are pairs of sunrise/set times in “hours from midnight” (24-hour time):
Plot it with some frills: