Skip to content

Commit

Permalink
Fix links from tract table page
Browse files Browse the repository at this point in the history
  • Loading branch information
sr525 committed Oct 31, 2024
1 parent 39ff8e4 commit a9ff556
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 30 deletions.
71 changes: 49 additions & 22 deletions python/lsst/production/tools/htmlUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ def mk_table_value(t, metric_defs, val_col_name, sig_col_name, n):
sig = t[sig_col_name][n]
sig_str = f"{sig:.3g}"
else:
return None, None
return None, None, None, None, None

bad_val = 0

link = "metrics.report_page"
if val_col_name in metric_defs:
debug_group = metric_defs[val_col_name]["debugGroup"]
else:
debug_group = None

if np.isnan(val):
val_str = f"<FONT CLASS=nanValue>{val:.3g} </FONT>"
Expand All @@ -24,18 +32,18 @@ def mk_table_value(t, metric_defs, val_col_name, sig_col_name, n):
if val_col_name in metric_defs:
high_val = metric_defs[val_col_name]["highThreshold"]
low_val = metric_defs[val_col_name]["lowThreshold"]
link = metric_defs[val_col_name]["debugGroup"] + "ReportPage.html"
debug_group = metric_defs[val_col_name]["debugGroup"]
if val < low_val or val > high_val:
#valStr = "<FONT CLASS=badValue><A HREF = " + link + f">{val:.3g}</A></FONT> "
val_str = f"<FONT CLASS=badValue>{val:.3g}</FONT>"
bad_val += 1
if sig_col_name in metric_defs:
high_sig = metric_defs[sig_col_name]["highThreshold"]
low_sig = metric_defs[sig_col_name]["lowThreshold"]
if sig < low_sig or sig > high_sig:
#sigStr = "<FONT CLASS=badValue><A HREF = " + link + f">{sig:.3g}</A></FONT>\n"
sig_str = f"<FONT CLASS=badValue>{sig:.3g}</FONT>\n"
bad_val += 1

return val_str, sig_str
return val_str, sig_str, bad_val, link, debug_group


def mk_table_headers(t, col_dict):
Expand Down Expand Up @@ -64,29 +72,28 @@ def mk_table_headers(t, col_dict):
for header in table_headers:
if header == "failed metrics":
# Needs to link to metric fail page
header_dict[header] = "metrics.index"
header_dict[header] = "metrics.histograms"
elif header == "corners":
# Needs to link to metric summary page
header_dict[header] = "metrics.index"
header_dict[header] = "metrics.histograms"
else:
# Needs to link to the correct point on the histogram page
#headerList.append("<A HREF = histPage.html#" + header.split("<BR>")[0] + f">{header}</A>")
header_dict[header] = "metrics.index"
header_dict[header] = "metrics.histograms"

return header_dict, bands


def mk_tract_cell(tract):
#tractStr = "<a href='summary" + str(tract) + ".html' class=tract>"
#tractStr += str(tract) + "</a>"
tract_str = str(tract)
tract_str = "metrics.single_tract"

return tract_str
return (tract_str, )


def mk_summary_plot_cell(tract):
plot_str = "<IMG SRC='static/summaryCalexp_" + str(tract) + "_i.png' CLASS=thumbnail>"
return plot_str
#plot_str = "<IMG SRC='static/summaryCalexp_" + str(tract) + "_i.png' CLASS=thumbnail>"
plot_str = "nav link needed"
return (plot_str, )


def mk_patch_num_cell(t, n, bands):
Expand All @@ -96,38 +103,58 @@ def mk_patch_num_cell(t, n, bands):
patch_col = "coaddPatchCount_" + band + "_patchCount"
patch_str += "<B>" + band + "</B>: " + str(int(t[patch_col][n])) + "<BR>\n"

return patch_str
return (patch_str, )


def mk_shape_cols(t, metric_defs, n, bands, col_dict):
shape_strs = []
for col in col_dict["shape_cols"]:
for sn in ["highSNStars", "lowSNStars"]:
shape_str = ""
num_bad = 0
debug_group_all = None
for band in ["g", "r", "i", "z", "y"]:
if band in bands:
val_col_name = col + "_" + band + "_" + sn + "_median"
sig_col_name = col + "_" + band + "_" + sn + "_sigmaMad"
val_str, sig_str = mk_table_value(t, metric_defs, val_col_name, sig_col_name, n)
val_str, sig_str, bad_val, link, debug_group = mk_table_value(t,
metric_defs,
val_col_name,
sig_col_name,
n)
num_bad += bad_val
shape_str += "<B>" + band + f"</B>: " + val_str + " <B>&sigma;</B>: "
shape_str += sig_str + "<BR>\n"
shape_strs.append(shape_str)
if debug_group is not None:
debug_group_all = debug_group
shape_strs.append((shape_str, num_bad, link, debug_group_all))
return shape_strs


def mk_stellar_locus_cols(t, metric_defs, n, col_dict):
row_strs = []
for col in col_dict["stellar_locus_cols"]:
for (flux, flux1) in zip(["psfFlux", "CModel"], ["PSF", "CModel"]):
if col[0] == "w" or col[0] == "x":
row_str = ""
num_bad = 0
debug_group_all = None
for (flux, flux1) in zip(["psfFlux", "cModelFlux"], ["PSF", "CModel"]):
if (col[0] == "w" or col[0] == "x") and flux1 == "PSF":
flux1 += "P"
val_col_name = col + flux1 + "_" + col + "_" + flux + "_median"
sig_col_name = col + flux1 + "_" + col + "_" + flux + "_sigmaMAD"
val_str, sig_str = mk_table_value(t, metric_defs, val_col_name, sig_col_name, n)
val_str, sig_str, bad_val, link, debug_group = mk_table_value(t,
metric_defs,
val_col_name,
sig_col_name,
n)
if val_str is None:
continue
row_str = "<B>Med</B>: " + val_str + " <B>&sigma;</B>: " + sig_str + "<BR>\n"
row_strs.append(row_str)
row_str += "<B>" + flux + "</B><BR><B>Med</B>: " + val_str + " <B>&sigma;</B>: " + sig_str + "<BR>"
row_str += "<BR>\n"
num_bad += bad_val
if debug_group is not None:
debug_group_all = debug_group
row_strs.append((row_str, num_bad, link, debug_group_all))

return row_strs

Expand Down
33 changes: 25 additions & 8 deletions python/lsst/production/tools/tractTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def collection(collection_urlencoded):
t = butler.get("objectTableCore_metricsTable", collections=collection, dataId=dataId)

#stellarLocusCols = ["yPerpPSF", "yPerpCModel", "wPerpCModel", "wPerpPSFP", "xPerpPSFP", "xPerpCModel"]
col_dict = {"table_cols": ["tract", "failed metrics", "corners", "nPatches"],
col_dict = {"table_cols": ["tract", "corners", "nPatches", "failed metrics"],
"shape_cols": ["shapeSizeFractionalDiff", "e1Diff", "e2Diff"],
"photom_cols": ["psfCModelScatter"],
"stellar_locus_cols": ["yPerp", "wPerp", "xPerp"],
Expand All @@ -88,19 +88,33 @@ def collection(collection_urlencoded):
row_list = []
row_list.append(mk_tract_cell(tract))

# Add a nan/bad summary cell next but need to calculate these numbers first
row_list.append("0")
# Add a summary plot in the i band of the tract
row_list.append(mk_summary_plot_cell(tract))
# Add the number of patches
row_list.append(mk_patch_num_cell(t, n, bands))
for cell_str in mk_shape_cols(t, metric_defs, n, bands, col_dict):
row_list.append(cell_str)
for cell_str in mk_stellar_locus_cols(t, metric_defs, n, col_dict):
row_list.append(cell_str)

num_bad = 0
cell_vals = []
# Get the number of failed values and prep cell contents
for (cell_val, bad_val, link, debug_group) in mk_shape_cols(t, metric_defs, n, bands, col_dict):
cell_vals.append((cell_val, link, debug_group))
if bad_val is not None:
num_bad += bad_val

for (cell_val, bad_val, link, debug_group) in mk_stellar_locus_cols(t, metric_defs, n, col_dict):
cell_vals.append((cell_val, link, debug_group))
if bad_val is not None:
num_bad += bad_val

# Add a nan/bad summary cell next but need to calculate these numbers first
row_list.append((num_bad, ))
for val in cell_vals:
row_list.append(val)

content_dict[tract] = row_list

return render_template("metrics/tracts.html", header_dict=header_dict, content_dict=content_dict)
return render_template("metrics/tracts.html", header_dict=header_dict, content_dict=content_dict,
collection_urlencoded=collection_urlencoded)

@bp.route("/histograms/<collection_name>")
def histograms(collection_name):
Expand All @@ -118,4 +132,7 @@ def single_tract(collection_name, tract):
return render_template("metrics/single_tract.html", tract=tract)


@bp.route("/report/<collection_name>/<metric>")
def report_page(collection_name, metric):

return render_template("metrics/report_page.html")

0 comments on commit a9ff556

Please sign in to comment.