1
0
forked from IPKM/nmreval

Remove matplotlib dependence to fix T234

This commit is contained in:
Dominik Demuth 2022-11-25 20:05:52 +01:00
parent 551a06cb4b
commit d91371406a
2 changed files with 66 additions and 66 deletions

View File

@ -41,8 +41,8 @@ AppDir:
- python3.9-minimal
- python3-pyqt5
- python3-numpy
- python3-matplotlib
- python-matplotlib-data
# - python3-matplotlib
# - python-matplotlib-data
- python3-scipy
- python3-bsddb3
- python3-h5py

View File

@ -2,7 +2,7 @@ from __future__ import annotations
import pathlib
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np
@ -148,9 +148,9 @@ class FCReader:
fit_path = fname_no_ext.joinpath('fit')
fit_path.mkdir(parents=True, exist_ok=True)
if save_fig:
image_path = fname_no_ext.joinpath('png')
image_path.mkdir(parents=True, exist_ok=True)
# if save_fig:
# image_path = fname_no_ext.joinpath('png')
# image_path.mkdir(parents=True, exist_ok=True)
header = 'm0\tt1\tbeta\toff\n'
@ -189,16 +189,16 @@ 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:
# 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)
freqs = np.asanyarray(freqs)
params = np.asanyarray(params)
@ -282,53 +282,53 @@ class FCReader:
fig_beta.savefig(path.joinpath(f'beta_{kind}.png'), bbox_inches="tight")
fig_mag.savefig(path.joinpath(f'mag_{kind}.png'), bbox_inches="tight")
fig_t1.savefig(path.joinpath(f't1_{kind}.png'), bbox_inches="tight")
plt.close(fig_mag)
plt.close(fig_beta)
plt.close(fig_t1)
# plt.close(fig_mag)
# plt.close(fig_beta)
# plt.close(fig_t1)
def plot_parameter(self, path, kind):
path = pathlib.Path(path)
path.mkdir(parents=True, exist_ok=True)
fig_mag, ax_mag = plt.subplots()
fig_t1, ax_t1 = plt.subplots()
fig_beta, ax_beta = plt.subplots()
if kind == 'temp':
_params = self.t_params
else:
_params = self.f_params
save_path = path.joinpath(kind)
if not save_path.exists():
save_path.mkdir(parents=True)
for key, par in _params.items():
pl, = ax_mag.plot(par[:, 0], par[:, 1], 'o', label=key)
ax_mag.plot(par[:, 0], par[:, 3], 's', color=pl.get_color())
ax_t1.plot(par[:, 0], par[:, 5], 'o', label=key)
ax_beta.plot(par[:, 0], par[:, 7], 'o', label=key)
for a in [ax_mag, ax_t1, ax_beta]:
if kind == 'freq':
a.legend(loc='upper left', bbox_to_anchor=(1, 1), ncol=2)
a.set_xlabel('T / K')
else:
a.set_xscale('log')
a.legend(loc='upper left', bbox_to_anchor=(1, 1))
a.set_xlabel('f / Hz')
ax_t1.set_yscale('log')
ax_t1.set_ylabel('T1 / s')
ax_beta.set_ylabel('beta')
ax_mag.set_ylabel('M0 (squares), Offset (circles)')
fig_beta.savefig(path.joinpath(f'beta_{kind}.png'), bbox_inches="tight")
fig_mag.savefig(path.joinpath(f'mag_{kind}.png'), bbox_inches="tight")
fig_t1.savefig(path.joinpath(f't1_{kind}.png'), bbox_inches="tight")
plt.close(fig_mag)
plt.close(fig_beta)
plt.close(fig_t1)
# fig_mag, ax_mag = plt.subplots()
# fig_t1, ax_t1 = plt.subplots()
# fig_beta, ax_beta = plt.subplots()
#
# if kind == 'temp':
# _params = self.t_params
# else:
# _params = self.f_params
#
# save_path = path.joinpath(kind)
# if not save_path.exists():
# save_path.mkdir(parents=True)
#
# for key, par in _params.items():
# pl, = ax_mag.plot(par[:, 0], par[:, 1], 'o', label=key)
# ax_mag.plot(par[:, 0], par[:, 3], 's', color=pl.get_color())
# ax_t1.plot(par[:, 0], par[:, 5], 'o', label=key)
# ax_beta.plot(par[:, 0], par[:, 7], 'o', label=key)
#
# for a in [ax_mag, ax_t1, ax_beta]:
# if kind == 'freq':
# a.legend(loc='upper left', bbox_to_anchor=(1, 1), ncol=2)
# a.set_xlabel('T / K')
# else:
# a.set_xscale('log')
# a.legend(loc='upper left', bbox_to_anchor=(1, 1))
# a.set_xlabel('f / Hz')
#
# ax_t1.set_yscale('log')
# ax_t1.set_ylabel('T1 / s')
# ax_beta.set_ylabel('beta')
# ax_mag.set_ylabel('M0 (squares), Offset (circles)')
#
# fig_beta.savefig(path.joinpath(f'beta_{kind}.png'), bbox_inches="tight")
# fig_mag.savefig(path.joinpath(f'mag_{kind}.png'), bbox_inches="tight")
# fig_t1.savefig(path.joinpath(f't1_{kind}.png'), bbox_inches="tight")
# plt.close(fig_mag)
# plt.close(fig_beta)
# plt.close(fig_t1)
def get_parameter(self, parameter='all', kind='freq', path=None, write=True, plot=True):
param_list = []
@ -359,10 +359,10 @@ class FCReader:
_params = self.f_params
fmt = '011.2f'
if plot:
fig_mag, ax_mag = plt.subplots()
fig_t1, ax_t1 = plt.subplots()
fig_beta, ax_beta = plt.subplots()
# if plot:
# fig_mag, ax_mag = plt.subplots()
# fig_t1, ax_t1 = plt.subplots()
# fig_beta, ax_beta = plt.subplots()
ret_val = []
for key, par in _params.items():
@ -374,15 +374,15 @@ class FCReader:
if write:
self._write_parameter(key, par, path, kind, fmt)
if plot:
self._plot_parameter(key, par, fig_mag, fig_t1, fig_beta)
# if plot:
# self._plot_parameter(key, par, fig_mag, fig_t1, fig_beta)
for i, name in param_list:
ret_val.append(Points(x=par[:, 0], y=par[:, 2*i+1], y_err=par[:, 2*i+2],
name=f'{key} ({name})', value=value))
if plot:
self._save_parameter_plot(path, kind, fig_mag, fig_t1, fig_beta)
# if plot:
# self._save_parameter_plot(path, kind, fig_mag, fig_t1, fig_beta)
return ret_val