Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions backend/src/spectre_server/core/batches/_iq_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class IQMetadata:
"""

center_frequencies: npt.NDArray[np.float32]
num_samples: npt.NDArray[np.int32]
num_samples: npt.NDArray[np.int64]


class _HdrFile(BatchFile[IQMetadata]):
Expand All @@ -96,8 +96,15 @@ def read(self) -> IQMetadata:

:return: A container for the metadata
"""
data = np.fromfile(self.file_path, dtype=np.float32)
return IQMetadata(data[0::2], data[1::2].astype(np.int32))
# The binary layout is [value_float32, nsamples_uint64] repeated (12 bytes per entry).
raw = np.fromfile(self.file_path, dtype=np.uint8)
entry_bytes = 12
n_entries = raw.size // entry_bytes
raw = raw[: n_entries * entry_bytes]

dt = np.dtype([("value", "<f4"), ("nsamples", "<u8")])
structured = np.frombuffer(raw.tobytes(), dtype=dt)
return IQMetadata(structured["value"], structured["nsamples"].astype(np.int64))


class _FitsFile(BatchFile[spectre_server.core.spectrograms.Spectrogram]):
Expand Down
20 changes: 10 additions & 10 deletions backend/src/spectre_server/core/events/_swept_center_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _average_over_steps(


def _compute_num_max_frames_in_step(
num_samples: npt.NDArray[np.int32], window_size: int, window_hop: int
num_samples: npt.NDArray[np.int64], window_size: int, window_hop: int
) -> int:
"""Compute the maximum number of frames for all steps, and all sweeps, in the batch."""
return get_num_spectrums(int(np.max(num_samples)), window_size, window_hop)
Expand Down Expand Up @@ -101,7 +101,7 @@ def _compute_stepped_dynamic_spectra(
window_hop: int,
num_full_sweeps: int,
num_steps_per_sweep: int,
num_samples: npt.NDArray[np.int32],
num_samples: npt.NDArray[np.int64],
) -> None:
"""For each full sweep, compute execute a short-time discrete Fourier transform on the IQ samples for each step."""
# Store the step index over all sweeps (doesn't reset each sweep).
Expand Down Expand Up @@ -159,7 +159,7 @@ def _compute_frequencies(

def _compute_times(
times: npt.NDArray[np.float32],
num_samples: npt.NDArray[np.int32],
num_samples: npt.NDArray[np.int64],
sample_rate: float,
num_full_sweeps: int,
num_steps_per_sweep: int,
Expand All @@ -176,7 +176,7 @@ def _compute_times(
end_step = (sweep_index + 1) * num_steps_per_sweep

# Update cumulative samples
cumulative_samples += np.sum(num_samples[start_step:end_step])
cumulative_samples += int(np.sum(num_samples[start_step:end_step]))


def _swept_stfft(
Expand All @@ -188,7 +188,7 @@ def _swept_stfft(
sample_rate: float,
frequency_hop: float,
center_frequencies: npt.NDArray[np.float32],
num_samples: npt.NDArray[np.int32],
num_samples: npt.NDArray[np.int64],
) -> tuple[npt.NDArray[np.float32], npt.NDArray[np.float32], npt.NDArray[np.float32]]:
_validate_center_frequencies_ordering(center_frequencies, frequency_hop)

Expand Down Expand Up @@ -239,10 +239,10 @@ def _swept_stfft(


def _prepend_num_samples(
carryover_num_samples: npt.NDArray[np.int32],
num_samples: npt.NDArray[np.int32],
carryover_num_samples: npt.NDArray[np.int64],
num_samples: npt.NDArray[np.int64],
final_step_spans_two_batches: bool,
) -> npt.NDArray[np.int32]:
) -> npt.NDArray[np.int64]:
"""Prepend the number of samples from the final sweep of the previous batch, to the first
sweep of the current batch."""
if final_step_spans_two_batches:
Expand Down Expand Up @@ -278,7 +278,7 @@ def _prepend_iq_data(
def _get_final_sweep(
previous_iq_data: npt.NDArray[np.complex64],
previous_iq_metadata: spectre_server.core.batches.IQMetadata,
) -> tuple[npt.NDArray[np.complex64], npt.NDArray[np.float32], npt.NDArray[np.int32]]:
) -> tuple[npt.NDArray[np.complex64], npt.NDArray[np.float32], npt.NDArray[np.int64]]:
"""Get IQ samples and metadata from the final sweep of the previous batch."""

if (
Expand Down Expand Up @@ -322,7 +322,7 @@ def _reconstruct_initial_sweep(
iq_data: npt.NDArray[np.complex64],
iq_metadata: spectre_server.core.batches.IQMetadata,
) -> tuple[
npt.NDArray[np.complex64], npt.NDArray[np.float32], npt.NDArray[np.int32], int
npt.NDArray[np.complex64], npt.NDArray[np.float32], npt.NDArray[np.int64], int
]:
"""Reconstruct the initial sweep of the current batch, using data from the previous batch.

Expand Down