Package: slidepy
slidePyslidepyis a fast multi-threaded python library for performing 3D landslide simulation and modelling usingopenMP,SIMDandnumpyobjects.Github repository:https://github.com/asenogles/slidepyPyPI:https://pypi.org/project/slidepyMotivationslidepywas developed to quickly perform landslide simulations, enabling self-supervised learning for landslide analyses.slidepyprovides a cython wrapper for optimizedopenMPccode with addtionalSIMDsupport for SSE & AVX instruction sets usingIntrinsics. Data objects are handled bynumpyallowing for straightforward memory management. Currently only conservation of mass modelling has been fully implemented, however this is open to expansion in the future. All code is still in development and thus it is recommended to test fully before use.Installationslidepyhas currently been tested on Linux and Microsoft windows operating systems. You will need python>=3.6 installed. If runningslidepyon non-x86 architecture, you will need to modify the SIMD code in order to compile. It is recommended to installslidepywithin a virtual environment.Install using pipTo installslidepyfrom PyPI using pip:pip install slidepyInstall from sourceTo buildslidepyfrom source, download this repository and run:python3 setup.py build_ext --inplaceNote: You will need to have the required build dependencies installed.ExampleimporttimeitimportnumpyasnpimportfasterrasterasfrimportslidepyasspfrompathlibimportPathNTESTS=10# Load grid filesdir=Path('./test_data/')dem=fr.read(dir/'dem.bil')mask=fr.read(dir/'mask.bil')ssem=fr.read(dir/'ssem.bil')vel=fr.Flo(dir/'vel.flo')# prep velocity gridsfr.multiplyFloMask(vel.raster,mask.raster)# 0 velocity values outslide of landslide extentu,v=fr.flo_to_u_v(vel.raster)# split velocity grid into u & v components# regular python implementation of com functiondefpy_com(dem,u,v,ssem,cell_size,epochs):dem_cpy=dem.copy()dl=2.*cell_sizerows=dem_cpy.shape[0]-2cols=dem_cpy.shape[1]-2# calculate depthh=dem_cpy-ssemforiinrange(epochs):foriinrange(1,rows):forjinrange(1,cols):dem_cpy[i,j]-=((h[i,j]*(u[i,j-1]-u[i,j+1])/dl)+(u[i,j]*(h[i,j-1]-h[i,j+1])/dl))+((h[i,j]*(v[i+1,j]-v[i-1,j])/dl)+(v[i,j]*(h[i+1,j]-h[i-1,j])/dl))foriinrange(1,rows):forjinrange(1,cols):h[i,j]=dem_cpy[i,j]-ssem[i,j]returndem_cpy# regular numpy implementation of com functiondefnp_com(dem,u,v,ssem,cell_size,epochs):dem_cpy=dem.copy()# calculate depthh=dem_cpy-ssem# calculate vel gradientsdu=np.gradient(u,axis=1)/cell_sizedv=np.gradient(v,axis=1)/cell_sizeforiinrange(epochs):# calculate depth gradientdh_v,dh_u=np.gradient(h)dh_u=-1*dh_u/cell_sizedh_v=dh_v/cell_size# calculate dzdz_u=(h*du)+(u*dh_u)dz_v=(h*dv)+(v*dh_v)dz=dz_u+dz_v# update dem & depthdem_cpy=dem_cpy-dzh=dem_cpy-ssemreturndem_cpy# Time Conservation of mass simulation using regular pythontime=timeit.timeit(lambda:py_com(dem.raster,u,v,ssem.raster,dem.XDIM,1),number=1)print(f'python COM took{time:.3f}seconds')# Time Conservation of mass simulation using numpytime=timeit.timeit(lambda:np_com(dem.raster,u,v,ssem.raster,dem.XDIM,1),number=1)print(f'numpy COM took{time:.3f}seconds')# Time Conservation of mass simulation using open-MP for numt-threadsnum_threads=[1,2,4,8]fornumtinnum_threads:time=timeit.timeit(lambda:sp.com_mp(dem.raster,u,v,ssem.raster,dem.XDIM,1,numt),number=NTESTS)print(f'MP COM averaged{time/NTESTS:.3f}seconds')# Time Conservation of mass simulation using open-MP and SIMD for numt-threadsfornumtinnum_threads:time=timeit.timeit(lambda:sp.com_sse(dem.raster,u,v,ssem.raster,dem.XDIM,1,numt),number=NTESTS)print(f'SSE COM averaged{time/NTESTS:.3f}seconds')Example output:python COM took 162.632 secondsnumpy COM took 7.911 secondsMP COM averaged 0.095 secondsMP COM averaged 0.092 secondsMP COM averaged 0.091 secondsMP COM averaged 0.088 secondsSSE COM averaged 0.048 secondsSSE COM averaged 0.033 secondsSSE COM averaged 0.028 secondsSSE COM averaged 0.030 seconds