SFalmanac-Py3 is a Python 3 script that creates the daily pages of the Nautical Almanac as well as Lunar Distance tables and charts. The daily pages are needed for celestial navigation with a sextant. Although you are strongly advised to purchase the official Nautical Almanac, this program will reproduce the tables with no warranty or guarantee of accuracy.
SFalmanac-Py3 was developed with the intention of having identical output format as Pyalmanac-Py3 to facilitate manual observation of data discrepancies. Also it is based entirely on the newer Skyfield astronomical library: https://rhodesmill.org/skyfield/. SFalmanac uses the star database in Skyfield, which is based on data from the Hipparcos Catalogue.
Users are encouraged to install the Python Package Index (PyPI) edition to be found here:
https://pypi.org/project/sfalmanac/
The results have been crosschecked with USNO data to some extent.
UPDATE: Nov 2019
Declination formatting has been changed to the standard used in Nautical Almanacs. In each 6-hour block of declinations, the degrees value is only printed on the first line if it doesn't change. It is printed whenever the degrees value changes. The fourth line has two dots indicating "ditto". This applies to all planet declinations and for the sun's declination, but not to the moon's declination as this is continuously changing.
This also includes some very minor changes and an improved title page for the full almanac with two star charts that indicate the equatorial navigational stars.
UPDATE: Jan 2020
The Nautical Almanac tables now indicate if the sun never sets or never rises; similarly if the moon never sets or never rises. For better performance, the SunNeverSets or SunNeverRises state is determined only by the month of year and hemisphere. (This is reliable for the set of latitudes printed in the Nautical Almanac tables.) The code also has cosmetic improvements.
P.S. The Overfull \hbox in paragraph... messages can be ignored - the PDF is correctly generated.
UPDATE: Feb 2020
The main focus was on cleaning up the TeX code and eliminating the Overfull/Underfull hbox/vbox messages. Other minor improvements were included. A Skyfield issue with days that have no moonrise or moonset at a specific latitude was resolved.
UPDATE: Mar 2020
A new parameter in config.py enables one to choose between A4 and Letter-sized pages. A new approach to string formatting has been implemented: the old style Python string formatting syntax has been replaced by the new style string formatting syntax.
UPDATE: Jun 2020
The Equation Of Time is shaded whenever EoT is negative indicating that apparent solar time is slow compared to mean solar time (mean solar time > apparent solar time). It is possible to extend the maximum year beyond 2050 by choosing a different ephemeris in config.py. Bugfix applied to correct the Meridian Passage times.
UPDATE: Jul 2020
A new option has been added into config.py: moonimg = True will display a graphic image of the moon phase (making the resulting PDF slightly larger). Use moonimg = False to revert to the previous format without the graphic moon image.
UPDATE: Feb 2021
Minor changes are included here to this original (non-PyPI) edition to reflect some of the adaptation that was required (e.g. integrate increments.py into sfalmanac.py as Option 5) to create a PyPI (Python Package Index) edition making this original (non-PyPI) and the PyPI editions similar. Both editions create identical almanacs and the PyPI edition is the preferred choice for users.
UPDATE: Mar 2021
UT is the timescale now employed in the almanac.
Two new options have been added into config.py: useIERS = True instructs Skyfield (if >= 1.31) to download Earth orientation data from IERS (International Earth Rotation and Reference Systems Service). ageIERS = 30 instructs Skyfield to download fresh data from IERS if older tham that number of days. This implies greater accuracy for the generated almanacs (if Skyfield >= 1.31).
Note that although you may be using the de421.bsp ephemeris (valid from 1900 to 2050), the IERS currently specifies the validity of Earth Orientation Parameters (EOP) from 2nd January 1973 to 15th May 2022. Refer to the IERS web site for current information.
UPDATE: Apr 2021
A double moonrise or moonset on the same day is now highlighted for better legibility. Event Time tables can now be generated - these are the tables containing data in hours:minutes:seconds, e.g. sunrise, sunset, moonrise, moonset and Meridian Passage. Accuracy to to the second of time is not required for navigational purposes, but may be used to compare accuracy with other algorithms. Some internal technical enhancements and minor changes to text are also included. For example, moonrise and moonset times now take into account the lunar distance from the Earth (which varies slightly).
UPDATE: May 2021
The indication of objects (Sun or Moon) continuously above or below the horizon has been corrected.
Regarding Moon Data: ".. .." has been added to indicate that the moonrise/moonset event occurs the following day (at the specified latitude). If there is no moonrise/moonset for two or more consecutive days, black boxes indicate "moon below horizon"; white boxes indicate "moon above horizon". This brings it in line with Nautical Almanacs. (Previously they were only displayed when there was no moonrise and no moonset on a single day.)
The additional calculations required are compensated with a transient Moon Data buffer store that always holds the latest five adjacent days of moon data, eliminating any need to recalculate data for the next or previous day (to determine if "moon above/below horizon" spans a minimum of two days.)
Correction to Sun Data: "Sun continually above/below horizon" now shown if it applies to both Sunrise and Sunset, or additionally to both Civil Twilight Start & End; or additionally to both Astronomical Twilight Start & End, i.e. as two, four or six events per day and latitude. This brings it in line with Nautical Almanacs.
:smiley: SFalmanac is now available on DockerHub here. :smiley:
The DockerHub image contains a Linux-based OS, TeX Live, the application code, and third party Python imports (including the astronomical libraries). It can be executed "in a container" on Windows 10 Pro, macOS or a Linux-based OS.
UPDATE: Jun 2021
This version introduces multiprocessing and thus a gain in performance. Single-processing is also a selectable option, if required. Testing has been successfully performed on Windows 10 and Ubuntu 20.04 LTS. (No testing can be performed on Mac OS.) Compared to single-processing ...
Windows 10 uses up to 8 threads; Linux uses up to 12 threads in parallel. Testing was performed on a PC with an AMD Ryzen 7 3700X 8-Core (16 threads) Processor. Windows & Mac OS spawn new processes; Linux forks new processes (the code is compatible with both techniques and will also run on CPUs with fewer cores/threads).
This performance gain infers that there is practically no justification to use the original Skyalmanac, which was an interim solution to overcome the poor performance in SFalmanac at the cost of marginally poorer accuracy in event times (sunset/twilight/sunrise; moonrise/moonset).
UPDATE: Jul 2021
The PDF filenames have been revised:
One command line argument may be appended to the run command:
de430t and de440 ephemerides have been added to config.py.
UPDATE: Nov 2021
Increased accuracy due to the following minor improvements:
The PDF filenames have been revised (again):
BUGFIX (solved here and in PyPI sfalmanac 1.6.1):
The first day in a Nautical Almanac did not initialize the moon state 'above or below horizon' when there was no Moonrise or Moonset at some latitudes on that day in Multiprocessing mode (only).
BUGFIX (solved here and in PyPI sfalmanac 1.6.2):
The Moon Declination on the last hour of the day did not indicate 'N' or 'S' when it had just changed, i.e. since 22h. This rare case occurs, for example, on 14th Jun 2024 and 15th Oct 2024.
BUGFIX (solved here and in PyPI sfalmanac 1.6.3):
Two import statements (essential for Linux and MacOS) were missing.
UPDATE: Apr 2022
Lunar Distance tables have been added as a new option.
Skyfield relies on the IERS, the International Earth Rotation Service, for accurate measurements of UT1 and for the schedule of leap seconds that keeps UTC from straying more than 0.9 seconds away from UT1.
However the IERS server is currently undergoing maintenance and thus unavailable, which causes SFalmanac to fail. This version first tests if the IERS server is available and otherwise downloads the EOP (Earth Orientation Parameters) data from USNO (US Naval Observatory) instead.
BUGFIX: Event Time tables no longer fail on 24.08.2063 (Lower Transit).
UPDATE: May 2022
Lunar Distance charts have been added as a new option to complement the Lunar Distance tables.
SFalmanac in DockerHub has been updated to match this May 2022 release: https://hub.docker.com/r/aendie/sfalmanac
The PDF filenames have been revised (again), where 'A4' (or 'Letter') is the selected papersize:
PATCH1: Sun SD added to Lunar Distance tables when appropriate
UPDATE: Aug 2022
The 'fancyhdr' LaTeX package is now used to format header and footer lines on a page. This is a more professional solution with added features. Footer lines now contain left-, center- and right-justified text.
BUGFIX (solved here and in PyPI sfalmanac 1.9): Previously execution could hang when aborting a multiprocessing task (in nautical.py or eventtables.py) on entering Ctrl-C to kill all processes.
UPDATE: Sep 2022
UPDATE: Oct 2022
BUGFIX (solved here and in PyPI sfalmanac 1.11.2): A Lunar Distance chart can now be created for 19 August 2038
UPDATE: Dec 2022
second ENHANCEMENT/BUGFIX (solved here and in PyPI sfalmanac 1.11.4): New Command Line options:
Using '-dtr', the Moon's hourly d-value is calculated "difference-then-round":
When using the "HMNAO Nautical Almanac"-compatible mode, e.g. with '-nao':
UPDATE: Apr 2023
ENHANCEMENT/BUGFIX (solved here and in PyPI sfalmanac 1.11.5):
UPDATE: Sep 2024
ENHANCEMENT/BUGFIX (solved here and in PyPI sfalmanac 1.12.1):
Some code improvements including code that depends on the Skyfield version installed, e.g. use of ...
Most of the computation is done by the Skyfield astronomical library.
Typesetting is done typically by MiKTeX or TeX Live.
Here are the requirements/recommendations:
If upgrading from an older version of Skyfield to 1.31 or higher, these files may be deleted:
deltat.data and deltat.preds
It is unlikely that the performance improvement with multiprocessing requires specific virtualization settings enabled in the BIOS. (Intel Virtualization Technology or VMM support is not required.) Furthermore Windows 10 Home (without Hyper-V support) is sufficient - Windows 10 Pro/Enterprise/Education is not required. Also Windows 11 Home is sufficient.
Tested on Windows 10 Pro, Version 21H2 with an AMD Ryzen 7 3700X 8-Core Processor
A PDF reader is required, e.g. Adobe Acrobat Reader DC
Install Python 3.11.3 It should be in the system environment variable PATH, e.g.
C:\Python311\Scripts;C:\Python311; .....
Install MiKTeX 22.10 from https://miktex.org/
Run basic-miktex-22.10-x64.exe as administrator
I prefer to install MiKTeX for all users on a private laptop
Reboot the computer to avoid the message:
"- - - Neither TeX Live nor MiKTeX is installed - - -"
When MiKTeX first runs confirm the installation of additional packages.
Run Command Prompt as Administrator, go to your Python folder and execute, e.g.:
cd C:\Python311
python.exe -m pip install --upgrade pip
... for a first install (it's preferable to install wheel first):
pip3 install wheel
pip3 install skyfield
pip3 install pandas
... if already installed, check for upgrades explicitly:
pip3 install --upgrade skyfield pandas
Put the required files for SFalmanac in a new folder, run Command Prompt in that folder and start with:
py -3 sfalmanac.py
If using MiKTeX 21 or higher, executing 'option 6' (Increments and Corrections) will probably fail with
! TeX capacity exceeded, sorry [main memory size=3000000].
To resolve this problem (assuming MiKTeX has been installed for all users),
open a Command Prompt as Administrator and enter:
initexmf --admin --edit-config-file=pdflatex
This opens pdflatex.ini in Notepad. Add the following line:
extra_mem_top = 1000000
and save the file. Problem solved. For more details go here
Ubuntu 18.04 and higher come with Python 3 preinstalled,
however pip may need to be installed:
sudo apt install python3-pip
Install the following TeX Live package:
sudo apt install texlive-latex-extra
Install the required astronomical libraries etc.:
pip3 install wheel
pip3 install skyfield
pip3 install pandas
Put the SFalmanac files in a folder and start with:
python3 sfalmanac.py
Every Mac comes with python preinstalled.
(Please choose this version of SFalmanac if Python 3.* is installed.)
You need to install the Ephem and Skyfield libraries to use SFalmanac.
Type the following commands at the commandline (terminal app):
sudo easy_install pip
pip install wheel
pip install skyfield
pip install pandas
If this command fails, your Mac asks you if you would like to install the header files.
Do so - you do not need to install the full IDE - and try again.
Install TeX/LaTeX from http://www.tug.org/mactex/
Now you are almost ready. Put the SFalmanac files in any directory and start with:
python sfalmanac
or
./sfalmanac