Skip to main content

Algorithms from Practical Astronomy, implemented in Python

Project description

practical-astronomy-python

Algorithms from "Practical Astronomy with your Calculator or Spreadsheet" by Peter Duffett-Smith, implemented in Python 3. API documentation is published here.

If you're interested in this topic, please buy the book! It provides far more detail and context.

CLI

Work is started on a command-line interface, but only the date/time functions are implemented, so far. Results are formatted as JSON.

Invoke as ./pa-cli.py -h to see all of the options:

$ ./pa-cli.py -h

usage: pa-cli.py [-h] [--cd CD] [--ct CT] [--dh DH] [--gd GD] [--gl GL] [--gst GST] [--lst LST] [--jd JD] [--ut UT] [--year YEAR] [--dst] [--st] [--zc ZC] [--doe] [--cd_to_dn] [--gd_to_jd] [--jd_to_gd] [--ct_to_dh] [--dh_to_ct] [--lct_to_ut] [--ut_to_lct] [--ut_to_gst] [--gst_to_ut] [--gst_to_lst] [--lst_to_gst]

Practical Astronomy CLI.

optional arguments:
  -h, --help    show this help message and exit

Actions:
  --doe         Calculate date of Easter, for a given year.
  --cd_to_dn    Convert civil date to day number.
  --gd_to_jd    Convert Greenwich date to Julian date.
  --jd_to_gd    Convert Julian date to Greenwich date.
  --ct_to_dh    Convert civil time to decimal hours.
  --dh_to_ct    Convert decimal hours to civil time.
  --lct_to_ut   Convert local civil time to universal time.
  --ut_to_lct   Convert universal time to local civil time.
  --ut_to_gst   Convert universal time to Greenwich sidereal time.
  --gst_to_ut   Convert Greenwich sidereal time to universal time.
  --gst_to_lst  Convert Greenwich sidereal time to local sidereal time.
  --lst_to_gst  Convert local sidereal time to Greenwich sidereal time.

Inputs (used by Actions):
  --cd CD       Civil date. Input format: 'mm/dd/yyyy'
  --ct CT       Civil time. Input format: 'hh:mm:ss'
  --dh DH       Decimal hours. Input format: floating point number, e.g., 18.52416667
  --gd GD       Greenwich date. Input format: 'mm/dd/yyyy'. Fractional day is allowed, e.g., '6/19.75/2009'
  --gl GL       Geographical longitude. Input format: (+/-)##.##, e.g., -64.00
  --gst GST     Greenwich sidereal time. Input format: 'hh:mm:ss'
  --lst LST     Local sidereal time. Input format: 'hh:mm:ss'
  --jd JD       Julian date. Input format: floating point number, e.g., 2455002.25
  --ut UT       Universal time. Input format: 'hh:mm:ss'
  --year YEAR   Calendar year, e.g. 2019.

Inputs (time zone management):
  --dst         Observe daylight savings time.
  --st          Observe standard time (default)
  --zc ZC       Offset, in hours, for time zone correction.

Example

Convert universal time to Greenwich sidereal time:

$./pa-cli.py --ut_to_gst --ut "14:36:51.67" --gd "4/22/1980"

{"greenwichSiderealTimeHours": 4, "greenwichSiderealTimeMinutes": 40, "greenwichSiderealTimeSeconds": 5.23}

Unit Tests

Unit test run can be invoked via the Make utility:

make all

Library Functions

Date/Time

Type Description
Calculate Date of Easter
Convert Civil Date to Day Number
Convert Greenwich Date <-> Julian Date
Convert Julian Date to Day-of-Week
Extract Day, Month, and Year parts of Julian Date
Convert Civil Time <-> Decimal Hours
Extract Hour, Minutes, and Seconds parts of Decimal Hours
Convert Local Civil Time <-> Universal Time
Convert Universal Time <-> Greenwich Sidereal Time
Convert Greenwich Sidereal Time <-> Local Sidereal Time

Coordinates

Type Description
Convert Angle <-> Decimal Degrees
Convert Right Ascension <-> Hour Angle
Convert Equatorial Coordinates <-> Horizon Coordinates
Calculate Obliquity of the Ecliptic
Convert Ecliptic Coordinates <-> Equatorial Coordinates
Convert Equatorial Coordinates <-> Galactic Coordinates
Calculate Angle between two objects
Calculate Rising and Setting times for an object
Calculate Precession (corrected coordinates between two epochs)
Calculate Nutation (in ecliptic longitude and obliquity) for a Greenwich date
Calculate Effects of aberration for ecliptic coordinates
Calculate RA and Declination values, corrected for atmospheric refraction and geocentric parallax
Calculate Heliographic coordinates
Calculate Carrington rotation number
Calculate Selenographic (lunar) coordinates (sub-Earth and sub-Solar)

The Sun

Type Description
Calculate Approximate and precise positions of the Sun
Calculate Sun's distance and angular size
Calculate Local sunrise and sunset
Calculate Morning and evening twilight
Calculate Equation of time
Calculate Solar elongation

Planets

Type Description
Calculate Approximate and precise position of planet
Calculate Visual aspects of planet (distance, angular diameter, phase, light time, position angle of bright limb, and apparent magnitude)
Calculate Position of comet (elliptical and parabolic)
Calculate Binary star orbit data

The Moon

Type Description
Calculate Approximate and precise position of Moon
Calculate Moon phase and position angle of bright limb
Calculate Times of new Moon and full Moon
Calculate Moon's distance, angular diameter, and horizontal parallax
Calculate Local moonrise and moonset

Eclipses

Type Description
Calculate Lunar eclipse occurrence and circumstances
Calculate Solar eclipse occurrence and circumstances

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

practical_astronomy-0.0.1.tar.gz (295.2 kB view details)

Uploaded Source

Built Distribution

practical_astronomy-0.0.1-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file practical_astronomy-0.0.1.tar.gz.

File metadata

  • Download URL: practical_astronomy-0.0.1.tar.gz
  • Upload date:
  • Size: 295.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for practical_astronomy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0148a3bd5607ec8c0be9b85e35ac96c589063d3e6e57d4e82f476322f3280153
MD5 a8a4d17b9f30e4b082a0d0857db4d3d6
BLAKE2b-256 6ca28ab49913f24d8565a1f0f43405665dbde4df68fc925e8bf101bb940624b0

See more details on using hashes here.

File details

Details for the file practical_astronomy-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for practical_astronomy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 11d3e2ecae9f21b078611dfab25e8b812d761d577c84f73d1cd2fc8a4ed2f58f
MD5 7be89a47378935fdebb86274c43eda3f
BLAKE2b-256 284dbaa1c70c01a79638cdbf5efb9af97525eccf0e17a2b55bd8e8e9dfd4ea39

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page