nodes: 0, module; 1, function_definition; 2, function_name:filter_catalog; 3, parameters; 4, block; 5, identifier:catalog; 6, dictionary_splat_pattern; 7, expression_statement; 8, comment:# interpret input pars; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, comment:# sort by magnitude; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, comment:# apply limits, insuring no more than full catalog gets selected; 19, expression_statement; 20, expression_statement; 21, comment:# Extract sources identified by selection; 22, expression_statement; 23, return_statement; 24, identifier:kwargs; 25, comment:""" 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.
      """; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, comparison_operator:max_bright is None; 34, block; 35, assignment; 36, assignment; 37, assignment; 38, identifier:new_catalog; 39, identifier:bright_limit; 40, call; 41, identifier:max_bright; 42, call; 43, identifier:min_bright; 44, call; 45, identifier:colname; 46, call; 47, identifier:phot_column; 48, subscript; 49, identifier:num_sources; 50, call; 51, identifier:sort_indx; 52, call; 53, identifier:max_bright; 54, None; 55, expression_statement; 56, identifier:limit_num; 57, call; 58, identifier:limit_num; 59, call; 60, identifier:new_catalog; 61, subscript; 62, attribute; 63, argument_list; 64, attribute; 65, argument_list; 66, attribute; 67, argument_list; 68, attribute; 69, argument_list; 70, identifier:catalog; 71, identifier:colname; 72, identifier:len; 73, argument_list; 74, attribute; 75, argument_list; 76, assignment; 77, identifier:max; 78, argument_list; 79, identifier:min; 80, argument_list; 81, identifier:catalog; 82, subscript; 83, identifier:kwargs; 84, identifier:get; 85, string; 86, float:1.00; 87, identifier:kwargs; 88, identifier:get; 89, string; 90, None; 91, identifier:kwargs; 92, identifier:get; 93, string; 94, integer:20; 95, identifier:kwargs; 96, identifier:get; 97, string; 98, string; 99, identifier:phot_column; 100, identifier:np; 101, identifier:argsort; 102, identifier:phot_column; 103, identifier:max_bright; 104, identifier:num_sources; 105, call; 106, identifier:min_bright; 107, identifier:max_bright; 108, identifier:limit_num; 109, identifier:num_sources; 110, identifier:sort_indx; 111, slice; 112, string_content:bright_limit; 113, string_content:max_bright; 114, string_content:min_bright; 115, string_content:colname; 116, string_content:vegamag; 117, identifier:int; 118, argument_list; 119, identifier:limit_num; 120, binary_operator:num_sources * bright_limit; 121, identifier:num_sources; 122, identifier:bright_limit
code: def filter_catalog(catalog, **kwargs):
      """ 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.
      """
      # 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