pybacktrack.read_interpolate_function
- pybacktrack.read_interpolate_function(curve_filename, x_column_index=0, y_column_index=1, *, out_of_bounds='clamp')
Read x and y columns from a curve file and return a function y(x) that linearly interpolates.
- Parameters:
curve_filename (string) – Name of input text file containing the x and y data from which to create the returned curve function.
x_column_index (int, optional) – Determines which column of input text file to read x values from.
y_column_index (int, optional) – Determines which column of input text file to read y values from.
out_of_bounds (string, optional) –
Determines the y value returned by curve function when x is outside the range of x values in curve file. This can be:
clamp to return the boundary y value, or
exclude to return None (eg, to indicate that there’s no y value), or
extrapolate to return an extrapolated value.
- Returns:
curve_function (function) – A callable function y=f(x) accepting a single x argument, and returning a y value or None (if no y value).
x_column (list of float) – The x values read from the curve file.
y_column (list of float) – The y values read from the curve file.
- Raises:
ValueError – If cannot read x and y columns, as floating-point numbers, from the curve file at column indices
x_column_indexandy_column_index.ValueError – If curve file contains no data.
ValueError – If
out_of_boundsis not clamp, exclude or extrapolate.
Notes
The returned x and y columns are useful if integrating the curve function with
scipy.integrate.quad(since can pass x column to its points argument and len(x) to its limit).Changed in version 1.5: The following changes were made:
Added
out_of_boundsargument. Ifout_of_boundsis exclude then returned curve function will returnNonefor any input x outside the range of x values in curve file.Some arguments (after
*) are now keyword-only (ie, can no longer be specified as positional arguments).