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

Functions
str2ub(arg) (INTERNAL) Helper, no-op. |
ub2str(arg) (INTERNAL) Helper, no-op. |
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. |
int1s(x) Count the number of 1-bits in an `int`, unsigned. |
isbool(obj) Check whether an object is `bool`ean. |
isclass(obj) Return `True` if `obj` is a `class` or `type`. |
isCartesian(obj, ellipsoidal=None) Is `obj` some `Cartesian`? |
iscomplex(obj) Check whether an object is a `complex` or complex `str`. |
isDEPRECATED(obj) Return `True` if `obj` is a `DEPRECATED` class, method or function, `False` if not or `None` if undetermined. |
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) Is `ob` an intance of one of the `classes`? |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
iskeyword(x, y) y in x. |
isLatLon(obj, ellipsoidal=None) Is `obj` some `LatLon`? |
islistuple(obj, minum=0) Check for list or tuple `type` with a minumal length. |
isNvector(obj, ellipsoidal=None) Is `obj` some `Nvector`? |
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, neg0=None) Negate `x` and optionally, negate `0.0` amd `-0.0`. |
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)`.

### int1s (x) |
Count the number of 1-bits in an `int`, unsigned. Note: `int1s(-x) == int1s(abs(x))`.

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

### isCartesian (obj, ellipsoidal=None) |
Is `obj` some `Cartesian`? Arguments: `obj` - The object (any `type`). `ellipsoidal` - If `None`, return the type of any `Cartesian`, if `True`, only an ellipsoidal `Cartesian type` or if `False`, only a spherical `Cartesian type`. Returns: `type(obj` if `obj` is a `Cartesian` instance of the required type, `False` if a `Cartesian` of an other type or `None` otherwise.

### 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) |
Is `ob` an intance of one of the `classes`? Arguments: `obj` - The instance (any `type`). `classes` - One or more classes (`class`). Returns: `type(obj` if `obj` is an instance of the `classes`, `None` 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`).

### isLatLon (obj, ellipsoidal=None) |
Is `obj` some `LatLon`? Arguments: `obj` - The object (any `type`). `ellipsoidal` - If `None`, return the type of any `LatLon`, if `True`, only an ellipsoidal `LatLon type` or if `False`, only a spherical `LatLon type`. Returns: `type(obj` if `obj` is a `LatLon` instance of the required type, `False` if a `LatLon` of an other type or {None} otherwise.

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

### isNvector (obj, ellipsoidal=None) |
Is `obj` some `Nvector`? Arguments: `obj` - The object (any `type`). `ellipsoidal` - If `None`, return the type of any `Nvector`, if `True`, only an ellipsoidal `Nvector type` or if `False`, only a spherical `Nvector type`. Returns: `type(obj` if `obj` is an `Nvector` instance of the required type, `False` if an `Nvector` of an other type or {None} 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, neg0=None) |
Negate `x` and optionally, negate `0.0` amd `-0.0`. Arguments: `neg0` - Defines the return value for zero `x`: if `None` return `0.0`, if `True` return `NEG0 if x=0.0` and `0.0 if x=NEG0` or if `False` return `x` as-is (`bool` or `None`). Returns: `-x if x else 0.0, NEG0 or x`.

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