gavo.utils.mathtricks module¶
Math-related helper functions.
- gavo.utils.mathtricks.cartToSpher(unitvector)[source]¶
returns spherical coordinates for a 3-unit vector.
We do not check if unitvector actually is a unit vector. The returned angles are in rad.
- gavo.utils.mathtricks.ceilInt(flt: float) float [source]¶
returns the smallest integer largest than flt, except if flt is a special float, in which case flt is returned.
- gavo.utils.mathtricks.findMinimum(f: Callable[[float], float], left: float, right: float, minInterval: float = 3e-08) float [source]¶
returns an estimate for the minimum of the single-argument function f on (left,right).
minInterval is a fourth of the smallest test interval considered.
For constant functions, a value close to left will be returned.
This function should only be used on functions having exactly one minimum in the interval.
- gavo.utils.mathtricks.floorInt(flt: float) float [source]¶
returns the largest integer smaller than flt, except if flt is a special float, in which case flt is returned.
- gavo.utils.mathtricks.getHexToBin() Dict[str, str] [source]¶
returns a dictionary mapping hex chars to their binary expansions.
- gavo.utils.mathtricks.getRotX(angle)[source]¶
returns a 3-rotation matrix for rotating angle radians around x.
- gavo.utils.mathtricks.getRotY(angle)[source]¶
returns a 3-rotation matrix for rotating angle radians around y.
- gavo.utils.mathtricks.getRotZ(angle)[source]¶
returns a 3-rotation matrix for rotating angle radians around z.
- gavo.utils.mathtricks.nprepr(npobj: Union[int, float, float64, ndarray[Any, dtype[ScalarType]]])[source]¶
formats a simple numpy array of value avoiding excessive digits.
This, realistically, is mainly for doctests.
- gavo.utils.mathtricks.roundO2M(num: float) int [source]¶
returns a plausible rounding of num.
This will round up the last couple of digits. For now, this will only do cardinals. >>> roundO2M(0) 0 >>> roundO2M(2.5) 2 >>> roundO2M(15) 20 >>> roundO2M(9900) 10000 >>> roundO2M(8321) 8400 >>> roundO2M(3.2349302e9) 3300000000
- gavo.utils.mathtricks.spherToCart(theta: Union[int, float, float64], phi: Union[int, float, float64]) ndarray[Any, dtype[ScalarType]] [source]¶
returns a 3-cartesian unit vector pointing to longitude theta, latitude phi.
The angles are in rad.
>>> print(spherToCart(0,0)) [1. 0. 0.] >>> nprepr(spherToCart(0, 90*DEG)) '[6.123e-17 0 1]' >>> nprepr(spherToCart(90*DEG, 90*DEG)) '[3.749e-33 6.123e-17 1]' >>> nprepr(spherToCart(90*DEG, 0)) '[6.123e-17 1 0]' >>> nprepr(spherToCart(180*DEG, -45*DEG)) '[-0.7071 8.66e-17 -0.7071]'
- gavo.utils.mathtricks.toBinary(anInt: int, desiredLength: Optional[int] = None) str [source]¶
returns anInt as a string with its binary digits, MSB first.
If desiredLength is given and the binary expansion is shorter, the value will be padded with zeros.
>>> toBinary(349) '101011101' >>> toBinary(349, 10) '0101011101'