docs: def process_input_data(filename, imager, grid_data, grid_norm, grid_weights):
      """Reads visibility data from a Measurement Set.
  
      The visibility grid or weights grid is updated accordingly.
  
      Visibility data are read from disk in blocks of size num_baselines.
  
      Args:
          filename (str):                    Name of Measurement Set to open.
          imager (oskar.Imager):             Handle to configured imager.
          grid_data (numpy.ndarray or None): Visibility grid to populate.
          grid_norm (float)                  Current grid normalisation.
          grid_weights (numpy.ndarray):      Weights grid to populate or read.
  
      Returns:
          grid_norm (float):                 Updated grid normalisation.
      """
      # Get data from the input Measurement Set.
      ms = oskar.MeasurementSet.open(filename)
      block_start = 0
      num_rows = ms.num_rows
      num_baselines = ms.num_stations * (ms.num_stations - 1) // 2
  
      # Loop over data blocks of size num_baselines.
      while block_start < num_rows:
          block_size = num_rows - block_start
          if block_size > num_baselines:
              block_size = num_baselines
  
          # Get the baseline coordinates. (Replace this with a query to LTS.)
          uvw = ms.read_column('UVW', block_start, block_size)
  
          # Read the Stokes-I visibility weights.
          vis_weights = ms.read_column('WEIGHT', block_start, block_size)
          if ms.num_pols == 4:
              vis_weights = 0.5 * (vis_weights[:, 0] + vis_weights[:, 3])
  
          # Loop over frequency channels.
          # (We expect there to be only one channel here, but loop just in case.)
          for j in range(ms.num_channels):
              # Get coordinates in wavelengths.
              coords = uvw * (ms.freq_start_hz + j * ms.freq_inc_hz) / 299792458.
  
              # Get the Stokes-I visibilities for this channel.
              vis_data = None
              if not imager.coords_only:
                  vis_data = ms.read_vis(block_start, j, 1, block_size)
                  if ms.num_pols == 4:
                      vis_data = 0.5 * (vis_data[0, :, 0] + vis_data[0, :, 3])
  
              # Update the grid plane with this visibility block.
              grid_norm = imager.update_plane(
                  coords[:, 0], coords[:, 1], coords[:, 2], vis_data,
                  vis_weights, grid_data, grid_norm, grid_weights)
  
          # Increment start row by block size.
          block_start += block_size
  
      # Return updated grid normalisation.
      return grid_norm