nodes: 0, module; 1, function_definition; 2, function_name:get_parameter_from_files; 3, parameters; 4, block; 5, identifier:files; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, if_statement; 14, expression_statement; 15, comment:# get the parameter from the file name; 16, for_statement; 17, return_statement; 18, identifier:parameters; 19, None; 20, identifier:unique; 21, False; 22, identifier:sort; 23, True; 24, string; 25, call; 26, assignment; 27, call; 28, block; 29, call; 30, block; 31, assignment; 32, identifier:file_name; 33, identifier:files; 34, block; 35, call; 36, string_content:Takes a list of files, searches for the parameter name in the file name and in the file.
      Returns a ordered dict with the file name in the first dimension and the corresponding parameter values in the second.
      If a scan parameter appears in the file name and in the file the first parameter setting has to be in the file name, otherwise a warning is shown.
      The file names can be sorted by the first parameter value of each file.
  
      Parameters
      ----------
      files : string, list of strings
      parameters : string, list of strings
      unique : boolean
          If set only one file per scan parameter value is used.
      sort : boolean
  
      Returns
      -------
      collections.OrderedDict; 37, attribute; 38, argument_list; 39, identifier:files_dict; 40, call; 41, identifier:isinstance; 42, argument_list; 43, expression_statement; 44, identifier:isinstance; 45, argument_list; 46, expression_statement; 47, identifier:parameter_values_from_file_names_dict; 48, call; 49, with_statement; 50, attribute; 51, argument_list; 52, identifier:logging; 53, identifier:debug; 54, binary_operator:'Get the parameter ' + str(parameters) + ' values from ' + str(len(files)) + ' files'; 55, attribute; 56, argument_list; 57, identifier:files; 58, identifier:basestring; 59, assignment; 60, identifier:parameters; 61, identifier:basestring; 62, assignment; 63, identifier:get_parameter_value_from_file_names; 64, argument_list; 65, with_clause; 66, comment:# open the actual file; 67, block; 68, identifier:collections; 69, identifier:OrderedDict; 70, conditional_expression:sorted(files_dict.iteritems(), key=itemgetter(1)) if sort else files_dict; 71, binary_operator:'Get the parameter ' + str(parameters) + ' values from ' + str(len(files)); 72, string; 73, identifier:collections; 74, identifier:OrderedDict; 75, identifier:files; 76, tuple; 77, identifier:parameters; 78, tuple; 79, identifier:files; 80, identifier:parameters; 81, keyword_argument; 82, keyword_argument; 83, with_item; 84, expression_statement; 85, try_statement; 86, if_statement; 87, if_statement; 88, call; 89, identifier:sort; 90, identifier:files_dict; 91, binary_operator:'Get the parameter ' + str(parameters) + ' values from '; 92, call; 93, string_content:files; 94, identifier:files; 95, identifier:parameters; 96, identifier:unique; 97, identifier:unique; 98, identifier:sort; 99, identifier:sort; 100, as_pattern; 101, assignment; 102, block; 103, except_clause; 104, not_operator; 105, comment:# if no scan parameter values could be set from file take the parameter found in the file name; 106, block; 107, else_clause; 108, boolean_operator; 109, block; 110, else_clause; 111, identifier:sorted; 112, argument_list; 113, binary_operator:'Get the parameter ' + str(parameters); 114, string; 115, identifier:str; 116, argument_list; 117, call; 118, as_pattern_target; 119, identifier:scan_parameter_values; 120, call; 121, expression_statement; 122, comment:# get the scan parameters from the scan parameter table; 123, if_statement; 124, for_statement; 125, attribute; 126, comment:# scan parameter table does not exist; 127, block; 128, identifier:scan_parameter_values; 129, try_statement; 130, comment:# use the parameter given in the file and cross check if it matches the file name parameter if these is given; 131, block; 132, identifier:unique; 133, comparison_operator:scan_parameter_values is not None; 134, expression_statement; 135, for_statement; 136, if_statement; 137, block; 138, call; 139, keyword_argument; 140, string; 141, call; 142, string_content:values from; 143, call; 144, attribute; 145, argument_list; 146, identifier:in_file_h5; 147, attribute; 148, argument_list; 149, assignment; 150, comparison_operator:parameters is None; 151, block; 152, identifier:parameter; 153, identifier:parameters; 154, block; 155, identifier:tb; 156, identifier:NoSuchNodeError; 157, try_statement; 158, block; 159, except_clause; 160, try_statement; 161, identifier:scan_parameter_values; 162, None; 163, assignment; 164, identifier:parameter; 165, identifier:scan_parameter_values; 166, comment:# loop to determine if any value of any scan parameter exists already; 167, block; 168, not_operator; 169, block; 170, else_clause; 171, expression_statement; 172, attribute; 173, argument_list; 174, identifier:key; 175, call; 176, string_content:Get the parameter; 177, identifier:str; 178, argument_list; 179, identifier:len; 180, argument_list; 181, identifier:tb; 182, identifier:open_file; 183, identifier:file_name; 184, keyword_argument; 185, identifier:collections; 186, identifier:OrderedDict; 187, identifier:scan_parameters; 188, subscript; 189, identifier:parameters; 190, None; 191, expression_statement; 192, try_statement; 193, block; 194, except_clause; 195, expression_statement; 196, identifier:KeyError; 197, comment:# no scan parameter found at all, neither in the file name nor in the file; 198, block; 199, block; 200, except_clause; 201, except_clause; 202, identifier:existing; 203, False; 204, expression_statement; 205, if_statement; 206, identifier:existing; 207, expression_statement; 208, block; 209, assignment; 210, identifier:files_dict; 211, identifier:iteritems; 212, identifier:itemgetter; 213, argument_list; 214, identifier:parameters; 215, identifier:files; 216, identifier:mode; 217, string:"r"; 218, attribute; 219, slice; 220, assignment; 221, block; 222, except_clause; 223, expression_statement; 224, comment:# get the scan parameters from the meta data; 225, if_statement; 226, attribute; 227, comment:# meta data table does not exist; 228, block; 229, assignment; 230, expression_statement; 231, for_statement; 232, identifier:KeyError; 233, comment:# parameter does not exists in the file name; 234, block; 235, identifier:IndexError; 236, block; 237, assignment; 238, call; 239, block; 240, assignment; 241, expression_statement; 242, subscript; 243, identifier:scan_parameter_values; 244, integer:1; 245, attribute; 246, identifier:scan_parameters; 247, identifier:parameters; 248, call; 249, expression_statement; 250, comment:# different scan parameter values used; 251, identifier:ValueError; 252, comment:# the scan parameter does not exists; 253, block; 254, assignment; 255, identifier:scan_parameters; 256, block; 257, identifier:tb; 258, identifier:NoSuchNodeError; 259, pass_statement; 260, identifier:scan_parameter_values; 261, subscript; 262, assignment; 263, pattern_list; 264, call; 265, block; 266, pass_statement; 267, raise_statement; 268, identifier:all_par_values; 269, list_comprehension; 270, identifier:any; 271, generator_expression; 272, expression_statement; 273, break_statement; 274, subscript; 275, identifier:scan_parameter_values; 276, call; 277, identifier:files_dict; 278, identifier:file_name; 279, identifier:in_file_h5; 280, identifier:root; 281, identifier:get_scan_parameter_names; 282, argument_list; 283, assignment; 284, pass_statement; 285, identifier:scan_parameters; 286, call; 287, try_statement; 288, identifier:parameter_values_from_file_names_dict; 289, identifier:file_name; 290, identifier:scan_parameter_values; 291, None; 292, identifier:key; 293, identifier:value; 294, attribute; 295, argument_list; 296, if_statement; 297, call; 298, subscript; 299, for_in_clause; 300, comparison_operator:x in [scan_parameter_values[parameter]]; 301, for_in_clause; 302, assignment; 303, identifier:files_dict; 304, identifier:file_name; 305, attribute; 306, argument_list; 307, identifier:scan_parameters; 308, subscript; 309, call; 310, identifier:get_scan_parameter; 311, argument_list; 312, block; 313, except_clause; 314, identifier:scan_parameter_values; 315, identifier:items; 316, boolean_operator; 317, comment:# parameter value exists: check if the first value is the file name value; 318, block; 319, identifier:IncompleteInputError; 320, argument_list; 321, identifier:values; 322, identifier:parameter; 323, identifier:values; 324, call; 325, identifier:x; 326, list; 327, identifier:x; 328, identifier:all_par_values; 329, identifier:existing; 330, True; 331, identifier:logging; 332, identifier:warning; 333, string; 334, identifier:file_name; 335, identifier:scan_parameter_values; 336, identifier:parameter; 337, attribute; 338, argument_list; 339, subscript; 340, expression_statement; 341, comment:# different scan parameter values used; 342, identifier:ValueError; 343, comment:# the scan parameter does not exists; 344, block; 345, identifier:value; 346, comparison_operator:value[0] != parameter_values_from_file_names_dict[file_name][key][0]; 347, expression_statement; 348, string; 349, attribute; 350, argument_list; 351, subscript; 352, string_content:Scan parameter value(s) from %s exists already, do not add to result; 353, call; 354, identifier:tolist; 355, attribute; 356, slice; 357, assignment; 358, pass_statement; 359, subscript; 360, subscript; 361, call; 362, string_content:Something wrong check!; 363, identifier:files_dict; 364, identifier:values; 365, identifier:scan_parameter_values; 366, identifier:parameter; 367, attribute; 368, argument_list; 369, attribute; 370, identifier:meta_data; 371, identifier:scan_parameter_values; 372, call; 373, identifier:value; 374, integer:0; 375, subscript; 376, integer:0; 377, attribute; 378, argument_list; 379, identifier:np; 380, identifier:unique; 381, subscript; 382, identifier:in_file_h5; 383, identifier:root; 384, attribute; 385, argument_list; 386, subscript; 387, identifier:key; 388, identifier:logging; 389, identifier:warning; 390, binary_operator:'Parameter values in the file name and in the file differ. Take ' + str(key) + ' parameters ' + str(value) + ' found in %s.'; 391, identifier:file_name; 392, identifier:scan_parameters; 393, identifier:parameter; 394, call; 395, identifier:tolist; 396, identifier:parameter_values_from_file_names_dict; 397, identifier:file_name; 398, binary_operator:'Parameter values in the file name and in the file differ. Take ' + str(key) + ' parameters ' + str(value); 399, string; 400, attribute; 401, argument_list; 402, binary_operator:'Parameter values in the file name and in the file differ. Take ' + str(key) + ' parameters '; 403, call; 404, string_content:found in %s.; 405, identifier:np; 406, identifier:unique; 407, subscript; 408, binary_operator:'Parameter values in the file name and in the file differ. Take ' + str(key); 409, string; 410, identifier:str; 411, argument_list; 412, identifier:scan_parameters; 413, identifier:parameters; 414, string; 415, call; 416, string_content:parameters; 417, identifier:value; 418, string_content:Parameter values in the file name and in the file differ. Take; 419, identifier:str; 420, argument_list; 421, identifier:key
code: def get_parameter_from_files(files, parameters=None, unique=False, sort=True):
      ''' Takes a list of files, searches for the parameter name in the file name and in the file.
      Returns a ordered dict with the file name in the first dimension and the corresponding parameter values in the second.
      If a scan parameter appears in the file name and in the file the first parameter setting has to be in the file name, otherwise a warning is shown.
      The file names can be sorted by the first parameter value of each file.
  
      Parameters
      ----------
      files : string, list of strings
      parameters : string, list of strings
      unique : boolean
          If set only one file per scan parameter value is used.
      sort : boolean
  
      Returns
      -------
      collections.OrderedDict
  
      '''
      logging.debug('Get the parameter ' + str(parameters) + ' values from ' + str(len(files)) + ' files')
      files_dict = collections.OrderedDict()
      if isinstance(files, basestring):
          files = (files, )
      if isinstance(parameters, basestring):
          parameters = (parameters, )
      parameter_values_from_file_names_dict = get_parameter_value_from_file_names(files, parameters, unique=unique, sort=sort)  # get the parameter from the file name
      for file_name in files:
          with tb.open_file(file_name, mode="r") as in_file_h5:  # open the actual file
              scan_parameter_values = collections.OrderedDict()
              try:
                  scan_parameters = in_file_h5.root.scan_parameters[:]  # get the scan parameters from the scan parameter table
                  if parameters is None:
                      parameters = get_scan_parameter_names(scan_parameters)
                  for parameter in parameters:
                      try:
                          scan_parameter_values[parameter] = np.unique(scan_parameters[parameter]).tolist()  # different scan parameter values used
                      except ValueError:  # the scan parameter does not exists
                          pass
              except tb.NoSuchNodeError:  # scan parameter table does not exist
                  try:
                      scan_parameters = get_scan_parameter(in_file_h5.root.meta_data[:])  # get the scan parameters from the meta data
                      if scan_parameters:
                          try:
                              scan_parameter_values = np.unique(scan_parameters[parameters]).tolist()  # different scan parameter values used
                          except ValueError:  # the scan parameter does not exists
                              pass
                  except tb.NoSuchNodeError:  # meta data table does not exist
                      pass
              if not scan_parameter_values:  # if no scan parameter values could be set from file take the parameter found in the file name
                  try:
                      scan_parameter_values = parameter_values_from_file_names_dict[file_name]
                  except KeyError:  # no scan parameter found at all, neither in the file name nor in the file
                      scan_parameter_values = None
              else:  # use the parameter given in the file and cross check if it matches the file name parameter if these is given
                  try:
                      for key, value in scan_parameter_values.items():
                          if value and value[0] != parameter_values_from_file_names_dict[file_name][key][0]:  # parameter value exists: check if the first value is the file name value
                              logging.warning('Parameter values in the file name and in the file differ. Take ' + str(key) + ' parameters ' + str(value) + ' found in %s.', file_name)
                  except KeyError:  # parameter does not exists in the file name
                      pass
                  except IndexError:
                      raise IncompleteInputError('Something wrong check!')
              if unique and scan_parameter_values is not None:
                  existing = False
                  for parameter in scan_parameter_values:  # loop to determine if any value of any scan parameter exists already
                      all_par_values = [values[parameter] for values in files_dict.values()]
                      if any(x in [scan_parameter_values[parameter]] for x in all_par_values):
                          existing = True
                          break
                  if not existing:
                      files_dict[file_name] = scan_parameter_values
                  else:
                      logging.warning('Scan parameter value(s) from %s exists already, do not add to result', file_name)
              else:
                  files_dict[file_name] = scan_parameter_values
      return collections.OrderedDict(sorted(files_dict.iteritems(), key=itemgetter(1)) if sort else files_dict)