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

# Module basics

Basic constants, definitions and functions.

Version: 20.04.12

Classes
| LenError Error raised for mis-matching `len` values.
| LimitError Error raised for lat- or longitudinal deltas exceeding the `limit` in functions equirectangular and equirectangular_ and `nearestOn*` and `simplify*` functions or methods.
| RangeError Error raised for lat- or longitude values outside the `clip`, `clipLat`, `clipLon` or `limit` range in function clipDMS, parse3llh, parseDMS or parseDMS2.
| 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. |
InvalidError(**name_value_Error) Create a `ValueError` for an invalid `name=value`. |
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. |
IsnotError(*noun_s, **name_value_Error) Create a `TypeError` for an invalid `name=value` type. |
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. |
limiterrors(raiser=None) Get/set the raising of LimitErrors. |
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. |
rangerrors(raiser=None) Get/set the raising of RangeErrors. |
scalar(value, low=2.22044604925e-16, high=1.0, name=`'``scalar``'`, Error=<type 'exceptions.ValueError'>) Validate a scalar. |

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

### InvalidError (**name_value_Error) |
Create a `ValueError` for an invalid `name=value`. Arguments: `name_value_Error` - One `name=value` pair and optionally an `Error=...` keyword argument to override the default `Error=ValueError`. Returns: A `ValueError` or an `Error` instance.

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

### IsnotError (*noun_s, **name_value_Error) |
Create a `TypeError` for an invalid `name=value` type. Arguments: `noun_s` - One or more expected class or type names, usually nouns (`str`). `name_value_Error` - One `name=value` pair and optionally an `Error=...` keyword argument to override the default `Error=TypeError`. Returns: A `TypeError` or an `Error` instance.

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

### limiterrors (raiser=None) |
Get/set the raising of LimitErrors. Arguments: `raiser` - Choose `True` to raise or `False` to ignore LimitError exceptions. Use `None` to leave the setting unchanged. Returns: Previous setting (`bool`).

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

### rangerrors (raiser=None) |
Get/set the raising of RangeErrors. Arguments: `raiser` - Choose `True` to raise or `False` to ignore RangeError exceptions. Use `None` to leave the setting unchanged. Returns: Previous setting (`bool`).

### scalar (value, low=2.22044604925e-16, high=1.0, name=`'``scalar``'`, Error=<type 'exceptions.ValueError'>) |
Validate a scalar. Arguments: `value` - The value (`scalar`). `low` - Optional lower bound (`scalar`). `high` - Optional upper bound (`scalar`). `name` - Optional name of value (`str`). `Error` - Exception to raise (`ValueError`). Returns: New value (`type` of `low`). Raises: `TypeError` - Non-scalar `value`. `Error` - Out-of-bounds `value`.