prdtools.table

class prdtools.table.TableParameters(ncols: int, nrows: int, prime_num: int, prime_root: int, design_freq: int, well_width: Optional[float] = 3.81, speed_of_sound: Optional[int] = 343)[source]

Bases: object

Parameters used to calculate a TableResult

ncols and nrows must be coprime factors of prime_num

ncols: int

Number of table columns

nrows: int

Number of table rows

prime_num: int

The basis prime number where prime_num - 1 == ncols * nrows

prime_root: int

A primitive root of prime_num used to calculate the sequence

design_freq: int

The lowest frequency (in Hz) the diffusor is designed for

well_width: Optional[float] = 3.81

The width of each well in centimeters

speed_of_sound: Optional[int] = 343

Speed of sound in meters per second

property high_frequency: int

The highest diffusion frequency possible with the specified well_width and speed_of_sound

property total_width: float

The total width of the diffusor in centimeters

property total_height: float

The total height of the diffusor in centimeters

validate() None[source]

Validate the parameters

Raises

ValidationError – If any parameters are invalid

calculate() prdtools.table.TableResult[source]

Calculate the well height table and return it as a TableResult

class prdtools.table.TableResult(parameters: prdtools.table.TableParameters, data: TableArray)[source]

Bases: object

A calculated table result

parameters: prdtools.table.TableParameters

The TableParameters used to generate the result

data: TableArray

The result array calculated by well_height_table()

well_heights: numpy.ndarray[Any, numpy.dtype[int]]

The well heights in data rounded to the nearest centimeter

classmethod from_parameters(parameters: prdtools.table.TableParameters) prdtools.table.TableResult[source]

Calculate the result from the given TableParameters

classmethod from_kwargs(**kwargs) prdtools.table.TableResult[source]

Calculate the result using parameter values as keyword arguments

The keyword arguments given must include all necessary values to create a TableParameters instance

get_well_counts() Dict[int, int][source]

Count the total number of each unique well height in well_heights

Returns the result as a dict of {well_height: count}

to_csv(separator: Optional[str] = ',', offset: Optional[int] = 0) str[source]

Format the well_heights array as a multiline string of comma-separated values

The offset argument will be added to the well_heights before output. For well heights of 0, there would be no block attached to the diffusor in that position. If (for aesthetic reasons) this is undesirable, an offset of 1 (for example) could be applied to all wells.

Parameters

offset (Optional[int]) – An offset to apply to the well heights. Can be used if wells of height 0 are undesired.

to_rst(offset: Optional[int] = 0) str[source]

Format the well_heights array as an rST table

The offset argument will be added to the well_heights before output. For well heights of 0, there would be no block attached to the diffusor in that position. If (for aesthetic reasons) this is undesirable, an offset of 1 (for example) could be applied to all wells.

Parameters

offset (Optional[int]) – An offset to apply to the well heights. Can be used if wells of height 0 are undesired.

prdtools.table.well_height_table(parameters: prdtools.table.TableParameters) TableArray[source]

Calculate the well heights in centimeters for the given TableParameters

The returned array will be of shape (nrows, ncols)

prdtools.table.prime_root_table(parameters: prdtools.table.TableParameters) TableArray[source]

Calculate well indices and prime elements for the given TableParameters

The returned array will be of shape (nrows, ncols)

prdtools.table.build_diag_indices(nrows: int, ncols: int) Tuple[numpy.ndarray[Any, numpy.dtype[int]], numpy.ndarray[Any, numpy.dtype[int]]][source]

Create indices for all diagonals of a 2-d array of shape (nrows, ncols)

The results may be used to directly index an array of shape (nrows, ncols) along the diagonals.

Parameters
  • nrows (int) – Number of rows in the array (shape[0])

  • ncols (int) – Number of columns in the array (shape[1])

exception prdtools.table.ValidationError(msg, *fields)[source]

Bases: ValueError

Raised by TableParameters if any parameter values are invalid

msg: str

Error message

fields: Sequence[Tuple[str, Any]]

Tuples of (field_name, value) that caused the error

field_names: Tuple[str]

Field name(s) that caused the error

prdtools.table.TableArray

A structured array of type TABLE_DTYPE

alias of numpy.ndarray

prdtools.table.TABLE_DTYPE = dtype([('primes', '<i8'), ('indices', '<i8'), ('wells', '<f8')])

A structured data type for table results

Parameters
  • primes – Value from the prime root sequence

  • indices – The index of the primes value within the sequence

  • wells – The physical well height calculated from primes and the design wavelength