def _calculate_event(self, template=None, template_st=None):
if template is not None and template.name != self.template_name:<EOL><INDENT>print("<STR_LIT>".format(<EOL>template.name, self.template_name))<EOL>return<EOL><DEDENT>det_time = str(self.detect_time.strftime('<STR_LIT>'))<EOL>ev = Event(resource_id=ResourceIdentifier(<EOL>id=self.template_name + '<STR_LIT:_>' + det_time,<EOL>prefix='<STR_LIT>'))<EOL>ev.creation_info = CreationInfo(<EOL>author='<STR_LIT>', creation_time=UTCDateTime())<EOL>ev.comments.append(<EOL>Comment(text='<STR_LIT>'.format(self.threshold)))<EOL>ev.comments.append(<EOL>Comment(text='<STR_LIT>'.format(self.detect_val)))<EOL>if self.chans is not None:<EOL><INDENT>ev.comments.append(<EOL>Comment(text='<STR_LIT>'.format(<EOL>'<STR_LIT:U+0020>'.join([str(pair) for pair in self.chans]))))<EOL><DEDENT>if template is not None:<EOL><INDENT>template_st = template.st<EOL><DEDENT>min_template_tm = min(<EOL>[tr.stats.starttime for tr in template_st])<EOL>for tr in template_st:<EOL><INDENT>if (tr.stats.station, tr.stats.channel)not in self.chans:<EOL><INDENT>continue<EOL><DEDENT>elif tr.stats.__contains__("<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>pick_time = self.detect_time + (<EOL>tr.stats.starttime - min_template_tm)<EOL>ev.picks.append(Pick(<EOL>time=pick_time, waveform_id=WaveformStreamID(<EOL>network_code=tr.stats.network,<EOL>station_code=tr.stats.station,<EOL>channel_code=tr.stats.channel,<EOL>location_code=tr.stats.location)))<EOL><DEDENT><DEDENT>self.event = ev<EOL>return<EOL>
Calculate an event for this detection using a given template.

:type template: Template
:param template: The template that made this detection
:type template_st: `obspy.core.stream.Stream`
:param template_st:
    Template stream, used to calculate pick times, not needed if
    template is given.

.. rubric:: Note
    Works in place on Detection - over-writes previous events.
    Does not correct for pre-pick.