Merge branch 'read_fc'
This commit is contained in:
commit
681b49a22f
@ -41,6 +41,7 @@ AppDir:
|
||||
# - zsync
|
||||
# - hicolor-icon-theme
|
||||
- libatlas3-base
|
||||
- gnuplot-nox
|
||||
- python3.9-minimal
|
||||
- python3-numpy
|
||||
- python3-scipy
|
||||
|
@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pathlib
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
# import matplotlib.pyplot as plt
|
||||
from scipy.optimize import curve_fit
|
||||
@ -9,6 +11,7 @@ import numpy as np
|
||||
from nmreval.data.points import Points
|
||||
from nmreval.io.asciireader import AsciiReader
|
||||
from nmreval.io.hdfreader import HdfReader
|
||||
from nmreval.lib.logger import logger
|
||||
from nmreval.utils.utils import get_temperature, roundrobin
|
||||
|
||||
|
||||
@ -54,7 +57,7 @@ class FCReader:
|
||||
_temp = self._read_from_dir(filename)
|
||||
|
||||
else:
|
||||
raise TypeError
|
||||
raise TypeError(f'{filename} is of unknown type')
|
||||
|
||||
if not _temp:
|
||||
raise OSError(-666, f'No magnetization found for {filename.name}.', filename.name)
|
||||
@ -178,6 +181,7 @@ class FCReader:
|
||||
fit_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if save_fig:
|
||||
data_path = fname_no_ext.joinpath('data')
|
||||
image_path = fname_no_ext.joinpath('png')
|
||||
image_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@ -218,16 +222,34 @@ class FCReader:
|
||||
np.savetxt(fit_path.joinpath(save_name), np.c_[xplot, yplot],
|
||||
header=header+'\t'.join([f'{p}+/-{err}' for p, err in zip(p0, perr)]))
|
||||
|
||||
# if save_fig:
|
||||
# fig, ax = plt.subplots()
|
||||
# ax.set_xlabel('t / s')
|
||||
# ax.set_ylabel('M')
|
||||
# axheader = f'T1: {p0[2]:.4g}(+/-{perr[2]:.4g}) beta: {p0[3]:.4g}(+/-{perr[3]:.4g})'
|
||||
# ax.set_title(f'f = {k:.4g} Hz\n{axheader}')
|
||||
# ax.semilogx(v.x, v.y, 'o')
|
||||
# ax.semilogx(xplot, yplot, '-')
|
||||
# fig.savefig(image_path.joinpath(save_name).with_suffix('.png'))
|
||||
# plt.close(fig)
|
||||
if save_fig:
|
||||
img_file = image_path.joinpath(save_name).with_suffix(".png")
|
||||
|
||||
gnuplot_args = [
|
||||
'set terminal png;',
|
||||
f'set output "{img_file}";',
|
||||
f'set title "f = {k:.4g} Hz\\n{p0[2]:.4g}(+/-{perr[2]:.4g}) beta: {p0[3]:.4g}(+/-{perr[3]:.4g})";',
|
||||
'set xlabel "t / s";',
|
||||
'set logscale x;',
|
||||
'set format x "10^{{%L}}";',
|
||||
'set ylabel "M";',
|
||||
'set key off;',
|
||||
f'plot "{data_path.joinpath(save_name)}" with points pointtype 5, "{fit_path.joinpath(save_name)}" with lines;',
|
||||
]
|
||||
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
['gnuplot', '-p'],
|
||||
shell=True,
|
||||
stdin=subprocess.PIPE,
|
||||
encoding='utf8',
|
||||
)
|
||||
for args in gnuplot_args:
|
||||
proc.stdin.write(args)
|
||||
proc.stdin.write('quit\n')
|
||||
proc.stdin.flush()
|
||||
except Exception as e:
|
||||
logger.error(f'saving image {save_name} failed', e)
|
||||
|
||||
freqs = np.asanyarray(freqs)
|
||||
params = np.asanyarray(params)
|
||||
|
Loading…
Reference in New Issue
Block a user