rsqsim_api.fault.utilities
Geometric utility functions for fault-trace analysis and manipulation.
Provides bearing arithmetic, line operations (strike, dip direction,
reversal, smoothing), and helpers for merging nearly-adjacent
LineString segments into single traces.
Functions
|
Return the smallest angular difference between two bearings. |
|
Normalise a bearing to the range [0, 360). |
|
Check whether a bearing is anticlockwise of (less than) another bearing. |
|
Check whether a bearing is clockwise of (greater than) another bearing. |
|
Return the bearing 180° opposite to the supplied bearing. |
|
Reverse the vertex order of a |
|
Fit a straight line to a 2-D point cloud and return the dip angle. |
|
Calculate the dip direction of a fault-trace LineString in NZTM. |
|
Calculate the strike of a fault-trace LineString in NZTM. |
|
Re-sample a LineString to approximately uniform point spacing. |
|
Smooth a polyline using Chaikin's corner-cutting algorithm. |
|
Smooth a fault-trace LineString using Chaikin's corner-cutting algorithm. |
|
Straighten a 3-D line by damping its across-strike deviations. |
|
Snap the closest endpoints of two nearly-adjacent LineStrings to their midpoint. |
|
Merge two nearly-adjacent LineStrings into one by snapping their endpoints. |
|
Iteratively merge a list of nearly-adjacent LineStrings into one. |
Module Contents
- rsqsim_api.fault.utilities.smallest_difference(value1, value2)[source]
Return the smallest angular difference between two bearings.
Accounts for the circular nature of bearings so that, for example, the difference between 350° and 10° is 20° rather than 340°.
- Parameters:
value1 (float or int) – First bearing in degrees.
value2 (float or int) – Second bearing in degrees.
- Returns:
Smallest non-negative angular difference in degrees (0–180).
- Return type:
float
- rsqsim_api.fault.utilities.normalize_bearing(bearing)[source]
Normalise a bearing to the range [0, 360).
- Parameters:
bearing (float or int) – Input bearing in degrees (any value).
- Returns:
Equivalent bearing in the range [0, 360).
- Return type:
float
- rsqsim_api.fault.utilities.bearing_leq(value, benchmark, tolerance=0.1)[source]
Check whether a bearing is anticlockwise of (less than) another bearing.
- Parameters:
value (int or float) – The bearing to test, in degrees.
benchmark (int or float) – The reference bearing, in degrees.
tolerance (int or float, optional) – Angular tolerance in degrees to account for rounding. Defaults to 0.1.
- Returns:
Trueifvalueis strictly anticlockwise ofbenchmark(i.e. less than, withintolerance).- Return type:
bool
- rsqsim_api.fault.utilities.bearing_geq(value, benchmark, tolerance=0.1)[source]
Check whether a bearing is clockwise of (greater than) another bearing.
- Parameters:
value (int or float) – The bearing to test, in degrees.
benchmark (int or float) – The reference bearing, in degrees.
tolerance (int or float, optional) – Angular tolerance in degrees to account for rounding. Defaults to 0.1.
- Returns:
Trueifvalueis strictly clockwise ofbenchmark(i.e. greater than, withintolerance).- Return type:
bool
- rsqsim_api.fault.utilities.reverse_bearing(bearing)[source]
Return the bearing 180° opposite to the supplied bearing.
- Parameters:
bearing (int or float) – Input bearing in degrees; must be in [0, 360].
- Returns:
Reversed bearing in the range [0, 360).
- Return type:
float
- Raises:
AssertionError – If
bearingis not a float or int, or is outside [0, 360].
- rsqsim_api.fault.utilities.reverse_line(line)[source]
Reverse the vertex order of a
LineString.Works with both 2-D and 3-D (has_z) lines.
- Parameters:
line (shapely.geometry.LineString) – Input line to reverse.
- Returns:
New line with vertices in the opposite order.
- Return type:
shapely.geometry.LineString
- Raises:
AssertionError – If
lineis not aLineString.
- rsqsim_api.fault.utilities.fit_2d_line(x, y)[source]
Fit a straight line to a 2-D point cloud and return the dip angle.
Fits both
y = f(x)andx = g(y)and selects whichever has the smaller residual, then converts the gradient to a dip angle.- Parameters:
x (numpy.ndarray) – x-coordinates of the points.
y (numpy.ndarray) – y-coordinates of the points.
- Returns:
Dip angle in degrees measured from the horizontal.
- Return type:
float
- Raises:
AssertionError – If either
xoryis not anumpy.ndarray.
- rsqsim_api.fault.utilities.calculate_dip_direction(line)[source]
Calculate the dip direction of a fault-trace LineString in NZTM.
Computes the strike of the line (best-fit gradient) and adds 90° to obtain the dip direction. The sign is chosen so that the dip direction is consistent with the majority of vertices being to the right of the strike vector.
- Parameters:
line (shapely.geometry.LineString or MultiLineString) – Fault-surface trace in NZTM (EPSG:2193) coordinates. A
MultiLineStringis first merged into a single line.- Returns:
Dip direction in degrees, range [0, 360).
- Return type:
float
- Raises:
AssertionError – If
lineis not a LineString or MultiLineString.
- rsqsim_api.fault.utilities.calculate_strike(line, lt180=False)[source]
Calculate the strike of a fault-trace LineString in NZTM.
Fits a best-fit gradient to the trace coordinates and converts it to an azimuthal strike. When
lt180isTruethe result is reduced to the half-circle convention [0, 180).- Parameters:
line (shapely.geometry.LineString or MultiLineString) – Fault-surface trace in NZTM (EPSG:2193) coordinates. A
MultiLineStringis first merged into a single line.lt180 (bool, optional) – If
True, return a strike in [0, 180) instead of [0, 360). Defaults toFalse.
- Returns:
Strike in degrees.
- Return type:
float
- Raises:
AssertionError – If
lineis not a LineString or MultiLineString.
- rsqsim_api.fault.utilities.optimize_point_spacing(line, spacing)[source]
Re-sample a LineString to approximately uniform point spacing.
Interpolates
num_pointscentre-points along the line, wherenum_pointsis chosen to matchspacingas closely as possible.- Parameters:
line (shapely.geometry.LineString or MultiLineString) – Input line. A
MultiLineStringis first merged into a single line.spacing (float) – Target point spacing in the same units as the line coordinates (metres for NZTM).
- Returns:
centre_points (list of shapely.geometry.Point) – Resampled centre points along the line.
new_width (float) – Actual spacing used (line length / number of points).
- Raises:
AssertionError – If
lineis not a LineString or MultiLineString, or ifspacingis not a positive float.
- rsqsim_api.fault.utilities.chaikins_corner_cutting(coords, refinements=5)[source]
Smooth a polyline using Chaikin’s corner-cutting algorithm.
Each refinement pass replaces every edge with two new points at the 1/4 and 3/4 positions, progressively rounding corners.
- Parameters:
- Returns:
Smoothed coordinate array with approximately
n * 2 ** refinementsvertices.- Return type:
numpy.ndarray
- rsqsim_api.fault.utilities.smooth_trace(trace, n_refinements=5)[source]
Smooth a fault-trace LineString using Chaikin’s corner-cutting algorithm.
- Parameters:
trace (shapely.geometry.LineString) – Input trace to smooth.
n_refinements (int, optional) – Number of corner-cutting passes. Defaults to 5.
- Returns:
Smoothed line with approximately
len(trace.coords) * 2 ** n_refinementsvertices.- Return type:
shapely.geometry.LineString
- Raises:
AssertionError – If
traceis not aLineString.
- rsqsim_api.fault.utilities.straighten(line, strike, damping)[source]
Straighten a 3-D line by damping its across-strike deviations.
Projects each vertex onto the along-strike and across-strike directions, then reconstructs new positions with the across-strike component multiplied by
damping.- Parameters:
line (shapely.geometry.LineString) – Input 3-D line (z coordinate included in
coords).strike (float) – Strike azimuth in degrees used to define the along/across direction.
damping (float) – Fractional weight applied to the across-strike displacement (0 = fully straight, 1 = unchanged).
- Returns:
New line with reduced across-strike curvature.
- Return type:
shapely.geometry.LineString
- rsqsim_api.fault.utilities.align_two_nearly_adjacent_segments(segment_list, tolerance=200.0)[source]
Snap the closest endpoints of two nearly-adjacent LineStrings to their midpoint.
Identifies which endpoints of the two segments are closest to each other and replaces both with the midpoint, making the segments exactly adjacent.
- Parameters:
segment_list (list of shapely.geometry.LineString) – Exactly two line segments.
tolerance (float, optional) – Maximum allowable distance (m) between the nearest endpoints for the operation to be valid. Defaults to 200.
- Returns:
Two new segments with snapped endpoints.
- Return type:
tuple of shapely.geometry.LineString
- Raises:
AssertionError – If
segment_listdoes not contain exactly 2 segments, or if the distance between them exceedstolerance.
- rsqsim_api.fault.utilities.merge_two_nearly_adjacent_segments(segment_list, tolerance=200.0)[source]
Merge two nearly-adjacent LineStrings into one by snapping their endpoints.
Calls
align_two_nearly_adjacent_segments()to snap the closest endpoints to their midpoint, then merges the result into a singleLineStringwithlinemerge().- Parameters:
segment_list (list of shapely.geometry.LineString) – Exactly two line segments.
tolerance (float, optional) – Maximum allowable gap (m) between segments. Defaults to 200.
- Returns:
Merged single line.
- Return type:
shapely.geometry.LineString
- rsqsim_api.fault.utilities.merge_multiple_nearly_adjacent_segments(segment_list, tolerance=200.0)[source]
Iteratively merge a list of nearly-adjacent LineStrings into one.
Repeatedly merges the first two segments using
merge_two_nearly_adjacent_segments()until a single line remains.- Parameters:
segment_list (list of shapely.geometry.LineString) – Two or more line segments to merge, ordered along the trace.
tolerance (float, optional) – Maximum allowable gap (m) between consecutive segments. Defaults to 200.
- Returns:
Single merged line.
- Return type:
shapely.geometry.LineString
- Raises:
AssertionError – If
segment_listcontains fewer than 2 segments.