Code Monkey home page Code Monkey logo

disbatomo's Introduction

DisbaTomo

Inversion of multimode dispersion curves of surface wave

The forwarding program is from disba, which is a computationally efficient Python library for the modeling of surface wave dispersion that implements a subset of codes from Computer Programs in Seismology (CPS) in Python compiled just-in-time with numba.

The optimization part is based on python pacakge scipy.optimize, where the gradient is implemented in C++[1], and converted into the library that can be imported by python with the help of pybind11.

Installation

There are two circumstances: with sudo permission and without sudo permission. The prior is typically for PC, and the latter is usually for clusters.

With sudo permission

  1. Install git, eigen3 and cmake through the package manager according to the system, e.g. apt-get, homebrew, pacman.

  2. Make sure your c++ compiler support c++14

  3. Install python packages

    1. Install miniconda
      > wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py38_4.9.2-Linux-x86_64.sh
      > bash ./Miniconda3-py38_4.9.2-Linux-x86_64.sh
      > source .bashrc
    2. Create environment
      > conda create -n disba python=3.8
      > conda activate disba
      > conda install numpy scipy matplotlib pyyaml mpi4py pandas
      > pip install disba mpi_master_slave

Without sudo permission

We use spack to install required softwares and libraries, which is a package manager for supercomputers, Linux, and macOS.

  1. Install spack

    > git clone https://github.com/spack/spack.git
    > echo ". spack/share/spack/setup-env.sh" >> .bashrc
    > source ~/.bashrc
  2. Install gcc of higher version

    > spack info gcc
    > spack install ${A_VERSION_OF_GCC}
    > spack location -i gcc
    # spack compiler find ${LOCATION_OF_GCC_NEW_VERSION}    
    > spack compiler find $(spack location -i gcc)

    ${A_VERSION_OF_GCC} is a version of gcc which you can choose from the list that "spack info gcc" shows, e.g. [email protected].

    ${LOCATION_OF_GCC_NEW_VERSION} is seen from "spack location -i gcc", e.g. /home/test/spack/opt/spack/linux-centos7-haswell/gcc-4.8.5/gcc-9.3.0-swta24mlro2t4z7rfka55y3aum2ckm32

  3. Install eigen3, git and cmake

    > spack install eigen
    > spack install cmake
    > spack install git
  4. Manage and load package using lmod

    > spack install lmod
    > echo ". $(spack location -i lmod)/lmod/lmod/init/bash" >> .bashrc
    > source .bashrc
    > module avail
  5. Load package and software

    > module load ${MODULE_NAME}

    ${MODULE_NAME} can be found from "module avail", and we need to load gcc, cmake, git and eigen3. when I installed, the command was below:

    > module load gcc-9.3.0-gcc-4.8.5-swta24m
    > module load cmake-3.18.4-gcc-9.3.0-nesdphq
    > module load git-2.29.0-gcc-9.3.0-y4b63yo
    > module load eigen-3.3.8-gcc-9.3.0-txefvoy

    You can add these module load command to your .bashrc.

  6. Install python package (the same procedure as above)

  7. Install problems

    1. tar (child): lbzip2: cannot exec: no such file or directory

    Solution:

    > spack install bzip2
    > export PATH=$(spack location -i bzip2):$PATH
    1. Error: COmmandNotFoundError: spack requires 'patch'

    Solutiin:

    > spack install patch
    > export PATH=$(spack location -i patch):$PATH

Compilation

After installing requirements, the program is installed in the following.

> git clone https://github.com/pan3rock/DisbaTomo.git
> cd DisbaTomo
> git submodule init
> git submodule update
> cd build
> cmake ..
> make -j4

Usage

Determine L-curve

> cd .. # in {DisbaTomo/}
> mkdir examples
> cp -r demo/* examples/
> cd examples/regular-large
> mpirun -np 4 ../../python/determine_lcurve.py
> ../../python/plot_lcurve.py 0

Inversion

> mpirun -np 4 ../../python/inversion.py --num_init 20
> ../../python/plot_inversion.py --data 0 --plot_model --plot_init
> ../../python/plot_inversion.py --data 0 --plot_model
> ../../python/plot_inversion.py --data 0 --plot_disp

Plot sensitivity kernel

The sensitivity is defined in [1].

> ../../python/forward.py --data data/0.txt
> ../../python/plot_disp.py disp.txt
> ../../python/plot_kernel.py model_output.txt --disp disp.txt --fmin 0.01 --fmax 0.4 --cmin 2.8 --cmax 4.5 --plot_dispersion --vmax 0.35 --mode 0 --out k0.png
> ../../python/plot_kernel.py model_output.txt --disp disp.txt --fmin 0.01 --fmax 0.4 --cmin 2.8 --cmax 4.5 --plot_dispersion --vmax 0.35 --mode 1 --out k1.png
> ../../python/plot_kernel.py model_output.txt --disp disp.txt --fmin 0.01 --fmax 0.4 --cmin 2.8 --cmax 4.5 --plot_dispersion --vmax 0.35 --mode 2 --out k2.png
> ../../python/plot_kernel.py model_output.txt --disp disp.txt --fmin 0.01 --fmax 0.4 --cmin 2.8 --cmax 4.5 --plot_dispersion --vmax 0.35 --mode 3 --out k3.png

Compute and display dispersion curves

> ../../python/forward.py -c config_forward2.yml --mode 3
> ../../python/plot_model.py model_data.txt --out model_data.png
> ../../python/plot_disp.py disp.txt --out disp_data.png

Configure file

TODO: translate into English

Brocher and Gardner empirical relation have been provided, and you can add other formula in python/empirical_relation.py.

References

[1] Pan, L., Chen, X., Wang, J., Yang, Z., & Zhang, D. (2019). Sensitivity analysis of dispersion curves of Rayleigh waves with fundamental and higher modes. Geophysical Journal International, 216(2), 1276โ€“1303. https://doi.org/10.1093/gji/ggy479

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.