Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Created September 5, 2023 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesBuchner/cda64a762dcbb663853b0799eae7f8d1 to your computer and use it in GitHub Desktop.
Save JohannesBuchner/cda64a762dcbb663853b0799eae7f8d1 to your computer and use it in GitHub Desktop.
Smoothly bending power law function of Ryde+98. The width of the bend can be controlled.
def sbpl(x, norm, lam1, lam2, x0, xbrk, Lambda):
"""Smoothly bending powerlaw
Parameterization from Ryde99
https://ui.adsabs.harvard.edu/abs/1999ApL%26C..39..281R/abstract
Parameters
----------
x: array of independent variable
xmax: only consider x values up to this value
norm: normalisation at x0
lam1: powerlaw slope below xbrk
lam2: powerlaw slope above xbrk
xbrk: x value where powerlaw break occurs
Lambda: width of bend at xbrk
"""
with np.errstate(over='ignore'):
q = log(x/xbrk) / Lambda
qpiv = log(x0/xbrk) / Lambda
return norm * (x/x0)**((lam1 + lam2 + 2)/2.) * \
((exp(q) + exp(-q))/(exp(qpiv) + exp(-qpiv))) ** ((lam2 - lam1)/2. * Lambda) * (x0 / x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment