Package pygeodesy :: Module basics |
[frames] | no frames]

# Module basics

Some, basic definitions and functions.

Version: 22.03.28

Functions
bool |
isinf(x) Check if float x is infinite (positive or negative). |
bool |
isnan(x) Check if float x is not a number (NaN). |
clips(bstr, limit=50, white='') Clip a string to the given length limit. |
copysign0(x, y) Like `math.copysign(x, y)` except `zero`, unsigned. |
copytype(x, y) Return the value of x as `type` of `y`. |
halfs2(str2) Split a string in 2 halfs. |
isbool(obj) Check whether an object is `bool`ean. |
isclass(obj) Return `True` if `obj` is a `class`. |
iscomplex(obj) Check whether an object is `complex`. |
isfinite(obj) Check for `Inf` and `NaN` values. |
isidentifier(obj) Return `True` if `obj` is a valid Python identifier. |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
iskeyword(x, y) y in x. |
isnear0(x, eps0=4.93038065763e-32) Is `x` near zero? |
isnear1(x, eps0=4.93038065763e-32) Is `x` near one? |
isneg0(x) Check for NEG0, negative `0.0`. |
isnon0(x, eps0=4.93038065763e-32) Is `x` non-zero? |
isodd(x) Is `x` odd? |
isscalar(obj) Check for scalar types. |
issequence(obj, *excluded) Check for sequence types. |
isstr(obj) Check for string types. |
issubclassof(Sub, *Supers) Check whether a class is a sub-class of some other class(es). |
len2(items) Make built-in function `len` work for generators, iterators, etc. |
map1(fun1, *xs) Apply each argument to a single-argument function and return a `tuple` of results. |
map2(func, *xs) Apply arguments to a function and return a `tuple` of results. |
neg(x) Negate `x` unless `zero` or `NEG0`. |
neg_(*xs) Negate all of `xs` with neg. |
signOf(x) Return sign of `x` as `int`. |
splice(iterable, n=2, **fill) Split an iterable into `n` slices. |
ub2str(ub) Convert `unicode` or `bytes` to `str`. |
unsigned0(x) Return `0.0` unsigned. |

Variables
| __all__ = `_ALL_LAZY.basics`

Function Details

### clips (bstr, limit=50, white='') |
Clip a string to the given length limit. Arguments: `bstr` - String (`bytes` or `str`). `limit` - Length limit (`int`). `white` - Optionally, replace all whitespace (`str`). Returns: The clipped or unclipped `bstr`.

### copysign0 (x, y) |
Like `math.copysign(x, y)` except `zero`, unsigned. Returns: `math.copysign(x, y)` if `x` else `type(x)(0)`.

### copytype (x, y) |
Return the value of x as `type` of `y`. Returns: `type(y)(x)`.

### halfs2 (str2) |
Split a string in 2 halfs. Arguments: `str2` - String to split (`str`). Returns: 2-Tuple (_1st, _2nd) half (`str`). Raises: `ValueError` - Zero or odd `len`(`str2`).

### isbool (obj) |
Check whether an object is `bool`ean. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `bool`ean, `False` otherwise.

### isclass (obj) |
Return `True` if `obj` is a `class`. See Also: Python's `inspect.isclass`.

### iscomplex (obj) |
Check whether an object is `complex`. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `complex`, `False` otherwise.

### isfinite (obj) |
Check for `Inf` and `NaN` values. Arguments: `obj` - Value (`scalar`). Returns: `False` if `obj` is `INF` or `NAN`, `True` otherwise. Raises: `TypeError` - Non-scalar `obj`.

### isint (obj, both=False) |
Check for `int` type or an integer `float` value. Arguments: `obj` - The object (any `type`). `both` - If `true`, check `float` and Fsum type and value (`bool`). Returns: `True` if `obj` is `int` or an integer `float` or Fsum, `False` otherwise. Note: `isint(True)` or `isint(False)` returns `False` (and no longer `True`).

### isnear0 (x, eps0=4.93038065763e-32) |
Is `x` near zero? Arguments: `x` - Value (`scalar`). `eps0` - Near-zero (`EPS0`). Returns: `True` if `abs(x) < eps0`, `False` otherwise. See Also: Function isnon0.

### isnear1 (x, eps0=4.93038065763e-32) |
Is `x` near one? Arguments: `x` - Value (`scalar`). `eps0` - Near-zero (`EPS0`). Returns: `isnear0(x - 1)`. See Also: Function isnear0.

### isneg0 (x) |
Check for NEG0, negative `0.0`. Arguments: `x` - Value (`scalar`). Returns: `True` if `x` is `NEG0` or `-0.0`, `False` otherwise.

### isnon0 (x, eps0=4.93038065763e-32) |
Is `x` non-zero? Arguments: `x` - Value (`scalar`). `eps0` - Near-zero (`EPS0`). Returns: `True` if `abs(x) > eps0`, `False` otherwise. See Also: Function isnear0.

### isodd (x) |
Is `x` odd? Arguments: `x` - Value (`scalar`). Returns: `True` if `x` is odd, `False` otherwise.

### isscalar (obj) |
Check for scalar types. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `scalar`, `False` otherwise.

### issequence (obj, *excluded) |
Check for sequence types. Arguments: `obj` - The object (any `type`). `excluded` - Optional exclusions (`type`). Returns: `True` if `obj` is a sequence, `False` otherwise. Note: Excluding `tuple` implies excluding `namedtuple`.

### isstr (obj) |
Check for string types. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `str`, `False` otherwise.

### issubclassof (Sub, *Supers) |
Check whether a class is a sub-class of some other class(es). Arguments: `Sub` - The sub-class (`class`). `Supers` - One or more C(super) classes (`class`). Returns: `True` if `Sub` is a sub-class of any `Supers`, `False` if not (`bool`) or `None` if `Sub` is not a class or if no `Supers` are given or none of those are a class.

### len2 (items) |
Make built-in function `len` work for generators, iterators, etc. since those can only be started exactly once. Arguments: `items` - Generator, iterator, list, range, tuple, etc. Returns: 2-Tuple `(n, items)` of the number of items (`int`) and the items (`list` or `tuple`).

### map1 (fun1, *xs) |
Apply each argument to a single-argument function and return a `tuple` of results. Arguments: `fun1` - 1-Arg function to apply (`callable`). `xs` - Arguments to apply (`any positional`). Returns: Function results (`tuple`).

### map2 (func, *xs) |
Apply arguments to a function and return a `tuple` of results. Unlike Python 2's built-in `map`, Python 3+ `map` returns a `map` object, an iterator-like object which generates the results only once. Converting the `map` object to a tuple maintains the Python 2 behavior. Arguments: `func` - Function to apply (`callable`). `xs` - Arguments to apply (`list, tuple, ...`). Returns: Function results (`tuple`).

### neg (x) |
Negate `x` unless `zero` or `NEG0`. Returns: `-x` if `x` else `0.0`.

### neg_ (*xs) |
Negate all of `xs` with neg. Returns: A `tuple(neg(x) for x in xs)`.

### signOf (x) |
Return sign of `x` as `int`. Returns: -1, 0 or +1 (`int`).

### splice (iterable, n=2, **fill) |
Split an iterable into `n` slices. Arguments: `iterable` - Items to be spliced (`list`, `tuple`, ...). `n` - Number of slices to generate (`int`). `fill` - Optional fill value for missing items. Returns: A generator for each of `n` slices, iterable[i::n] for i=0..n. Raises: `TypeError` - Invalid `n`. Note: Each generated slice is a `tuple` or a `list`, the latter only if the `iterable` is a `list`. Example:
    >>> from pygeodesy import splice
    >>> a, b = splice(range(10))
    >>> a, b
    ((0, 2, 4, 6, 8), (1, 3, 5, 7, 9))
    >>> a, b, c = splice(range(10), n=3)
    >>> a, b, c
    ((0, 3, 6, 9), (1, 4, 7), (2, 5, 8))
    >>> a, b, c = splice(range(10), n=3, fill=-1)
    >>> a, b, c
    ((0, 3, 6, 9), (1, 4, 7, -1), (2, 5, 8, -1))
    >>> tuple(splice(list(range(9)), n=5))
    ([0, 5], [1, 6], [2, 7], [3, 8], [4])
    >>> splice(range(9), n=1)
    <generator object splice at 0x0...>

### unsigned0 (x) |
Return `0.0` unsigned. Returns: `x` if `x` else `0.0`.