nodes: 0, module; 1, function_definition; 2, function_name:threenum; 3, parameters; 4, block; 5, identifier:h5file; 6, identifier:var; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, for_statement; 19, expression_statement; 20, expression_statement; 21, return_statement; 22, identifier:post_col; 23, string; 24, comment:""" Calculates the three number summary for a variable.
  
      The three number summary is the minimum, maximum and the mean
      of the data. Traditionally one would summerise data with the
      five number summary: max, min, 1st, 2nd (median), 3rd quartile.
      But quantiles are hard to calculate without sorting the data
      which hard to do out-of-core.
      """; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, identifier:x; 35, call; 36, block; 37, call; 38, assignment; 39, tuple; 40, string_content:mult; 41, identifier:f; 42, call; 43, identifier:d; 44, subscript; 45, identifier:w; 46, subscript; 47, identifier:s; 48, subscript; 49, identifier:n; 50, subscript; 51, identifier:maxval; 52, unary_operator; 53, identifier:minval; 54, call; 55, identifier:total; 56, integer:0; 57, identifier:wsum; 58, integer:0; 59, identifier:range; 60, argument_list; 61, expression_statement; 62, expression_statement; 63, expression_statement; 64, expression_statement; 65, expression_statement; 66, expression_statement; 67, expression_statement; 68, expression_statement; 69, expression_statement; 70, attribute; 71, argument_list; 72, identifier:mean; 73, binary_operator:total/float(wsum); 74, identifier:minval; 75, identifier:maxval; 76, identifier:mean; 77, attribute; 78, argument_list; 79, identifier:f; 80, identifier:var; 81, identifier:f; 82, identifier:post_col; 83, attribute; 84, integer:0; 85, attribute; 86, integer:0; 87, call; 88, attribute; 89, argument_list; 90, integer:0; 91, identifier:n; 92, identifier:s; 93, assignment; 94, assignment; 95, assignment; 96, assignment; 97, assignment; 98, assignment; 99, assignment; 100, augmented_assignment; 101, augmented_assignment; 102, identifier:f; 103, identifier:close; 104, identifier:total; 105, call; 106, identifier:h5py; 107, identifier:File; 108, identifier:h5file; 109, string; 110, identifier:d; 111, identifier:chunks; 112, identifier:d; 113, identifier:shape; 114, attribute; 115, argument_list; 116, identifier:np; 117, identifier:abs; 118, subscript; 119, identifier:aN; 120, unary_operator; 121, identifier:d_c; 122, subscript; 123, identifier:w_c; 124, subscript; 125, identifier:chunk_max; 126, call; 127, identifier:chunk_min; 128, call; 129, identifier:maxval; 130, conditional_expression:chunk_max if chunk_max > maxval else maxval; 131, identifier:minval; 132, conditional_expression:chunk_min if chunk_min < minval else minval; 133, identifier:total; 134, call; 135, identifier:wsum; 136, call; 137, identifier:float; 138, argument_list; 139, string_content:r; 140, identifier:np; 141, identifier:abs; 142, subscript; 143, identifier:d; 144, integer:0; 145, call; 146, subscript; 147, identifier:aN; 148, subscript; 149, identifier:aN; 150, attribute; 151, argument_list; 152, attribute; 153, argument_list; 154, identifier:chunk_max; 155, comparison_operator:chunk_max > maxval; 156, identifier:maxval; 157, identifier:chunk_min; 158, comparison_operator:chunk_min < minval; 159, identifier:minval; 160, attribute; 161, argument_list; 162, attribute; 163, argument_list; 164, identifier:wsum; 165, identifier:d; 166, integer:0; 167, attribute; 168, argument_list; 169, identifier:d; 170, slice; 171, identifier:w; 172, slice; 173, identifier:np; 174, identifier:max; 175, identifier:d_c; 176, identifier:np; 177, identifier:min; 178, identifier:d_c; 179, identifier:chunk_max; 180, identifier:maxval; 181, identifier:chunk_min; 182, identifier:minval; 183, identifier:np; 184, identifier:sum; 185, binary_operator:w_c*d_c; 186, identifier:np; 187, identifier:sum; 188, identifier:w_c; 189, identifier:np; 190, identifier:logical_or; 191, call; 192, call; 193, identifier:x; 194, binary_operator:x+s; 195, identifier:x; 196, binary_operator:x+s; 197, identifier:w_c; 198, identifier:d_c; 199, attribute; 200, argument_list; 201, attribute; 202, argument_list; 203, identifier:x; 204, identifier:s; 205, identifier:x; 206, identifier:s; 207, identifier:np; 208, identifier:isnan; 209, subscript; 210, identifier:np; 211, identifier:isinf; 212, subscript; 213, identifier:d; 214, slice; 215, identifier:d; 216, slice; 217, identifier:x; 218, binary_operator:x+s; 219, identifier:x; 220, binary_operator:x+s; 221, identifier:x; 222, identifier:s; 223, identifier:x; 224, identifier:s
code: def threenum(h5file, var, post_col='mult'):
      """ Calculates the three number summary for a variable.
  
      The three number summary is the minimum, maximum and the mean
      of the data. Traditionally one would summerise data with the
      five number summary: max, min, 1st, 2nd (median), 3rd quartile.
      But quantiles are hard to calculate without sorting the data
      which hard to do out-of-core.
      """
      f = h5py.File(h5file, 'r')
      d = f[var]
      w = f[post_col]
      s = d.chunks[0]
  
      n = d.shape[0]
      maxval = -np.abs(d[0])
      minval = np.abs(d[0])
      total = 0
      wsum = 0
  
      for x in range(0, n, s):
  
          aN = ~np.logical_or(np.isnan(d[x:x+s]), np.isinf(d[x:x+s]))
  
          d_c = d[x:x+s][aN]
          w_c = w[x:x+s][aN]
  
          chunk_max = np.max(d_c)
          chunk_min = np.min(d_c)
  
          maxval = chunk_max if chunk_max > maxval else maxval
          minval = chunk_min if chunk_min < minval else minval
  
          total += np.sum(w_c*d_c)
          wsum  += np.sum(w_c)
      f.close()
  
      mean = total/float(wsum)
  
      return (minval, maxval, mean)