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: 23.06.23

Functions
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`. |
iscomplex(obj) Check whether an object is a `complex` or complex `str`. |
isfloat(obj) Check whether an object is a `float` or float `str`. |
isidentifier(obj) Return `True` if `obj` is a Python identifier. |
isinstanceof(obj, *classes) Check an instance of one or several `classes`. |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
iskeyword(x, y) y in x. |
islistuple(obj, minum=0) Check for list or tuple `type` with a minumal length. |
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). |
len2(items) Make built-in function `len` work for generators, iterators, etc. |
map1(fun1, *xs) Apply each `xs` 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 `xs` with neg. |
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) Unsign if `0.0`. |

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 a `complex` or complex `str`. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `complex`, otherwise `False`.

### 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`, otherwise `False`.

### isinstanceof (obj, *classes) |
Check an instance of one or several `classes`. Arguments: `obj` - The instance (`any`). `classes` - One or more classes (`class`). Returns: `True` if `obj` is in instance of one of the `classes`.

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

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

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

### 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 `xs` 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 `xs` with neg. Returns: A `map(neg, 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) |
Unsign if `0.0`. Returns: `x` if `x` else `0.0`.