data0.latlon
Functions
|
Shift the given longitude value between ranges [0, 360] and [-180, 180]. |
|
Shift the given array of longitude values between ranges [0, 360] and [-180, 180]. |
Module Contents
- data0.latlon.shift_lon(lon_value, PM_centered=True)
Shift the given longitude value between ranges [0, 360] and [-180, 180].
If the Prime Meridian is centered and the longitude value is in the range [0, 360], shift it to the range [-180, 180]. If the Prime Meridian is not centered (i.e. the International Date Line is centered) and the longitude value is in the range [-180, 180], shift it to the range [0, 360]. Otherwise, return the same value. If the longitude value is not a number or is NaN, or is outside the relevant range for the specified PM_centered, raise a ValueError.
- Parameters:
lon_value (float) – The longitude value to shift.
PM_centered (bool, optional) – If True, shift the longitude value from the range [0, 360] to [-180, 180]. If False, shift from [-180, 180] to [0, 360]. Defaults to True.
- Returns:
lon_value – The shifted longitude value.
- Return type:
float
Examples
>>> lon_value = shift_lon(45.0, PM_centered=True) 45.0 >>> lon_value = shift_lon(270.0, PM_centered=True) -90.0 >>> lon_value = shift_lon(-70.0, PM_centered=False) 290.0 >>> lon_value = shift_lon(200.0, PM_centered=False) 200.0
- data0.latlon.shift_lon_arr(in_array, **kwargs)
Shift the given array of longitude values between ranges [0, 360] and [-180, 180].
Map the shift_lon function to shift each value in the array.
- Parameters:
in_array (numpy.ndarray or xarray.Dataset) – The array of longitude values to shift.
**kwargs (keyword arguments) – Additional keyword arguments to pass to shift_lon().
- Returns:
The shifted longitude values in the range [-180, 180].
- Return type:
numpy.ndarray or xarray.Dataset
Examples
>>> in_array = np.array([0, 90, 180, 270, 360]) >>> shifted_lon = shift_lon_arr(in_array) array([0, 90, 180, -90, 0])
>>> xarray_dataset.coords['lon'].values array([ 0. , 1.125, 2.25 , ... 357.75 , 358.875], dtype=float32) >>> xarray_dataset = shift_lon_arr(xarray_dataset) >>> xarray_dataset.coords['lon'].values array([ 0. , 1.125, 2.25 , ... -2.25 , -1.125], dtype=float32)