"""Read bathymetry.This module contains *Landlab* components to read bathymetry into a`SequenceModelGrid`."""from__future__importannotationsfromosimportPathLikeimportnumpyasnpfromlandlabimportComponentfromnumpy.typingimportNDArrayfromscipyimportinterpolatefromsequence.gridimportSequenceModelGrid
[docs]classBathymetryReader(Component):"""Landlab component that reads bathymetry from a file."""_name="Bathymetry"_unit_agnostic=True_info={"topographic__elevation":{"dtype":"float","intent":"out","optional":False,"units":"m","mapping":"node","doc":"Surface elevation",}}
[docs]def__init__(self,grid:SequenceModelGrid,filepath:str|PathLike[str],kind:str="linear",):"""Generate a bathymetric profile from a file. Parameters ---------- grid: SequenceModelGrid A landlab grid. filepath: str Name of csv-formatted bathymetry file. kind: str, optional Kind of interpolation as a string (one of 'linear', 'nearest', 'zero', 'slinear', 'quadratic', 'cubic'). Default is 'linear'. """super().__init__(grid)data=np.loadtxt(filepath,delimiter=",",comments="#")self._bathymetry=interpolate.interp1d(data[:,0],data[:,1],kind=kind,copy=True,assume_sorted=True,bounds_error=True,)if"topographic__elevation"notinself.grid.at_node:self.grid.add_zeros("topographic__elevation",at="node")
@propertydefx(self)->NDArray[np.floating]:"""Return the x-coordinates of the grid."""returnself.grid.x_of_node[self.grid.nodes_at_bottom_edge]@propertydefz(self)->NDArray[np.floating]:"""Return the elevations along the grid."""returnself.grid.at_node["topographic__elevation"][self.grid.nodes_at_bottom_edge]
[docs]defrun_one_step(self,dt:float|None=None)->None:"""Update the grid's bathymetry. Parameters ---------- dt : float, optional Time step to update the component by. Currently this value is unused. """z=self.grid.at_node["topographic__elevation"].reshape(self.grid.shape)z[:]=self._bathymetry(self.grid.x_of_node[self.grid.nodes_at_bottom_edge])
def_create_initial_profile(x:NDArray[np.floating],sl_plain:float=0.0008,init_shore:float=19750.0,hgt:float=15.0,alpha:float=1/2000.0,sl_sh:float=0.001,wavebase:float=60.0,)->NDArray[np.floating]:# check shoreline is in array, else put in center of arrayifx[-1]<init_shore:init_shore=(x[0]+x[-1])/2z=np.empty_like(x)land=x<init_shorez[land]=(init_shore-x[land])*sl_plainz[~land]=(init_shore-x[~land])*sl_sh-hgt*(1-np.exp((init_shore-x[~land])*alpha))returnz