gavo.utils.mathtricks module

Math-related helper functions.

class gavo.utils.mathtricks.Matrix3(row1, row2, row3)[source]

Bases: object

A quick and easy 3d matrix.

This is just so we don’t depend on numpy for trivial stuff. The components are stored in a tuple of rows.

getColumns()[source]

returns the column vectors of this matrix in a 3-tuple.

indices = [0, 1, 2]
matMul(mat)[source]

returns the result of multiplying mat to self from the right.

vecMul(vec)[source]

returns the result of right-multiplying self to vec.

The sequence vec is interpreted as a column vector.

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.crossprod3(seq1, seq2)[source]
gavo.utils.mathtricks.dotprod3(seq1, seq2, inds=(0, 1, 2))[source]
gavo.utils.mathtricks.findMinimum(f, left, right, minInterval=3e-08)[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.

class gavo.utils.mathtricks.getHexToBin(arg)[source]

Bases: gavo.utils.codetricks.CachedResource

returns a dictionary mapping hex chars to their binary expansions.

classmethod impl()[source]
gavo.utils.mathtricks.getRotX(angle)[source]

returns a 3-rotation matrix for rotating angle radians around x.

gavo.utils.mathtricks.getRotZ(angle)[source]

returns a 3-rotation matrix for rotating angle radians around z.

gavo.utils.mathtricks.normalize3(vec)[source]
gavo.utils.mathtricks.roundO2M(num)[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.spherDist(vec1, vec2)[source]

returns the spherical distance (in radian) between the unit vectors vec1 and vec2.

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, desiredLength=None)[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'