Skip to content
Snippets Groups Projects
Commit f6fa53d5 authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

use latex table with 3 columns for input parameters

parent 8e0ac83b
No related branches found
No related tags found
1 merge request!72Feat: Change formatting of list of input parameters
......@@ -442,6 +442,62 @@ def concurrent_run(temp_path, nb, nbname, args, cparm=None, cval=None,
return jobid
def make_par_table(parms, temp_path, run_uuid):
'''
Create a table with input parameters if the notebook
:param parms: parameters of the notebook
:param temp_path: path to temporary directory for job outputs
:param run_uuid: inset of folder name containing job output
'''
def split_len(seq, length):
l = [seq[i:i+length] for i in range(0, len(seq), length)]
return ' '.join(l)
# prepare strings and estimate their length
l_parms = []
len_parms = [0, 0]
max_len = [30, 30]
for p in parms:
name = p.name.replace('_', '-')
if len(name)>max_len[0]:
len_parms[0] = max_len[0]
name = split_len(name, max_len[0])
value = str(p.value)
if len(value)>max_len[1]:
len_parms[1] = max_len[1]
value = split_len(value, max_len[1])
if p.type is str:
value = "``{}''".format(value)
value = value.replace('_', '\\_')
comment = str(p.comment)[1:].replace('_', '\\_')
l_parms.append([name, value, comment ])
with open("{}/slurm_tmp_{}/InputParameters.rst".format(temp_path, run_uuid), "w") as finfile:
finfile.write("Input of the calibration pipeline \n")
finfile.write("================================= \n\n")
finfile.write(".. math::\n")
col_type = ['l', 'c', 'p{.3\\textwidth}']
# fix column width is needed
if len_parms[0]==max_len[0]:
col_type[0] = 'p{.3\\textwidth}'
if len_parms[1]==max_len[1]:
col_type[1] = 'p{.3\\textwidth}'
finfile.write(" \\begin{{tabular}}{{ {} {} {} }}\n".format(*col_type))
finfile.write(" \\hline\n")
for p in l_parms:
tmpl = " \\textbf{{-{{}}-{} }} & {} & {}\\\\\n"
finfile.write(tmpl.format(*p))
finfile.write(" \\hline\n")
finfile.write(" \\end{tabular}\n")
def run():
""" Run a calibration task with parser arguments """
......@@ -527,25 +583,7 @@ def run():
# Write all input parameters to rst file to be included to final report
parms = parameter_values(parms, **args)
with open("{}/slurm_tmp_{}/InputParameters.rst".format(temp_path, run_uuid), "w") as finfile:
finfile.write("Input of the calibration pipeline \n")
finfile.write("================================= \n\n")
finfile.write(".. math::\n")
finfile.write(" \\begin{tabular}{ll}\n")
finfile.write(" \\hline\n")
for p in parms:
#finfile.write("{} \n\n".format(p.comment))
#finfile.write(".. parsed-literal::\n")
if p.type is str:
tmpl = " \\textbf{{-{{}}-{} }} & ``{}'', {}\\\\\n"
else:
tmpl = " \\textbf{{-{{}}-{} }} & {}, {}\\\\\n"
finfile.write(tmpl.format(p.name.replace('_', '-'),
str(p.value).replace('_', '\\_'),
str(p.comment)[1:].replace('_', '\\_')))
finfile.write(" \\hline\n")
finfile.write(" \\end{tabular}\n")
make_par_table(parms, temp_path, run_uuid)
# wait on all jobs to run and then finalize the run by creating a report from the notebooks
out_path = "{}/{}/{}/{}".format(report_path, detector.upper(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment