Rising, Transit, Setting

Computing Twilight

You will note that the Navy printout in the previous section contains another kind of information, besides simple risings and settings: it specifies the beginning and end of twilight, which is the time during the morning and evening when there is light but the Sun is still below the horizon.

To compute the beginning and end of twilight, ask when the Sun reaches a position several degrees below the horizon. There are different horizon values you should use depending on which twilight (civil, nautical, or astronomical) you are interested in:

  • Civil twilight uses the value –6 degrees.
  • Nautical twilight uses the value –12 degrees.
  • Astronomical twilight uses the value –18 degrees.

Note, however, that these twilight definitions specify the position of the center of the Sun, while the rising and setting functions normally pay attention to the top edge of an object instead. To make them use the Sun’s center, simply set the use_center parameter to True when doing the calculation. For example, here is how you would use the Observer created in the section above to calculate the civil twilight in Atlanta:

>>> atlanta.horizon = '-6'
>>> print(atlanta.previous_rising(ephem.Sun(), use_center=True))
2009/9/6 10:49:40
>>> print(atlanta.next_setting(ephem.Sun(), use_center=True))
2009/9/7 00:21:23

As you can see, these values match quite precisely the times given in the table in the previous section for civil twilight.