Is there a way in Mathematica or Wolfram Alpha to get a plot of daylight hours vs calendar date and rate of change of daylight hours vs calendar date. Lets say I want the plot for latitude 45 degrees north?
Asked
Active
Viewed 244 times
3
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
LA_Ross
- 31
- 1
-
1Like this https://mathematica.stackexchange.com/questions/124903/plotting-how-sunrise-times-change-over-the-year? – Moo Sep 21 '19 at 15:34
-
should also have wolfram-alpha-query tag but I don't know how to add an additional tag. – LA_Ross Sep 22 '19 at 00:54
-
2Here's how I did it: https://www.wolfram.com/language/12/core-visualization/daily-dose-of-sunshine.html – Brett Champion Sep 22 '19 at 02:58
1 Answers
2
As Brett's example that he linked to in his comment shows, this can be easily done using the Sunrise and Sunset functions:
days = DateRange[{2019, 1, 1}, {2019, 12, 31}, "Day"];
daylightHours = QuantityMagnitude@DateDifference[Sunrise[#], Sunset[#], "Hour"] & /@ days;
DateListPlot@Transpose[{days, daylightHours}]

The rate of change can be approximated by:
DateListPlot@Transpose[{Most[days], Differences@daylightHours}]

As a bonus, this page shows how to estimate the daylight time based on the sun's altitude, which is available through SunPosition:
gothenburg = Entity["City",{"Goteborg","VastraGotaland","Sweden"}];
latitude = gothenburg["Latitude"];
{azimuth,altitude} = SunPosition[gothenburg];
daysSinceVernalEquinox = QuantityMagnitude@DateDifference[
DateObject[{2019, 3, 21}],
DateObject[],
"Days"
];
declination = Quantity[23.5 Sin[(daysSinceVernalEquinox/365) 365 Degree], "Degree"];
localHourAngle = ArcCos[-Tan[latitude] Tan[declination]]/Degree;
daylight = 2 Quantity[24, "Hours"] (localHourAngle/360)
11.5259
The corresponding value obtained using Sunrise and Sunset:
DateDifference[Sunset[gothenburg], Sunrise[gothenburg], "Hour"]
11.7667
C. E.
- 70,533
- 6
- 140
- 264
-
That's fabulous, thank you. Note that in the 'daylightHours = " line it should be "Hour" ; "Hours" resulted in an error on my system running Mathematica 11.0.1. – LA_Ross Sep 22 '19 at 16:38
-
@LA_Ross Thanks, that's good to know. "Hours" works in Mathematica 12, but edited for better compatibility. – C. E. Sep 22 '19 at 17:05