nodes: 0, module; 1, function_definition; 2, function_name:get_data_file_names_from_scan_base; 3, parameters; 4, block; 5, identifier:scan_base; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, if_statement; 13, for_statement; 14, if_statement; 15, if_statement; 16, return_statement; 17, identifier:filter_str; 18, list; 19, identifier:sort_by_time; 20, True; 21, identifier:meta_data_v2; 22, True; 23, comment:"""
      Generate a list of .h5 files which have a similar file name.
  
      Parameters
      ----------
      scan_base : list, string
          List of string or string of the scan base names. The scan_base will be used to search for files containing the string. The .h5 file extension will be added automatically.
      filter : list, string
          List of string or string which are used to filter the returned filenames. File names containing filter_str in the file name will not be returned. Use None to disable filter.
      sort_by_time : bool
          If True, return file name list sorted from oldest to newest. The time from meta table will be used to sort the files.
      meta_data_v2 : bool
          True for new (v2) meta data format, False for the old (v1) format.
  
      Returns
      -------
      data_files : list
          List of file names matching the obove conditions.
      """; 24, assignment; 25, comparison_operator:scan_base is None; 26, block; 27, call; 28, block; 29, identifier:scan_base_str; 30, identifier:scan_base; 31, block; 32, identifier:filter_str; 33, block; 34, boolean_operator; 35, block; 36, identifier:data_files; 37, string; 38, string; 39, string; 40, string; 41, string; 42, identifier:data_files; 43, list; 44, identifier:scan_base; 45, None; 46, return_statement; 47, identifier:isinstance; 48, argument_list; 49, expression_statement; 50, if_statement; 51, if_statement; 52, expression_statement; 53, identifier:sort_by_time; 54, comparison_operator:len(data_files) > 1; 55, expression_statement; 56, for_statement; 57, expression_statement; 58, string_content:_analyzed.h5; 59, string_content:_interpreted.h5; 60, string_content:_cut.h5; 61, string_content:_result.h5; 62, string_content:_hists.h5; 63, identifier:data_files; 64, identifier:scan_base; 65, identifier:basestring; 66, assignment; 67, comparison_operator:'.h5' == os.path.splitext(scan_base_str)[1]; 68, block; 69, else_clause; 70, call; 71, block; 72, assignment; 73, call; 74, integer:1; 75, assignment; 76, identifier:data_file; 77, identifier:data_files; 78, block; 79, assignment; 80, identifier:scan_base; 81, list; 82, string; 83, subscript; 84, expression_statement; 85, block; 86, identifier:isinstance; 87, argument_list; 88, expression_statement; 89, identifier:data_files; 90, call; 91, identifier:len; 92, argument_list; 93, identifier:f_list; 94, dictionary; 95, with_statement; 96, identifier:data_files; 97, call; 98, identifier:scan_base; 99, string_content:.h5; 100, call; 101, integer:1; 102, call; 103, expression_statement; 104, identifier:filter_str; 105, identifier:basestring; 106, assignment; 107, identifier:filter; 108, argument_list; 109, identifier:data_files; 110, with_clause; 111, block; 112, identifier:list; 113, argument_list; 114, attribute; 115, argument_list; 116, attribute; 117, argument_list; 118, call; 119, identifier:filter_str; 120, list; 121, lambda; 122, identifier:data_files; 123, with_item; 124, try_statement; 125, call; 126, attribute; 127, identifier:splitext; 128, identifier:scan_base_str; 129, identifier:data_files; 130, identifier:append; 131, identifier:scan_base_str; 132, attribute; 133, argument_list; 134, identifier:filter_str; 135, lambda_parameters; 136, not_operator; 137, as_pattern; 138, block; 139, except_clause; 140, else_clause; 141, identifier:sorted; 142, argument_list; 143, identifier:os; 144, identifier:path; 145, identifier:data_files; 146, identifier:extend; 147, call; 148, identifier:data_file; 149, call; 150, call; 151, as_pattern_target; 152, expression_statement; 153, attribute; 154, block; 155, block; 156, identifier:f_list; 157, keyword_argument; 158, keyword_argument; 159, attribute; 160, argument_list; 161, identifier:any; 162, argument_list; 163, attribute; 164, argument_list; 165, identifier:h5_file; 166, assignment; 167, identifier:tb; 168, identifier:NoSuchNodeError; 169, expression_statement; 170, try_statement; 171, identifier:key; 172, attribute; 173, identifier:reverse; 174, False; 175, identifier:glob; 176, identifier:glob; 177, binary_operator:scan_base_str + '*.h5'; 178, list_comprehension; 179, identifier:tb; 180, identifier:open_file; 181, identifier:data_file; 182, keyword_argument; 183, identifier:meta_data; 184, attribute; 185, call; 186, block; 187, except_clause; 188, else_clause; 189, identifier:f_list; 190, identifier:__getitem__; 191, identifier:scan_base_str; 192, string; 193, parenthesized_expression; 194, for_in_clause; 195, identifier:mode; 196, string:"r"; 197, attribute; 198, identifier:meta_data; 199, attribute; 200, argument_list; 201, if_statement; 202, identifier:IndexError; 203, block; 204, block; 205, string_content:*.h5; 206, conditional_expression:True if x in data_file else False; 207, identifier:x; 208, identifier:filter_str; 209, identifier:h5_file; 210, identifier:root; 211, identifier:logging; 212, identifier:warning; 213, binary_operator:"File %s is missing meta_data" % h5_file.filename; 214, identifier:meta_data_v2; 215, block; 216, else_clause; 217, expression_statement; 218, expression_statement; 219, True; 220, comparison_operator:x in data_file; 221, False; 222, string:"File %s is missing meta_data"; 223, attribute; 224, expression_statement; 225, block; 226, call; 227, assignment; 228, identifier:x; 229, identifier:data_file; 230, identifier:h5_file; 231, identifier:filename; 232, assignment; 233, expression_statement; 234, attribute; 235, argument_list; 236, subscript; 237, identifier:timestamp; 238, identifier:timestamp; 239, subscript; 240, assignment; 241, identifier:logging; 242, identifier:info; 243, binary_operator:"File %s has empty meta_data" % h5_file.filename; 244, identifier:f_list; 245, identifier:data_file; 246, subscript; 247, string:"timestamp_start"; 248, identifier:timestamp; 249, subscript; 250, string:"File %s has empty meta_data"; 251, attribute; 252, identifier:meta_data; 253, integer:0; 254, subscript; 255, string:"timestamp"; 256, identifier:h5_file; 257, identifier:filename; 258, identifier:meta_data; 259, integer:0
code: def get_data_file_names_from_scan_base(scan_base, filter_str=['_analyzed.h5', '_interpreted.h5', '_cut.h5', '_result.h5', '_hists.h5'], sort_by_time=True, meta_data_v2=True):
      """
      Generate a list of .h5 files which have a similar file name.
  
      Parameters
      ----------
      scan_base : list, string
          List of string or string of the scan base names. The scan_base will be used to search for files containing the string. The .h5 file extension will be added automatically.
      filter : list, string
          List of string or string which are used to filter the returned filenames. File names containing filter_str in the file name will not be returned. Use None to disable filter.
      sort_by_time : bool
          If True, return file name list sorted from oldest to newest. The time from meta table will be used to sort the files.
      meta_data_v2 : bool
          True for new (v2) meta data format, False for the old (v1) format.
  
      Returns
      -------
      data_files : list
          List of file names matching the obove conditions.
      """
      data_files = []
      if scan_base is None:
          return data_files
      if isinstance(scan_base, basestring):
          scan_base = [scan_base]
      for scan_base_str in scan_base:
          if '.h5' == os.path.splitext(scan_base_str)[1]:
              data_files.append(scan_base_str)
          else:
              data_files.extend(glob.glob(scan_base_str + '*.h5'))
  
      if filter_str:
          if isinstance(filter_str, basestring):
              filter_str = [filter_str]
          data_files = filter(lambda data_file: not any([(True if x in data_file else False) for x in filter_str]), data_files)
      if sort_by_time and len(data_files) > 1:
          f_list = {}
          for data_file in data_files:
              with tb.open_file(data_file, mode="r") as h5_file:
                  try:
                      meta_data = h5_file.root.meta_data
                  except tb.NoSuchNodeError:
                      logging.warning("File %s is missing meta_data" % h5_file.filename)
                  else:
                      try:
                          if meta_data_v2:
                              timestamp = meta_data[0]["timestamp_start"]
                          else:
                              timestamp = meta_data[0]["timestamp"]
                      except IndexError:
                          logging.info("File %s has empty meta_data" % h5_file.filename)
                      else:
                          f_list[data_file] = timestamp
  
          data_files = list(sorted(f_list, key=f_list.__getitem__, reverse=False))
      return data_files