def write(self, filename, format='<STR_LIT>', write_detection_catalog=True,<EOL>catalog_format="<STR_LIT>", debug=<NUM_LIT:0>):
if catalog_format not in CAT_EXT_MAP.keys():<EOL><INDENT>raise TypeError("<STR_LIT>".format(catalog_format))<EOL><DEDENT>if format.lower() == '<STR_LIT>':<EOL><INDENT>if os.path.isfile(filename):<EOL><INDENT>raise MatchFilterError(<EOL>'<STR_LIT>' % filename)<EOL><DEDENT>for family in self.families:<EOL><INDENT>for detection in family.detections:<EOL><INDENT>detection.write(fname=filename, append=True)<EOL><DEDENT><DEDENT><DEDENT>elif format.lower() == '<STR_LIT>':<EOL><INDENT>if os.path.exists(filename):<EOL><INDENT>raise IOError('<STR_LIT>'<EOL>% filename)<EOL><DEDENT>with temporary_directory() as temp_dir:<EOL><INDENT>Tribe([f.template for f in self.families]).write(<EOL>filename=temp_dir, compress=False,<EOL>catalog_format=catalog_format)<EOL>if write_detection_catalog:<EOL><INDENT>all_cat = Catalog()<EOL>for family in self.families:<EOL><INDENT>all_cat += family.catalog<EOL><DEDENT>if not len(all_cat) == <NUM_LIT:0>:<EOL><INDENT>all_cat.write(<EOL>join(temp_dir, '<STR_LIT>'.format(<EOL>CAT_EXT_MAP[catalog_format])),<EOL>format=catalog_format)<EOL><DEDENT><DEDENT>for i, family in enumerate(self.families):<EOL><INDENT>debug_print('<STR_LIT>' % i, <NUM_LIT:0>, debug)<EOL>name = family.template.name + '<STR_LIT>'<EOL>name_to_write = join(temp_dir, name)<EOL>_write_family(family=family, filename=name_to_write)<EOL><DEDENT>with tarfile.open(filename + '<STR_LIT>', "<STR_LIT>") as tar:<EOL><INDENT>tar.add(temp_dir, arcname=os.path.basename(filename))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>self.get_catalog().write(filename=filename, format=format)<EOL><DEDENT>return self<EOL>
Write Family out, select output format.

:type format: str
:param format:
    One of either 'tar', 'csv', or any obspy supported
    catalog output. See note below on formats
:type filename: str
:param filename: Path to write file to.
:type debug: int
:param debug: Whether to output progress or not.
:type write_detection_catalog: bool
:param write_detection_catalog:
    Whether to write the detection catalog object or not - writing
    large catalog files can be slow, and catalogs can be reconstructed
    from the Tribe.
:type catalog_format: str
:param catalog_format:
    What format to write the detection-catalog with. Only Nordic,
    SC3ML, QUAKEML are supported. Note that not all information is
    written for all formats (QUAKEML is the most complete, but is
    slow for IO).

.. NOTE::
    csv format will write out detection objects, all other
    outputs will write the catalog.  These cannot be rebuilt into
    a Family object.  The only format that can be read back into
    Family objects is the 'tar' type.

.. NOTE::
    We recommend writing to the 'tar' format, which will write out
    all the template information (wavefiles as miniseed and metadata)
    alongside the detections and store these in a tar archive. This
    is readable by other programs and maintains all information
    required for further study.

.. rubric:: Example

>>> party = Party().read()
>>> party.write('test_tar_write', format='tar', debug=1)
Writing family 0
Writing family 1
Writing family 2
Writing family 3
Party of 4 Families.
>>> party.write('test_csv_write.csv', format='csv')
Party of 4 Families.
>>> party.write('test_quakeml.xml', format='quakeml')
Party of 4 Families.