def write(self, filename, compress=True, catalog_format="<STR_LIT>"):
if catalog_format not in CAT_EXT_MAP.keys():<EOL><INDENT>raise TypeError("<STR_LIT>".format(catalog_format))<EOL><DEDENT>if not os.path.isdir(filename):<EOL><INDENT>os.makedirs(filename)<EOL><DEDENT>self._par_write(filename)<EOL>tribe_cat = Catalog()<EOL>for t in self.templates:<EOL><INDENT>if t.event is not None:<EOL><INDENT>tribe_cat.append(t.event)<EOL><DEDENT><DEDENT>if len(tribe_cat) > <NUM_LIT:0>:<EOL><INDENT>tribe_cat.write(<EOL>os.path.join(filename, '<STR_LIT>'.format(<EOL>CAT_EXT_MAP[catalog_format])), format=catalog_format)<EOL><DEDENT>for template in self.templates:<EOL><INDENT>template.st.write(filename + '<STR_LIT:/>' + template.name + '<STR_LIT>',<EOL>format='<STR_LIT>')<EOL><DEDENT>if compress:<EOL><INDENT>with tarfile.open(filename + '<STR_LIT>', "<STR_LIT>") as tar:<EOL><INDENT>tar.add(filename, arcname=os.path.basename(filename))<EOL><DEDENT>shutil.rmtree(filename)<EOL><DEDENT>return self<EOL>
Write the tribe to a file using tar archive formatting.

:type filename: str
:param filename:
    Filename to write to, if it exists it will be appended to.
:type compress: bool
:param compress:
    Whether to compress the tar archive or not, if False then will
    just be files in a folder.
: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).

.. rubric:: Example

>>> tribe = Tribe(templates=[Template(name='c', st=read())])
>>> tribe.write('test_tribe')
Tribe of 1 templates