def _group_events(catalog, process_len, template_length, data_pad):
<EOL>if len(catalog) == <NUM_LIT:1>:<EOL><INDENT>return [catalog]<EOL><DEDENT>sub_catalogs = []<EOL>catalog.events = sorted(<EOL>catalog.events,<EOL>key=lambda e: (e.preferred_origin() or e.origins[<NUM_LIT:0>]).time)<EOL>sub_catalog = Catalog([catalog[<NUM_LIT:0>]])<EOL>for event in catalog[<NUM_LIT:1>:]:<EOL><INDENT>origin_time = (event.preferred_origin() or event.origins[<NUM_LIT:0>]).time<EOL>last_pick = sorted(event.picks, key=lambda p: p.time)[-<NUM_LIT:1>]<EOL>max_diff = (<EOL>process_len - (last_pick.time - origin_time) - template_length)<EOL>max_diff -= <NUM_LIT:2> * data_pad<EOL>if origin_time - sub_catalog[<NUM_LIT:0>].origins[<NUM_LIT:0>].time < max_diff:<EOL><INDENT>sub_catalog.append(event)<EOL><DEDENT>else:<EOL><INDENT>sub_catalogs.append(sub_catalog)<EOL>sub_catalog = Catalog([event])<EOL><DEDENT><DEDENT>sub_catalogs.append(sub_catalog)<EOL>return sub_catalogs<EOL>
Internal function to group events into sub-catalogs based on process_len.

:param catalog: Catalog to groups into sub-catalogs
:type catalog: obspy.core.event.Catalog
:param process_len: Length in seconds that data will be processed in
:type process_len: int

:return: List of catalogs
:rtype: list