nodes: 0, module; 1, function_definition; 2, function_name:interpolate_1d; 3, parameters; 4, block; 5, identifier:x; 6, identifier:xp; 7, list_splat_pattern; 8, dictionary_splat_pattern; 9, expression_statement; 10, comment:# Pull out keyword args; 11, expression_statement; 12, expression_statement; 13, comment:# Make x an array; 14, expression_statement; 15, comment:# Save number of dimensions in xp; 16, expression_statement; 17, comment:# Sort input data; 18, expression_statement; 19, expression_statement; 20, comment:# indices for sorting; 21, expression_statement; 22, comment:# sort xp; 23, expression_statement; 24, comment:# Ensure pressure in increasing order; 25, expression_statement; 26, comment:# Make x broadcast with xp; 27, expression_statement; 28, expression_statement; 29, expression_statement; 30, expression_statement; 31, comment:# Calculate value above interpolated value; 32, expression_statement; 33, expression_statement; 34, comment:# If fill_value is none and data is out of bounds, raise value error; 35, if_statement; 36, comment:# Warn if interpolated values are outside data bounds, will make these the values; 37, comment:# at end of data range.; 38, if_statement; 39, if_statement; 40, comment:# Get indices for broadcasting arrays; 41, expression_statement; 42, expression_statement; 43, if_statement; 44, comment:# Create empty output list; 45, expression_statement; 46, comment:# Calculate interpolation for each variable; 47, for_statement; 48, if_statement; 49, identifier:args; 50, identifier:kwargs; 51, comment:r"""Interpolates data with any shape over a specified axis.
  
      Interpolation over a specified axis for arrays of any shape.
  
      Parameters
      ----------
      x : array-like
          1-D array of desired interpolated values.
  
      xp : array-like
          The x-coordinates of the data points.
  
      args : array-like
          The data to be interpolated. Can be multiple arguments, all must be the same shape as
          xp.
  
      axis : int, optional
          The axis to interpolate over. Defaults to 0.
  
      fill_value: float, optional
          Specify handling of interpolation points out of data bounds. If None, will return
          ValueError if points are out of bounds. Defaults to nan.
  
      Returns
      -------
      array-like
          Interpolated values for each point with coordinates sorted in ascending order.
  
      Examples
      --------
       >>> x = np.array([1., 2., 3., 4.])
       >>> y = np.array([1., 2., 3., 4.])
       >>> x_interp = np.array([2.5, 3.5])
       >>> metpy.calc.interp(x_interp, x, y)
       array([2.5, 3.5])
  
      Notes
      -----
      xp and args must be the same shape.
  
      """; 52, assignment; 53, assignment; 54, assignment; 55, assignment; 56, assignment; 57, assignment; 58, assignment; 59, assignment; 60, assignment; 61, assignment; 62, assignment; 63, assignment; 64, assignment; 65, assignment; 66, assignment; 67, boolean_operator; 68, block; 69, comparison_operator:np.max(minv) == xp.shape[axis]; 70, block; 71, comparison_operator:np.min(minv) == 0; 72, block; 73, assignment; 74, assignment; 75, call; 76, block; 77, assignment; 78, identifier:var; 79, identifier:variables; 80, comment:# Var needs to be on the *left* of the multiply to ensure that if it's a pint; 81, comment:# Quantity, it gets to control the operation--at least until we make sure; 82, comment:# masked arrays and pint play together better. See https://github.com/hgrecco/pint#633; 83, block; 84, comparison_operator:len(ret) == 1; 85, block; 86, else_clause; 87, identifier:fill_value; 88, call; 89, identifier:axis; 90, call; 91, identifier:x; 92, call; 93, identifier:ndim; 94, attribute; 95, identifier:sort_args; 96, call; 97, identifier:sort_x; 98, call; 99, identifier:sorter; 100, call; 101, identifier:xp; 102, subscript; 103, identifier:variables; 104, list_comprehension; 105, identifier:x_array; 106, subscript; 107, identifier:expand; 108, binary_operator:[np.newaxis] * ndim; 109, subscript; 110, call; 111, identifier:x_array; 112, subscript; 113, identifier:minv; 114, call; 115, identifier:minv2; 116, call; 117, parenthesized_expression; 118, comparison_operator:fill_value is None; 119, raise_statement; 120, call; 121, subscript; 122, expression_statement; 123, expression_statement; 124, call; 125, integer:0; 126, expression_statement; 127, identifier:above; 128, call; 129, identifier:below; 130, call; 131, attribute; 132, argument_list; 133, expression_statement; 134, identifier:ret; 135, list; 136, expression_statement; 137, comment:# Set points out of bounds to fill value.; 138, expression_statement; 139, expression_statement; 140, comment:# Check for input points in decreasing order and return output to match.; 141, if_statement; 142, comment:# Output to list; 143, expression_statement; 144, call; 145, integer:1; 146, return_statement; 147, block; 148, attribute; 149, argument_list; 150, attribute; 151, argument_list; 152, attribute; 153, argument_list; 154, identifier:xp; 155, identifier:ndim; 156, attribute; 157, argument_list; 158, attribute; 159, argument_list; 160, identifier:broadcast_indices; 161, argument_list; 162, identifier:xp; 163, identifier:sorter; 164, subscript; 165, for_in_clause; 166, identifier:x; 167, identifier:sort_x; 168, list; 169, identifier:ndim; 170, identifier:expand; 171, identifier:axis; 172, identifier:slice; 173, argument_list; 174, identifier:x_array; 175, call; 176, attribute; 177, argument_list; 178, attribute; 179, argument_list; 180, boolean_operator; 181, identifier:fill_value; 182, None; 183, call; 184, attribute; 185, argument_list; 186, attribute; 187, identifier:axis; 188, call; 189, assignment; 190, attribute; 191, argument_list; 192, assignment; 193, identifier:broadcast_indices; 194, argument_list; 195, identifier:broadcast_indices; 196, argument_list; 197, identifier:np; 198, identifier:any; 199, comparison_operator:x_array < xp[below]; 200, call; 201, assignment; 202, assignment; 203, assignment; 204, comparison_operator:x[0] > x[-1]; 205, block; 206, call; 207, identifier:len; 208, argument_list; 209, subscript; 210, return_statement; 211, identifier:kwargs; 212, identifier:pop; 213, string; 214, attribute; 215, identifier:kwargs; 216, identifier:pop; 217, string; 218, integer:0; 219, call; 220, identifier:reshape; 221, unary_operator; 222, identifier:np; 223, identifier:argsort; 224, identifier:xp; 225, keyword_argument; 226, identifier:np; 227, identifier:argsort; 228, identifier:x; 229, identifier:xp; 230, identifier:sort_args; 231, identifier:ndim; 232, identifier:axis; 233, identifier:arr; 234, identifier:sorter; 235, identifier:arr; 236, identifier:args; 237, attribute; 238, None; 239, identifier:tuple; 240, argument_list; 241, identifier:np; 242, identifier:apply_along_axis; 243, attribute; 244, identifier:axis; 245, identifier:xp; 246, subscript; 247, identifier:np; 248, identifier:copy; 249, identifier:minv; 250, parenthesized_expression; 251, parenthesized_expression; 252, identifier:ValueError; 253, argument_list; 254, identifier:np; 255, identifier:max; 256, identifier:minv; 257, identifier:xp; 258, identifier:shape; 259, attribute; 260, argument_list; 261, subscript; 262, binary_operator:xp.shape[axis] - 1; 263, identifier:np; 264, identifier:min; 265, identifier:minv; 266, subscript; 267, integer:1; 268, identifier:xp; 269, identifier:minv2; 270, identifier:ndim; 271, identifier:axis; 272, identifier:xp; 273, binary_operator:minv2 - 1; 274, identifier:ndim; 275, identifier:axis; 276, identifier:x_array; 277, subscript; 278, attribute; 279, argument_list; 280, identifier:var_interp; 281, binary_operator:var[below] + (var[above] - var[below]) * ((x_array - xp[below])
                                                                 / (xp[above] - xp[below])); 282, subscript; 283, identifier:fill_value; 284, subscript; 285, identifier:fill_value; 286, subscript; 287, subscript; 288, expression_statement; 289, attribute; 290, argument_list; 291, identifier:ret; 292, identifier:ret; 293, integer:0; 294, identifier:ret; 295, string_content:fill_value; 296, identifier:np; 297, identifier:nan; 298, string_content:axis; 299, attribute; 300, argument_list; 301, integer:1; 302, identifier:axis; 303, identifier:axis; 304, identifier:np; 305, identifier:newaxis; 306, identifier:expand; 307, identifier:np; 308, identifier:searchsorted; 309, identifier:x; 310, identifier:sort_x; 311, comparison_operator:np.max(minv) == xp.shape[axis]; 312, comparison_operator:np.min(minv) == 0; 313, string; 314, identifier:warnings; 315, identifier:warn; 316, string; 317, identifier:minv2; 318, comparison_operator:minv == xp.shape[axis]; 319, subscript; 320, integer:1; 321, identifier:minv2; 322, comparison_operator:minv == 0; 323, identifier:minv2; 324, integer:1; 325, identifier:xp; 326, identifier:below; 327, identifier:warnings; 328, identifier:warn; 329, string; 330, subscript; 331, binary_operator:(var[above] - var[below]) * ((x_array - xp[below])
                                                                 / (xp[above] - xp[below])); 332, identifier:var_interp; 333, comparison_operator:minv == xp.shape[axis]; 334, identifier:var_interp; 335, comparison_operator:x_array < xp[below]; 336, identifier:x; 337, integer:0; 338, identifier:x; 339, unary_operator; 340, assignment; 341, identifier:ret; 342, identifier:append; 343, identifier:var_interp; 344, identifier:np; 345, identifier:asanyarray; 346, identifier:x; 347, call; 348, subscript; 349, call; 350, integer:0; 351, string_content:Interpolation point out of data bounds encountered; 352, string_content:Interpolation point out of data bounds encountered; 353, identifier:minv; 354, subscript; 355, attribute; 356, identifier:axis; 357, identifier:minv; 358, integer:0; 359, string_content:Interpolation point out of data bounds encountered; 360, identifier:var; 361, identifier:below; 362, parenthesized_expression; 363, parenthesized_expression; 364, identifier:minv; 365, subscript; 366, identifier:x_array; 367, subscript; 368, integer:1; 369, identifier:var_interp; 370, call; 371, attribute; 372, argument_list; 373, attribute; 374, identifier:axis; 375, attribute; 376, argument_list; 377, attribute; 378, identifier:axis; 379, identifier:xp; 380, identifier:shape; 381, binary_operator:var[above] - var[below]; 382, binary_operator:(x_array - xp[below])
                                                                 / (xp[above] - xp[below]); 383, attribute; 384, identifier:axis; 385, identifier:xp; 386, identifier:below; 387, attribute; 388, argument_list; 389, identifier:np; 390, identifier:max; 391, identifier:minv; 392, identifier:xp; 393, identifier:shape; 394, identifier:np; 395, identifier:min; 396, identifier:minv; 397, identifier:xp; 398, identifier:shape; 399, subscript; 400, subscript; 401, parenthesized_expression; 402, parenthesized_expression; 403, identifier:xp; 404, identifier:shape; 405, identifier:np; 406, identifier:swapaxes; 407, subscript; 408, integer:0; 409, identifier:axis; 410, identifier:var; 411, identifier:above; 412, identifier:var; 413, identifier:below; 414, binary_operator:x_array - xp[below]; 415, binary_operator:xp[above] - xp[below]; 416, call; 417, slice; 418, identifier:x_array; 419, subscript; 420, subscript; 421, subscript; 422, attribute; 423, argument_list; 424, unary_operator; 425, identifier:xp; 426, identifier:below; 427, identifier:xp; 428, identifier:above; 429, identifier:xp; 430, identifier:below; 431, identifier:np; 432, identifier:swapaxes; 433, identifier:var_interp; 434, integer:0; 435, identifier:axis; 436, integer:1
code: def interpolate_1d(x, xp, *args, **kwargs):
      r"""Interpolates data with any shape over a specified axis.
  
      Interpolation over a specified axis for arrays of any shape.
  
      Parameters
      ----------
      x : array-like
          1-D array of desired interpolated values.
  
      xp : array-like
          The x-coordinates of the data points.
  
      args : array-like
          The data to be interpolated. Can be multiple arguments, all must be the same shape as
          xp.
  
      axis : int, optional
          The axis to interpolate over. Defaults to 0.
  
      fill_value: float, optional
          Specify handling of interpolation points out of data bounds. If None, will return
          ValueError if points are out of bounds. Defaults to nan.
  
      Returns
      -------
      array-like
          Interpolated values for each point with coordinates sorted in ascending order.
  
      Examples
      --------
       >>> x = np.array([1., 2., 3., 4.])
       >>> y = np.array([1., 2., 3., 4.])
       >>> x_interp = np.array([2.5, 3.5])
       >>> metpy.calc.interp(x_interp, x, y)
       array([2.5, 3.5])
  
      Notes
      -----
      xp and args must be the same shape.
  
      """
      # Pull out keyword args
      fill_value = kwargs.pop('fill_value', np.nan)
      axis = kwargs.pop('axis', 0)
  
      # Make x an array
      x = np.asanyarray(x).reshape(-1)
  
      # Save number of dimensions in xp
      ndim = xp.ndim
  
      # Sort input data
      sort_args = np.argsort(xp, axis=axis)
      sort_x = np.argsort(x)
  
      # indices for sorting
      sorter = broadcast_indices(xp, sort_args, ndim, axis)
  
      # sort xp
      xp = xp[sorter]
      # Ensure pressure in increasing order
      variables = [arr[sorter] for arr in args]
  
      # Make x broadcast with xp
      x_array = x[sort_x]
      expand = [np.newaxis] * ndim
      expand[axis] = slice(None)
      x_array = x_array[tuple(expand)]
  
      # Calculate value above interpolated value
      minv = np.apply_along_axis(np.searchsorted, axis, xp, x[sort_x])
      minv2 = np.copy(minv)
  
      # If fill_value is none and data is out of bounds, raise value error
      if ((np.max(minv) == xp.shape[axis]) or (np.min(minv) == 0)) and fill_value is None:
          raise ValueError('Interpolation point out of data bounds encountered')
  
      # Warn if interpolated values are outside data bounds, will make these the values
      # at end of data range.
      if np.max(minv) == xp.shape[axis]:
          warnings.warn('Interpolation point out of data bounds encountered')
          minv2[minv == xp.shape[axis]] = xp.shape[axis] - 1
      if np.min(minv) == 0:
          minv2[minv == 0] = 1
  
      # Get indices for broadcasting arrays
      above = broadcast_indices(xp, minv2, ndim, axis)
      below = broadcast_indices(xp, minv2 - 1, ndim, axis)
  
      if np.any(x_array < xp[below]):
          warnings.warn('Interpolation point out of data bounds encountered')
  
      # Create empty output list
      ret = []
  
      # Calculate interpolation for each variable
      for var in variables:
          # Var needs to be on the *left* of the multiply to ensure that if it's a pint
          # Quantity, it gets to control the operation--at least until we make sure
          # masked arrays and pint play together better. See https://github.com/hgrecco/pint#633
          var_interp = var[below] + (var[above] - var[below]) * ((x_array - xp[below])
                                                                 / (xp[above] - xp[below]))
  
          # Set points out of bounds to fill value.
          var_interp[minv == xp.shape[axis]] = fill_value
          var_interp[x_array < xp[below]] = fill_value
  
          # Check for input points in decreasing order and return output to match.
          if x[0] > x[-1]:
              var_interp = np.swapaxes(np.swapaxes(var_interp, 0, axis)[::-1], 0, axis)
          # Output to list
          ret.append(var_interp)
      if len(ret) == 1:
          return ret[0]
      else:
          return ret