cratermaker.utils.general_utils.normalize_coords

cratermaker.utils.general_utils.normalize_coords#

cratermaker.utils.general_utils.normalize_coords(location)[source]#

Normalize geographic coordinates to ensure longitude is within [-180, 180) degrees and latitude within [-90, 90] degrees.

This function takes a tuple of longitude and latitude values in degrees, normalizes them to the specified ranges, and handles cases where latitude values exceed the polar extremes, adjusting both latitude and longitude accordingly.

Parameters:

location (tuple) – A tuple containing two elements: (longitude, latitude) in degrees. Longitude and latitude can be any float values.

Returns:

tuple – A tuple of two elements: (normalized_longitude, normalized_latitude). The normalized longitude is in the range [-180, 180) degrees, and the normalized latitude is in the range [-90, 90] degrees.

Notes

  • The longitude is normalized using a modulo operation with 360 degrees and then adjusted to the range [-180, 180).

  • Latitude values beyond 90 or below -90 degrees are adjusted by reflecting them within the range and flipping the longitude by 180 degrees, then re-normalizing it to the [-180, 180) range.

Examples

>>> normalize_coords((370, 95))
(10.0, 85.0)
>>> normalize_coords((-185, -100))
(-5.0, 80.0)