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

# Module basics

Basic constants, definitions and functions.

Version: 20.08.08

Classes
| property_RO

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. |
halfs2(str2) Split a string in 2 halfs. |
isfinite(obj) Check for `Inf` and `NaN` values. |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
isneg0(obj) Check for NEG0, negative 0.0. |
isscalar(obj) Check for scalar types. |
issequence(obj, *excluded) Check for sequence types. |
isstr(obj) Check for string types. |
issubclassof(Sub, Super) Check whether a class is a sub-class of a super class. |
len2(items) Make built-in function `len` work for generators, iterators, etc. |
map1(func, *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. |
property_doc_(doc) Decorator for a property with documentation. |

Variables
| PI = `3.14159265359`
| __all__ = `_ALL_LAZY.basics`
| EPS = `2.22044604925e-16` Epsilon (`float`) 2**-52?
| MANTIS = `53` Mantissa bits ≈53 (`int`)
| MAX = `1.79769313486e+308` Float max (`float`) ≈10**308, 2**1024?
| MIN = `2.22507385851e-308` System's float min (`float`)
| EPS_2 = `1.11022302463e-16` EPS / 2 ≈1.110223024625e-16 (`float`)
| EPS1 = `1.0` 1 - EPS ≈0.9999999999999998 (`float`)
| EPS1_2 = `1.0` 1 - EPS_2 ≈0.9999999999999999 (`float`)
| INF = `inf` Infinity (`float`), see function `isinf`, `isfinite`
| NAN = `nan` Not-A-Number (`float`), see function `isnan`
| NEG0 = `-0.0` Negative 0.0 (`float`), see function `isneg0`
| PI2 = `6.28318530718` Two PI, PI * 2 aka Tau (`float`) # PYCHOK expected
| PI_2 = `1.57079632679` Half PI, PI / 2 (`float`)
| PI_4 = `0.785398163397` Quarter PI, PI / 4 (`float`)
| R_M = `6371008.77141` Mean, spherical earth radius (`meter`).

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

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

### 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` - Optionally, check `float` type and value (`bool`). Returns: `True` if `obj` is `int` or an integer `float`, `False` otherwise.

### isneg0 (obj) |
Check for NEG0, negative 0.0. Arguments: `obj` - Value (`scalar`). Returns: `True` if `obj` is `NEG0` or -0.0, `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, Super) |
Check whether a class is a sub-class of a super class. Arguments: `Sub` - The sub-class (`class`). `Super` - The super class (`class`). Returns: `True` if `Sub` is a sub-class of `Super`, `False` otherwise (`bool`).

### 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 (func, *xs) |
Apply each argument to a single-argument function and return a `tuple` of results. Arguments: `func` - 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 Python 2 behavior. Arguments: `func` - Function to apply (`callable`). `xs` - Arguments to apply (`list, tuple, ...`). Returns: Function results (`tuple`).

### property_doc_ (doc) |
Decorator for a property with documentation. Arguments: `doc` - The property documentation (`str`). Example:
    >>> @property_doc_("documentation text.")
    >>> def name(self):
    >>>     ...
    >>>
    >>> @name.setter
    >>> def name(self, value):
    >>>     ...