Single Dish Radio Astronomy Software Tools

For an overview of SDRAST and the current status please visit https://sdrast.github.io/.

Todo

Change import * from math to import math.

Math Package

Local mathematical functions in addition to the Python ‘math’ module.

The smoothing functions are adapted from: http://www.swharden.com/blog/2008-11-17-linear-data-smoothing-in-python/

Functions

acos

Return the arc cosine (measured in radians) of x.

acosh

Return the inverse hyperbolic cosine of x.

allan_variance(data)

Computes Allan variance

asin

Return the arc sine (measured in radians) of x.

asinh

Return the inverse hyperbolic sine of x.

atan

Return the arc tangent (measured in radians) of x.

atan2

Return the arc tangent (measured in radians) of y/x.

atanh

Return the inverse hyperbolic tangent of x.

binary_to_decimal(string)

Converts a binary string, sign bit then msb on left, to an integer.

ceil

Return the ceiling of x as an Integral.

copysign

Return a float with the magnitude (absolute value) of x but the sign of y.

cos

Return the cosine of x (measured in radians).

cosh

Return the hyperbolic cosine of x.

decimal_to_binary(integer[, nbits, grouped])

Converts integer to binary string of length nbits, sign bit and then m.s.b.

degrees

Convert angle x from radians to degrees.

erf

Error function at x.

erfc

Complementary error function at x.

exp

Return e raised to the power of x.

expm1

Return exp(x)-1.

fabs

Return the absolute value of the float x.

factorial

Find x!.

floor

Return the floor of x as an Integral.

fmod

Return fmod(x, y), according to platform C.

frexp

Return the mantissa and exponent of x, as pair (m, e).

fsum

Return an accurate floating point sum of values in the iterable seq.

gamma

Gamma function at x.

gaussian(x, mean, stdev)

Un-normalized gaussian

gcd

greatest common divisor of x and y

group_variance(data, n_data, n_grps)

Computes the variance of n_data points of data[], averaged in groups of n_grps and returns the variance for these groups

hypot

Return the Euclidean distance, sqrt(x*x + y*y).

isclose

Determine whether two floating point numbers are close in value.

isfinite

Return True if x is neither an infinity nor a NaN, and False otherwise.

isinf

Return True if x is a positive or negative infinity, and False otherwise.

isnan

Return True if x is a NaN (not a number), and False otherwise.

ldexp

Return x * (2**i).

lgamma

Natural logarithm of absolute value of Gamma function at x.

log(x, [base=math.e])

Return the logarithm of x to the given base.

log10

Return the base 10 logarithm of x.

log1p

Return the natural logarithm of 1+x (base e).

log2

Return the base 2 logarithm of x.

modf

Return the fractional and integer parts of x.

normalized_gaussian(x, mean, stdev)

gaussian function whose area under the curve is unity.

pow

Return x**y (x to the power of y).

power_of_2_ge(number)

This finds the integer greater than ‘number’ which is a power of two.

radians

Convert angle x from degrees to radians.

remainder

Difference between x and the closest integer multiple of y.

scaled_gaussian(x, mean, fwhm)

returns a normalized gauusian’s value at x, given the mean and full width at half maximam

sin

Return the sine of x (measured in radians).

sinh

Return the hyperbolic sine of x.

smoothList(datalist[, degree])

Smooth a list of numbers by averaging ‘degree’ samples.

smoothListGaussian(datalist[, degree])

Gaussian data smoothing function.

smoothListTriangle(datalist[, degree])

Smooth a list of numbers by convolving with a triangle.

solid_angle(angle)

Solid angle for a circular pattern

sqrt

Return the square root of x.

tan

Return the tangent of x (measured in radians).

tanh

Return the hyperbolic tangent of x.

trunc

Truncates the Real x to the nearest Integral toward 0.

Math.Bin Module

Binary operations

Example::

In [1]: import Math.Bin as B

In [2]: B.setbit(0,12) Out[2]: 4096

In [3]: “%x” % B.setbit(0,12) Out[3]: ‘1000’

Functions

bitcnt(val)

Counts the number of set bits in the binary value.

clrbit(word, bit)

Clear bit in word (set to 0)

field_mask(bits[, leftshift])

Set a bit mask

get_field(word[, mask])

Extract a value from a range of bits (bit field)

getbit(word, bit)

get the value of bit in word

reverse(x, n)

Reverse the pattern

rol(val, r_bits, max_bits)

ror(val, r_bits, max_bits)

set_field(word, value[, mask])

Set a value into a bit field

setbit(word, bit)

set bit in word to 1

Math.geometry Module

Classes for properties of geometrical objects.

This isn’t exactly difficult math but it illustrates object-oriented programming pretty well.

For simple calculations it isn’t necessary to create instances of the objects. For example:

In [1]: from Math.geometry import *

In [2]: Sphere(6000).area
Out[2]: 452389342.11693019

In [3]: Sphere(6000).horizon(0.01)
Out[3]: 10.95443745708116

Sometimes, an instance is useful though:

In [4]: s = Sphere(6000)

In [5]: r = s.horizon(300)

In [6]: visible_fraction = Circle(r).area/s.area

In [7]: visible_fraction
Out[7]: 0.023242630385487552

Classes

Circle(radius)

Circle, a subclass of Circular()

Circular(radius)

Superclass for circular objects, like Circle() and Sphere()

Sphere(radius)

Sphere, a subclass of Circular()

Class Inheritance Diagram

Inheritance diagram of Math.geometry.Circle, Math.geometry.Circular, Math.geometry.Sphere

Math.least_squares Module

leastsq_support - short-cuts for scipy.optimize.leastsq

Functions

factorial

Find x!.

fit_gaussian(error_function, initial_guess, x, y)

Invoke least squares fit to a Gaussian function

gaussian(x, p)

Gaussian function

gaussian_error_function(p, x, y)

Difference between model and actual data

leastsq(func, x0[, args, Dfun, full_output, …])

Minimize the sum of squares of a set of equations.

log(x, [base=math.e])

Return the logarithm of x to the given base.

savitzky_golay(y, window_size, order[, …])

Smooth (and optionally differentiate) data with a Savitzky-Golay filter.

savitzky_golay_piecewise(xvals, data[, …])

In cyclic voltammetry, voltage (being the abcissa) changes like a triangle wave.

simple_gaussian(x, p)

un-normalized gaussian for fitting

sqrt

Return the square root of x.

st_dev(width_half_max)

Standard deviation from Gaussian full width at half maxiuam

width_half_max(st_dev)

Gaussian full width at half maximum from standard deviation

Math.multigauss Module

Functions

MMgauss(x, pos, std, *args)

A form of ‘multigauss’ that curfit can use.

gaussian(x, mean, stdev)

Un-normalized gaussian

multigaussian(x, pos, std, *args)

Returns the value of the sum of multiple Gaussians.

Math.statistics Module

Allan variance

not yet tested since bug fixes - tbhk 2007-10-12

Functions

allan_variance(data)

Computes Allan variance

group_variance(data, n_data, n_grps)

Computes the variance of n_data points of data[], averaged in groups of n_grps and returns the variance for these groups

Indices and tables