nodes: 0, module; 1, function_definition; 2, function_name:load_grid_data; 3, parameters; 4, block; 5, identifier:file_list; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# If there's only one file, we pretend it's a list; 11, if_statement; 12, expression_statement; 13, comment:# Initialize empty data array; 14, expression_statement; 15, comment:# Loop through file list, reading in data; 16, for_statement; 17, return_statement; 18, identifier:data_type; 19, string:"binary"; 20, identifier:sort; 21, True; 22, identifier:delim; 23, string:" "; 24, comment:"""
      Loads data from one or multiple grid_task files.
  
      Arguments:
          file_list - either a string or a list of strings indicating files to
                      load data from. Files are assumed to be in grid_task.dat
                      format (space delimited values, one per cell).
  
          data_type - a string representing what type of data is in the file.
                      Either "binary", "int", "float", or "string".
  
          sort      - If you're making a movie, you want the files to be in
                      chronological order. By default, they will be sorted.
                      If for some reason you don't want them in chronological
                      order, set sort to False.
  
      Returns: A three-dimensional array. The first dimension is columns, the
      second is rows. At each row,column index in the array is another list
      which holds the values that each of the requested files has at that
      location in the grid. If you want this list collapsed to a single
      representative number, you should use agg_niche_grid.
      """; 25, not_operator; 26, block; 27, elif_clause; 28, assignment; 29, assignment; 30, identifier:f; 31, identifier:file_list; 32, block; 33, identifier:data; 34, comparison_operator:type(file_list) is list; 35, expression_statement; 36, identifier:sort; 37, comment:# put file_list in chronological order; 38, block; 39, identifier:world_size; 40, call; 41, identifier:data; 42, call; 43, expression_statement; 44, expression_statement; 45, for_statement; 46, expression_statement; 47, call; 48, identifier:list; 49, assignment; 50, expression_statement; 51, identifier:get_world_dimensions; 52, argument_list; 53, identifier:initialize_grid; 54, argument_list; 55, assignment; 56, assignment; 57, identifier:i; 58, call; 59, block; 60, call; 61, identifier:type; 62, argument_list; 63, identifier:file_list; 64, list; 65, call; 66, subscript; 67, identifier:delim; 68, identifier:world_size; 69, list; 70, identifier:infile; 71, call; 72, identifier:lines; 73, call; 74, identifier:range; 75, argument_list; 76, expression_statement; 77, for_statement; 78, attribute; 79, argument_list; 80, identifier:file_list; 81, identifier:file_list; 82, attribute; 83, argument_list; 84, identifier:file_list; 85, integer:0; 86, identifier:open; 87, argument_list; 88, attribute; 89, argument_list; 90, subscript; 91, assignment; 92, identifier:j; 93, call; 94, block; 95, identifier:infile; 96, identifier:close; 97, identifier:file_list; 98, identifier:sort; 99, keyword_argument; 100, identifier:f; 101, identifier:infile; 102, identifier:readlines; 103, identifier:world_size; 104, integer:1; 105, subscript; 106, call; 107, identifier:range; 108, argument_list; 109, if_statement; 110, expression_statement; 111, identifier:key; 112, lambda; 113, identifier:lines; 114, identifier:i; 115, attribute; 116, argument_list; 117, subscript; 118, comparison_operator:data_type == "binary"; 119, block; 120, elif_clause; 121, elif_clause; 122, elif_clause; 123, else_clause; 124, call; 125, lambda_parameters; 126, call; 127, call; 128, identifier:split; 129, identifier:delim; 130, identifier:world_size; 131, integer:0; 132, identifier:data_type; 133, string:"binary"; 134, expression_statement; 135, comparison_operator:data_type == "float"; 136, block; 137, comparison_operator:data_type == "int"; 138, block; 139, comparison_operator:data_type == "string"; 140, block; 141, block; 142, attribute; 143, argument_list; 144, identifier:f; 145, identifier:int; 146, argument_list; 147, attribute; 148, argument_list; 149, assignment; 150, identifier:data_type; 151, string:"float"; 152, expression_statement; 153, identifier:data_type; 154, string:"int"; 155, expression_statement; 156, identifier:data_type; 157, string:"string"; 158, expression_statement; 159, expression_statement; 160, return_statement; 161, subscript; 162, identifier:append; 163, identifier:val; 164, call; 165, subscript; 166, identifier:strip; 167, identifier:val; 168, call; 169, assignment; 170, assignment; 171, assignment; 172, call; 173, subscript; 174, identifier:j; 175, attribute; 176, argument_list; 177, identifier:lines; 178, identifier:i; 179, identifier:bin; 180, argument_list; 181, identifier:val; 182, call; 183, identifier:val; 184, call; 185, identifier:val; 186, call; 187, identifier:print; 188, argument_list; 189, identifier:data; 190, identifier:i; 191, identifier:re; 192, identifier:sub; 193, string:"[^0-9]"; 194, string:""; 195, identifier:f; 196, call; 197, identifier:float; 198, argument_list; 199, identifier:int; 200, argument_list; 201, identifier:str; 202, argument_list; 203, string:"Unsupported data_type passed to load_grid"; 204, identifier:int; 205, argument_list; 206, subscript; 207, subscript; 208, subscript; 209, subscript; 210, subscript; 211, identifier:j; 212, subscript; 213, identifier:j; 214, subscript; 215, identifier:j; 216, subscript; 217, identifier:j; 218, identifier:lines; 219, identifier:i; 220, identifier:lines; 221, identifier:i; 222, identifier:lines; 223, identifier:i; 224, identifier:lines; 225, identifier:i
code: def load_grid_data(file_list, data_type="binary", sort=True, delim=" "):
      """
      Loads data from one or multiple grid_task files.
  
      Arguments:
          file_list - either a string or a list of strings indicating files to
                      load data from. Files are assumed to be in grid_task.dat
                      format (space delimited values, one per cell).
  
          data_type - a string representing what type of data is in the file.
                      Either "binary", "int", "float", or "string".
  
          sort      - If you're making a movie, you want the files to be in
                      chronological order. By default, they will be sorted.
                      If for some reason you don't want them in chronological
                      order, set sort to False.
  
      Returns: A three-dimensional array. The first dimension is columns, the
      second is rows. At each row,column index in the array is another list
      which holds the values that each of the requested files has at that
      location in the grid. If you want this list collapsed to a single
      representative number, you should use agg_niche_grid.
      """
  
      # If there's only one file, we pretend it's a list
      if not type(file_list) is list:
          file_list = [file_list]
      elif sort:
          # put file_list in chronological order
          file_list.sort(key=lambda f: int(re.sub("[^0-9]", "", f)))
  
      world_size = get_world_dimensions(file_list[0], delim)
  
      # Initialize empty data array
      data = initialize_grid(world_size, [])
  
      # Loop through file list, reading in data
      for f in file_list:
          infile = open(f)
          lines = infile.readlines()
          for i in range(world_size[1]):
              lines[i] = lines[i].strip().split(delim)
  
              for j in range(world_size[0]):
                  if data_type == "binary":
                      val = bin(int(lines[i][j]))
                  elif data_type == "float":
                      val = float(lines[i][j])
                  elif data_type == "int":
                      val = int(lines[i][j])
                  elif data_type == "string":
                      val = str(lines[i][j])
                  else:
                      print("Unsupported data_type passed to load_grid")
                      return
                  data[i][j].append(val)
  
          infile.close()
  
      return data