code: def filter_catalog(catalog, **kwargs):
      
      # interpret input pars
      bright_limit = kwargs.get('bright_limit', 1.00)
      max_bright = kwargs.get('max_bright', None)
      min_bright = kwargs.get('min_bright', 20)
      colname = kwargs.get('colname', 'vegamag')
  
      # sort by magnitude
      phot_column = catalog[colname]
      num_sources = len(phot_column)
      sort_indx = np.argsort(phot_column)
      if max_bright is None:
          max_bright = num_sources
  
      # apply limits, insuring no more than full catalog gets selected
      limit_num = max(int(num_sources * bright_limit), min_bright)
      limit_num = min(max_bright, limit_num, num_sources)
  
      # Extract sources identified by selection
      new_catalog = catalog[sort_indx[:limit_num]]
  
      return new_catalog
docs: Create a new catalog selected from input based on photometry.
  
      Parameters
      ----------
      bright_limit : float
          Fraction of catalog based on brightness that should be retained.
          Value of 1.00 means full catalog.
  
      max_bright : int
          Maximum number of sources to keep regardless of `bright_limit`.
  
      min_bright : int
          Minimum number of sources to keep regardless of `bright_limit`.
  
      colname : str
          Name of column to use for selection/sorting.
  
      Returns
      -------
      new_catalog : `~astropy.table.Table`
          New table which only has the sources that meet the selection criteria.