nenupy.io.tf_utils


Support to Time-Frequency data

blocks_to_tf_data(data, n_block_times, ...)

Inverts the halves of each beamlet and reshape the array in 2D (time, frequency) or 4D (time, frequency, 2, 2) if this is an 'ejones' matrix.

compute_spectra_frequencies(...)

class nenupy.io.tf_utils.ReducedSpectra(file_name)[source]

Bases: object

close()[source]
get(subarray_pointing_id=0, beam_id=0, data_key=None)[source]

_summary_

Parameters:

data_key (str, optional) – _description_, by default None

Returns:

_description_

Return type:

np.ndarray

Raises:

KeyError – _description_

infos()[source]
plot(subarray_pointing_id=0, beam_id=0, data_key=None, **kwargs)[source]
class nenupy.io.tf_utils.TFPipelineParameters(*parameters)[source]

Bases: object

copy()[source]
info()[source]
reset()[source]

Reset all parameters to their original values.

Returns:

_description_

Return type:

_type_

classmethod set_default(time_min, time_max, freq_min, freq_max, beams, channels, dt, df)[source]
nenupy.io.tf_utils.blocks_to_tf_data(data, n_block_times, n_channels)[source]

Inverts the halves of each beamlet and reshape the array in 2D (time, frequency) or 4D (time, frequency, 2, 2) if this is an ‘ejones’ matrix.

nenupy.io.tf_utils.compute_spectra_frequencies(subband_start_hz, n_channels, frequency_step_hz)[source]
nenupy.io.tf_utils.compute_spectra_time(block_start_time_unix, ntime_per_block, time_step_s)[source]
nenupy.io.tf_utils.compute_stokes_parameters(data_array, stokes)[source]

data_array: >2 D, last 2 dimensions are ((XX, XY), (YX, YY))

nenupy.io.tf_utils.correct_bandpass(data, n_channels)[source]

Correct the Polyphase-filter band-pass response at each sub-band.

_images/bandpass_corr.png
Parameters:
  • data (np.ndarray) – _description_

  • n_channels (int) – _description_

Raises:

ValueError – _description_

Returns:

_description_

Return type:

np.ndarray

nenupy.io.tf_utils.crop_subband_edges(data, n_channels, lower_edge_channels, higher_edge_channels)[source]
nenupy.io.tf_utils.de_disperse_array(data, frequencies, time_step, dispersion_measure)[source]

De-disperse in time an array data whose first two dimensions are time and frequency respectively. The array must be regularly sampled in time. The de-dispersion is made relatively to the highest frequency. De-dedispersed array is filled with NaN in time-frequency places where the shifted values were.

Parameters:
  • data (ndarray) – Data array to de-disperse.

  • frequencies (Quantity) – 1D array of frequencies corresponding to the second dimension of data.

  • time_step (Quantity) – Time step between two spectra.

  • dispersion_measure (Quantity) – Dispersion Measure (in pc/cm3).

nenupy.io.tf_utils.de_faraday_data(frequency, data, rotation_measure)[source]
nenupy.io.tf_utils.flatten_subband(data, channels)[source]
nenupy.io.tf_utils.get_bandpass(n_channels)[source]
nenupy.io.tf_utils.plot_dynamic_spectrum(data, time, frequency, fig=None, ax=None, **kwargs)[source]

_summary_

Parameters:
  • data (np.ndarray) – _description_

  • time (Time) – _description_

  • frequency (u.Quantity) – _description_

  • fig (mpl.figure.Figure, optional) – _description_, by default None

  • ax (mpl.axes.Axes, optional) – _description_, by default None

Returns:

_description_

Return type:

Tuple[mpl.figure.Figure, mpl.axes.Axes]

nenupy.io.tf_utils.polarization_angle(stokes_u, stokes_q)[source]
nenupy.io.tf_utils.rebin_along_dimension(data, axis_array, axis, dx, new_dx)[source]
nenupy.io.tf_utils.remove_channels_per_subband(data, n_channels, channels_to_remove)[source]

Set channel indices of a time-frequency dataset to NaN values. The data array is first re-shaped as (n_times, n_subbands, n_channels, 2, 2) using reshape_to_subbands().

Parameters:
  • data (ndarray) – Time-frequency correlations array, its dimensions must be (n_times, n_frequencies, 2, 2). The data type must be float.

  • n_channels (int) – Number of channels per sub-band.

  • channels_to_remove (ndarray or list) – Array of channel indices to set at NaN values.

Raises:
  • TypeError – If channels_to_remove is not of the correct type.

  • IndexError – If any of the indices listed in channels_to_remove does not correspond to the n_channels argument.

Returns:

Time-frequency correlations array, shaped as the original input, except that some channels are set to NaN.

Return type:

ndarray

Example:
>>> from nenupy.io.tf_utils import remove_channels_per_subband
>>> import numpy as np
>>>
>>> data = np.arange(2*4*2*2, dtype=float).reshape((2, 4, 2, 2))
>>> result = remove_channels_per_subband(data, 2, [0])
>>> result[:, :, 0, 0]
array([[nan,  4., nan, 12.],
       [nan, 20., nan, 28.]])
nenupy.io.tf_utils.reshape_to_subbands(data, n_channels)[source]

Reshape a time-frequency data array by the sub-band dimension. Given a data array with one frequency axis of size n_frequencies, this functions split this axis in two axes of size n_subbands and n_channels.

Parameters:
  • data (ndarray) – Time-frequency correlations array, its second dimension must be the frequencies.

  • n_channels (int) – _description_

Raises:

ValueError – _description_

Returns:

_description_

Return type:

ndarray

Example:

>>> from nenupy.io.tf_utils import reshape_to_subbands
>>> import numpy as np
>>>
>>> data = np.arange(3*10).reshape((3, 10))
>>> result = reshape_to_subbands(data, 5)
>>> result.shape
(3, 2, 5)

nenupy.io.tf_utils.sort_beam_edges(beam_array, n_channels)[source]

Find out where in the frequency axis a beam starts and end. This outputs a dictionnary such as: {

“<beam_index>”: (freq_axis_start_idx, freq_axis_end_idx,), …

}

nenupy.io.tf_utils.spectra_data_to_matrix(fft0, fft1)[source]

fft0[…, :] = [XX, YY] = [XrXr+XiXi : YrYr+YiYi] = [ExEx*, EyEy*] fft1[…, :] = [Re(X*Y), Im(X*Y)] = [XrYr+XiYi : XrYi-XiYr] = [Re(ExEy*), Im(ExEy*)] Returns a (…, 2, 2) matrix (Dask)

ExEy* = (XrYr+XiYi) + i(XiYr - XrYi) EyEx* = (YrXr+YiXi) + i(YiXr - YrXi)

nenupy.io.tf_utils.store_dask_tf_data(file_name, data, time, frequency, polarization, beam=0, stored_frequency_unit='MHz', mode='auto', **metadata)[source]