pycontrails.core.coordinates¶
Coordinates utilities.
Functions
|
Return boolean mask of |
|
Return slice of |
- pycontrails.core.coordinates.intersect_domain(domain, request)¶
Return boolean mask of
requestthat are within the bounds ofdomain.- Parameters:
domain (
numpy.ndarray) – Full set of domain valuesrequest (
numpy.ndarray) – Full set of requested values
- Returns:
numpy.ndarray– Boolean array ofrequestvalues within the bounds ofdomain- Raises:
ValueError – Raises a ValueError when
domainhas allnanvalues.
Examples
>>> domain = np.array([3.0, 4.0, 2.0]) >>> request = np.arange(1.0, 6.0) >>> intersect_domain(domain, request) array([False, True, True, True, False])
>>> domain = np.array([3.0, np.nan, np.nan]) >>> request = np.arange(1.0, 6.0) >>> intersect_domain(domain, request) array([False, False, True, False, False])
- pycontrails.core.coordinates.slice_domain(domain, request, buffer=(0.0, 0.0))¶
Return slice of
domaincontaining coordinates overlappingrequest.Computes index-based slice (to be used with
xarray.Dataset.isel()method) as opposed to value-based slice.Returns
slice(None, None)whendomainhas a length <= 2 or therequesthas allnanvalues.Changed in version 0.24.1: The returned slice is the minimum index-based slice that contains the requested coordinates. In other words, it’s now possible for
domain[sl][0]to equalmin(request)whereslis the output of this function. Previously, we were guaranteed thatdomain[sl][0]would be less thanmin(request).- Parameters:
domain (
numpy.ndarray) – Full set of domain valuesrequest (
npt.ArrayLike) – Requested values. Only the nanmin and nanmax values are considered.buffer (
tuple[float | np.timedelta64,float | np.timedelta64], optional) – Extend the domain past the requested coordinates bybuffer[0]on the low side andbuffer[1]on the high side. Units ofbuffermust be the same asdomain.
- Returns:
slice– Slice object for slicing out encompassing, or nearest, domain values- Raises:
ValueError – Raises a ValueError when
domainhas allnanvalues.
Examples
>>> domain = np.arange(-180, 180, 0.25)
>>> # Call with request as np.array >>> request = np.linspace(-20, 20, 100) >>> slice_domain(domain, request) slice(np.int64(640), np.int64(801), None)
>>> # Call with request as tuple >>> request = -20, 20 >>> slice_domain(domain, request) slice(np.int64(640), np.int64(801), None)
>>> # Call with a buffer >>> request = -16, 13 >>> buffer = 4, 7 >>> slice_domain(domain, request, buffer) slice(np.int64(640), np.int64(801), None)
>>> # Call with request as a single number >>> request = -20 >>> slice_domain(domain, request) slice(np.int64(640), np.int64(641), None)
>>> request = -19.9 >>> slice_domain(domain, request) slice(np.int64(640), np.int64(642), None)