Different way to define a skewed distribution with a constant value after the peak

18 Views Asked by At

I would like to be able to define a function for the vertical (z) based on the following constants

  1. L1: height of the transition layer (ramping to the maximum value)
  2. A: amplitude (maximum value)
  3. c: center of the peak
  4. L2: height of the transition layer below
  5. B: maximum level background value below the peak

I have some very simple code I am using to test that using two tanhs, but it doesn`t seem very accurate. I think that I am summing or subtracting wrong constants here. And I am not including the background value below the peak. Any suggestions? I know this is a very simple problem (way simpler than those posted here) that I could crack if I just think a little bit more. But just wanted to share with you looking for the best solution to that. I was trying to avoid piecewise funtions.

enter image description here

The way I am doing right now

import numpy as np
import matplotlib.pyplot as plt

z = np.arange(-500,0+1)

L1 = 20 # height of the transition layer
L2 = 100 # height of the pycnocline below transition layer
c = -200 # center of thermocline
A = 1e-5 # amplitude

fig,ax = plt.subplots(1, 2)
fig.subplots_adjust(wspace=0.4)

f1 = 0.5*(np.tanh(-2*(z-c-2*L1)/(L1/2))+1)
f2 = 0.5*(np.tanh(2*(z-c+L2/2)/(L2/2))+1)

ax[0].plot(A*f1, z)
ax[0].plot(A*f2, z)

ax[1].plot(A*f1*f2, z, color="red")

ax[0].axhline(c+2*L1, linestyle="--", color="0.3")
ax[0].axhline(c, linestyle="--", color="0.3")
ax[0].axhline(c-L2, linestyle="--", color="0.3")

ax[0].set(title="N2 tanh functions", ylabel="z [m]")
ax[1].set(title="N2 total")

enter image description here