pespace.utils.utils

Utility functions and data structures.

Functions

complex_numpy_array_dict_to_taichi_field(...)

Convert a dictionary of complex NumPy arrays to a Taichi field.

get_gw_propagation_unit_vector(lam, beta)

Compute the gravitational wave propagation unit vector.

get_polarization_tensor_ssb(lam, beta, psi)

Compute the polarization tensors in the Solar System Barycenter frame.

lagrange_interpolate_kernel()

Lagrange interpolation kernel (not implemented).

linear_interpolate_kernel(left, right, frac)

Perform linear interpolation between two values.

next_power_of_2(n)

Compute the next power of 2 greater than or equal to n.

recursively_load_dict_contents_from_group(...)

Recursively load an HDF5 group into a dictionary.

recursively_save_dict_contents_to_group(...)

Recursively save a dictionary to an HDF5 group.

sinc(x)

Compute the sinc function: sin(x)/x.

sinc_interpolate_kernel()

Sinc interpolation kernel (not implemented).

taichi_field_to_complex_numpy_array_dict(...)

Convert a Taichi field to a dictionary of complex NumPy arrays.

pespace.utils.utils.next_power_of_2(n)[source]

Compute the next power of 2 greater than or equal to n.

Parameters:

n (ti.u32) – Input unsigned 32-bit integer.

Returns:

The smallest power of 2 that is greater than or equal to n.

Return type:

ti.u32

pespace.utils.utils.sinc(x)[source]

Compute the sinc function: sin(x)/x.

Parameters:

x (float) – Input value.

Returns:

The value of sinc(x). Returns 1.0 when x = 0.0.

Return type:

float

pespace.utils.utils.linear_interpolate_kernel(left, right, frac)[source]

Perform linear interpolation between two values.

Parameters:
  • left (float) – Left boundary value.

  • right (float) – Right boundary value.

  • frac (float) – Fractional position between left and right, in the range [0, 1].

Returns:

Interpolated value.

Return type:

float

pespace.utils.utils.lagrange_interpolate_kernel()[source]

Lagrange interpolation kernel (not implemented).

Notes

This function is a placeholder for future implementation.

pespace.utils.utils.sinc_interpolate_kernel()[source]

Sinc interpolation kernel (not implemented).

Notes

This function is a placeholder for future implementation.

pespace.utils.utils.get_polarization_tensor_ssb(lam, beta, psi)[source]

Compute the polarization tensors in the Solar System Barycenter frame.

Parameters:
  • lam (float) – Ecliptic longitude in radians.

  • beta (float) – Ecliptic latitude in radians, in the range \((-\pi/2, \pi/2)\).

  • psi (float) – Polarization angle in radians.

Returns:

A struct containing two 3x3 matrices:

  • plus: Plus polarization tensor (\(e_+ = p \otimes p - q \otimes q\))

  • cross: Cross polarization tensor (\(e_\times = p \otimes q + q \otimes p\))

Return type:

PolarizationStruct

pespace.utils.utils.get_gw_propagation_unit_vector(lam, beta)[source]

Compute the gravitational wave propagation unit vector.

Parameters:
  • lam (float) – Ecliptic longitude in radians.

  • beta (float) – Ecliptic latitude in radians, in the range \((-\pi/2, \pi/2)\).

Returns:

Unit vector pointing in the direction of GW propagation in the SSB frame.

Return type:

ti.types.vector(3, float)

Notes

The propagation direction is opposite to the source direction.

pespace.utils.utils.taichi_field_to_complex_numpy_array_dict(field_container)[source]

Convert a Taichi field to a dictionary of complex NumPy arrays.

Parameters:

field_container (ti.Field) – Taichi field container with shape (N, 2), where the last dimension represents [real, imaginary] components.

Returns:

Dictionary mapping field names to complex-valued NumPy arrays of shape (N,).

Return type:

dict[str, NDArray]

pespace.utils.utils.complex_numpy_array_dict_to_taichi_field(array_dict, field_container)[source]

Convert a dictionary of complex NumPy arrays to a Taichi field.

Parameters:
  • array_dict (dict[str, NDArray]) – Dictionary mapping field names to 1D complex-valued NumPy arrays.

  • field_container (ti.Field) – Target Taichi field container with shape (N, 2) to store [real, imaginary] components.

Return type:

None

pespace.utils.utils.recursively_save_dict_contents_to_group(h5file, path, dic)[source]

Recursively save a dictionary to an HDF5 group.

Parameters:
  • h5file (h5py.File) – HDF5 file object.

  • path (str) – Path inside the HDF5 file where the dictionary will be saved.

  • dic (dict) – Dictionary containing the data to save. Supports nested dictionaries, lists, NumPy arrays, and None values.

Raises:

ValueError – If the dictionary contains values of unsupported types.

Notes

This function is adapted from bilby.core.utils.io.recursively_save_dict_contents_to_group. Supported value types: dict, list, np.ndarray, None.

pespace.utils.utils.recursively_load_dict_contents_from_group(h5file, path)[source]

Recursively load an HDF5 group into a dictionary.

Parameters:
  • h5file (h5py.File) – HDF5 file object.

  • path (str) – Path within the HDF5 file to load from.

Returns:

Dictionary containing the contents of the HDF5 group, with nested structure preserved.

Return type:

dict

Notes

This function is adapted from bilby.core.utils.io.recursively_load_dict_contents_from_group.