runBatches - josalggui/MaRGE GitHub Wiki

runBatches method

Description

The runBatches method executes multiple waveform batches generated from PyPulseq sequences, manages data acquisition from the hardware (or demo mode), and stores both oversampled and decimated RX data in the internal mapVals dictionary.

This method is designed to handle long MRI sequences by splitting them into hardware-compatible batches, executing each batch sequentially, and ensuring data integrity by automatically repeating acquisitions if data loss is detected.


Parameters

  • waveforms (dict)
    Dictionary containing waveform sequences for each batch.

    • Keys: batch identifiers (e.g., "batch_1", "batch_2")
    • Values: waveform data generated by PyPulseq and interpreted by FloSeq.
  • n_readouts (dict)
    Dictionary specifying the number of readout points per batch.

    • Keys must match the batch identifiers in waveforms.
    • Values represent the number of readout points per batch before oversampling.
  • n_adc (int)
    Number of ADC windows in the full sequence.
    All ADC windows must have the same length.

  • frequency (float, optional)
    Larmor frequency in MHz used for the acquisition.
    Defaults to hw.larmorFreq.

  • bandwidth (float, optional)
    Acquisition bandwidth in MHz.
    The sampling period is computed as 1 / bandwidth.
    Defaults to 0.03.

  • decimate (str, optional)
    Decimation mode applied after acquisition:

    • 'Normal': Standard decimation without preprocessing.
    • 'PETRA': Adjusts pre-readout points to align with the desired acquisition start.
      Useful to avoid oscillations caused by anti-aliasing filters on signal jumps between consecutive readouts.
  • add_rd_points (int, optional)
    Number of additional points acquired before and after each readout window.
    These points are handled during decimation and can be used to mitigate filter transients.
    Defaults to hw.addRdPoints.

  • oversampling_factor (int, optional)
    Oversampling factor applied during acquisition.
    Defaults to hw.oversamplingFactor.

  • decimation_factor (int, optional)
    Decimation factor applied when reducing oversampled data using an FIR filter.
    Defaults to hw.oversamplingFactor.

  • hardware (bool, optional)
    If True, gradient and ADC delays defined in the hardware configuration are applied.

  • output (str, optional)
    Optional suffix appended to the output keys stored in mapVals.
    Useful for distinguishing multiple acquisitions.

  • channels (list, optional)
    List of receiver channels used for acquisition (e.g., [0], [0, 1]).
    Currently supports single-channel RX; multi-channel (MIMO) support is planned.


Returns

  • bool
    Returns True if all batches are executed successfully.
    Returns False if an error occurs (e.g., waveform constraints exceed hardware limits).

Stored Outputs

After execution, the following entries are added to self.mapVals:

  • n_readouts
    List containing the number of readout points per batch (before oversampling).

  • n_batches
    Total number of executed batches.

  • data_over or data_over_<output>
    Concatenated oversampled complex RX data from all batches and scans.

  • data_decimated or data_decimated_<output>
    Decimated RX data after applying the selected decimation method.


Execution Flow

  1. Store batch metadata (n_readouts, n_batches) in mapVals.
  2. Initialize an empty container for oversampled RX data.
  3. For each batch:
    • Initialize the Red Pitaya experiment (unless running in demo mode).
    • Convert PyPulseq waveforms to mriBlankSeq format using pypulseq2mriblankseq.
    • Load waveforms into the hardware and validate hardware limits.
  4. For each scan:
    • Execute the batch.
    • Verify the number of acquired points:
      • Expected points = n_readouts[batch] × oversampling_factor
    • Automatically repeat the batch if data loss is detected.
  5. Concatenate oversampled RX data across all batches and scans.
  6. Apply decimation using utils.decimate, including:
    • Oversampling and decimation factors
    • Additional readout points (add_rd_points)
    • Selected decimation mode (Normal or PETRA)
  7. Store oversampled and decimated data in mapVals.
  8. Optionally plot the sequence instead of executing it.
  9. Release hardware resources.

Notes

  • In demo mode, synthetic complex Gaussian noise is generated instead of acquiring hardware data.
  • The method automatically retries a batch if the number of acquired points does not match the expected count.
  • Oversampled data is always preserved before decimation for further processing or debugging.
  • When plotSeq is enabled and standalone=True, the sequence is visualized and not executed on hardware.
  • Decimation is performed using an FIR filter and supports PETRA-style preprocessing via add_rd_points.
⚠️ **GitHub.com Fallback** ⚠️