Edit twilights by location-dependent thresholds.
move_twilights.RdThis filter identify and act on false twilights that fulfil two conditions: first, the twilight must be clearly different from its adjacent twilights of the same type (e.g sunsets), and second, both adjacent twilights must occur at a similar time of day. If these conditions are fulfilled, the time of day for the identified twilight is changed to the average of both adjacent twilights. The filter will have no effect in periods where the variation in twilight timing is high, either due to migration, or the unfortunate influence of shadow and artificial light is present over several days.
Details
This function performs the following steps:
Make time circular.
Make a reference table for selecting thresholds (daily change of light per lat/month in min*2 + 15m variance).
Define the threshold in minutes for which A and C is considered the same (twilight A will define the threshold):
For this we use the reference table to select the right month and which reference latitude that is closest to the birds' approx. latitude
During an approx equinox period the function use estimated lats based on 10 lats before and after equinox period
for a few remaining NA's, the average threshold across lats and months is used (22 min)
Threshold for B different from A and C: minutes_different <- (speed / 24) * 8 (20 min is minimum) + rate of change in daylight
Produce plot with affected twilights highlighted