Python
Python
spectropath is an R package. If your analysis stack is in Python, the cleanest option is usually to call it through Rscript and read the result back into Python.
Through subprocess
import subprocess
code = r'''
library(spectropath)
u <- seq(-5, 5, length.out = 500)
f <- dnorm(u, 0, 1) + 0.25 * dnorm(u, 1.8, 0.45)
path <- cbind(u, f)
print(path_features(path))
'''
subprocess.run(["Rscript", "-e", code], check=True)Through rpy2
If you already use rpy2, you can call the same functions directly from a Python session.
import numpy as np
from rpy2 import robjects
robjects.r("library(spectropath)")
robjects.r("""
u <- seq(-5, 5, length.out = 500)
f <- dnorm(u, 0, 1) + 0.25 * dnorm(u, 1.8, 0.45)
path <- cbind(u, f)
print(path_features(path))
""")A small notebook version is included here: