split simulating and evaluating and stuff
This commit is contained in:
parent
5b5aacff0b
commit
e90c4c9543
49
angle_dependence.py
Normal file
49
angle_dependence.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import pathlib
|
||||||
|
import re
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
|
||||||
|
from python.helpers import read_parameter_file
|
||||||
|
|
||||||
|
angles = []
|
||||||
|
tau_cc = []
|
||||||
|
tau_ss = []
|
||||||
|
tau2 = []
|
||||||
|
|
||||||
|
tevo = [5e-6, 10e-6]
|
||||||
|
|
||||||
|
|
||||||
|
for fit_files in pathlib.Path('.').glob(f'IsotropicAngle/angle=*/Delta/tau=*/ste_fit_*.dat'):
|
||||||
|
folder = fit_files.parent
|
||||||
|
|
||||||
|
file_base = fit_files.stem.replace('ste_fit_', '')
|
||||||
|
parameter = read_parameter_file(folder / ('ste_' + file_base + '_parameter.txt'))
|
||||||
|
angles.append(parameter['angle'])
|
||||||
|
|
||||||
|
with fit_files.open('r') as f:
|
||||||
|
# tau of F2 is hidden in the second header line
|
||||||
|
for _ in range(2):
|
||||||
|
line = f.readline()
|
||||||
|
tau2.append(float(re.search('tau=(.+?)\s', line).group(1)))
|
||||||
|
|
||||||
|
fit_values = np.loadtxt(fit_files)
|
||||||
|
x = fit_values[:, 0]
|
||||||
|
|
||||||
|
# get indexes for given evolution times
|
||||||
|
nearest_idx = [np.searchsorted(x, tt) for tt in tevo]
|
||||||
|
tau_cc.append(fit_values[nearest_idx, 1])
|
||||||
|
tau_ss.append(fit_values[nearest_idx, 4])
|
||||||
|
|
||||||
|
|
||||||
|
plt.semilogy(angles, tau_cc, '-.')
|
||||||
|
plt.semilogy(angles, tau_ss, '--')
|
||||||
|
plt.semilogy(angles, tau2)
|
||||||
|
|
||||||
|
np.savetxt(
|
||||||
|
'tau_angles.dat',
|
||||||
|
np.c_[angles, tau_cc, tau_ss, tau2],
|
||||||
|
header=f"Angle dependence of correlation times\nfor evolution times {tevo}\nangle->tau_cc->tauss->tau2"
|
||||||
|
)
|
||||||
|
|
||||||
|
plt.show()
|
@ -1,17 +1,8 @@
|
|||||||
|
import pathlib
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from python.ste import *
|
from python.ste import *
|
||||||
from python.helpers import *
|
|
||||||
|
|
||||||
# Simulation parameter
|
|
||||||
motion = 'IsotropicAngle'
|
|
||||||
distribution = 'Delta'
|
|
||||||
# parameter = {}
|
|
||||||
parameter = {
|
|
||||||
"angle": [10],
|
|
||||||
}
|
|
||||||
|
|
||||||
parameter = prepare_rw_parameter(parameter)
|
|
||||||
|
|
||||||
fig_tau_cc, ax_tau_cc = plt.subplots()
|
fig_tau_cc, ax_tau_cc = plt.subplots()
|
||||||
ax_tau_cc.set_title('tau_cc')
|
ax_tau_cc.set_title('tau_cc')
|
||||||
@ -31,12 +22,8 @@ ax_beta_ss.set_title('beta_ss')
|
|||||||
fig_finfty_ss, ax_finfty_ss = plt.subplots()
|
fig_finfty_ss, ax_finfty_ss = plt.subplots()
|
||||||
ax_finfty_ss.set_title('f_infty_ss')
|
ax_finfty_ss.set_title('f_infty_ss')
|
||||||
|
|
||||||
for variation in parameter:
|
for conf_file in pathlib.Path('.').glob(f'IsotropicAngle/angle=*/Delta/tau=*/*_parameter.txt'):
|
||||||
print(f"\nRun RW for {motion}/{distribution} with arguments {variation}\n")
|
print(conf_file)
|
||||||
# run_sims(motion, distribution, ste=True, spectrum=False, **variation)
|
|
||||||
|
|
||||||
conf_file = find_config_file(motion, distribution, variation)
|
|
||||||
|
|
||||||
vary_string, tau_cc, beta_cc, finfty_cc = fit_ste(conf_file, f'coscos', plot_decays=False, verbose=False)
|
vary_string, tau_cc, beta_cc, finfty_cc = fit_ste(conf_file, f'coscos', plot_decays=False, verbose=False)
|
||||||
_, tau_ss, beta_ss, finfty_ss = fit_ste(conf_file, f'sinsin', plot_decays=False, verbose=False)
|
_, tau_ss, beta_ss, finfty_ss = fit_ste(conf_file, f'sinsin', plot_decays=False, verbose=False)
|
||||||
_, tau_2, beta_2, finfty_2 = fit_ste(conf_file, f'f2', plot_decays=True, verbose=True)
|
_, tau_2, beta_2, finfty_2 = fit_ste(conf_file, f'f2', plot_decays=True, verbose=True)
|
||||||
@ -50,9 +37,8 @@ for variation in parameter:
|
|||||||
ax_beta_ss.plot(*beta_ss.T, label=vary_string)
|
ax_beta_ss.plot(*beta_ss.T, label=vary_string)
|
||||||
ax_finfty_ss.plot(*finfty_ss.T, label=vary_string)
|
ax_finfty_ss.plot(*finfty_ss.T, label=vary_string)
|
||||||
|
|
||||||
|
|
||||||
np.savetxt(
|
np.savetxt(
|
||||||
f'ste_fit_{vary_string}.dat',
|
conf_file.with_name(f'ste_fit_{vary_string}.dat'),
|
||||||
np.c_[
|
np.c_[
|
||||||
tau_cc, beta_cc[:, 1], finfty_cc[:, 1],
|
tau_cc, beta_cc[:, 1], finfty_cc[:, 1],
|
||||||
tau_ss[:, 1], beta_ss[:, 1], finfty_ss[:, 1],
|
tau_ss[:, 1], beta_ss[:, 1], finfty_ss[:, 1],
|
||||||
@ -62,8 +48,6 @@ for variation in parameter:
|
|||||||
f'tevo\ttaucc\tbetacc\tfinftycc\ttauss\tbetass\tfinftyss',
|
f'tevo\ttaucc\tbetacc\tfinftycc\ttauss\tbetass\tfinftyss',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for ax in [ax_tau_cc, ax_beta_cc, ax_finfty_cc, ax_tau_ss, ax_beta_ss, ax_finfty_ss]:
|
for ax in [ax_tau_cc, ax_beta_cc, ax_finfty_cc, ax_tau_ss, ax_beta_ss, ax_finfty_ss]:
|
||||||
ax.legend()
|
ax.legend()
|
||||||
plt.show()
|
plt.show()
|
@ -54,23 +54,11 @@ def run_sims(
|
|||||||
subprocess.run(arguments)
|
subprocess.run(arguments)
|
||||||
|
|
||||||
|
|
||||||
def find_config_file(motion: str, distribution: str, var_params: dict) -> pathlib.Path:
|
def find_config_file(config_path: str | pathlib.Path, varied_params: dict[str, float]) -> dict[str, float]:
|
||||||
# TODO handle situation if multiple files fit
|
parameter = read_parameter_file(config_path)
|
||||||
p_file = None
|
parameter.update(varied_params)
|
||||||
if var_params:
|
|
||||||
var_string = '|'.join(([f'{k}={v:1.6e}' for (k, v) in var_params.items()])).replace('.', '\.').replace('+', '\+')
|
|
||||||
pattern = re.compile(var_string)
|
|
||||||
for p_file in pathlib.Path('.').glob('*_parameter.txt'):
|
|
||||||
if len(re.findall(pattern, str(p_file))) == len(var_params) and re.search(f'{motion}_{distribution}', str(p_file)):
|
|
||||||
return p_file
|
|
||||||
raise ValueError(f'No parameter file found for {motion}, {distribution}, {var_params}')
|
|
||||||
else:
|
|
||||||
for p_file in pathlib.Path('.').glob('*_parameter.txt'):
|
|
||||||
if re.search(f'{motion}_{distribution}', str(p_file)):
|
|
||||||
return p_file
|
|
||||||
raise ValueError(f'No parameter file found for {motion}, {distribution}, {var_params}')
|
|
||||||
|
|
||||||
|
|
||||||
|
return parameter
|
||||||
|
|
||||||
|
|
||||||
def read_parameter_file(path: str | pathlib.Path) -> dict[str, float]:
|
def read_parameter_file(path: str | pathlib.Path) -> dict[str, float]:
|
||||||
@ -81,8 +69,9 @@ def read_parameter_file(path: str | pathlib.Path) -> dict[str, float]:
|
|||||||
parameter_dict = {}
|
parameter_dict = {}
|
||||||
with path.open('r') as f:
|
with path.open('r') as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
|
if line.startswith('#'):
|
||||||
|
continue
|
||||||
k, v = line.split('=')
|
k, v = line.split('=')
|
||||||
parameter_dict[k] = float(v)
|
parameter_dict[k] = float(v)
|
||||||
|
|
||||||
k, v = line.split('=')
|
|
||||||
return parameter_dict
|
return parameter_dict
|
||||||
|
@ -74,7 +74,7 @@ def fit_ste(
|
|||||||
# make evolution times
|
# make evolution times
|
||||||
tevo = np.linspace(parameter['tevo_start'], parameter['tevo_stop'], num=int(parameter['tevo_steps']))
|
tevo = np.linspace(parameter['tevo_start'], parameter['tevo_stop'], num=int(parameter['tevo_steps']))
|
||||||
|
|
||||||
raw_data = np.loadtxt(f'{prefix}_{varied_string}.dat')
|
raw_data = np.loadtxt(parameter_file.with_name(f'{prefix}_{varied_string}.dat'))
|
||||||
|
|
||||||
t_mix = raw_data[:, 0]
|
t_mix = raw_data[:, 0]
|
||||||
decay = raw_data[:, 1:]
|
decay = raw_data[:, 1:]
|
||||||
|
14
start_sims.py
Normal file
14
start_sims.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from python.helpers import *
|
||||||
|
|
||||||
|
#Simulation parameter
|
||||||
|
motion = 'IsotropicAngle'
|
||||||
|
distribution = 'Delta'
|
||||||
|
parameter = {
|
||||||
|
"angle": [10, 109.47],
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter = prepare_rw_parameter(parameter)
|
||||||
|
|
||||||
|
for variation in parameter:
|
||||||
|
print(f"\nRun RW for {motion}/{distribution} with arguments {variation}\n")
|
||||||
|
run_sims(motion, distribution, ste=True, spectrum=False, **variation)
|
Loading…
Reference in New Issue
Block a user