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

Functions
 
str2ub(arg)
(INTERNAL) Helper, no-op.
 
ub2str(arg)
(INTERNAL) Helper, no-op.
 
clips(sb, limit=50, white='', length=False)
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)
Is object a boolean?
 
isCartesian(obj, ellipsoidal=None)
Is object some Cartesian?
 
isclass(obj)
Is object a Class or type?
 
iscomplex(obj, both=False)
Is object a complex or complex literal str?
 
isDEPRECATED(obj)
Is object a DEPRECATED class, method or function?
 
isfloat(obj, both=False)
Is object a float or float literal str?
 
isidentifier(obj)
Is object a Python identifier?
 
isinstanceof(obj, *Classes)
Is object an instance of one of the Classes?
 
isint(obj, both=False)
Is object an int or integer float value?
 
isiterable(obj)
Is object iterable?
 
isiterablen(obj)
Is object iterable and has length?
 
iskeyword(x, y)
y in x.
 
isLatLon(obj, ellipsoidal=None)
Is object some LatLon?
 
islistuple(obj, minum=0)
Is object a list or tuple with non-zero length?
 
isNvector(obj, ellipsoidal=None)
Is object some Nvector?
 
isodd(x)
Is x odd?
 
isscalar(obj, both=False)
Is object an int or integer float value?
 
issequence(obj, *excls)
Is object some sequence type?
 
isstr(obj)
Is object some string type?
 
issubclassof(Sub, *Supers)
Is Sub a class and sub-class of some other class(es)?
 
itemsorted(adict, *items_args, **asorted_reverse)
Return the items of adict sorted alphabetically, case-insensitively and in ascending order.
 
len2(items)
Make built-in function len work for generators, iterators, etc.
 
map1(fun1, *xs)
Call a single-argument function to each xs and return a tuple of results.
 
map2(fun, *xs)
Like Python's map but returning a tuple of results.
 
neg(x, neg0=None)
Negate x and optionally, negate 0.0 and -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='', length=False)

 

Clip a string to the given length limit.

Arguments:
  • sb - String (str or bytes).
  • limit - Length limit (int).
  • white - Optionally, replace all whitespace (str).
  • length - If True, append the original [length] (bool).
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)

 

Is object a boolean?

Arguments:
  • obj - The object (any type).
Returns:
True if boolean, False otherwise.

isCartesian (obj, ellipsoidal=None)

 

Is object 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 a Cartesian of the required type, False if a Cartesian of an other type or {None} otherwise.

iscomplex (obj, both=False)

 

Is object a complex or complex literal str?

Arguments:
  • obj - The object (any type).
  • both - If True, check complex str (bool).
Returns:
True if complex, False otherwise.

isDEPRECATED (obj)

 

Is object a DEPRECATED class, method or function?

Returns:
True if DEPRECATED, {False} if not or None if undetermined.

isfloat (obj, both=False)

 

Is object a float or float literal str?

Arguments:
  • obj - The object (any type).
  • both - If True, check float str (bool).
Returns:
True if float, False otherwise.

isinstanceof (obj, *Classes)

 

Is object an instance of one of the Classes?

Arguments:
  • obj - The object (any type).
  • Classes - One or more classes (Class).
Returns:
type(obj if one of the Classes, None otherwise.

isint (obj, both=False)

 

Is object an int or integer float value?

Arguments:
  • obj - The object (any type).
  • both - If True, check float and Fsum type and value (bool).
Returns:
True if int or integer float or Fsum, False otherwise.

Note: Both isint(True) and isint(False) return False (and no longer True).

isiterable (obj)

 

Is object iterable?

Arguments:
  • obj - The object (any type).
Returns:
True if iterable, False otherwise.

isiterablen (obj)

 

Is object iterable and has length?

Arguments:
  • obj - The object (any type).
Returns:
True if iterable with length, False otherwise.

isLatLon (obj, ellipsoidal=None)

 

Is object 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 a LatLon of the required type, False if a LatLon of an other type or {None} otherwise.

islistuple (obj, minum=0)

 

Is object a list or tuple with non-zero length?

Arguments:
  • obj - The object (any type).
  • minum - Minimal len required C({int}).
Returns:
True if a list or tuple with len at least minum, False otherwise.

isNvector (obj, ellipsoidal=None)

 

Is object 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 an Nvector 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 odd, False otherwise.

isscalar (obj, both=False)

 

Is object an int or integer float value?

Arguments:
  • obj - The object (any type).
  • both - If True, check Fsum and Fsum2Tuple residuals.
Returns:
True if int, float or Fsum/-2Tuple with zero residual, False otherwise.

issequence (obj, *excls)

 

Is object some sequence type?

Arguments:
  • obj - The object (any type).
  • excls - Classes to exclude (type), all positional.
Returns:
True if a sequence, False otherwise.

Note: Excluding tuple implies excluding namedtuple.

isstr (obj)

 

Is object some string type?

Arguments:
  • obj - The object (any type).
Returns:
True if a str, bytes, ..., False otherwise.

issubclassof (Sub, *Supers)

 

Is Sub a class and sub-class of some other class(es)?

Arguments:
  • Sub - The sub-class (Class).
  • Supers - One or more C(super) classes (Class).
Returns:
True if a sub-class of any Supers, False if not (bool) or None if not a class or if no Supers are given or none of those are a class.

itemsorted (adict, *items_args, **asorted_reverse)

 

Return the items of adict sorted alphabetically, case-insensitively and in ascending order.

Arguments:
  • items_args - Optional positional argument(s) for method adict.items(B*{items_args}).
  • asorted_reverse - Use asorted=False for alphabetical, case-sensitive sorting and reverse=True for sorting in descending order.

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)

 

Call a single-argument function to each xs and return a tuple of results.

Arguments:
  • fun1 - 1-Arg function (callable).
  • xs - Arguments (any positional).
Returns:
Function results (tuple).

map2 (fun, *xs)

 

Like Python's map but returning 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:
  • fun - Function (callable).
  • xs - Arguments (all positional).
Returns:
Function results (tuple).

neg (x, neg0=None)

 

Negate x and optionally, negate 0.0 and -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.