docs: def save_disagg_to_csv(metadata, matrices):
      """
      Save disaggregation matrices to multiple .csv files.
      """
      skip_keys = ('Mag', 'Dist', 'Lon', 'Lat', 'Eps', 'TRT')
      base_header = ','.join(
          '%s=%s' % (key, value) for key, value in metadata.items()
          if value is not None and key not in skip_keys)
      for disag_tup, (poe, iml, matrix, fname) in matrices.items():
          header = '%s,poe=%.7f,iml=%.7e\n' % (base_header, poe, iml)
  
          if disag_tup == ('Mag', 'Lon', 'Lat'):
              matrix = numpy.swapaxes(matrix, 0, 1)
              matrix = numpy.swapaxes(matrix, 1, 2)
              disag_tup = ('Lon', 'Lat', 'Mag')
  
          axis = [metadata[v] for v in disag_tup]
          header += ','.join(v for v in disag_tup)
          header += ',poe'
  
          # compute axis mid points
          axis = [(ax[: -1] + ax[1:]) / 2. if ax.dtype == float
                  else ax for ax in axis]
  
          values = None
          if len(axis) == 1:
              values = numpy.array([axis[0], matrix.flatten()]).T
          else:
              grids = numpy.meshgrid(*axis, indexing='ij')
              values = [g.flatten() for g in grids]
              values.append(matrix.flatten())
              values = numpy.array(values).T
  
          writers.write_csv(fname, values, comment=header, fmt='%.5E')