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.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, phi)[source]¶
returns a 3-cartesian unit vector pointing to longitude theta, latitude phi.
The angles are in rad.
- 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'