base.py¶
LevelSetSolverBase
dataclass
¶
LevelSetSolverBase(
Δ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.base.LevelSetSolverBase[LevelSetSolverBase]
erosionfront.levelset.speed.LevelSetSpeedMethods[LevelSetSpeedMethods]
erosionfront.levelset.grid.LevelSetGridMethods[LevelSetGridMethods]
erosionfront.levelset.elementary.LevelSetElementaryMethods[LevelSetElementaryMethods]
erosionfront.levelset.data.LevelSetData[LevelSetData]
erosionfront.levelset.speed.LevelSetSpeedMethods --> erosionfront.levelset.base.LevelSetSolverBase
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.base.LevelSetSolverBase href "" "erosionfront.levelset.base.LevelSetSolverBase"
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"
Solver for propagating an erosion front using a level-set scheme.
Subclasses LevelSetSpeedMethods.
Attributes¶
ρ: NDArray Rasterized surface-line grid. ρ_padded: NDArray Rasterized surface-line grid with padding. ρ_offsets: NDArray Gridded surface-normal distances. T_slices: dict Dictionary recording time T slice data of erosion front evolution. T_arrival: MaskedArray | None = None Grid of interpolated arrival times T, with mask removing pixels in air or in uneroded substrate.
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).
-
evolve–Iteratively propagate the erosion front surface.
-
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).
-
initialize–Initialize level-set solver.
-
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_T_slices–Rasterize time T slices onto grids.
-
rasterize_line–Rasterize surface line as x,z points into grid pixels using Rasterio.
-
record_T_slice–Record selected sim data for a single time step.
-
redo_φ_everywhere–Reassign signed distance values to pixels beyond the narrow band.
-
update–Update method that must be implemented by the actual solver.
-
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
evolve
¶
evolve(
Δt: float = 0,
t_span: float | None = None,
n_steps: int | None = None,
Δt_reinitialize: float | None = None,
κ_boost: float = 1,
report_pc: int = 5,
n_record_steps: int = 5,
do_initial: bool = False,
do_timing: bool = False,
) -> None
Iteratively propagate the erosion front surface.
Parameters¶
Δt: float=0
Simulation time step.
t_span: float | None = None
Duration of simulation.
n_steps: int | None = None
Number of time steps to take in the simulation.
If neither t_span nor n_steps is specified,
If neither are, a single step is assumed.
Δt_reinitialize: float | None = None
Period of reinitialization of φ signed-distance function grid.
κ_boost: float = 1
Scale factor for boosting numerical viscosity.
report_pc: int = 5
Reporting interval as percentage of runtime.
n_record_steps: int = 5
Number of steps between T slicings.
do_initial: bool=False
Specify if this is the first update, and act accordingly.
do_timing: bool=False
Choose whether to perform timings of sim stages.
Attributes
Most of the sim grids are modified.
Source code in erosionfront/levelset/base.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
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
initialize
¶
initialize(do_timing: bool = False) -> None
Initialize level-set solver.
Parameters¶
do_timing: bool=False Perform timing estimates for each computational stage.
Attributes¶
Many class attributes are modified.
Source code in erosionfront/levelset/base.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
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_T_slices
¶
rasterize_T_slices(n_subset: int = 1) -> None
Rasterize time T slices onto grids.
Parameters¶
n_subset: int=1 Rate of subsetting of T slices (n=1 means all of them).
Source code in erosionfront/levelset/base.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
record_T_slice
¶
Record selected sim data for a single time step.
Recorded data are placed in a 'T_slice' dictionary.
Parameters¶
step: int Simulation step number. t_total: float Total time in simulation so far.
Attributes¶
Data for this sim time step are appended to the time-slicing dict.
Source code in erosionfront/levelset/base.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
update
abstractmethod
¶
update(
Δt: float,
Δt_reinitialize: float | None = None,
do_finalize: bool = False,
do_timing: bool = False,
) -> None
Update method that must be implemented by the actual solver.
Parameters¶
Δt: float Time step. Δt_reinitialize: float | None=None Periodicity of reinitialization of φ signed-distance grid. do_finalize: bool=False Just finish up, don't do another loop of computation. do_timing: bool=False Measure and report compute times taken at steps during the loop.
Attributes¶
Most of the sim grids are modified.
Source code in erosionfront/levelset/base.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