Commit 9b3ab44c authored by Médéric Boquien's avatar Médéric Boquien

Use f-strings in pcigale-plots rather than regular string as their are easier to read.

parent f6dbdafa
......@@ -69,7 +69,7 @@ def _chi2_worker(obj_name, var_name, format, outdir):
ax = figure.add_subplot(111)
var_name = var_name.replace('/', '_')
fnames = glob.glob("{}/{}_{}_chi2-block-*.npy".format(outdir, obj_name, var_name))
fnames = glob.glob(f"{outdir}/{obj_name}_{var_name}_chi2-block-*.npy")
for fname in fnames:
data = np.memmap(fname, dtype=np.float64)
data = np.memmap(fname, dtype=np.float64, shape=(2, data.size // 2))
......@@ -78,7 +78,7 @@ def _chi2_worker(obj_name, var_name, format, outdir):
ax.set_ylabel("Reduced $\chi^2$")
ax.set_ylim(0., )
ax.minorticks_on()
figure.suptitle("Reduced $\chi^2$ distribution of {} for {}."
.format(var_name, obj_name))
figure.savefig("{}/{}_{}_chi2.{}".format(outdir, obj_name, var_name, format))
figure.suptitle(f"Reduced $\chi^2$ distribution of {var_name} for "
f"{obj_name}.")
figure.savefig(f"{outdir}/{obj_name}_{var_name}_chi2.{format}")
plt.close(figure)
......@@ -46,13 +46,13 @@ def mock(config, nologo, outdir):
try:
exact = Table.read(best_results_file)
except FileNotFoundError:
print("Best models file {} not found.".format(best_results_file))
print(f"Best models file {best_results_file} not found.")
sys.exit(1)
try:
estimated = Table.read(mock_results_file)
except FileNotFoundError:
print("Mock models file {} not found.".format(mock_results_file))
print(f"Mock models file {mock_results_file} not found.")
sys.exit(1)
params = config.configuration['analysis_params']['variables']
......@@ -109,7 +109,7 @@ def _mock_worker(exact, estimated, param, logo, outdir):
linestyle='None', capsize=0.)
plt.plot(range_exact, range_exact, color='r', label='1-to-1')
plt.plot(range_exact, slope * range_exact + intercept, color='b',
label='exact-fit $r^2$ = {:.2f}'.format(r_value**2))
label=f'exact-fit $r^2$ = {r_value**2:.2f}')
plt.xlabel('Exact')
plt.ylabel('Estimated')
plt.title(param)
......@@ -120,6 +120,6 @@ def _mock_worker(exact, estimated, param, logo, outdir):
plt.figimage(logo, 510, 55, origin='upper', zorder=10, alpha=1)
plt.tight_layout()
plt.savefig('{}/mock_{}.pdf'.format(outdir, param))
plt.savefig(f'{outdir}/mock_{param}.pdf')
plt.close()
......@@ -65,12 +65,11 @@ def _pdf_worker(obj_name, var_name, format, outdir):
gbl_counter.inc()
var_name = var_name.replace('/', '_')
if var_name.endswith('_log'):
fnames = glob.glob("{}/{}_{}_chi2-block-*.npy".format(outdir, obj_name,
var_name[:-4]))
fnames = glob.glob(f"{outdir}/{obj_name}_{var_name[:-4]}_chi2-block-"
f"*.npy")
log = True
else:
fnames = glob.glob("{}/{}_{}_chi2-block-*.npy".format(outdir, obj_name,
var_name))
fnames = glob.glob(f"{outdir}/{obj_name}_{var_name}_chi2-block-*.npy")
log = False
likelihood = []
model_variable = []
......@@ -111,7 +110,7 @@ def _pdf_worker(obj_name, var_name, format, outdir):
ax.set_xlabel(var_name)
ax.set_ylabel("Probability density")
ax.minorticks_on()
figure.suptitle("Probability distribution function of {} for {}"
.format(var_name, obj_name))
figure.savefig("{}/{}_{}_pdf.{}".format(outdir, obj_name, var_name, format))
figure.suptitle(f"Probability distribution function of {var_name} for "
f"{obj_name}")
figure.savefig(f"{outdir}/{obj_name}_{var_name}_pdf.{format}")
plt.close(figure)
......@@ -114,7 +114,7 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series,
"""
gbl_counter.inc()
id_best_model_file = path.join(outdir, '{}_best_model.fits'.format(obs['id']))
id_best_model_file = path.join(outdir, f"{obs['id']}_best_model.fits")
if path.isfile(id_best_model_file):
sed = Table.read(id_best_model_file)
......@@ -330,10 +330,8 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series,
ax2.legend(fontsize=6, loc='best', frameon=False)
plt.setp(ax1.get_xticklabels(), visible=False)
plt.setp(ax1.get_yticklabels()[1], visible=False)
figure.suptitle(r"Best model for {} at z = {}. Reduced $\chi^2$={}".
format(obs['id'], np.round(z, decimals=3),
np.round(mod['best.reduced_chi_square'],
decimals=2)))
figure.suptitle(f"Best model for {obs['id']} at z = {z:.3}. "
f"Reduced χ²={mod['best.reduced_chi_square']:.2}")
if logo is not False:
# Multiplying the dpi by 2 is a hack so the figure is small
# and not too pixelated
......@@ -341,10 +339,11 @@ def _sed_worker(obs, mod, filters, sed_type, logo, xrange, yrange, series,
figure.figimage(logo, figwidth-logo.shape[0], 0,
origin='upper', zorder=0, alpha=1)
figure.savefig(path.join(outdir, '{}_best_model.{}'.format(obs['id'], format)),
figure.savefig(path.join(outdir,
f"{obs['id']}_best_model.{format}"),
dpi=figure.dpi * 2.)
plt.close(figure)
else:
print("No valid best SED found for {}. No plot created.".format(obs['id']))
print(f"No valid best SED found for {obs['id']}. No plot created.")
else:
print("No SED found for {}. No plot created.".format(obs['id']))
print(f"No SED found for {obs['id']}. No plot created.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment