forked from IPKM/nmreval
restore optionality to figure saving
This commit is contained in:
parent
6e9dd4d45f
commit
3dcd44c3ee
@ -213,7 +213,7 @@ class FCReader:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
self.f_params[k] = [new_entry]
|
self.f_params[k] = [new_entry]
|
||||||
|
|
||||||
if True: # save_fits or save_fig:
|
if save_fits or save_fig:
|
||||||
xplot = np.geomspace(v.x[0], v.x[-1], num=10*len(v.x))
|
xplot = np.geomspace(v.x[0], v.x[-1], num=10*len(v.x))
|
||||||
yplot = FCReader.kww(xplot, *p0)
|
yplot = FCReader.kww(xplot, *p0)
|
||||||
save_name = f'{filename.stem}_{k:011.2f}'.replace('.', 'p') + '.dat'
|
save_name = f'{filename.stem}_{k:011.2f}'.replace('.', 'p') + '.dat'
|
||||||
@ -222,33 +222,34 @@ class FCReader:
|
|||||||
np.savetxt(fit_path.joinpath(save_name), np.c_[xplot, yplot],
|
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)]))
|
header=header+'\t'.join([f'{p}+/-{err}' for p, err in zip(p0, perr)]))
|
||||||
|
|
||||||
img_file = image_path.joinpath(save_name).with_suffix(".png")
|
if save_fig:
|
||||||
|
img_file = image_path.joinpath(save_name).with_suffix(".png")
|
||||||
|
|
||||||
gnuplot_args = [
|
gnuplot_args = [
|
||||||
'set terminal png;',
|
'set terminal png;',
|
||||||
f'set output "{img_file}";',
|
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})";',
|
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 xlabel "t / s";',
|
||||||
'set logscale x;',
|
'set logscale x;',
|
||||||
'set format x "10^{{%L}}";',
|
'set format x "10^{{%L}}";',
|
||||||
'set ylabel "M";',
|
'set ylabel "M";',
|
||||||
'set key off;',
|
'set key off;',
|
||||||
f'plot "{data_path.joinpath(save_name)}" with points pointtype 5, "{fit_path.joinpath(save_name)}" with lines;',
|
f'plot "{data_path.joinpath(save_name)}" with points pointtype 5, "{fit_path.joinpath(save_name)}" with lines;',
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
['gnuplot', '-p'],
|
['gnuplot', '-p'],
|
||||||
shell=True,
|
shell=True,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
encoding='utf8',
|
encoding='utf8',
|
||||||
)
|
)
|
||||||
for args in gnuplot_args:
|
for args in gnuplot_args:
|
||||||
proc.stdin.write(args)
|
proc.stdin.write(args)
|
||||||
proc.stdin.write('quit\n')
|
proc.stdin.write('quit\n')
|
||||||
proc.stdin.flush()
|
proc.stdin.flush()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'saving image {save_name} failed', e)
|
logger.error(f'saving image {save_name} failed', e)
|
||||||
|
|
||||||
freqs = np.asanyarray(freqs)
|
freqs = np.asanyarray(freqs)
|
||||||
params = np.asanyarray(params)
|
params = np.asanyarray(params)
|
||||||
|
Loading…
Reference in New Issue
Block a user