I want to use notation like this for loop (which was used in an answer to this question) for some code I have written to calculate the "solar time" of a timestamp given it's location and time of year.
I'm doing some animal circadian activity research and animals change their activity with the sun (and moon, some of the time), but because sunrise and sunset change over the course of a year and at different latitudes it is useful to convert 24 hour time to a proxy value which is kind of the location of the sun throughout the day, standardized to a 0 to 2π interval with sunrise at π/2 and sunset at 3π/2.
Here's the actual code; it works like this:
riseis the sunrise, andsetthe sunset at that time a latitude.houris the timestamp of the animal sightingsolaris the sun-time scaled to the nearest solar event (sunrise and sunset)
if (hour <= rise):
solar = pi/2 * hour/rise #predawn
elseif (hour <= set):
solar = {(hour - rise) / (set - rise)} * pi + pi/2 #daylight
else:
solar = {(hour - set) / (2pi - set)} * pi/2 + 3pi/2 #postdusk
It would be great if this could be written succinctly for a publication I am working on to show what "solar time" is without having all of the code.