speed.py¶
LevelSetSpeedMethods
dataclass
¶
LevelSetSpeedMethods(
Δx: float,
Δt: float = 0,
n_total: int | None = None,
i_step: int | None = None,
t_total: float = 0,
Δt_reinitialize: float = 0.1,
κ_boost: float = 1,
n_slabfailure: int | None = None,
n_pad_pixels: int | None = None,
band_width: float | None = None,
fm_order: int | None = None,
n_pixels_xz0: tuple[int, int] | None = None,
n_pixels_xz: tuple[int, int] | None = None,
do_extend_line: bool = True,
do_φ_everywhere: bool | None = None,
domain: Domain | None = None,
raw_domain: Domain | None = None,
surface: (
StraightLineSurface
| ErrorFunctionSurface
| SemiCircularArcSurface
| QuarterCircularArcSurface
| None
) = None,
substrate: (
OneLayerSubstrate | TwoLayerSubstrate | MultiLayerSubstrate | None
) = None,
model: Isotropic | Step | ExponentialActivation | None = None,
gma: GeometricMechanicsAnalysis | None = None,
)
flowchart TD
erosionfront.levelset.speed.LevelSetSpeedMethods[LevelSetSpeedMethods]
erosionfront.levelset.grid.LevelSetGridMethods[LevelSetGridMethods]
erosionfront.levelset.elementary.LevelSetElementaryMethods[LevelSetElementaryMethods]
erosionfront.levelset.data.LevelSetData[LevelSetData]
erosionfront.levelset.grid.LevelSetGridMethods --> erosionfront.levelset.speed.LevelSetSpeedMethods
erosionfront.levelset.elementary.LevelSetElementaryMethods --> erosionfront.levelset.grid.LevelSetGridMethods
erosionfront.levelset.data.LevelSetData --> erosionfront.levelset.elementary.LevelSetElementaryMethods
click erosionfront.levelset.speed.LevelSetSpeedMethods href "" "erosionfront.levelset.speed.LevelSetSpeedMethods"
click erosionfront.levelset.grid.LevelSetGridMethods href "" "erosionfront.levelset.grid.LevelSetGridMethods"
click erosionfront.levelset.elementary.LevelSetElementaryMethods href "" "erosionfront.levelset.elementary.LevelSetElementaryMethods"
click erosionfront.levelset.data.LevelSetData href "" "erosionfront.levelset.data.LevelSetData"
Speed-related methods for use in erosion front modeling.
Subclasses LevelSetGridMethods.
Attributes¶
φ: MaskedArray Signed-distance grid at this time step. φ_next: MaskedArray | None Signed-distance grid at next time step.
Methods:
-
__post_init__–Complete instantiation by computing domain, pixel size, offset.
-
above_or_below_ji–Test whether pixel i,j lies above or below surface.
-
above_or_below_xz–Test whether point x,z lies above or below surface.
-
compute_contour–Generate a continuous (for now) contour of grid function f.
-
compute_domain–(Re)build domain after resizing.
-
compute_line_pixel_offsets–Measure signed offsets between rasterized line pixels and line curve.
-
compute_pixel_dimensions–Calculate numbers of pixels spanning the grid.
-
compute_pixel_origin–Calculate pixel offset of domain x,z position (0,0).
-
fm_distance–Use fast marching to compute signed distance from a ref grid (zeroset).
-
fm_distance_everywhere–FM compute a narrowband signed distance and then extend everywhere.
-
get_extent–Get domain (x,z) extent.
-
get_front_points–Fetch points along erosion front surface aka zeroset of f.
-
get_line_points–Convert Shapely geometry Line into (x,z) points.
-
get_points_xz–Get surface (x,z) coordinates.
-
get_substrate_ξ0–Generate relative η grid (effective speed ξ0).
-
get_x_limits–Get domain x min, max.
-
get_z_limits–Get domain z min, max.
-
get_φ_next–Return next signed-distance grid φ_next or just φ if not available.
-
ij_to_xz–Convert pixel indices [i,j] into pixel center coords (x,z).
-
ji_to_xz–Convert reversed pixel indices [j,i] into pixel center coords (x,z).
-
make_line–Convert surface (x,z) coordinates into a Shapely Line geometry.
-
make_polygon–Create a 'bounding' polygon from surface x,z points.
-
measure_normal_distance–Compute distance between line and point using Shapely.
-
measure_φ_ji–Compute signed distance between line and i,j pixel using Shapely.
-
measure_φ_xz–Compute signed distance between line and xz point using Shapely.
-
pad_domain–Expand the domain vertically by pixel width amounts.
-
pad_grid–Pad grid with specified number of pixels below and above.
-
rasterize_line–Rasterize surface line as x,z points into grid pixels using Rasterio.
-
redo_φ_everywhere–Reassign signed distance values to pixels beyond the narrow band.
-
xz_to_ij–Convert pixel center coords (x,z) into pixel indices [i,j].
__post_init__
¶
Complete instantiation by computing domain, pixel size, offset.
Attributes¶
raw_domain: Domain Model domain instance. n_pixels_xz: tuple[int, int]: Grid pixel size. n_pixels_xz0: tuple[int, int]: Origin location in pixels.
Source code in erosionfront/levelset/elementary.py
above_or_below_ji
¶
Test whether pixel i,j lies above or below surface.
Uses "in_rock_polygon" to test if pixel is within the bedrock or in the air. In other words, it tests which side of the surface zeroset the pixel lies.
The pixel center is used in this computation.
Parameters¶
ji: tuple[float,float] | NDArray Test pixel with reversed indexes. in_rock_polygon: Polygon Shapely polygon defining "below ground".
Atrributes¶
Uses ji_to_xz method.
Returns¶
-1 if "in the air" and +1 if "in the rock".
Source code in erosionfront/levelset/grid.py
above_or_below_xz
staticmethod
¶
Test whether point x,z lies above or below surface.
Uses "in_rock_polygon" to test if point is within the bedrock or in the air. In other words, it tests which side of the surface zeroset the point lies.
Parameters¶
xz: tuple[float,float] | NDArray Test point. in_rock_polygon: Polygon Shapely polygon defining "below ground".
Returns¶
-1 if "in the air" and +1 if "in the rock".
Source code in erosionfront/levelset/grid.py
compute_contour
¶
compute_contour(f: NDArray | MaskedArray, level: float = 0) -> NDArray
Generate a continuous (for now) contour of grid function f.
BUG: the contouring function actually returns a set of disjoint contour segments, often with more than one segment. Here it's incorrectly assumed these segments are contiguous and can simply be concatenated. This is not true! But to do better downstream use of this method needs to handle the segment set properly, which is going to be inconvenient.
Parameters¶
f: NDArray | MaskedArray Smooth grid (e.g., signed distance) on which to compute contour. level: float=0 Chosen contour level.
Attributes¶
Uses ij_to_xz method.
Returns¶
NDArray Single sequence of x,z contour coordinates as (2,N) array.
Source code in erosionfront/levelset/grid.py
compute_domain
staticmethod
¶
(Re)build domain after resizing.
Parameters¶
x: tuple | NDArray Vectors of x coordinates for which a domain geometry needs to be measured. z: tuple | NDArray Vectors of z coordinates for which a domain geometry needs to be measured. resolution: float Grid pixel size.
Returns¶
Domain Domain geometry class instance.
Source code in erosionfront/levelset/elementary.py
compute_line_pixel_offsets
¶
compute_line_pixel_offsets(
line: LineString, ρ: NDArray, do_φ_everywhere: bool | None = False
) -> NDArray
Measure signed offsets between rasterized line pixels and line curve.
Spatial aliasing during rasterization means each line pixel is likely offset a bit from the line curve, so this function computes these offsets.
Parameters¶
line: LineString ρ: NDArray
bool
Compute distances for all grid pixels, not just those not masked.
Attributes¶
Uses measure_φ_ji and above_or_below_ji methods.
Returns¶
NDArray Grid with signed-distance normal offsets from the line curve at each rasterized line pixel.
Source code in erosionfront/levelset/grid.py
compute_pixel_dimensions
staticmethod
¶
Calculate numbers of pixels spanning the grid.
Parameters¶
domain: Domain Grid domain geometry. resolution: float Grid pixel size.
Returns¶
tuple[int, int] Width and height of grid in pixel numbers.
Source code in erosionfront/levelset/elementary.py
compute_pixel_origin
staticmethod
¶
Calculate pixel offset of domain x,z position (0,0).
Parameters¶
domain: Domain Grid domain geometry. resolution: float Grid pixel size.
Returns¶
tuple[int, int] Pixel indexes of bottom-left origin of grid.
Source code in erosionfront/levelset/elementary.py
fm_distance
staticmethod
¶
fm_distance(
f: NDArray, band_width: float | None, resolution: float, order: int | None
) -> MaskedArray
Use fast marching to compute signed distance from a ref grid (zeroset).
The reference grid (typically travel time, but may be rasterized line offsets) provides a zero contour from which the signed distance is computed by fast marching.
Parameters¶
f: NDArray Reference grid to provide a zero contour. band_width: float | None, Width of the narrow band. resolution: float Grid pixel width (and height). order: int Fast-marching order of computational stencil (1 or 2).
Returns¶
MaskedArray Signed distance grid.
Source code in erosionfront/levelset/grid.py
fm_distance_everywhere
¶
fm_distance_everywhere(
φ: MaskedArray, φ_everywhere: NDArray, resolution: float, order: int | None
) -> NDArray
FM compute a narrowband signed distance and then extend everywhere.
The previous 'everywhere' grid of signed distance is used to supply values beyond the narrowband.
Parameters¶
φ: MaskedArray Reference grid to provide a zero contour. φ_everywhere: NDArray Previous grid of signed distance everywhere. resolution: float Grid pixel width (and height). order: int Fast-marching order of computational stencil (1 or [2]).
Attributes¶
Uses the fm_distance method.
Returns¶
MaskedArray Grid with signed distance values everywhere, not just on the nb.
Source code in erosionfront/levelset/grid.py
get_extent
¶
Get domain (x,z) extent.
Returns¶
NDArray: Domain bounds as [x_min, x_max, z_max, z_min].
Source code in erosionfront/levelset/elementary.py
get_front_points
¶
Fetch points along erosion front surface aka zeroset of f.
Parameters¶
f: NDArray | MaskedArray Presumably a signed distance grid (but not necessarily).
Attributes¶
Uses compute_contour method.
Returns¶
NDArray Coordinate sequence (x,z)*N along surface as (2,N) array.
Source code in erosionfront/levelset/grid.py
get_line_points
¶
get_points_xz
¶
get_substrate_ξ0
¶
Generate relative η grid (effective speed ξ0).
Parameters¶
φ: MaskedArray Any grid of the size being used in the sim.
Attributes¶
substrate: OneLayerSubstrate | TwoLayerSubstrate | MultiLayerSubstrate Instance of class containing substrate info. surface.height: float Top height of surface above z=0 base. η_upperlayer: float Relative erodiblity of strong layer (weak layer assumed = 1). do_hardtop: bool Whether to fake a highly resistant, very thin, upper "caprock". do_hardbase: bool Whether to fake a highly resistant, very thin, lower "bedrock". η_hardtopbase: float Relative erodiblity of base/top layers (weak layer assumed = 1).
Returns¶
MaskedArray Modulated erodbility (ref speed) grid ξ0 across the narrow band.
Source code in erosionfront/levelset/speed.py
get_x_limits
¶
get_x_limits() -> tuple
Get domain x min, max.
Returns¶
tuple: x_min, x_max pair.
Source code in erosionfront/levelset/elementary.py
get_z_limits
¶
get_z_limits() -> tuple
Get domain z min, max.
Returns¶
tuple: z_min, z_max pair.
Source code in erosionfront/levelset/elementary.py
get_φ_next
¶
Return next signed-distance grid φ_next or just φ if not available.
Returns¶
MaskedArray: Next signed-distance φ grid or just current φ if next unavailable.
Source code in erosionfront/levelset/speed.py
ij_to_xz
¶
ij_to_xz(ij: NDArray | tuple) -> NDArray
Convert pixel indices [i,j] into pixel center coords (x,z).
Parameters¶
ij: NDArray | tuple Pixel index pairs [i,j] as numpy array or tuple.
Returns¶
NDArray: Pixel (x,z) coordinate pairs as float64 numpy array.
Source code in erosionfront/levelset/elementary.py
ji_to_xz
¶
ji_to_xz(ji: NDArray | tuple) -> NDArray
Convert reversed pixel indices [j,i] into pixel center coords (x,z).
Parameters¶
ji: NDArray | tuple Pixel (reversed) index pairs [j,i] as numpy array or tuple.
Returns¶
NDArray: Pixel (x,z) coordinate pairs as float64 numpy array.
Source code in erosionfront/levelset/elementary.py
make_line
staticmethod
¶
Convert surface (x,z) coordinates into a Shapely Line geometry.
Parameters¶
points_xz: NDArray Stacked vectors of x and z surface point coordinates.
Returns¶
LineString: Shapely LineString geometry of surface line.
Source code in erosionfront/levelset/elementary.py
make_polygon
staticmethod
¶
Create a 'bounding' polygon from surface x,z points.
This polygon is used to decide whether a point lies within the bedrock or outside it.
BUG: Crudely done. Should be much tighter geometry close to domain.
Parameters¶
points_xz: NDArray Surface coordinates n_pixels_xz: tuple | NDArray Grid dimensions resolution: float Grid pixel size.
Returns¶
Polygon Shapely geometry of bounding polygon.
Source code in erosionfront/levelset/elementary.py
measure_normal_distance
staticmethod
¶
measure_normal_distance(
line: tuple | NDArray | LineString, point: tuple | NDArray | Point
) -> float
Compute distance between line and point using Shapely.
Parameters¶
line: tuple | NDArray | LineString Line represented by various possible types. point: tuple | NDArray | Point Coordinate (x,z) represented by various possible types.
Returns¶
float Perpendicular distance from line curve to point.
Source code in erosionfront/levelset/grid.py
measure_φ_ji
¶
Compute signed distance between line and i,j pixel using Shapely.
The sign is -1 for "in the air" and +1 for "in the rock".
Parameters¶
line: LineString Surface line. ji: tuple[int,int] | NDArray Pixel indexes in reversed format.
Attributes¶
Uses measure_φ_xz method to test which side of the surface the pixel lies.
Returns¶
float Signed perpendicular distance from the line to the pixel.
Source code in erosionfront/levelset/grid.py
measure_φ_xz
¶
Compute signed distance between line and xz point using Shapely.
The sign is -1 for "in the air" and +1 for "in the rock".
Parameters¶
line: LineString Surface line. xz: tuple[float,float] | NDArray Point coordinates.
Attributes¶
Uses above_or_below_xz method to test which side of the surface the point lies.
Returns¶
float Signed perpendicular distance from the line to the point.
Source code in erosionfront/levelset/grid.py
pad_domain
staticmethod
¶
Expand the domain vertically by pixel width amounts.
Parameters¶
domain: Domain (Initial) domain to be padded. resolution: float Grid pixel size. n_pad_pixels: int Number of pixel widths to pad by below the current domain.
Returns¶
New domain instance padded vertically.
Source code in erosionfront/levelset/elementary.py
pad_grid
staticmethod
¶
pad_grid(grid: NDArray, n_pad_pixels: int) -> NDArray
Pad grid with specified number of pixels below and above.
Parameters¶
grid: NDArray Grid to be padded. n_pad_pixels: int Number of pixels to pad below.
Returns¶
NDArray Padded grid.
Source code in erosionfront/levelset/elementary.py
rasterize_line
¶
rasterize_line(points_xz: NDArray, do_extend_line: bool = True) -> NDArray
Rasterize surface line as x,z points into grid pixels using Rasterio.
The x,z bounds of the raster grid are precisely set by the bounding box of the line.
Parameters¶
points_xz: NDArray Surface line as a series of x,z points. do_extend_line: bool=True Artificially extend the surface line so it reaches the boundary.
Attributes¶
Uses n_pixels_xz and xz_to_ij methods.
Returns¶
NDArray Grid of rasterized line.
Source code in erosionfront/levelset/grid.py
redo_φ_everywhere
staticmethod
¶
Reassign signed distance values to pixels beyond the narrow band.
Assumes that pixels beyond the narrow band have signed-distance signs that are currently correct: given these signs, each beyond-nb pixel is assigned either the min or max value of the nb signed-distance values.
Parameters¶
φ_everywhere: NDArray Beyond narrow-band signed-distance grid to be recomputed. φ: MaskedArray Narrow-band signed-distance grid.
Returns¶
NDArray Recomputed signed-distances beyond narrow band.
Source code in erosionfront/levelset/grid.py
xz_to_ij
¶
xz_to_ij(xz: NDArray | tuple) -> NDArray
Convert pixel center coords (x,z) into pixel indices [i,j].
Parameters¶
xz: NDArray | tuple Pixel (x,z) coordinate pairs as numpy array or tuple.
Returns¶
NDArray: Pixel index pairs [i,j] as int64 numpy array