nodes: 0, module; 1, function_definition; 2, function_name:read; 3, parameters; 4, block; 5, identifier:fname; 6, dictionary_splat_pattern; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, with_statement; 11, return_statement; 12, identifier:kw; 13, string; 14, boolean_operator; 15, block; 16, assignment; 17, with_clause; 18, block; 19, identifier:d; 20, string_content:Reads an lsp output file and returns a raw dump of data,
      sectioned into quantities either as an dictionary or a typed numpy array.
  
      Parameters:
      -----------
  
      fname -- filename of thing to read
      
      Keyword Arguments:
      ------------------
  
      vprint   --  Verbose printer. Used in scripts
      override --  (type, start) => A tuple of a dump type and a place to start
                   in the passed file, useful to attempting to read semicorrupted
                   files.
      gzip     --  Read as a gzip file.
  
      flds/sclr Specific Arguments:
      -----------------------------
      var          -- list of quantities to be read. For fields, this can consist
                      of strings that include vector components, e.g., 'Ex'. If 
                      None (default), read all quantities.
      keep_edges   -- If set to truthy, then don't remove the edges from domains before
                      concatenation and don't reshape the flds data.
      sort         -- If not None, sort using these indices, useful for avoiding
                      resorting. If True and not an ndarray, just sort.
      first_sort   -- If truthy, sort, and return the sort data for future flds
                      that should have the same shape.
      keep_xs      -- Keep the xs's, that is, the grid information. Usually redundant
                      with x,y,z returned.
      return_array -- If set to truthy, then try to return a numpy array with a dtype.
                      Requires of course that the quantities have the same shape.; 21, call; 22, comparison_operator:kw['gzip'] == 'guess'; 23, expression_statement; 24, identifier:openf; 25, conditional_expression:gzip.open if test(kw, 'gzip') else open; 26, with_item; 27, if_statement; 28, expression_statement; 29, if_statement; 30, expression_statement; 31, try_statement; 32, identifier:test; 33, argument_list; 34, subscript; 35, string; 36, assignment; 37, attribute; 38, call; 39, identifier:open; 40, as_pattern; 41, call; 42, block; 43, else_clause; 44, assignment; 45, comparison_operator:2 <= header['dump_type'] <= 3; 46, block; 47, assignment; 48, block; 49, except_clause; 50, identifier:kw; 51, string; 52, identifier:kw; 53, string; 54, string_content:guess; 55, subscript; 56, comparison_operator:re.search(r'\.gz$', fname) is not None; 57, identifier:gzip; 58, identifier:open; 59, identifier:test; 60, argument_list; 61, call; 62, as_pattern_target; 63, identifier:test; 64, argument_list; 65, expression_statement; 66, expression_statement; 67, expression_statement; 68, if_statement; 69, block; 70, identifier:vprint; 71, conditional_expression:kw['vprint'] if test(kw, 'vprint') else lambda s: None; 72, integer:2; 73, subscript; 74, integer:3; 75, if_statement; 76, expression_statement; 77, expression_statement; 78, if_statement; 79, expression_statement; 80, expression_statement; 81, identifier:readers; 82, dictionary; 83, expression_statement; 84, identifier:KeyError; 85, block; 86, string_content:gzip; 87, string_content:gzip; 88, identifier:kw; 89, string; 90, call; 91, None; 92, identifier:kw; 93, string; 94, identifier:openf; 95, argument_list; 96, identifier:file; 97, identifier:kw; 98, string; 99, assignment; 100, call; 101, assignment; 102, boolean_operator; 103, block; 104, expression_statement; 105, subscript; 106, call; 107, lambda; 108, identifier:header; 109, string; 110, not_operator; 111, block; 112, else_clause; 113, assignment; 114, assignment; 115, call; 116, block; 117, else_clause; 118, assignment; 119, assignment; 120, pair; 121, pair; 122, pair; 123, pair; 124, pair; 125, assignment; 126, raise_statement; 127, string_content:gzip; 128, attribute; 129, argument_list; 130, string_content:gzip; 131, identifier:fname; 132, string; 133, string_content:override; 134, pattern_list; 135, subscript; 136, attribute; 137, argument_list; 138, identifier:header; 139, dictionary; 140, not_operator; 141, comparison_operator:2 <= header['dump_type'] <= 3; 142, raise_statement; 143, assignment; 144, identifier:kw; 145, string; 146, identifier:test; 147, argument_list; 148, lambda_parameters; 149, None; 150, string_content:dump_type; 151, call; 152, expression_statement; 153, block; 154, identifier:keep_edges; 155, call; 156, identifier:first_sort; 157, call; 158, identifier:test; 159, argument_list; 160, expression_statement; 161, block; 162, identifier:keep_xs; 163, call; 164, identifier:return_array; 165, call; 166, integer:1; 167, lambda; 168, integer:2; 169, lambda; 170, integer:3; 171, lambda; 172, integer:6; 173, lambda; 174, integer:10; 175, lambda; 176, identifier:d; 177, call; 178, call; 179, identifier:re; 180, identifier:search; 181, string; 182, identifier:fname; 183, string_content:rb; 184, identifier:dump; 185, identifier:start; 186, identifier:kw; 187, string; 188, identifier:file; 189, identifier:seek; 190, identifier:start; 191, pair; 192, call; 193, integer:2; 194, subscript; 195, integer:3; 196, call; 197, identifier:header; 198, call; 199, string_content:vprint; 200, identifier:kw; 201, string; 202, identifier:s; 203, identifier:test; 204, argument_list; 205, assignment; 206, expression_statement; 207, identifier:test; 208, argument_list; 209, identifier:test; 210, argument_list; 211, identifier:kw; 212, string; 213, assignment; 214, expression_statement; 215, identifier:test; 216, argument_list; 217, identifier:test; 218, argument_list; 219, call; 220, call; 221, call; 222, call; 223, call; 224, subscript; 225, argument_list; 226, identifier:NotImplementedError; 227, argument_list; 228, string_content:\.gz$; 229, string_content:override; 230, string; 231, identifier:dump; 232, identifier:test; 233, argument_list; 234, identifier:header; 235, string; 236, identifier:ValueError; 237, argument_list; 238, identifier:get_header; 239, argument_list; 240, string_content:vprint; 241, identifier:kw; 242, string; 243, identifier:var; 244, list_comprehension; 245, assignment; 246, identifier:kw; 247, string; 248, identifier:kw; 249, string; 250, string_content:sort; 251, identifier:sort; 252, subscript; 253, assignment; 254, identifier:kw; 255, string; 256, identifier:kw; 257, string; 258, identifier:read_particles; 259, argument_list; 260, identifier:read_flds; 261, argument_list; 262, identifier:read_flds; 263, argument_list; 264, identifier:read_movie; 265, argument_list; 266, identifier:read_pext; 267, argument_list; 268, identifier:readers; 269, subscript; 270, string:"Other file types not implemented yet!"; 271, string_content:dump_type; 272, identifier:kw; 273, string; 274, string_content:dump_type; 275, string:"If you want to force to read as a scalar, you need to supply the quantities"; 276, identifier:file; 277, string_content:var; 278, subscript; 279, for_in_clause; 280, identifier:var; 281, subscript; 282, string_content:keep_edges; 283, string_content:first_sort; 284, identifier:kw; 285, string; 286, identifier:sort; 287, None; 288, string_content:keep_xs; 289, string_content:return_array; 290, identifier:file; 291, identifier:header; 292, identifier:file; 293, identifier:header; 294, identifier:var; 295, identifier:vprint; 296, keyword_argument; 297, keyword_argument; 298, keyword_argument; 299, keyword_argument; 300, keyword_argument; 301, identifier:file; 302, identifier:header; 303, identifier:var; 304, identifier:vprint; 305, keyword_argument; 306, keyword_argument; 307, keyword_argument; 308, keyword_argument; 309, keyword_argument; 310, keyword_argument; 311, identifier:file; 312, identifier:header; 313, identifier:file; 314, identifier:header; 315, identifier:header; 316, string; 317, string_content:var; 318, identifier:i; 319, integer:0; 320, identifier:i; 321, subscript; 322, identifier:kw; 323, string; 324, string_content:sort; 325, identifier:keep_edges; 326, identifier:keep_edges; 327, identifier:first_sort; 328, identifier:first_sort; 329, identifier:sort; 330, identifier:sort; 331, identifier:keep_xs; 332, identifier:keep_xs; 333, identifier:return_array; 334, identifier:return_array; 335, identifier:keep_edges; 336, identifier:keep_edges; 337, identifier:first_sort; 338, identifier:first_sort; 339, identifier:sort; 340, identifier:sort; 341, identifier:keep_xs; 342, identifier:keep_xs; 343, identifier:return_array; 344, identifier:return_array; 345, identifier:vector; 346, False; 347, string_content:dump_type; 348, identifier:header; 349, string; 350, string_content:var; 351, string_content:quantities
code: def read(fname,**kw):
      '''
      Reads an lsp output file and returns a raw dump of data,
      sectioned into quantities either as an dictionary or a typed numpy array.
  
      Parameters:
      -----------
  
      fname -- filename of thing to read
      
      Keyword Arguments:
      ------------------
  
      vprint   --  Verbose printer. Used in scripts
      override --  (type, start) => A tuple of a dump type and a place to start
                   in the passed file, useful to attempting to read semicorrupted
                   files.
      gzip     --  Read as a gzip file.
  
      flds/sclr Specific Arguments:
      -----------------------------
      var          -- list of quantities to be read. For fields, this can consist
                      of strings that include vector components, e.g., 'Ex'. If 
                      None (default), read all quantities.
      keep_edges   -- If set to truthy, then don't remove the edges from domains before
                      concatenation and don't reshape the flds data.
      sort         -- If not None, sort using these indices, useful for avoiding
                      resorting. If True and not an ndarray, just sort.
      first_sort   -- If truthy, sort, and return the sort data for future flds
                      that should have the same shape.
      keep_xs      -- Keep the xs's, that is, the grid information. Usually redundant
                      with x,y,z returned.
      return_array -- If set to truthy, then try to return a numpy array with a dtype.
                      Requires of course that the quantities have the same shape.
      '''
      if test(kw,'gzip') and kw['gzip'] == 'guess':
          kw['gzip'] = re.search(r'\.gz$', fname) is not None;
      openf = gzip.open if test(kw, 'gzip') else open;
      with openf(fname,'rb') as file:
          if test(kw,'override'):
              dump, start = kw['override'];
              file.seek(start);
              header = {'dump_type': dump};
              if not test(kw, 'var') and 2 <= header['dump_type'] <= 3 :
                  raise ValueError(
                      "If you want to force to read as a scalar, you need to supply the quantities"
                  );
          else:
              header = get_header(file);
          vprint = kw['vprint'] if test(kw, 'vprint') else lambda s: None;
          if 2 <= header['dump_type'] <= 3 :
              if not test(kw, 'var'):
                  var=[i[0] for i in header['quantities']];
              else:
                  var=kw['var'];
              keep_edges = test(kw, 'keep_edges');
              first_sort = test(kw, 'first_sort');
              if test(kw,'sort'):
                  sort = kw['sort']
              else:
                  sort = None;
              keep_xs = test(kw, 'keep_xs');
              return_array = test(kw, 'return_array');
          readers = {
              1: lambda: read_particles(file, header),
              2: lambda: read_flds(
                  file,header,var,vprint,
                  keep_edges=keep_edges,
                  first_sort=first_sort,
                  sort=sort,
                  keep_xs=keep_xs,
                  return_array=return_array),
              3: lambda: read_flds(
                  file,header,var, vprint,
                  keep_edges=keep_edges,
                  first_sort=first_sort,
                  sort=sort,
                  keep_xs=keep_xs,
                  return_array=return_array,
                  vector=False),
              6: lambda: read_movie(file, header),
              10:lambda: read_pext(file,header)
          };
          
          try:
              d = readers[header['dump_type']]();
          except KeyError:
              raise NotImplementedError("Other file types not implemented yet!");
      return d;