This module contains helper functions used by Apex.

apexpy.helpers.checklat(lat, name='lat')[source]

Makes sure the latitude is inside [-90, 90], clipping close values (tolerance 1e-4).

  • lat (array_like) – latitude
  • name (str, optional) – parameter name to use in the exception message

lat (ndarray or float) – Same as input where values just outside the range have been clipped to [-90, 90]


ValueError – if any values are too far outside the range [-90, 90]


Computes sinIm from modified apex latitude.

Parameters:alat (array_like) – Modified apex latitude
Returns:sinIm (ndarray or float)

Computes cosIm from modified apex latitude.

Parameters:alat (array_like) – Modified apex latitude
Returns:cosIm (ndarray or float)

Converts datetime.date or datetime.datetime to decimal year.

Parameters:date (datetime.date or datetime.datetime)
Returns:year (float) – Decimal year


The algorithm is taken from http://stackoverflow.com/a/6451892/2978652


Converts geocentric latitude to geodetic latitude using WGS84.

Parameters:gclat (array_like) – Geocentric latitude
Returns:gdlat (ndarray or float) – Geodetic latitude

Finds subsolar geocentric latitude and longitude.

Parameters:datetime (datetime.datetime)
  • sbsllat (float) – Latitude of subsolar point
  • sbsllon (float) – Longitude of subsolar point


Based on formulas in Astronomical Almanac for the year 1996, p. C24. (U.S. Government Printing Office, 1994). Usable for years 1601-2100, inclusive. According to the Almanac, results are good to at least 0.01 degree latitude and 0.025 degrees longitude between years 1950 and 2050. Accuracy for other years has not been tested. Every day is assumed to have exactly 86400 seconds; thus leap seconds that sometimes occur on December 31 are ignored (their effect is below the accuracy threshold of the algorithm).

After Fortran code by A. D. Richmond, NCAR. Translated from IDL by K. Laundal.