piecewise_linear_1d

Class summary

PolyLine(*args) A Polyline is a series of x y points joined by straight lines

Function summary

avg_x1_x2_y1_y2_between_xi_xj(x1, x2, y1, ...) Average of x1_x2_y1_y2 data between xi and xj
avg_x_y_between_xi_xj(x, y, xi, xj) Average between xi and xj piecewise-linear x_y data
convert_x1_x2_y1_y2_to_x_y(x1, x2, y1, y2) Convert data defined at start and end of each segment to a line of data
convert_x_y_to_x1_x2_y1_y2(x, y) Convert a line of data to data defined at start and end of each segment
force_non_decreasing(x[, y]) Force non-increasing x, y data to non_decreasing by reversing the data
force_strictly_increasing(x[, y, ...]) Force a non-decreasing or non-increasing list to be strictly increasing
has_steps(x) Check if data points have any step changes
integrate_x1_x2_y1_y2_between_xi_xj(x1, x2, ...) Integrate layered x1_x2_y1_y2 data between xi and xj
integrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between(...) Integrate between two points a composite function made of two x1_x2_y1_y2 piecewise-linear data representations.
integrate_x_y_between_xi_xj(x, y, xi, xj) Integrate piecewise-linear x_y data between xi and xj
interp_x1_x2_y1_y2(x1, x2, y1, y2, xi[, ...]) Linear interpolation of x1_x2_y1_y2 data
interp_x_y(x, y, xi[, choose_max]) Linear interpolation of x_y data
interp_xa_ya_multipy_x1b_x2b_y1b_y2b(xa, ya, ...) Interpolate a composite function made of x_y and x1b_x2b_y1b_y2b piecewise-linear representations.
is_initially_increasing(x) Are first two values increasing?
layer_coords(h, segs[, min_segs]) Divide layer heights into segments and calculate offset from start
non_decreasing(x) Checks all x[i+1] >= x[i]
non_increasing(x) Checks all x[i+1] <= x[i]
non_increasing_and_non_decreasing_parts(x[, ...]) Indexes of each non-increasing and non-decreasing section of a list
pavg_x1_x2_y1_y2_between_xi_xj(a, xi, xj, ...) Average of PolyLine data between xi and xj; wrapper for avg_x1_x2_y1_y2_between_xi_xj.
pavg_x_y_between_xi_xj(a, xi, xj, **kwargs) Average between xi and xj for PolyLine data; wrapper for avg_x_y_between_xi_xj.
pintegrate_x1_x2_y1_y2_between_xi_xj(a, xi, ...) Integrate PolyLine data between xi and xj; wrapper for integrate_x1_x2_y1_y2_between_xi_xj.
pintegrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between(a, ...) Integrate between two points a composite function made of two PolyLine objects; wrapper for integrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between.
pintegrate_x_y_between_xi_xj(a, xi, xj, **kwargs) Integrate PolyLine data between xi and xj; wrapper for integrate_x_y_between_xi_xj.
pinterp_x1_x2_y1_y2(a, xi, **kwargs) Linear interpolation using PolyLine; wrapper for interp_x1_x2_y1_y2.
pinterp_x_y(a, xi, **kwargs) Linear interpolation using PolyLine; wrapper for interp_x_y.
pinterp_xa_ya_multipy_x1b_x2b_y1b_y2b(a, b, ...) Interpolate a composite function made of two PolyLines; wrapper for interp_xa_ya_multipy_x1b_x2b_y1b_y2b.
polyline_make_x_common(*p_lines) Add appropriate points to multiple PolyLine objetcs so that each has matching x1_x2 intevals.
pxa_ya_cos_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(a, ...) Respectively interpolate at one point, and integrate between two points, the cosine multiplied by PolyLine, and two multipled PolyLine portions of a composite function of piecewise-linear representations.
pxa_ya_cos_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between_super(a, ...) Superpose results of respectively interpolate at one point, and integrate between two points, the cosine multiplied by PolyLine, and two multipled PolyLine portions of a composite function of piecewise-linear representations.
pxa_ya_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(a, ...) Respectively interpolate at one point, and integrate between two points, the first PolyLine and the multiplied second and third PolyLine portions of a composite function of piecewise-linear representations.
pxa_ya_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between_super(a, ...) Superpose results of respectively interpolate at one point, and integrate between two points, the first PolyLine and the multiplied second and third PolyLine portions of a composite function of piecewise-linear representations.
pxa_ya_multipy_avg_x1b_x2b_y1b_y2b_between(a, ...) Respectively interpolate at one point, and average between two points, the a composiute function of two PolyLine objects.
ramps_constants_steps(x, y) Find the ramp, constant, and step line segments in x, y data
remove_superfluous_from_x_y(x, y[, atol]) Remove points that are on a line between other points
segment_containing_also_segments_less_than_xi(x, ...) Determine ramp, constant and step segments containing xi as well as segments less than xi.
segment_containing_xi(x, xi[, subset, ...]) Find start index of line segment in which xi falls
segment_containing_xi_also_containing_xj(x, ...) Find start index of segments that xi and xj fall in trying to have them in the same section.
segments_between_xi_and_xj(x, xi, xj) Find line segments that exclusively contain both, only one of, and in between xi and xj.
segments_less_than_xi(x, xi[, subset, ...]) Find start index of line segments that end before xi
start_index_of_constants(x, y) Find the start indices of the constant line-segments in x, y data.
start_index_of_ramps(x, y) Find the start indices of the ramp line segments in x, y data.
start_index_of_steps(x, y) Find the start indices of the step line-segments in x, y data.
strictly_decreasing(x) Checks all x[i+1] < x[i]
strictly_increasing(x) Checks all x[i+1] > x[i]
subdivide_into_elements([n, h, p, symmetry]) Subdivide a length into elements where sizes are proportional to adjacent elements.
subdivide_x_into_segments(x[, dx, ...]) Subdivide sequential x values into subsegments.
subdivide_x_y_into_segments(x, y[, dx, ...]) Subdivide piecewise-linear line segment x, y data by interpolation
xa_ya_cos_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(xa, ...) Respectively interpolate at one point, and integrate between two points, the cosine multiplied by x_y, and two multipled x1_x2_y1_y2 portions of a composite function of piecewise-linear representations.
xa_ya_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(xa, ...) Respectively interpolate at one point, and integrate between two points, the x_y and two multipled x1_x2_y1_y2 portions of a composite function of piecewise-linear representations.
xa_ya_multipy_avg_x1b_x2b_y1b_y2b_between(xa, ...) Respectively interpolate at one point, and average between two points, the x_y and x1_x2_y1_y2 portions of a composite function of piecewise-linear representations.

Module listing

One dimensional piecwise linear relationships and manipulations

class geotecha.piecewise.piecewise_linear_1d.PolyLine(*args)[source]

Bases: object

A Polyline is a series of x y points joined by straight lines

Provides some extra functionality beyond just using an x array and y array to represent a multi-point line.

Functinality of PolyLines:

  • PolyLines can be intialized in different ways e.g. use a single array of x-y points; use separate x-arrays and y-arrays; use x values at the start and end of each interval and y values at the start and end of each interval. This can be useful if you want to work with layer/interval data but to plot those intervals you want x-y points.
  • Multiply a PolyLine by a scalar and only the y values will be changed.
  • Add to/from a PolyLine with a scalar and only the y values will be changed.
  • PolyLines can be added together to create a new PolyLine; the x values of each PolyLine will be maintained. Any x values that are not common to both PolyLines will have their y values interpolated and then added.
Parameters:

*args : array like

A PolyLine object can be initialized with 1, 2, or 4 positional arguments (a different number of arguments will raise an error):

  • A single n-by-2 two-dimensional array of n (x, y) points. i.e. first column is x values, second column is y values.
  • Two one-dimensional arrays of equal length. The first array is the x values. The second array is the corresponding y values.
  • Four one-dimensional arrays of equal length. First array x1 is x values at the start of a interval. The second array x2 is x values at the end of a interval (note x1[1:] must equal x2[0:-1]). The third array y1 is the y values at the start of each interval. The fourth array y2 is the y values at the end of each interval.

Attributes

xy Get the xy values.
x1_x2_y1_y2 Get the x1_x2_y1_y2 values
x, y (1d numpy array) Arrays containing all the x values and all the y values in the PolyLine.
x1, x2, y1, y2 (1d numpy array) When you want the start and end values of each of the intervals/layers in the PolyLine. x1 is the x values at the start of each interval, x2 is the x values at the end of each interval. y1 is the y values at the start of each interval, y2 is the y values at the end of each interval. Note that when dealing with intervals any vertical intervals will be lost e.g. say our x-y values are defined by joining the dots: PolyLine([0,1,1,2], [4,4,5,5]) is defined by 4 points but it will have only 2 layers/intervals i.e. x1 will be [0,1], x2 will be [1,0], y1 will be [4,5], y2 will be [4,5]. Just be careful when initialising PolyLines using x1_x2_y1_y2 values, any initial or final vertical section cannot be defined.
atol, rtol (float) Absolute and relative tolerance when comparing equality of points in a PolyLine using numpy.allclose
_prefix_for_numpy_array_repr (string) When using the repr function on Numpy arrays the default output will print array([...]). Because PolyLines use numpy arrays to store data when using repr on PolyLines you would get PolyLine(array([...])). Now if in your code you have done import numpy.array as array” or some such import then you can just copy the repr of a PolylIne into you code . However I usually use “import numpy as np” so ideally I want ‘np.’ prepended to all my numpy array reprs. _prefix_for_numpy_array_repr does just this with the default prefix = “np.” (if you wish to change the prefix for all numpy arrays not just the PolyLine repr then see numpy.`set_string_function` )
x

Get the x values of xy data.

x1

Get the x1 values of x1_x2_y1_y2 data.

x1_x2_y1_y2

Get the x1_x2_y1_y2 values

x2

Get the x2 values of x1_x2_y1_y2 data.

xy

Get the xy values.

y

Get the y values of xy data.

y1

Get the y1 values of x1_x2_y1_y2 data.

y2

Get the y2 values of x1_x2_y1_y2 data.

geotecha.piecewise.piecewise_linear_1d.avg_x1_x2_y1_y2_between_xi_xj(x1, x2, y1, y2, xi, xj)[source]

Average of x1_x2_y1_y2 data between xi and xj

Parameters:

x1, y1 : array_like, float

x and y values at start of each segment

x2, y2 : array_like, float

x and y values at end of each segment (note x1[1:]==x2[:-1])

xi, xj : array_like, float

x values to integrate between

Returns:

A : 1d array of float

Average for each xi, xj pair. len(A) == len(xi).

See also

integrate_x1_x2_y1_y2_between_xi_xj
Integration is intermediate step for average calculation.
geotecha.piecewise.piecewise_linear_1d.avg_x_y_between_xi_xj(x, y, xi, xj)[source]

Average between xi and xj piecewise-linear x_y data

Parameters:

x, y : 1d array_like, float

x and y values of x_y part of interpolation function.

xi, xj : array_like, float

x values to interpolate between.

Returns:

A : 1d array of float

Interpolated values. len(A)=len(xi)

See also

integrate_x_y_between_xi_xj
Integration is intemediate step in average calculation.
geotecha.piecewise.piecewise_linear_1d.convert_x1_x2_y1_y2_to_x_y(x1, x2, y1, y2)[source]

Convert data defined at start and end of each segment to a line of data

x1_x2_y1_y2 data is defined by x1[1:]==x2[:-1]

Parameters:

x1, y1 : array_like, float

x and y values at start of each segment.

x2, y2 : array_like, float

x and y values at end of each segment (note x1[1:]==x2[:-1]).

Returns:

x, y : 1d ndarray, float

x and y data of continuous line that matches the x1_x2_y1_y2 data.

See also

convert_x_y_to_x1_x2_y1_y2
Reverse of this function.

Notes

Graphs showing x1_x2_y1_y2 data and x_y data are shown below.

x1_x2_y1_y2 type data
y                                              y2[2]
^                                             /|
|                                            / |
|                           y2[0]           /  |
|                          /|              /   |
|                         / |       y1[2] /    |
|                        /  |            |     |
|                       /   |y1[1]  y2[1]|     |
|                 y1[0]/    |------------|     |
|                     | (0) |     (1)    | (2) |
|                     |     |            |     |
|----------------------------------------------------------->x
                    x1[0] x1[1]        x1[2]
                          x2[0]        x2[1] x2[2]

e.g. x1 = [0.0, 0.3, 0.7], y1 = [1, 1, 2]
     x2 = [0.3, 0.7, 1.0], y2 = [3, 1, 4]

x_y_data
y                                              y[5]
^                                             /|
|                                            / |
|                           y[1]            /  |
|                          /|              /   |
|                         / |         y[4]/    |
|                        /  |            |     |
|                       /   |y[2]    y[3]|     |
|                  y[0]/    |------------|     |
|                     |     |            |     |
|                     |     |            |     |
|----------------------------------------------------------->x
                    x[0]   x[1]         x[3]  x[5]
                           x[2]         x[4]

e.g. x = [0.0, 0.3, 0.3, 0.7, 0.7, 1.0]
     y = [1.0, 3.0, 1.0, 1.0, 2.0, 4.0]
geotecha.piecewise.piecewise_linear_1d.convert_x_y_to_x1_x2_y1_y2(x, y)[source]

Convert a line of data to data defined at start and end of each segment

Parameters:

x1, y1 : array_like, float

x and y values at start of each segment.

x2, y2 : array_like, float

x and y values at end of each segment (note x1[1:]==x2[:-1]).

Returns:

x1, y1 : 1d array, float

x and y values at start of each segment.

x2, y2 : 1d array, float

x and y values at end of each segment (note x1[1:]==x2[:-1]).

See also

convert_x1_x2_y1_y2_to_x_y
Reverse of this function.

Notes

Graphs showing x1_x2_y1_y2 data and x_y data are shown below.

x_y_data
y                                              y[5]
^                                             /|
|                                            / |
|                           y[1]            /  |
|                          /|              /   |
|                         / |         y[4]/    |
|                        /  |            |     |
|                       /   |y[2]    y[3]|     |
|                  y[0]/    |------------|     |
|                     |     |            |     |
|                     |     |            |     |
|----------------------------------------------------------->x
                    x[0]   x[1]         x[3]  x[5]
                           x[2]         x[4]

e.g. x = [0.0, 0.3, 0.3, 0.7, 0.7, 1.0]
     y = [1.0, 3.0, 1.0, 1.0, 2.0, 4.0]

x1_x2_y1_y2 type data
y                                              y2[2]
^                                             /|
|                                            / |
|                           y2[0]           /  |
|                          /|              /   |
|                         / |       y1[2] /    |
|                        /  |            |     |
|                       /   |y1[1]  y2[1]|     |
|                 y1[0]/    |------------|     |
|                     | (0) |     (1)    | (2) |
|                     |     |            |     |
|----------------------------------------------------------->x
                    x1[0] x1[1]        x1[2]
                          x2[0]        x2[1] x2[2]

e.g. x1 = [0.0, 0.3, 0.7], y1 = [1, 1, 2]
     x2 = [0.3, 0.7, 1.0], y2 = [3, 1, 4]
geotecha.piecewise.piecewise_linear_1d.force_non_decreasing(x, y=None)[source]

Force non-increasing x, y data to non_decreasing by reversing the data

Leaves already non-decreasing data alone.

Parameters:

x, y: array_like

x and y coordinates

Returns:

x, y : 1d ndarray, 1d ndarray

Non-decreasing version of x, y

geotecha.piecewise.piecewise_linear_1d.force_strictly_increasing(x, y=None, keep_end_points=True, eps=1e-15)[source]

Force a non-decreasing or non-increasing list to be strictly increasing

Adds or subtracts tiny amounts (multiples of eps) from the x values in step changes to ensure no two consecutive x values are equal (i.e. make x strictly increasing). The adjustments are small enough that for all intents and purposes the data behaves as before; it can now however be easily used in straightforward interpolation functions that require strictly increasing x data.

Any data where x is non-increasing will be reversed.

Parameters:

x : array_like

List of x coordinates.

y : array_like, optional

List of y coordinates, (Default y=None, if known that x is non-decreasing then y will not be affected).

keep_end_points : boolean, optional

Determines which x value of the step change is adjusted. Consider x=[1,1] and y=[20,40]. If keep_end_points==True then new data will be x=[0.9999,1], y=[20,40]. If keep_end_points==False then data will be x=[1, 1.0001], y=[20,40]

eps : float, optional

Amount to add/subtract from x (default is 1e-15). To ensure consecutive step changes are handled correctly multipes of eps will be added and subtracted. e.g. if there are a total of five steps in the data then the first step would get 5*`eps` adjustment, the second step 4*`eps` adjustment and so on.

geotecha.piecewise.piecewise_linear_1d.has_steps(x)[source]

Check if data points have any step changes

True if any two consecutive x values are equal.

Parameters:

x : array_like

x-coordinates

Returns:

out : boolean

Returns True if any two consecutive x values are equal.

geotecha.piecewise.piecewise_linear_1d.integrate_x1_x2_y1_y2_between_xi_xj(x1, x2, y1, y2, xi, xj)[source]

Integrate layered x1_x2_y1_y2 data between xi and xj

Parameters:

x1, y1 : array_like, float

x and y values at start of each segment.

x2, y2 : array_like, float

x and y values at end of each segment (note x1[1:]==x2[:-1]).

xi, xj : array_like, float

x values to integrate between.

Returns:

A : 1d array of float

Results of integrations. len(A) == len(xi).

See also

interp_x1_x2_y1_y2
Interpolation of x1_x2_y1_y2 data.
segments_between_xi_and_xj
Line segments between xi and xj.
geotecha.piecewise.piecewise_linear_1d.integrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between(x1a, x2a, y1a, y2a, x1b, x2b, y1b, y2b, xi, xj)[source]

Integrate between two points a composite function made of two x1_x2_y1_y2 piecewise-linear data representations.

Evaluate integrate[f(x)*g(x), (xi, xj)] where f(x) and g(x) are defined by x1_x2_y1_y2 data.

The two data sets must have the same x values, i.e. the layers must match up, x1a==x1b, x2a==x2b.

Parameters:

x1a, y1a : array_like, float

x and y values at start of each segment for first x1_x2_y1_y2 part of composite function.

x2a, y2a : array_like, float

x and y values at end of each segment for first x1_x2_y1_y2 part of composite function (note x1[1:]==x2[:-1]).

x1b, y1b : array_like, float

x and y values at start of each segment for second x1_x2_y1_y2 part of composite function.

x2b, y2b : array_like, float

x and y values at end of each segment for second x1_x2_y1_y2 part of composite function (note x1[1:]==x2[:-1]).

xi, xj : array_like, float

x values to integrate between.

Returns:

A : len(xi) 1d array of float

Results of integrations.

geotecha.piecewise.piecewise_linear_1d.integrate_x_y_between_xi_xj(x, y, xi, xj)[source]

Integrate piecewise-linear x_y data between xi and xj

Parameters:

x, y : 1d array_like, float

x and y values for piecewise linear integration.

xi, xj : array_like, float

x values to interpolate between.

Returns:

A : 1d array of float

Interpolated values. len(A) == len(xi)

See also

interp_x_y
Interpolate the x_y part.
segments_between_xi_and_xj
Line segments between xi and xj.
geotecha.piecewise.piecewise_linear_1d.interp_x1_x2_y1_y2(x1, x2, y1, y2, xi, choose_max=False)[source]

Linear interpolation of x1_x2_y1_y2 data

x1_x2_y1_y2 data is defined by x1[1:]==x2[:-1] if xi is beyond bounds of x then the first or last value of y will be returned as appropriate

Parameters:

x1, y1 : array_like, float

x and y values at start of each segment

x2, y2 : array_like, float

x and y values at end of each segment (note x1[1:]==x2[:-1])

xi : array_like, float

x values to interpolate at

Returns:

A : 1d ndarray, float

Interpolated y value corresponding to xi.

geotecha.piecewise.piecewise_linear_1d.interp_x_y(x, y, xi, choose_max=False)[source]

Linear interpolation of x_y data

If xi is beyond bounds of x then the first or last value of y will be returned as appropriate.

Parameters:

x, y : array_like, float

x and y values.

xi : array_like, float

x values to interpolate at.

Returns:

A : 1d ndarray, float

Interpolated y value corresponding to xi.

geotecha.piecewise.piecewise_linear_1d.interp_xa_ya_multipy_x1b_x2b_y1b_y2b(xa, ya, x1b, x2b, y1b, y2b, xai, xbi, achoose_max=False, bchoose_max=True)[source]

Interpolate a composite function made of x_y and x1b_x2b_y1b_y2b piecewise-linear representations.

Evaluate f(xai)*g(xbi) where f(xa) is defined with x_y data and g(xb) is defined by x1_x2_y1_y2 data.

Does little calculation, mostly calls other functions. Calculates array A[len(xbi),len(xai)]

Parameters:

xa, ya : 1d array_like, float

x and y values of x_y part of interpolation function.

x1b, y1b : array_like, float

x and y values at start of each segment for x1_x2_y1_y2 part of interpolation function

x2b, y2b : array_like, float

x and y values at end of each segment for x1_x2_y1_y2 part of interpolation function (note x1[1:]==x2[:-1])

xai : array_like, float

x values to interpolate at for x_y part

xbi : array_like, float

x values to interpolate at for x1_x2_y1_y2 part

achoose_max : boolean, optional

If False (default), if xai falls on boundary of segments choose the minimum segment to interpolate within.

bchoose_max : boolean, optional

If True (default), if xbi falls on boundary of segments choose the maximum segment to interpolate within.

See also

interp_x_y
Interpolate the x_y part.
interp_x1_x2_y1_y2
Interpolate the x1_x2_y1_y2 part.
geotecha.piecewise.piecewise_linear_1d.is_initially_increasing(x)[source]

Are first two values increasing?

Finds 1st instance where x[i+1] != x[i] and checks if x[i+1] > x[i].

Parameters:

x : array_like

1 dimensional data to check

Returns:

out : int

Returns True if 2nd value is greater than the 1st value. Returns False if 2nd value is less than the 1st value.

geotecha.piecewise.piecewise_linear_1d.layer_coords(h, segs, min_segs=1)[source]

Divide layer heights into segments and calculate offset from start

Subdivide each layer. Calculate offset.

Useful when you are interested in the end points of each layer as well as some intermediate points.

Parameters:

h : list/array

1d array of layer heights.

segs : int

Approximate number of segments to subdivide the whole profile into.

min_segs : int, optional

Minimum number of segments to subdivide a layer into. Default min_segs=2.

Returns:

z : 1d array

Depths.

Examples

>>> layer_coords([4], 2)
array([ 0.,  2.,  4.])
>>> layer_coords([2], 1, 4)
array([ 0. ,  0.5,  1. ,  1.5,  2. ])
>>> layer_coords([2,4,2], 5, 2)
array([ 0.,  1.,  2.,  4.,  6.,  7.,  8.])
>>> layer_coords([5,1,5], 3, 2)
array([  0. ,   2.5,   5. ,   5.5,   6. ,   8.5,  11. ])
geotecha.piecewise.piecewise_linear_1d.non_decreasing(x)[source]

Checks all x[i+1] >= x[i]

Parameters:

x : 1d array

Series of x values

Returns:

out : True/False

True if each x value is greater than or equal to the preceeding value.

See also

strictly_increasing
Check for increasing values, no equality allowed
strictly_decreasing
Check for decreasing values, no equality allowed
non_increasing
Less stringent decreasing check, allows equal values
geotecha.piecewise.piecewise_linear_1d.non_increasing(x)[source]

Checks all x[i+1] <= x[i]

Parameters:

x : 1d array

Series of x values

Returns:

out : True/False

True if each x value is less than or equal to the preceeding value.

See also

strictly_increasing
Check for increasing values, no equality allowed.
strictly_decreasing
Check for decreasing values, no equality allowed.
non_decreasing
Less stringent increasing check, allows equal values.
geotecha.piecewise.piecewise_linear_1d.non_increasing_and_non_decreasing_parts(x, include_end_point=False)[source]

Indexes of each non-increasing and non-decreasing section of a list

Parameters:

x : list or 1d array

List of values.

include_end_point : True/False, optional

If True then the index of the last point in a non-increasing or non-decreasing run is included. Default include_end_point=False, i.e. only the start index of each line segment is given.

Returns:

A : list of list

Each element of A is a list of the start indices of each line segment that is part of a particular non-increasing or non-decreasing run.

Notes

This funciton only returns start indices for each line segment. Lets say x is [0, 4 , 5.5] then A will be [[0,1]]. If you do x[A[0]] then you will get [0, 4] i.e. no end point. To get the whole increasing or decreasing portion including the end point you need to do something like x[A[0].append[A[0][-1]+1]].

geotecha.piecewise.piecewise_linear_1d.pavg_x1_x2_y1_y2_between_xi_xj(a, xi, xj, **kwargs)[source]

Average of PolyLine data between xi and xj; wrapper for avg_x1_x2_y1_y2_between_xi_xj.

Parameters:

a : PolyLine object

PolyLine containing data for integrating.

xi, xj : array_like, float

x values to integrate between.

Returns:

A : 1d array of float

Average for each xi, xj pair. len(A) == len(xi).

See also

avg_x1_x2_y1_y2_between_xi_xj
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.pavg_x_y_between_xi_xj(a, xi, xj, **kwargs)[source]

Average between xi and xj for PolyLine data; wrapper for avg_x_y_between_xi_xj.

Parameters:

a : PolyLine object

PolyLine containing data for averaging.

xi, xj : array_like, float

x values to interpolate between.

Returns:

A : 1d array of float

Interpolated values. len(A)=len(xi)

See also

avg_x_y_between_xi_xj
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.pintegrate_x1_x2_y1_y2_between_xi_xj(a, xi, xj, **kwargs)[source]

Integrate PolyLine data between xi and xj; wrapper for integrate_x1_x2_y1_y2_between_xi_xj.

Parameters:

a : PolyLine object

PolyLine containing data for integrating.

xi, xj : array_like, float

x values to integrate between.

Returns:

A : 1d array of float

Results of integrations. len(A) == len(xi).

See also

integrate_x1_x2_y1_y2_between_xi_xj
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.pintegrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between(a, b, xi, xj, **kwargs)[source]

Integrate between two points a composite function made of two PolyLine objects; wrapper for integrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between.

Evaluate integrate[f(x)*g(x), (xi, xj)] where f(x) and g(x) are defined by PolyLine objects.

The two PolyLines must have the same x values, i.e. the layers must match up, x1a==x1b, x2a==x2b.

Parameters:

a, b : PolyLine object

PolyLine objects multiplied together to define the composite function. x and y values at start of each segment for first x1_x2_y1_y2 part of composite function.

xi, xj : array_like, float

x values to integrate between.

Returns:

A : len(xi) 1d array of float

Integrations for each xi, xj pair.

See also

integrate_x1a_x2a_y1a_y2a_multiply_x1b_x2b_y1b_y2b_between
Wrapped function.
polyline_make_x_common
Ensure PolyLine object have same x values.
geotecha.piecewise.piecewise_linear_1d.pintegrate_x_y_between_xi_xj(a, xi, xj, **kwargs)[source]

Integrate PolyLine data between xi and xj; wrapper for integrate_x_y_between_xi_xj.

Parameters:

a : PolyLine object

PolyLine containing data for integrating.

xi, xj : array_like, float

x values to interpolate between.

Returns:

A : 1d array of float

Interpolated values. len(A) == len(xi).

See also

integrate_x_y_between_xi_xj
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.pinterp_x1_x2_y1_y2(a, xi, **kwargs)[source]

Linear interpolation using PolyLine; wrapper for interp_x1_x2_y1_y2.

Parameters:

a : PolyLine object

PolyLine to interpolate from.

xi : float, 1d array of float

Values to interpolate at.

**kwargs : keyword arguments

Keyword arguments will be passed through interp_x1_x2_y1_y2.

Returns:

A : 1d ndarray, float

Interpolated y value corresponding to xi

See also

interp_x1_x2_y1_y2
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.pinterp_x_y(a, xi, **kwargs)[source]

Linear interpolation using PolyLine; wrapper for interp_x_y.

Parameters:

a : PolyLine object

PolyLine to interpolate from.

xi : float, 1d array of float

Values to interpolate at.

**kwargs : keyword arguments

Keyword arguments will be passed through interp_x_y.

Returns:

A : 1d ndarray, float

Interpolated y value corresponding to xi

See also

interp_x_y
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.pinterp_xa_ya_multipy_x1b_x2b_y1b_y2b(a, b, xai, xbi, **kwargs)[source]

Interpolate a composite function made of two PolyLines; wrapper for interp_xa_ya_multipy_x1b_x2b_y1b_y2b.

Evaluate f(xai)*g(xbi) where f(xa) and f(xb) are defined by PolyLine objects.

Parameters:

a, b : PolyLine objects

PolyLine objects that make up the separable interpolation function a(xa) * b(xb) x and y values of x_y part of interpolation function.

xai : array_like, float

x values to interpolate at for a part

xbi : array_like, float

x values to interpolate at for b part

achoose_max : boolean, optional

If False (default), if xai falls on boundary of segments choose the minimum segment to interpolate within.

bchoose_max : boolean, optional

If True (default), if xbi falls on boundary of segments choose the maximum segment to interpolate within.

**kwargs : keyword arguments

Keyword arguments such as achoose_max and bchoose_max that will be passed through to interp_xa_ya_multipy_x1b_x2b_y1b_y2b.

See also

interp_xa_ya_multipy_x1b_x2b_y1b_y2b
Wrapped Function.
geotecha.piecewise.piecewise_linear_1d.polyline_make_x_common(*p_lines)[source]

Add appropriate points to multiple PolyLine objetcs so that each has matching x1_x2 intevals.

Parameters:

p_lines : PolyLine

One or more instances of PolyLine.

Returns:

out : tuple of PolyLine

Same number of Polyline’s as p_lines.

geotecha.piecewise.piecewise_linear_1d.pxa_ya_cos_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(a, omega, phase, b, c, xai, xbi, xbj, **kwargs)[source]

Respectively interpolate at one point, and integrate between two points, the cosine multiplied by PolyLine, and two multipled PolyLine portions of a composite function of piecewise-linear representations.

Evaluate f(xai) * cos(omega*xai + phase) * integrate[g(xb) * h(xb), (xbi, xbj)], where f(xa), g(xb), and h(xb) are PolyLine objects.

The b and c PolyLine objects do NOT need to have the same x values, they will be forced to do so using polyline_make_x_common.

Parameters:

a, b, c : PolyLine object

PolyLine obects making up the composite function.

omega, phase : float

Values for defining cos(omega * t + phase).

xai : array_like, float

x values to interpolate the a part of the composite function.

xbi, xbj : array_like, float

x values to integrate the b * c part of the composite function. between.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : (len(xbi), len(xai)) 2d array

Results for each xbi, xbj pair and xai value.

geotecha.piecewise.piecewise_linear_1d.pxa_ya_cos_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between_super(a, b, c, xai, xbi, xbj, omega_phase=None, **kwargs)[source]

Superpose results of respectively interpolate at one point, and integrate between two points, the cosine multiplied by PolyLine, and two multipled PolyLine portions of a composite function of piecewise-linear representations.

For each f(xa), g(xb) pair sum f(xai) * cos(omega*xai + phase) * integrate[g(xb) * h(xb), (xbi, xbj)], where f(xa), g(xb), and h(xb) are PolyLine objects.

The function is a bit specialised in that a and b and omega_phase can be lists of PolyLine objects. The contribution of each composite function (a[0], omega_phase[0], b[0], c), (a[1], b[1], omega_phase[1], c), ... will be summed.

The b and c PolyLine objects do NOT need to have the same x values, they will be forced to do so using polyline_make_x_common.

Parameters:

a, b, c : PolyLine object

PolyLine obects making up the composite function.

xai : array_like, float

x values to interpolate the a part of the composite function.

xbi, xbj : array_like, float

x values to integrate the b * c part of the composite function. between.

omega_phase : 2 element tuple, optional

(omega, phase) for use in cos(omega * t + phase), Default omega_phase=None i.e. no cosine term.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : (len(xbi), len(xai)) 2d array

Results for each xbi, xbj pair and xai value.

geotecha.piecewise.piecewise_linear_1d.pxa_ya_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(a, b, c, xai, xbi, xbj, **kwargs)[source]

Respectively interpolate at one point, and integrate between two points, the first PolyLine and the multiplied second and third PolyLine portions of a composite function of piecewise-linear representations.

Evaluate f(xai) * integrate[g(xb) * h(xb), (xbi, xbj)], where f(xa), g(xb), and h(xb) are defined with PolyLine objects.

The b and c PolyLine objects do NOT need to have the same x values, they will be forced to do so using polyline_make_x_common.

Parameters:

a, b, c : PolyLine object

PolyLine obects making up the composite function.

xai : array_like, float

x values to interpolate the a part of the composite function.

xbi, xbj : array_like, float

x values to integrate the b * c part of the composite function. between.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : (len(xbi), len(xai)) 2d array

Results for each xbi, xbj pair and xai value.

geotecha.piecewise.piecewise_linear_1d.pxa_ya_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between_super(a, b, c, xai, xbi, xbj, **kwargs)[source]

Superpose results of respectively interpolate at one point, and integrate between two points, the first PolyLine and the multiplied second and third PolyLine portions of a composite function of piecewise-linear representations.

For each f(xa), g(xb) pair sum f(xai) * integrate[g(xb) * h(xb), (xbi, xbj)], where f(xa), g(xb), and h(xb) are defined with PolyLine objects.

The function is a bit specialised in that a and b can be lists of PolyLine objects. The contribution of each composite function (a[0], b[0], c), (a[1], b[1], c), ... will be summed.

The b and c PolyLine objects do NOT need to have the same x values, they will be forced to do so using polyline_make_x_common.

Parameters:

a, b, c : PolyLine object, or list of PolyLine objects

PolyLine obects making up the composite function. a and b can be lists of equal length.

xai : array_like, float

x values to interpolate the a part of the composite function.

xbi, xbj : array_like, float

x values to integrate the b * c part of the composite function.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : (len(xbi), len(xai)) 2d array

Results for each xbi, xbj pair and xai value.

geotecha.piecewise.piecewise_linear_1d.pxa_ya_multipy_avg_x1b_x2b_y1b_y2b_between(a, b, xai, xbi, xbj, **kwargs)[source]

Respectively interpolate at one point, and average between two points, the a composiute function of two PolyLine objects.

Evaluate f(xai) * integrate[g(xb), (xbi, xbj)] / (xbi - xbj), where f(xa) and g(xb) are PolyLine objects; wrapper for xa_ya_multipy_avg_x1b_x2b_y1b_y2b_between.

Parameters:

a, b : PolyLine object

PolyLine object s containing data. The b Polyline will be averaged between xbi, and xbj; the a PolyLine will be interpolated at xai.

xai : array_like, float

x values to interpolate at for x_y part.

xbi, xbj : array_like, float

x values to average between for the x1_x2_y1_y2 part.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : 2d array of float

Result of averageing and interpolating. shape(A) == (len(xbi), len(xai)).

See also

xa_ya_multipy_avg_x1b_x2b_y1b_y2b_between
Wrapped function.
geotecha.piecewise.piecewise_linear_1d.ramps_constants_steps(x, y)[source]

Find the ramp, constant, and step line segments in x, y data

Returns:

ramps : 1d ndarray

start_index_of_ramps

constants : 1d ndarray

start_index_of_constants

steps : 1d ndarray

start_index_of_constants

See also

start_index_of_ramps
Find ramps.
start_index_of_steps
Find steps.
start_index_of_constants
Find constants.
geotecha.piecewise.piecewise_linear_1d.remove_superfluous_from_x_y(x, y, atol=1e-08)[source]

Remove points that are on a line between other points

Intermediate points are judged to be ‘on a line’ and therefore superfluous when the distance of the point from the line is below atol.

Parameters:

x, y : 1d array_like, float

x and y values.

atol : float, optional

atol is the threshold. Default atol=1e-8.

Returns:

xnew, ynew : 1d ndarray, float

Cleaned up x and y values.

Notes

#TODO: put in equation for distance of point to a line from wolfram http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

geotecha.piecewise.piecewise_linear_1d.segment_containing_also_segments_less_than_xi(x, y, xi, steps_or_equal_to=True, ramp_const_or_equal_to=False, choose_max=False)[source]

Determine ramp, constant and step segments containing xi as well as segments less than xi.

Function does minimal calculations itself, essentially calling other functions and returning a tuple. Useful for piecewise linear loading functions when you segements after a certain time are irrelevant.

Parameters:

x, y : array_like

x and y coords (must be non-decreasing).

xi : array_like, float

Values to check check segments against.

steps_or_equal_to : boolean, optional

If True (default) then any step segment that xi falls on/in will be included in the steps ‘less than’ list.

ramp_const_or_equal_to : boolean, optional

If False (default) then any ramp or constant segment that xi falls on the start will not be included in the ramps and constants ‘less than’ list.

choose_max : boolean, optional

If False (default), then the minimum segment of multiple ramp segments that contain xi falls will be included in the ‘contains’ lists. If True then the maximum segment will be included.

Returns:

ramps_less_than_xi : ndarray

segments_less_than_xi for ramps.

constants_less_than_xi : ndarray

segments_less_than_xi for constants.

steps_less_than_xi : ndarray

segments_less_than_xi for steps.

ramps_containing_xi : ndarray

Start index of ramp segment containing xi.

constants_containing_xi : ndarray

Start index of constant segment containing xi.

See also

ramps_constants_steps
find ramp, constant, and step segments
segments_less_than_xi
find segments after xi
segment_containing_xi
find segments that contain xi
geotecha.piecewise.piecewise_linear_1d.segment_containing_xi(x, xi, subset=None, choose_max=False)[source]

Find start index of line segment in which xi falls

Find index where x[i] <= xi <= x[i+1] ignoring steps. choose_max determines what happens when more than one segment satisfies the condition e.g. the boundary between two segments; taking either the maximum index (choose_max True), or the minimum index (`choose_max`= False).

Parameters:

x : array_like, float

x coordinates.

xi : array_like, float

Values to place in segments.

subset : array_like, optional

Restrict search to segments starting with indices in subset. Default subset=None i.e. search all segments.

choose_max : boolean, optional

When False (default), the minumum index that satisfies the condition is returned. When True the maximum index that satisfies the condition is returned. Default choose_max=False. See Notes below

Returns:

A : list of single element lists

Each sub-list is the start index of the segment that contains xi. Returning each value in a list allows “for i in A[0]” type constructs which for an empty list will do nothing.

Notes

If x data has switch backs (i.e. not non-decreasing and not non-increasing) then if choose_max = True then the index returned will be in the last group of segments. This can be useful as when determining when something ends. e.g. say x are strictly incresing time values and y zig zags up and down for a time then decays to zero. A regular interpolation will give you any y value at a given x value. But you might want to answer a question such as ‘at what time does y finally fall below 10’. You want to search only the last decaying section. By plugging the y values in as x and using choose_max = True, you will get the segment where this happens.

This function is somewhat similar to the numpy.digitize function that places x values into bins. segment_containing_xi however, does not insist on monotonic data and won’t break down if steps are included; it is also possible to put both bounds in the same segement. Say for x = [0,1,2,3] and xi1 = 1 and xi2 = 2. If choose_max is False for both points then xi1 will be in segment 0, and xi2 in segment 1. But if you use choose_max = True for xi1 then it be in segment 1 (the same as xi2).

geotecha.piecewise.piecewise_linear_1d.segment_containing_xi_also_containing_xj(x, xi, xj, subset=None)[source]

Find start index of segments that xi and xj fall in trying to have them in the same section.

Find highest i where x[i] <= xi <= x[i+1] ignoring steps. Find lowest j where x[j] <= xj <= x[j+1] ignoring steps. This will minimise the number of segments between xi and xj. Usually xj should be greater than xi.

Function does no calculations itself, rather calling segment_containing_xi twice and returning a tuple.

Parameters:

x : array_like, float

x coordinates.

xi, xj : array_like, float

x values to from which to determin containing segment.

subset : array_like, optional

Restrict search to segments starting with indices in subset. Default subset=None which searches all segments.

Returns:

seg_xi, seg_xj : list of single element lists

Each sub-list is the start index of the segement that contains xi or xj.

See also

segments_containing_xi
Function called for xi and xj.
geotecha.piecewise.piecewise_linear_1d.segments_between_xi_and_xj(x, xi, xj)[source]

Find line segments that exclusively contain both, only one of, and in between xi and xj.

Determine if xi and xj are both in the same segment. When xi and xj are in different segments find the segment that contains xi and the segment that contains xj and any segments in between them. Results are only obvious when x is strictly increasing and xi<xj.

This is useful when integrating between two points; the integration limits in each relevant segment are different.

Parameters:

x : array_like, float

x coordinates

xi, xj : array_like, float

x values to from which to determine segments.

Returns:

segment_both : list of single element lists

Each sub-list is the start index of the segment that contains xi or xj.

segment_xi_only : list of single element lists

When xi and xj not in the same segment, segment_xi_only will be the segment that contains xi.

segment_xj_only : list of single element lists

When xi and xj not in the same segment, segment_xj_only will be the segment that contains xj.

segments_between : list of single element lists

When xi and xj not in the same segment, segments_between will be the segments in between xi and xj but not containing xi or xj.

See also

segment_containing_xi_also_containing_xj
Find segment of xi and xj.
geotecha.piecewise.piecewise_linear_1d.segments_less_than_xi(x, xi, subset=None, or_equal_to=False)[source]

Find start index of line segments that end before xi

Finds all segments where end point of segment is less than xi.

Assumes non-decreasing x data.

Parameters:

x : array_like, float

x coordinates.

xi : array_like, float

Values to check if segments start after.

subset : array_like, optional

Restrict search to segments starting with indices in subset. Default subset=None, which searches all segments.

or_equal_to : boolean, optional

If False (default) then conditon is formulated with ‘<’. If True then condition is formulated with ‘<=’. Generally only used to include/exclude step loads.

Returns:

out : list of 1d numpy.ndarray

List contains len(xi) 1d numpy.ndarray corresponding to xi.

geotecha.piecewise.piecewise_linear_1d.start_index_of_constants(x, y)[source]

Find the start indices of the constant line-segments in x, y data.

An example of a ‘constant’ x=[0,2], y=[15,15]. i.e. a horizontal line

Assumes data is non_decreasing.

Segments such as x=[1,1], y=[2,2] are ignored.

Parameters:

x, y : array_like

x and y coords (must be non-decreasing).

Returns:

out : 1d ndarray

Start indices of all constant segments.

geotecha.piecewise.piecewise_linear_1d.start_index_of_ramps(x, y)[source]

Find the start indices of the ramp line segments in x, y data.

An example of a ‘ramp’ x=[0,2], y=[10,15]. i.e. not a vertical line and not a horizontal line.

Assumes data is non_decreasing.

Parameters:

x, y : array_like

x and y coords (must be non-decreasing).

Returns:

out : 1d ndarray

Start indices of all ramps.

geotecha.piecewise.piecewise_linear_1d.start_index_of_steps(x, y)[source]

Find the start indices of the step line-segments in x, y data.

An example of a ‘step’ x=[0, 0], y=[10, 15]. i.e. a vertical line.

Assumes data is non_decreasing.

Segments such as x=[1, 1], y=[2, 2] are ignored.

Parameters:

x, y : array_like

x and y coords (must be non-decreasing)

Returns:

out : 1d ndarray

Start indices of all step segments.

geotecha.piecewise.piecewise_linear_1d.strictly_decreasing(x)[source]

Checks all x[i+1] < x[i]

Parameters:

x : 1d array

Series of x values

Returns:

out : True/False

True if each x value is less than the preceeding value.

See also

strictly_increasing
Check for increasing values, no equality allowed.
non_increasing
Less stringent decreasing check, allows equal values.
non_decreasing
Less stringent increasing check, allows equal values.
geotecha.piecewise.piecewise_linear_1d.strictly_increasing(x)[source]

Checks all x[i+1] > x[i]

Parameters:

x : 1d array

Series of x values

Returns:

out : True/False

True if each x value is greater than the preceeding value.

See also

strictly_decreasing
Check for decreasing values, no equality allowed.
non_increasing
Less stringent decreasing check, allows equal values.
non_decreasing
Less stringent increasing check, allows equal values.
geotecha.piecewise.piecewise_linear_1d.subdivide_into_elements(n=2, h=1.0, p=1, symmetry=True)[source]

Subdivide a length into elements where sizes are proportional to adjacent elements.

  • element_0 = x * p**0
  • element_1 = x * p**1
  • element_2 = x * p**2
  • etc.

x is such that sum of n elements equals h.

Parameters:

n : int, optional

Number of elements to subdivide into. Default n=2.

h : float, optional

Length to subdivide. Default h=1.

p : float, optional

Ratio of subsequent elements. If p<1 then succesive elements will reduce in length. If p>1 then successive elements will increase in lenght. Default p=1

symmetry : True/False, optional

If True then elements will be symmetrical abount middle. Default symmetry=True.

Returns:

out : array of float

Length of each element. Should sum to h.

See also

np.logspace, np.linspace, subdivide_x_into_segments, subdivide_x_y_into_segments

Examples

>>> subdivide_into_elements(n=3, h=6.0, p=1, symmetry=True)
array([ 2.,  2.,  2.])
>>> subdivide_into_elements(n=4, h=6.0, p=1, symmetry=True)
array([ 1.5,  1.5,  1.5,  1.5])
>>> subdivide_into_elements(n=4, h=6.0, p=1, symmetry=False)
array([ 1.5,  1.5,  1.5,  1.5])
>>> subdivide_into_elements(n=3, h=6.0, p=2, symmetry=True)
array([ 1.5,  3. ,  1.5])
>>> subdivide_into_elements(n=3, h=6.0, p=0.5, symmetry=True)
array([ 2.4,  1.2,  2.4])
>>> subdivide_into_elements(n=4, h=6.0, p=2, symmetry=True)
array([ 1.,  2.,  2.,  1.])
>>> subdivide_into_elements(n=4, h=6.0, p=0.5, symmetry=True)
array([ 2.,  1.,  1.,  2.])
>>> subdivide_into_elements(n=4, h=6.0, p=0.5, symmetry=False)
array([ 3.2,  1.6,  0.8,  0.4])
>>> subdivide_into_elements(n=3, h=3.5, p=2, symmetry=False)
array([ 0.5,  1. ,  2. ])
>>> sum(subdivide_into_elements(n=20, h=3.5, p=1.05, symmetry=False))
3.5
geotecha.piecewise.piecewise_linear_1d.subdivide_x_into_segments(x, dx=None, min_segments=2, just_before=None, logx=False, logxzero=0.1, rtol=1e-05, atol=1e-08)[source]

Subdivide sequential x values into subsegments.

Intervals are evenly spaced in linear or log space

Parameters:

x : 1d array-like

List of x values to subdivide.

dx : float, optional

Approximate length or log10(length) of subsegment. Say logx is True, segment x values are (1, 10), and x=0.2 then int((log(10)-log(1))/0.2)=5 subsegments will be created (i.e. 5 extra points will be inserted in the segment). The new x values will be will be 10**(log(1)+0.2), 10**(log(1)+0.4), 10**(log(1)+0.6) etc. Default dx=None i.e. no dx check and min_segments will be used.

min_segments : int, optional

Minuimum number of subsegments per inteval. This will be used if int(segment_lenght/dx)<min_segments. Default min_segments=2.

just_before : float, optional

If just_before is not None then in terms of subdividing, each segment will be treated as if it begins at its starting value but ends a distance of just_before multiplied by the interval length before its end value. This means that an extra point will be added just before all of the original points. Default just_before=None i.e dont use just before point. Use a small number e.g. 1e-6. just_before can be useful for example when getting times to evaluate pore pressure during a soil consoliation analysis. Say you have a PolyLine representing load_vs_time. If there are step changes in your load then there will be step changes in your pore pressure. To capture the step change in your output you need an output time just before and just after the step change in your load. Using just_before can achieve this.

logx : True/False, optional

Use log scale on x data. Default logx=False.

logxzero : float, optional

If log scale is used, force zero value to be given number. Useful when 1st point is zero but you really want to start from close to zero. Default logxzero=0.01.

rtol, atol : float, optional

For determining equal to zero when using log scale with numpy. Default atol=1e-8, rtol = 1e-5.

Returns:

xnew : 1d array

new x values

See also

subdivide_x_y_into_segments
Subdivide both x and y data, y data is interpolated from the new x values.
geotecha.piecewise.piecewise_linear_1d.subdivide_x_y_into_segments(x, y, dx=None, min_segments=2, just_before=None, logx=False, logy=False, logxzero=0.1, logyzero=0.1, rtol=1e-05, atol=1e-08)[source]

Subdivide piecewise-linear line segment x, y data by interpolation

Subsegments are evenly spaced in linear or log space.

Parameters:

x : 1d array-like

List of x values to subdivide.

y : 1d array-like

List of y values to subdivide (y subdivision is based on interpolation at the new x values).

dx : float, optional

Approximate length or log10(length) of subsegment. Say logx is True, segment x values are (1, 10), and x=0.2 then int((log(10)-log(1))/0.2)=5 subsegments will be created (i.e. 5 extra points will be inserted in the segment). The new x values will be will be 10**(log(1)+0.2), 10**(log(1)+0.4), 10**(log(1)+0.6) etc. Default dx=None i.e. no dx check and min_segments will be used.

min_segments : int, optional

Minuimum number of subsegments per inteval. This will be used if int(segment_lenght/dx)<min_segments. Default min_segments=2.

just_before : float, optional

If just_before is not None then in terms of subdividing, each segment will be treated as if it begins at its starting value but ends a distance of just_before multiplied by the interval length before its end value. This means that an extra point will be added just before all of the original points. Default just_before=None i.e dont use just before point. Use a small number e.g. 1e-6. just_before can be useful for example when getting times to evaluate pore pressure during a soil consoliation analysis. Say you have a PolyLine representing load_vs_time. If there are step changes in your load then there will be step changes in your pore pressure. To capture the step change in your output you need an output time just before and just after the step change in your load. Using just_before can achieve this.

logx, logy : True/False, optional

Use log scale on x and y axes. Default logx=logy=False.

logxzero, logyzero : float, optional

If log scale is used, force zero value to be given number. Useful when 1st point is zero but you really want to start from close to zero. Default logxzero=logyzero=0.01.

rtol, atol : float, optional

For determining equal to zero when using log scale with numpy. Default atol=1e-8, rtol = 1e-5.

Returns:

xnew, ynew : 1d array

New x and y coordinates.

See also

subdivide_x_into_segments
Subdivide only x data.
geotecha.piecewise.piecewise_linear_1d.xa_ya_cos_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(xa, ya, omega, phase, x1b, x2b, y1b, y2b, x1c, x2c, y1c, y2c, xai, xbi, xbj, achoose_max=False)[source]

Respectively interpolate at one point, and integrate between two points, the cosine multiplied by x_y, and two multipled x1_x2_y1_y2 portions of a composite function of piecewise-linear representations.

Evaluate f(xai) * cos(omega*xai + phase) * integrate[g(xb) * h(xb), (xbi, xbj)], where f(xa) is defined with x_y data and g(xb) and h(xb) are defined with x1_x2_y1_y2 data.

Parameters:

xa, ya : 1d array_like, float

x and y values of x_y part of interpolation function.

omega, phase : float

Values for defining cos(omega * t + phase).

x1b, y1b : array_like, float

x and y values at start of each segment for the first 1st x1_x2_y1_y2 part of the composite function.

x2b, y2b : array_like, float

x and y values at end of each segment for the first 1st x1_x2_y1_y2 part of the composite function (note x1[1:]==x2[:-1])

x1c, y1c : array_like, float

x and y values at start of each segment for the second x1_x2_y1_y2 part of the composite function.

x2c, y2c : array_like, float

x and y values at end of each segment for the second x1_x2_y1_y2 part of the composite function (note x1[1:]==x2[:-1]).

xai : array_like, float

x values to interpolate the xc_yc part at and evaluate the cos(omega*xai + phase) part.

xbi, xbj : array_like, float

x values to integrate the x1b_x2b_y1b_y2b * x1c_x2c_y1c_y2c part between.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : (len(xbi), len(xai)) 2d array

Results for each xbi, xbj pair and xai value.

geotecha.piecewise.piecewise_linear_1d.xa_ya_multiply_integrate_x1b_x2b_y1b_y2b_multiply_x1c_x2c_y1c_y2c_between(xa, ya, x1b, x2b, y1b, y2b, x1c, x2c, y1c, y2c, xai, xbi, xbj, achoose_max=False)[source]

Respectively interpolate at one point, and integrate between two points, the x_y and two multipled x1_x2_y1_y2 portions of a composite function of piecewise-linear representations.

Evaluate f(xai) * integrate[g(xb) * h(xb), (xbi, xbj)], where f(xa) is defined with x_y data and g(xb) and h(xb) are defined with x1_x2_y1_y2 data.

Parameters:

xa, ya : 1d array_like, float

x and y values of x_y part of the composite function.

x1b, y1b : array_like, float

x and y values at start of each segment for the first x1_x2_y1_y2 part of the composite function.

x2b, y2b : array_like, float

x and y values at end of each segment for the first x1_x2_y1_y2 part of the composite function (note x1[1:]==x2[:-1]).

x1c, y1c : array_like, float

x and y values at start of each segment for the secondx1_x2_y1_y2 part of the composite function.

x2c, y2c : array_like, float

x and y values at end of each segment for the second x1_x2_y1_y2 part of the composite function (note x1[1:]==x2[:-1]).

xai : array_like, float

x values to interpolate the x_y part at.

xbi, xbj : array_like, float

x values to integrate the x1b_x2b_y1b_y2b * x1c_x2c_y1c_y2c part between.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : (len(xbi), len(xai)) 2d array

Results for each xbi, xbj pair and xai value.

geotecha.piecewise.piecewise_linear_1d.xa_ya_multipy_avg_x1b_x2b_y1b_y2b_between(xa, ya, x1b, x2b, y1b, y2b, xai, xbi, xbj, achoose_max=False)[source]

Respectively interpolate at one point, and average between two points, the x_y and x1_x2_y1_y2 portions of a composite function of piecewise-linear representations.

Evaluate f(xai) * integrate[g(xb), (xbi, xbj)] / (xbi - xbj), where f(xa) is defined with x_y data and g(xb) is defined with x1_x2_y1_y2 data.

Parameters:

xa, ya : 1d array_like, float

x and y values of x_y part of function.

x1b, y1b : array_like, float

x and y values at start of each segment for x1_x2_y1_y2 part of function.

x2b, y2b : array_like, float

x and y values at end of each segment for x1_x2_y1_y2 part of function (note x1[1:]==x2[:-1])

xai : array_like, float

x values to interpolate at for x_y part.

xbi, xbj : array_like, float

x values to average between for the x1_x2_y1_y2 part.

achoose_max : boolean, optional

If False (default), when xai falls on boundary of segments choose the minimum segment to interpolate within.

Returns:

A : 2d array of float

Result. shape(A) == (len(xbi), len(xai)), i.e. rows represent

See also

interp_x_y
Interpolate the x_y part.
avg_x1_x2_y1_y2_between_xi_xj
Average the x1_x2_y1_y2 part between xbi, xbj.