nodes: 0, module; 1, function_definition; 2, function_name:filter_picks; 3, parameters; 4, block; 5, identifier:catalog; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, comment:# Don't work in place on the catalog; 14, expression_statement; 15, if_statement; 16, if_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, comment:# Remove events without picks; 22, expression_statement; 23, for_statement; 24, return_statement; 25, identifier:stations; 26, None; 27, identifier:channels; 28, None; 29, identifier:networks; 30, None; 31, identifier:locations; 32, None; 33, identifier:top_n_picks; 34, None; 35, identifier:evaluation_mode; 36, string; 37, comment:"""
      Filter events in the catalog based on a number of parameters.
  
      :param catalog: Catalog to filter.
      :type catalog: obspy.core.event.Catalog
      :param stations: List for stations to keep picks from.
      :type stations: list
      :param channels: List of channels to keep picks from.
      :type channels: list
      :param networks: List of networks to keep picks from.
      :type networks: list
      :param locations: List of location codes to use
      :type locations: list
      :param top_n_picks: Filter only the top N most used station-channel pairs.
      :type top_n_picks: int
      :param evaluation_mode:
          To select only manual or automatic picks, or use all (default).
      :type evaluation_mode: str
  
  
      :return:
          Filtered Catalog - if events are left with no picks, they are removed
          from the catalog.
      :rtype: obspy.core.event.Catalog
  
      .. note::
          Will filter first by station, then by channel, then by network, if
          using top_n_picks, this will be done last, after the other filters
          have been applied.
  
      .. note::
          Doesn't work in place on the catalog, your input catalog will be safe
          unless you overwrite it.
  
      .. note:: Doesn't expand wildcard characters.
  
      .. rubric:: Example
  
      >>> from obspy.clients.fdsn import Client
      >>> from eqcorrscan.utils.catalog_utils import filter_picks
      >>> from obspy import UTCDateTime
      >>> client = Client('NCEDC')
      >>> t1 = UTCDateTime(2004, 9, 28)
      >>> t2 = t1 + 86400
      >>> catalog = client.get_events(starttime=t1, endtime=t2, minmagnitude=3,
      ...                             minlatitude=35.7, maxlatitude=36.1,
      ...                             minlongitude=-120.6, maxlongitude=-120.2,
      ...                             includearrivals=True)
      >>> print(len(catalog))
      12
      >>> filtered_catalog = filter_picks(catalog, stations=['BMS', 'BAP',
      ...                                                    'PAG', 'PAN',
      ...                                                    'PBI', 'PKY',
      ...                                                    'YEG', 'WOF'])
      >>> print(len(filtered_catalog))
      12
      >>> stations = []
      >>> for event in filtered_catalog:
      ...     for pick in event.picks:
      ...         stations.append(pick.waveform_id.station_code)
      >>> print(sorted(list(set(stations))))
      ['BAP', 'BMS', 'PAG', 'PAN', 'PBI', 'PKY', 'WOF', 'YEG']
      """; 38, assignment; 39, identifier:stations; 40, block; 41, identifier:channels; 42, block; 43, identifier:networks; 44, block; 45, identifier:locations; 46, block; 47, comparison_operator:evaluation_mode == 'manual'; 48, block; 49, elif_clause; 50, elif_clause; 51, identifier:top_n_picks; 52, block; 53, assignment; 54, identifier:event; 55, identifier:filtered_catalog; 56, block; 57, identifier:tmp_catalog; 58, string_content:all; 59, identifier:filtered_catalog; 60, call; 61, for_statement; 62, for_statement; 63, for_statement; 64, for_statement; 65, identifier:evaluation_mode; 66, string; 67, for_statement; 68, comparison_operator:evaluation_mode == 'automatic'; 69, block; 70, comparison_operator:evaluation_mode != 'all'; 71, block; 72, expression_statement; 73, for_statement; 74, expression_statement; 75, expression_statement; 76, comment:# Hack around sorting the counter object: Py 2 does it differently to 3; 77, for_statement; 78, for_statement; 79, identifier:tmp_catalog; 80, call; 81, if_statement; 82, attribute; 83, argument_list; 84, identifier:event; 85, identifier:filtered_catalog; 86, block; 87, identifier:event; 88, identifier:filtered_catalog; 89, block; 90, identifier:event; 91, identifier:filtered_catalog; 92, block; 93, identifier:event; 94, identifier:filtered_catalog; 95, block; 96, string_content:manual; 97, identifier:event; 98, identifier:filtered_catalog; 99, block; 100, identifier:evaluation_mode; 101, string; 102, for_statement; 103, identifier:evaluation_mode; 104, string; 105, expression_statement; 106, assignment; 107, identifier:event; 108, identifier:filtered_catalog; 109, block; 110, assignment; 111, assignment; 112, identifier:i; 113, call; 114, block; 115, identifier:event; 116, identifier:filtered_catalog; 117, block; 118, identifier:Catalog; 119, argument_list; 120, comparison_operator:len(event.picks) > 0; 121, block; 122, identifier:catalog; 123, identifier:copy; 124, if_statement; 125, expression_statement; 126, if_statement; 127, expression_statement; 128, if_statement; 129, expression_statement; 130, if_statement; 131, expression_statement; 132, expression_statement; 133, string_content:automatic; 134, identifier:event; 135, identifier:filtered_catalog; 136, block; 137, string_content:all; 138, call; 139, identifier:all_picks; 140, list; 141, expression_statement; 142, identifier:counted; 143, call; 144, identifier:all_picks; 145, list; 146, identifier:range; 147, argument_list; 148, expression_statement; 149, comment:# Sort them by alphabetical order in station; 150, expression_statement; 151, for_statement; 152, if_statement; 153, if_statement; 154, expression_statement; 155, call; 156, integer:0; 157, expression_statement; 158, comparison_operator:len(event.picks) == 0; 159, block; 160, assignment; 161, comparison_operator:len(event.picks) == 0; 162, block; 163, assignment; 164, comparison_operator:len(event.picks) == 0; 165, block; 166, assignment; 167, comparison_operator:len(event.picks) == 0; 168, block; 169, assignment; 170, assignment; 171, expression_statement; 172, attribute; 173, argument_list; 174, augmented_assignment; 175, attribute; 176, argument_list; 177, subscript; 178, assignment; 179, assignment; 180, identifier:stachan; 181, identifier:highest; 182, block; 183, comparison_operator:len(all_picks) > top_n_picks; 184, block; 185, comparison_operator:len(event.picks) == 0; 186, block; 187, assignment; 188, identifier:len; 189, argument_list; 190, call; 191, call; 192, integer:0; 193, continue_statement; 194, attribute; 195, list_comprehension; 196, call; 197, integer:0; 198, continue_statement; 199, attribute; 200, list_comprehension; 201, call; 202, integer:0; 203, continue_statement; 204, attribute; 205, list_comprehension; 206, call; 207, integer:0; 208, continue_statement; 209, attribute; 210, list_comprehension; 211, attribute; 212, list_comprehension; 213, assignment; 214, identifier:warnings; 215, identifier:warn; 216, binary_operator:'Unrecognised evaluation_mode: %s, using all picks' %
                        evaluation_mode; 217, identifier:all_picks; 218, list_comprehension; 219, call; 220, identifier:most_common; 221, subscript; 222, integer:1; 223, identifier:highest; 224, list_comprehension; 225, identifier:highest; 226, call; 227, if_statement; 228, call; 229, identifier:top_n_picks; 230, expression_statement; 231, break_statement; 232, call; 233, integer:0; 234, continue_statement; 235, attribute; 236, list_comprehension; 237, attribute; 238, attribute; 239, argument_list; 240, identifier:len; 241, argument_list; 242, identifier:event; 243, identifier:picks; 244, identifier:pick; 245, for_in_clause; 246, if_clause; 247, identifier:len; 248, argument_list; 249, identifier:event; 250, identifier:picks; 251, identifier:pick; 252, for_in_clause; 253, if_clause; 254, identifier:len; 255, argument_list; 256, identifier:event; 257, identifier:picks; 258, identifier:pick; 259, for_in_clause; 260, if_clause; 261, identifier:len; 262, argument_list; 263, identifier:event; 264, identifier:picks; 265, identifier:pick; 266, for_in_clause; 267, if_clause; 268, identifier:event; 269, identifier:picks; 270, identifier:pick; 271, for_in_clause; 272, if_clause; 273, attribute; 274, list_comprehension; 275, string; 276, identifier:evaluation_mode; 277, tuple; 278, for_in_clause; 279, identifier:Counter; 280, argument_list; 281, identifier:counted; 282, integer:0; 283, subscript; 284, for_in_clause; 285, if_clause; 286, identifier:sorted; 287, argument_list; 288, comparison_operator:stachan not in all_picks; 289, block; 290, identifier:len; 291, argument_list; 292, assignment; 293, identifier:len; 294, argument_list; 295, identifier:event; 296, identifier:picks; 297, identifier:pick; 298, for_in_clause; 299, if_clause; 300, identifier:event; 301, identifier:picks; 302, identifier:tmp_catalog; 303, identifier:append; 304, identifier:event; 305, attribute; 306, identifier:pick; 307, attribute; 308, comparison_operator:pick.waveform_id.station_code in stations; 309, attribute; 310, identifier:pick; 311, attribute; 312, comparison_operator:pick.waveform_id.channel_code in channels; 313, attribute; 314, identifier:pick; 315, attribute; 316, comparison_operator:pick.waveform_id.network_code in networks; 317, attribute; 318, identifier:pick; 319, attribute; 320, comparison_operator:pick.waveform_id.location_code in locations; 321, identifier:pick; 322, attribute; 323, comparison_operator:pick.evaluation_mode == 'manual'; 324, identifier:event; 325, identifier:picks; 326, identifier:pick; 327, for_in_clause; 328, if_clause; 329, string_content:Unrecognised evaluation_mode: %s, using all picks; 330, attribute; 331, attribute; 332, identifier:pick; 333, attribute; 334, identifier:all_picks; 335, identifier:item; 336, integer:0; 337, identifier:item; 338, identifier:counted; 339, comparison_operator:item[1] >= counted[0][1] - i; 340, identifier:highest; 341, keyword_argument; 342, identifier:stachan; 343, identifier:all_picks; 344, expression_statement; 345, identifier:all_picks; 346, identifier:all_picks; 347, subscript; 348, attribute; 349, identifier:pick; 350, attribute; 351, comparison_operator:(pick.waveform_id.station_code,
                                 pick.waveform_id.channel_code) in all_picks; 352, identifier:event; 353, identifier:picks; 354, identifier:event; 355, identifier:picks; 356, attribute; 357, identifier:stations; 358, identifier:event; 359, identifier:picks; 360, identifier:event; 361, identifier:picks; 362, attribute; 363, identifier:channels; 364, identifier:event; 365, identifier:picks; 366, identifier:event; 367, identifier:picks; 368, attribute; 369, identifier:networks; 370, identifier:event; 371, identifier:picks; 372, identifier:event; 373, identifier:picks; 374, attribute; 375, identifier:locations; 376, identifier:event; 377, identifier:picks; 378, attribute; 379, string; 380, identifier:pick; 381, attribute; 382, comparison_operator:pick.evaluation_mode == 'automatic'; 383, attribute; 384, identifier:station_code; 385, attribute; 386, identifier:channel_code; 387, identifier:event; 388, identifier:picks; 389, subscript; 390, binary_operator:counted[0][1] - i; 391, identifier:key; 392, lambda; 393, call; 394, identifier:all_picks; 395, slice; 396, identifier:event; 397, identifier:picks; 398, identifier:event; 399, identifier:picks; 400, tuple; 401, identifier:all_picks; 402, attribute; 403, identifier:station_code; 404, attribute; 405, identifier:channel_code; 406, attribute; 407, identifier:network_code; 408, attribute; 409, identifier:location_code; 410, identifier:pick; 411, identifier:evaluation_mode; 412, string_content:manual; 413, identifier:event; 414, identifier:picks; 415, attribute; 416, string; 417, identifier:pick; 418, identifier:waveform_id; 419, identifier:pick; 420, identifier:waveform_id; 421, identifier:item; 422, integer:1; 423, subscript; 424, identifier:i; 425, lambda_parameters; 426, subscript; 427, attribute; 428, argument_list; 429, integer:0; 430, identifier:top_n_picks; 431, attribute; 432, attribute; 433, identifier:pick; 434, identifier:waveform_id; 435, identifier:pick; 436, identifier:waveform_id; 437, identifier:pick; 438, identifier:waveform_id; 439, identifier:pick; 440, identifier:waveform_id; 441, identifier:pick; 442, identifier:evaluation_mode; 443, string_content:automatic; 444, subscript; 445, integer:1; 446, identifier:tup; 447, identifier:tup; 448, integer:0; 449, identifier:all_picks; 450, identifier:append; 451, identifier:stachan; 452, attribute; 453, identifier:station_code; 454, attribute; 455, identifier:channel_code; 456, identifier:counted; 457, integer:0; 458, identifier:pick; 459, identifier:waveform_id; 460, identifier:pick; 461, identifier:waveform_id
code: def filter_picks(catalog, stations=None, channels=None, networks=None,
                   locations=None, top_n_picks=None, evaluation_mode='all'):
      """
      Filter events in the catalog based on a number of parameters.
  
      :param catalog: Catalog to filter.
      :type catalog: obspy.core.event.Catalog
      :param stations: List for stations to keep picks from.
      :type stations: list
      :param channels: List of channels to keep picks from.
      :type channels: list
      :param networks: List of networks to keep picks from.
      :type networks: list
      :param locations: List of location codes to use
      :type locations: list
      :param top_n_picks: Filter only the top N most used station-channel pairs.
      :type top_n_picks: int
      :param evaluation_mode:
          To select only manual or automatic picks, or use all (default).
      :type evaluation_mode: str
  
  
      :return:
          Filtered Catalog - if events are left with no picks, they are removed
          from the catalog.
      :rtype: obspy.core.event.Catalog
  
      .. note::
          Will filter first by station, then by channel, then by network, if
          using top_n_picks, this will be done last, after the other filters
          have been applied.
  
      .. note::
          Doesn't work in place on the catalog, your input catalog will be safe
          unless you overwrite it.
  
      .. note:: Doesn't expand wildcard characters.
  
      .. rubric:: Example
  
      >>> from obspy.clients.fdsn import Client
      >>> from eqcorrscan.utils.catalog_utils import filter_picks
      >>> from obspy import UTCDateTime
      >>> client = Client('NCEDC')
      >>> t1 = UTCDateTime(2004, 9, 28)
      >>> t2 = t1 + 86400
      >>> catalog = client.get_events(starttime=t1, endtime=t2, minmagnitude=3,
      ...                             minlatitude=35.7, maxlatitude=36.1,
      ...                             minlongitude=-120.6, maxlongitude=-120.2,
      ...                             includearrivals=True)
      >>> print(len(catalog))
      12
      >>> filtered_catalog = filter_picks(catalog, stations=['BMS', 'BAP',
      ...                                                    'PAG', 'PAN',
      ...                                                    'PBI', 'PKY',
      ...                                                    'YEG', 'WOF'])
      >>> print(len(filtered_catalog))
      12
      >>> stations = []
      >>> for event in filtered_catalog:
      ...     for pick in event.picks:
      ...         stations.append(pick.waveform_id.station_code)
      >>> print(sorted(list(set(stations))))
      ['BAP', 'BMS', 'PAG', 'PAN', 'PBI', 'PKY', 'WOF', 'YEG']
      """
      # Don't work in place on the catalog
      filtered_catalog = catalog.copy()
  
      if stations:
          for event in filtered_catalog:
              if len(event.picks) == 0:
                  continue
              event.picks = [pick for pick in event.picks
                             if pick.waveform_id.station_code in stations]
      if channels:
          for event in filtered_catalog:
              if len(event.picks) == 0:
                  continue
              event.picks = [pick for pick in event.picks
                             if pick.waveform_id.channel_code in channels]
      if networks:
          for event in filtered_catalog:
              if len(event.picks) == 0:
                  continue
              event.picks = [pick for pick in event.picks
                             if pick.waveform_id.network_code in networks]
      if locations:
          for event in filtered_catalog:
              if len(event.picks) == 0:
                  continue
              event.picks = [pick for pick in event.picks
                             if pick.waveform_id.location_code in locations]
      if evaluation_mode == 'manual':
          for event in filtered_catalog:
              event.picks = [pick for pick in event.picks
                             if pick.evaluation_mode == 'manual']
      elif evaluation_mode == 'automatic':
          for event in filtered_catalog:
              event.picks = [pick for pick in event.picks
                             if pick.evaluation_mode == 'automatic']
      elif evaluation_mode != 'all':
          warnings.warn('Unrecognised evaluation_mode: %s, using all picks' %
                        evaluation_mode)
      if top_n_picks:
          all_picks = []
          for event in filtered_catalog:
              all_picks += [(pick.waveform_id.station_code,
                             pick.waveform_id.channel_code)
                            for pick in event.picks]
          counted = Counter(all_picks).most_common()
          all_picks = []
          # Hack around sorting the counter object: Py 2 does it differently to 3
          for i in range(counted[0][1]):
              highest = [item[0] for item in counted
                         if item[1] >= counted[0][1] - i]
              # Sort them by alphabetical order in station
              highest = sorted(highest, key=lambda tup: tup[0])
              for stachan in highest:
                  if stachan not in all_picks:
                      all_picks.append(stachan)
              if len(all_picks) > top_n_picks:
                  all_picks = all_picks[0:top_n_picks]
                  break
          for event in filtered_catalog:
              if len(event.picks) == 0:
                  continue
              event.picks = [pick for pick in event.picks
                             if (pick.waveform_id.station_code,
                                 pick.waveform_id.channel_code) in all_picks]
      # Remove events without picks
      tmp_catalog = Catalog()
      for event in filtered_catalog:
          if len(event.picks) > 0:
              tmp_catalog.append(event)
  
      return tmp_catalog