satsim.math package — SatSim 0.21.0 documentation

# 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:

    - a0 – float, an angle in degrees.

    - a1 – float, an angle in degrees.

    - max_diff – float, 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:

    - tt – list, list of times to interpolate between t0 and t1.

    - t0 – float, time for a0.

    - t1 – float, time for a1.

    - a0 – float, angle in degrees.

    - a1 – float, angle in degrees.

    - max_diff – float, maximum angle difference before concidering the opposite angle. default=180.

    - normalize_360 – boolean, 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:

    - a0 – float, an angle in degrees.

    - a1 – float, an angle in degrees.

    - max_diff – float, maximum angle difference before concidering the opposite angle. default=180.

    - normalize_360 – boolean, 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:

    - x – Tensor, input image as a 2D tensor.

    - y – Tensor, input kernel as a 2D tensor.

    - dtype – dtype, 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:

    - x – Tensor, 2D input tensor.

    - y – Tensor, 2D input tensor of the same shape as x.

    - dtype – tf.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:

    - x – Tensor, 2D input tensor.

    - y – Tensor, 2D input tensor of the same shape as x.

    - pad – int, number of pixels to pad all sides before calculating the FFT

    - dtype – dtype, float32, complex64 or complex128

    - cache_last_y – bool, 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:

    - x – Tensor, input tensor.

    - dims – int, 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:

    - x – array_like, x represents the x-coordinates of a set of data points.

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

    - new_x – float or array_like, x-coordinates to interpolate y-coordinates.

    - order – int, 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:

    - type – string, numpy.random RNG name (see numpy.random docs)

    - seed – int, rng seed

    - negate – float, probability between 0 and 1 of negating the sample

    - kargs – dict, 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:

    - bins – list, list of bins. Should be one length larger than density list

    - density – list, number of occurrences per bin

    - mult – float, 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:

    - mu – float, Mean or median value of log normal distribution

    - sigma – float, Standard deviation of the log normal distribution, valid for mu_mode == mean

    - size – int or tuple of ints, Output shape

    - mu_mode – string, mean or median

    - seed – int, 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:

    - signal – array, signal in total photoelectrons

    - background – array, background in total photoelectrons (includes total dark current)

    - noise – float, RMS noise

  Returns:

    An array, signal to noise ratio