Web App to plot Sunrise / Sunset times

Justin Pearson, 2015-08-05

sunrise-sunset-plot_1.png

Summary

Here is a function that plots the time of day of the sunrise and sunset at a given location:

sunrise-sunset-plot_2.png

sunrise-sunset-plot_3.png

sunrise-sunset-plot_4.gif

The sunrise and sunset times are pretty constant near the equator:

sunrise-sunset-plot_5.png

sunrise-sunset-plot_6.png

sunrise-sunset-plot_7.png

sunrise-sunset-plot_8.gif

The sunrise and sunset times vary farther from the equator:

sunrise-sunset-plot_9.png

sunrise-sunset-plot_10.png

sunrise-sunset-plot_11.png

sunrise-sunset-plot_12.gif

In the following extreme high-latitude case, you get so much sunlight during the Summer that the yellow filling doesn’t work quite right:

sunrise-sunset-plot_13.png

sunrise-sunset-plot_14.png

sunrise-sunset-plot_15.png

sunrise-sunset-plot_16.gif

CloudDeploy to make it a web app

First we make a FormFunction -- this does not cost any Cloud Credits to execute.

sunrise-sunset-plot_17.png

Here is a screenshot of what happens when you call form[] :

sunrise-sunset-plot_18.gif

Fill it out and Submit:

sunrise-sunset-plot_19.gif

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

sunrise-sunset-plot_20.png

sunrise-sunset-plot_21.png

sunrise-sunset-plot_22.png

How it works

The heavy-lifting functions are Sunrise and Sunset:

sunrise-sunset-plot_23.png

sunrise-sunset-plot_24.png

sunrise-sunset-plot_25.png

sunrise-sunset-plot_26.png

Calling these functions with a list of dates yields an EventSeries:

sunrise-sunset-plot_27.png

sunrise-sunset-plot_28.png

sunrise-sunset-plot_29.png

sunrise-sunset-plot_30.gif

An EventSeries has {time,value} pairs. In this case, the times are AbsoluteTimes of each of the days:

sunrise-sunset-plot_31.png

sunrise-sunset-plot_32.png

sunrise-sunset-plot_33.png

sunrise-sunset-plot_34.png

sunrise-sunset-plot_35.png

sunrise-sunset-plot_36.png

... and the values are the corresponding sunrise times:

sunrise-sunset-plot_37.png

sunrise-sunset-plot_38.png

Here are the {time,value} pairs themselves:

sunrise-sunset-plot_39.png

sunrise-sunset-plot_40.png

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:

sunrise-sunset-plot_41.png

Test it on 6:30am, 6.5 hours after midnight:

sunrise-sunset-plot_42.png

sunrise-sunset-plot_43.png

Test it on 8:45pm:

sunrise-sunset-plot_44.png

sunrise-sunset-plot_45.png

sunrise-sunset-plot_46.png

sunrise-sunset-plot_47.gif

sunrise-sunset-plot_48.png

sunrise-sunset-plot_49.png

Since the values are just numbers, you can plot the EventSeries’s path:

sunrise-sunset-plot_50.png

sunrise-sunset-plot_51.gif

Now do it across many days

Here are the days for which we’ll compute sunrise/set times:

sunrise-sunset-plot_52.png

sunrise-sunset-plot_53.png

sunrise-sunset-plot_54.png

sunrise-sunset-plot_55.png

sunrise-sunset-plot_56.png

sunrise-sunset-plot_57.png

sunrise-sunset-plot_58.png

sunrise-sunset-plot_59.png

sunrise-sunset-plot_60.png

Compute the sunrise and sunset times for each day, at a particular location:

sunrise-sunset-plot_61.png

sunrise-sunset-plot_62.png

sunrise-sunset-plot_63.png

sunrise-sunset-plot_64.png

sunrise-sunset-plot_65.gif

Here is a slick way of combining two EventSeries and applying a function to combine values with the same corresponding times:

sunrise-sunset-plot_66.png

sunrise-sunset-plot_67.gif

The result is a EventSeries whose values are pairs of sunrise/set times in “hours from midnight” (24-hour time):

sunrise-sunset-plot_68.png

sunrise-sunset-plot_69.png

Plot it with some frills:

sunrise-sunset-plot_70.png

sunrise-sunset-plot_71.png

sunrise-sunset-plot_72.png

sunrise-sunset-plot_73.gif

Created with the Wolfram Language