code: def filter_picks(catalog, stations=None, channels=None, networks=None,
                   locations=None, top_n_picks=None, evaluation_mode='all'):
      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 = []
          for i in range(counted[0][1]):
              highest = [item[0] for item in counted
                         if item[1] >= counted[0][1] - i]
              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]
      tmp_catalog = Catalog()
      for event in filtered_catalog:
          if len(event.picks) > 0:
              tmp_catalog.append(event)
      return tmp_catalog