Skip to content

redplanet.helper_functions.coordinates._slon2plon

_slon2plon(
    slon: float | list | numpy.ndarray,
) -> float | list | numpy.ndarray

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

Parameters:

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

Longitude value(s) in signed format.

required

Returns:

Type Description
float | list | np.ndarray

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

See Also

_plon2slon : Converts positive longitudes to signed longitudes.

Source code in src/redplanet/helper_functions/coordinates.py
def _slon2plon(
    slon: float | list | np.ndarray
) -> float | list | np.ndarray:
    """
    Convert signed longitudes (in range [-180, 180]) to positive longitudes (in range [0, 360]). Inputs in range [180, 360] are returned as is.

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

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

    See Also
    --------
    _plon2slon : Converts positive longitudes to signed longitudes.
    """
    def convert(slon):
        return slon % 360

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