docs: def write_source_model(dest, sources_or_groups, name=None,
                         investigation_time=None):
      """
      Writes a source model to XML.
  
      :param dest:
          Destination path
      :param sources_or_groups:
          Source model in different formats
      :param name:
          Name of the source model (if missing, extracted from the filename)
      """
      if isinstance(sources_or_groups, nrml.SourceModel):
          with open(dest, 'wb') as f:
              nrml.write([obj_to_node(sources_or_groups)], f, '%s')
          return
      if isinstance(sources_or_groups[0], sourceconverter.SourceGroup):
          groups = sources_or_groups
      else:  # passed a list of sources
          srcs_by_trt = groupby(
              sources_or_groups, operator.attrgetter('tectonic_region_type'))
          groups = [sourceconverter.SourceGroup(trt, srcs_by_trt[trt])
                    for trt in srcs_by_trt]
      name = name or os.path.splitext(os.path.basename(dest))[0]
      nodes = list(map(obj_to_node, sorted(groups)))
      attrs = {"name": name}
      if investigation_time is not None:
          attrs['investigation_time'] = investigation_time
      source_model = Node("sourceModel", attrs, nodes=nodes)
      with open(dest, 'wb') as f:
          nrml.write([source_model], f, '%s')
      return dest