# file to evaluate a measurement import os.path, glob from os.path import join import json import pandas as pd from scipy.ndimage import gaussian_filter1d from scipy.optimize import minimize, curve_fit import scipy.constants as c import numpy as np import matplotlib.pyplot as pl from helper import * from style import * path_data_repo = "../data_supplementary" meas = { "path": "current_phase_relation.csv", "save_path": "Projects/Shapiro/Shapiro_steps/current_phase_relation" } # open data data = pd.read_csv(join(path_data_repo, meas["path"])) current = data["current"].to_numpy() phase = data['phase'].to_numpy() phase_err = data["phase_err"].to_numpy() phi_0 = np.mean(phase[0:5]) phase = phase - phi_0 p0 = [0.8, 0.01] # function for the minimization fitting phi_fit = np.arange(0, np.pi/2, 0.001) def func_mini(x): f = x[0]* np.sin(phase * np.pi) + x[1] * np.sin(2 * phase * np.pi) f_phi = x[0]* np.sin(phi_fit) + x[1] * np.sin(2 * phi_fit) return np.sum(current - f)**2 + 1e2 * (1-np.max(f_phi))**2 res = minimize(func_mini, p0, method='Nelder-Mead', tol=1e-8) print(res.x) def current_theo(phi): return np.sin(phi * np.pi) def func(phi, a, b): return ( a* np.sin(phi * np.pi) + b * np.sin(2 * phi * np.pi)) phi_fit = np.arange(0, 0.65, 0.001) print(np.max(func(phi_fit, *res.x))) fig = pl.figure(figsize=(3.5 * 1.61, 3.5)) pl.errorbar(func(phi_fit, *res.x), phi_fit, label='Fit', color=RPTU_COLORS["himbeere"],zorder = 2,alpha = 0.8) pl.errorbar(current_theo(phi_fit), phi_fit, label=fr'$\sin(\varphi)$', color=RPTU_COLORS["mango"],zorder = 2,alpha = 0.95) pl.errorbar(current, phase, yerr=phase_err, **get_style(RPTU_COLORS["nacht"]),zorder = 1) pl.ylabel(r"Phase $\varphi [\pi]$") pl.xlabel(r"Current $I/I_\mathrm{c}$") pl.legend() pl.tight_layout() #pl.savefig(("current_phase_relation.pdf"),dpi=300) pl.show()