Skip to content

Instantly share code, notes, and snippets.

@SHDShim
Last active January 13, 2024 21:55
Show Gist options
  • Save SHDShim/f55462a5f21c42aad343ee75149bfa30 to your computer and use it in GitHub Desktop.
Save SHDShim/f55462a5f21c42aad343ee75149bfa30 to your computer and use it in GitHub Desktop.
PREM depth-pressure conversion

Python code to convert depth to pressure in PREM

from scipy.interpolate import UnivariateSpline

# from depth to pressure
tck = (np.asarray([ 660.,  660.,  660.,  660., 2900., 2900., 2900., 2900.]), 
       np.asarray([ 23.3585891 ,  56.70896396,  91.92747561, 136.58456648,
         0.        ,   0.        ,   0.        ,   0.        ]), 3)
d2p = UnivariateSpline._from_tck(tck)

# from pressure to depth
tck = (np.asarray([ 23.43242857,  23.43242857,  23.43242857,  23.43242857, 
                   82.06069689, 136.70084875, 136.70084875, 136.70084875, 136.70084875]), 
       np.asarray([ 660.93580208, 1103.14147695, 1905.82480619, 2601.16357254, 
                   2901.12743122,    0.        ,    0.        ,    0.        , 661.23099218]), 3)

p2d = UnivariateSpline._from_tck(tck)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment