Skip to content

redplanet.helper_functions.coordinates._plon2slon

_plon2slon(
    plon: float | list | numpy.ndarray,
) -> float | list | numpy.ndarray

Convert positive longitudes (in range [0, 360]) to signed longitudes (in range [-180, 180]). Inputs in range [-180, 0] are returned as is.

Parameters:

Name Type Description Default
plon float | list | np.ndarray

Longitude value(s) in positive format.

required

Returns:

Type Description
float | list | np.ndarray

Converted longitude value(s) in signed format. The return type matches the input type.

Notes

Actual mapping over the full input range:

  • [-180, 180) --> [-180, 180)
  • [180, 360] --> [-180, 0]

Self reminder:

  • Signed longitude [-180, 180] --> Arabia Terra in middle & Hellas on right.
  • Positive longitude [0, 360] --> Olympus Mons in middle & Hellas on left.
Source code in src/redplanet/helper_functions/coordinates.py
def _plon2slon(
    plon: float | list | np.ndarray
) -> float | list | np.ndarray:
    """
    Convert positive longitudes (in range [0, 360]) to signed longitudes (in range [-180, 180]). Inputs in range [-180, 0] are returned as is.

    Parameters
    ----------
    plon : float | list | np.ndarray
        Longitude value(s) in positive format.

    Returns
    -------
    float | list | np.ndarray
        Converted longitude value(s) in signed format. The return type matches the input type.

    Notes
    -----
    Actual mapping over the full input range:

    - [-180, 180) --> [-180, 180)
    - [180, 360]  --> [-180, 0]

    Self reminder:

    - Signed longitude   [-180, 180]  -->  Arabia Terra in middle & Hellas on right.
    - Positive longitude [0, 360]     -->  Olympus Mons in middle & Hellas on left.
    """
    def convert(plon):
        return ((plon - 180) % 360) - 180

    if isinstance(plon, (float, np.ndarray)):
        return convert(plon)
    else:
        return convert(np.array(plon)).tolist()