satsim.math package

Submodules

satsim.math.angle module

satsim.math.angle.diff_degrees(a0, a1, max_diff=180)

Calculates the difference between two angles and accounts for crossover at 0 degrees based on max_diff.

Parameters:
  • a0float, an angle in degrees.

  • a1float, an angle in degrees.

  • max_difffloat, maximum angle difference before concidering the opposite angle. default=180.

Returns:

A float, a1 - a0

satsim.math.angle.interp_degrees(tt, t0, t1, a0, a1, max_diff=180, normalize_360=True)

Interpolate between two angles and accounts for crossover at 0 degrees based on max_diff.

Parameters:
  • ttlist, list of times to interpolate between t0 and t1.

  • t0float, time for a0.

  • t1float, time for a1.

  • a0float, angle in degrees.

  • a1float, angle in degrees.

  • max_difffloat, maximum angle difference before concidering the opposite angle. default=180.

  • normalize_360boolean, normalize angle between 0 and 360. default=True

Returns:

A list, interpolated angles at tt

satsim.math.angle.mean_degrees(a0, a1, max_diff=180, normalize_360=True)

Calculates the mean of two angles and accounts for crossover at 0 degrees based on max_diff.

Parameters:
  • a0float, an angle in degrees.

  • a1float, an angle in degrees.

  • max_difffloat, maximum angle difference before concidering the opposite angle. default=180.

  • normalize_360boolean, normalize angle between 0 and 360. default=True

Returns:

A float, mean of a0 and a1

satsim.math.const module

satsim.math.conv module

satsim.math.conv.conv2(x, y, pad=32, dtype=tf.float32)

Convolve two 2-dimensional arrays with traditional convolution.

Parameters:
  • xTensor, input image as a 2D tensor.

  • yTensor, input kernel as a 2D tensor.

  • dtypedtype, float32, complex64 or complex128

Returns:

A Tensor, The 2D tensor containing the approximate discrete linear convolution of x with y.

satsim.math.fft module

satsim.math.fft.fftconv2(x, y, dtype=tf.complex64)

Convolve two 2-dimensional arrays using FFT. Convolve x and y using the fast Fourier transform method. NOTE: x and y must have the same shape.

Parameters:
  • xTensor, 2D input tensor.

  • yTensor, 2D input tensor of the same shape as x.

  • dtypetf.dtype, tf.complex64 or tf.complex128

Returns:

A Tensor, The 2D tensor containing the discrete linear convolution of x with y.

satsim.math.fft.fftconv2p(x, y, pad=32, dtype=tf.float32, cache_last_y=True)

Convolve two 2-dimensional arrays using FFT. Convolve x and y using the fast Fourier transform method. The result is an approximate for the convolution. If more numeric precision is required, use fftconv2 which pads the array to N + L - 1. NOTE: x and y must have the same shape. NOTE: x and y dimensions should be a multiple of 2.

Parameters:
  • xTensor, 2D input tensor.

  • yTensor, 2D input tensor of the same shape as x.

  • padint, number of pixels to pad all sides before calculating the FFT

  • dtypedtype, float32, complex64 or complex128

  • cache_last_ybool, if True, cache the last y FFT which improves performance if y is static and called multiple times. Note y needs to be a tf.Tensor type if set to True.

Returns:

A Tensor, The 2D tensor containing the approximate discrete linear convolution of x with y.

satsim.math.fft.fftshift(x, dims=2)

Shift the zero-frequency component to the center of the spectrum. This function swaps half-spaces for all axes listed.

Examples:

x = fftshift([ 0.,  1.,  2.,  3.,  4., -5., -4., -3., -2., -1.])
x.numpy() # array([-5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.])
Parameters:
  • xTensor, input tensor.

  • dimsint, number of dimensions in x. (1 or 2)

Returns:

A Tensor, the shifted tensor.

satsim.math.interpolate module

satsim.math.interpolate.lagrange(x, y, new_x, order=5)

Lagrange interpolator. x can be one dimensional or two dimensional (if segment boundaries are specified). y should have the same length as x and the coordinates can be multi-dimensional, for example, cartesian coordinates [[x0, y0, z0], [x1, y1, z1], …].

Parameters:
  • xarray_like, x represents the x-coordinates of a set of data points.

  • yarray_like, y represents the y-coordinates of a set of data points, i.e., f(x).

  • new_xfloat or array_like, x-coordinates to interpolate y-coordinates.

  • orderint, Lagrange polynomial order. Nearest order + 2 points to be used for fit.

Returns:

A float or array_like, new_x Lagrange interpolated y-coordinates.

satsim.math.random module

satsim.math.random.gen_sample(type='uniform', seed=None, negate=0.0, **kwargs)

A wrapper function to generate a numpy random number using the random number generator (RNG) function name. Useful for specifying random samples based on a configuration files.

Examples::

x = gen_sample(**{“type”:”normal”, “loc”:0.0, “scale”:3.0}) y = gen_sample(**{“type”:”uniform”, “low”:-5.0, “high”:5.0})

Parameters:
  • typestring, numpy.random RNG name (see numpy.random docs)

  • seedint, rng seed

  • negatefloat, probability between 0 and 1 of negating the sample

  • kargsdict, key value args for the RNG

Returns:

A float, the sample generated from the specified RNG

satsim.math.random.gen_samples_from_bins(bins, density, mult=1.0)

Generates random samples base on discrete bins. The number of samples of each bin is calculated from its density. A density multiplier can be specified in the case that density is rate based. Values are uniformly sampled between the min and max of each bin.

Examples:

s = gen_samples_from_bins([200,100,10], [30,50], 10.0)
Parameters:
  • binslist, list of bins. Should be one length larger than density list

  • densitylist, number of occurrences per bin

  • multfloat, density multiplier (e.g. density is rate based)

Returns:

A list, samples

satsim.math.random.lognormal(mu=1.0, sigma=1.0, size=1, mu_mode='median', seed=None)

Draw samples from a log-normal distribution. Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are the values for the distribution itself.

Parameters:
  • mufloat, Mean or median value of log normal distribution

  • sigmafloat, Standard deviation of the log normal distribution, valid for mu_mode == mean

  • sizeint or tuple of ints, Output shape

  • mu_modestring, mean or median

  • seedint, Seed for the random number generator

Returns:

A ndarray or scalar, the drawn samples from log-normal distribution

satsim.math.stats module

satsim.math.stats.signal_to_noise_ratio(signal, background, noise)

Calculates signal to noise ratio.

Examples:

snr = signal_to_noise_ratio(100, 20, 10)
Parameters:
  • signalarray, signal in total photoelectrons

  • backgroundarray, background in total photoelectrons (includes total dark current)

  • noisefloat, RMS noise

Returns:

An array, signal to noise ratio