docs: def detect_format(self, candidates):
          """
          Detects the format of the fileset from a list of possible
          candidates. If multiple candidates match the potential files, e.g.
          NiFTI-X (see dcm2niix) and NiFTI, then the first matching candidate is
          selected.
  
          If a 'format_name' was specified when the fileset was
          created then that is used to select between the candidates. Otherwise
          the file extensions of the primary path and potential auxiliary files,
          or extensions of the files within the directory for directories are
          matched against those specified for the file formats
  
          Parameters
          ----------
          candidates : FileFormat
              A list of file-formats to select from.
          """
          if self._format is not None:
              raise ArcanaFileFormatError(
                  "Format has already been set for {}".format(self))
          matches = [c for c in candidates if c.matches(self)]
          if not matches:
              raise ArcanaFileFormatError(
                  "None of the candidate file formats ({}) match {}"
                  .format(', '.join(str(c) for c in candidates), self))
          return matches[0]