Dimension class

Contents

Dimension class#

class Dimension(name: str, n: int, d_pos: float, pos_min: float, freq_min: float, dynamically_traced_coords: bool)[source]#

Properties of an Array grid for one dimension.

This class encapsulates all the properties of the position and frequency coordinate grids for one dimension.

Note that properties associated with the position grid are denoted by pos, whereas the frequency grid properties are denoted with freq. Frequencies are rotational frequencies in cycles as opposed to angular frequencies.

Parameters:
  • name (str) – Name of the dimension.

  • n (int) – Number of grid points.

  • d_pos (float) – Distance between two neighboring position grid points.

  • pos_min (float) – Smallest position grid point.

  • freq_min (float) – Smallest frequency grid point

  • dynamically_traced_coords (bool) – Only relevant for use with JAX tracing. Whether the coordinate values should be dynamically traced such that the grid can be altered inside a jitted function. See also Working with JAX.

Notes

Implementation details

The grid in both spaces (position and frequency) goes from min to max including both points. Therefore d_pos = (pos_max-pos_min)/(n-1). In the case of even n, pos_middle is the sample on the right hand side of the exact center of the grid.

Examples:

n = 4
                pos_middle
     pos_min           pos_max
        |-----|-----|-----|
index:  0     1     2     3
         d_pos d_pos d_pos

n = 5
                pos_middle
     pos_min                 pos_max
        |-----|-----|-----|-----|
index:  0     1     2     3     4
         d_pos d_pos d_pos d_pos

In the case of even n, freq_middle is the sample on the right hand side of the exact center of the grid.

Examples:

n = 4
                  freq_middle
     freq_min             freq_max
        |------|------|------|
index:  0      1      2      3
         d_freq d_freq d_freq

n = 6

     freq_min           freq_middle     freq_max
        |------|------|------|------|------|
index:  0      1      2      3      4      5
         d_freq d_freq d_freq d_freq d_freq

These are the symbolic definitions of all the different names (for even n):

pos_extent = pos_max - pos_min
pos_middle = 0.5 * (pos_min + pos_max + d_pos)
d_pos = pos_extent/(n-1)

freq_extent = freq_max - freq_min
freq_middle = 0.5 * (freq_max + freq_min + d_freq)
d_freq = freq_extent/(n-1)

d_freq * d_pos * n = 1

For odd n the definitions for pos_middle and freq_middle change to ensure that they and the minimum and maximum position and frequency are actually sampled and not in between two samples.:

pos_middle = 0.5 * (pos_min + pos_max)
freq_middle = 0.5 * (freq_max + freq_min)

For performance reasons it is recommended to have n be a power of two.

Individual array coordinates:

pos = np.arange(0, n) * d_pos + pos_min
freq = np.arange(0, n) * d_freq + freq_min

These arrays fulfill the following properties:

np.max(pos) = pos_max
np.min(pos) = pos_min
np.max(freq) = freq_max
np.min(freq) = freq_min

Methods

Dimension.index_from_coord(coord, space, *)

For the Dimension, retrieve the index corresponding to a given coordinate in a specified space.

Dimension.values(space, /, *[, xp, dtype, ...])

Returns the Dimension values for the respective space.

Attributes