This commit is contained in:
gobbo_a
2025-01-14 16:18:27 +01:00
parent 8beeb7dbc7
commit 7a0da7c48c
80 changed files with 1698 additions and 590 deletions

18
script/CPython/hfitoff.py Executable file → Normal file
View File

@@ -1,25 +1,21 @@
import numpy as np
from scipy.optimize import leastsq
def hfitoff(data, xdeg):
"""
Harmonic fit with offset
"""
start, end = min(xdeg), max(xdeg)
guess_amplitude = 2 ** 0.5 * np.std(data)
guess_amplitude = 4 * np.std(data)
guess_phase = 0
guess_offset = np.mean(data)
xrad = xdeg / 180 * np.pi
optimize_func = lambda x: x[0] * np.sin(xrad + x[1]) + x[2] - data
optimize_func = lambda x: x[0] * np.sin((xdeg + x[1]) * np.pi / 180) + x[2] - data
fit_amplitude, fit_phase, fit_offset = leastsq(optimize_func, [guess_amplitude, guess_phase, guess_offset])[0]
if fit_amplitude < 0:
fit_amplitude = -fit_amplitude
fit_phase = fit_phase - np.pi
fit_phase = fit_phase + 180
fit_xdeg = np.linspace(start, end, 100)
fit_data = fit_amplitude * np.sin(fit_xdeg / 180 * np.pi + fit_phase) + fit_offset
fit_phase_deg = fit_phase / np.pi * 180
ph_crest = 90 - fit_phase_deg
if ph_crest > 180:
ph_crest = ph_crest - 360
return (fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_xdeg, fit_data)
fit_data = fit_amplitude * np.sin((fit_xdeg + fit_phase) * np.pi / 180) + fit_offset
ph_crest = 90 - fit_phase
ph_crest = ph_crest % 360
return (fit_amplitude, fit_phase, fit_offset, ph_crest, fit_xdeg, fit_data)

View File

@@ -16,6 +16,8 @@ def linfit(x, y):
ret = call_jep("CPython/linfit", "linfit", [to_npa(x),to_npa(y)])
return (ret[0].data, ret[1].data, ret[2].data, ret[3])
def python_version():
return eval_jep("import sys; sys.version")