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

# Module basics

Some, basic definitions, functions and dependencies.

Use env variable `PYGEODESY_XPACKAGES` to avoid import of dependencies `geographiclib`, `numpy` and/or `scipy`. Set `PYGEODESY_XPACKAGES` to a comma-separated list of package names to be excluded from import.

Version: 22.08.14

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). |
str2ub(x) NOP, pass thru. |
ub2str(x) NOP, pass thru. |
clips(sb, 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` or `type`. |
isclose(a, b, rel_tol=1e-12, abs_tol=4.93038065763e-32) Like `math.isclose`, but with defaults such that `isclose(0, EPS0)` is `True` by default. |
iscomplex(obj) Check whether an object is `complex`. |
isfinite(obj) Check a finite `scalar` or `complex` value. |
isfloat(obj) Check whether an object is a `float` or float `str`. |
isidentifier(obj) Return `True` if `obj` is a valid Python identifier. |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
isint0(obj, both=False) Check for INT0 or `int(0)` 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`. |
isninf(x) Check for NINF, negative `INF`. |
isnon0(x, eps0=4.93038065763e-32) Is `x` non-zero? |
isodd(x) Is `x` odd? |
isscalar(obj) Check for scalar types. |
issequence(obj, *excls) 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). |
istuplist(obj, minum=0) Check for tuple or list types and minumal length. |
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. |
remainder(x, y) Mimick Python 3.7+ `math.remainder`. |
signBit(x) Return `signbit(x)`, like C++. |
signOf(x) Return sign of `x` as `int`. |
splice(iterable, n=2, **fill) Split an iterable into `n` slices. |
unsigned0(x) Return `0.0` unsigned. |

Variables
| __all__ = `_ALL_LAZY.basics`

Function Details

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

### 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` or `type`. 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 a finite `scalar` or `complex` value. Arguments: `obj` - Value (`scalar` or `complex`). Returns: `False` if `obj` is `INF`, `NINF` or `NAN`, `True` otherwise. Raises: `TypeError` - Non-scalar and non-complex `obj`.

### isfloat (obj) |
Check whether an object is a `float` or float `str`. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is a `float`, `False` otherwise.

### 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 integer `float` or Fsum, `False` otherwise. Note: Both `isint(True)` and `isint(False)` return `False` (and no longer `True`).

### isint0 (obj, both=False) |
Check for INT0 or `int(0)` value. Arguments: `obj` - The object (any `type`). `both` - If `true`, also check `float(0)` (`bool`). Returns: `True` if `obj` is INT0, `int(0)` or `float(0)`, `False` otherwise.

### 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.

### isninf (x) |
Check for NINF, negative `INF`. Arguments: `x` - Value (`scalar`). Returns: `True` if `x` is `NINF` or `-inf`, `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, *excls) |
Check for sequence types. Arguments: `obj` - The object (any `type`). `excls` - Classes to exclude (`type`), all positional. 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.

### istuplist (obj, minum=0) |
Check for tuple or list types and minumal length. Arguments: `obj` - The object (any `type`). `minum` - Minimal `len` required C({int}). Returns: `True` if `obj` is `tuple` or `list` with `len` at least `minum`, `False` otherwise.

### 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)`.

### signBit (x) |
Return `signbit(x)`, like C++. Returns: `True` if `x < 0` or `NEG0` (`bool`).

### 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`.