From 2018f077c51e8dcef6ee1d8a410c85e1129bace2 Mon Sep 17 00:00:00 2001 From: Jenna Delozier <jennakate998@gmail.com> Date: Thu, 25 Mar 2021 18:39:39 -0400 Subject: [PATCH] Clean up code format --- scripts/Calibration/tofpd/diagnostics.py | 33 ++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/scripts/Calibration/tofpd/diagnostics.py b/scripts/Calibration/tofpd/diagnostics.py index 516240ea79e..70599ae9e15 100644 --- a/scripts/Calibration/tofpd/diagnostics.py +++ b/scripts/Calibration/tofpd/diagnostics.py @@ -587,29 +587,36 @@ def plot_corr(tof_ws): tof_ws = mtd[str(tof_ws)] - detTOF = tof_ws.getNumberHistograms() + numHist = tof_ws.getNumberHistograms() - fig, ax = plt.subplots() - ax.set_xlabel("det IDs") - ax.set_ylabel("Pearson correlation coefficient (TOF, d)") + # Create an array for Pearson corr coef + r_vals = np.empty((numHist,), dtype=float) + r_vals.fill(np.nan) + + # Create an array for detector IDs + detectors = tof_ws.detectorInfo().detectorIDs() + detID = np.empty((numHist,), dtype=float) + detID.fill(np.nan) - r_vals = [] - detID = [] - for det in range(detTOF): + for workspaceIndex in range(numHist): # Get Pearson correlation coefficient for each detector - x = tof_ws.dataY(det) - y = tof_ws.dataX(det) + x = tof_ws.dataY(workspaceIndex) + y = tof_ws.dataX(workspaceIndex) mask = np.logical_not(np.isnan(x)) if np.sum(mask) > 1: r, p = np.corrcoef(x[mask], y[mask]) - r_vals.append(r[1]) + # Use r[1] because the corr coef is always the off-diagonal element here + r_vals[workspaceIndex] = r[1] else: - r_vals.append(np.nan) + r_vals[workspaceIndex] = np.nan # Get detector ID for this spectrum - detector = tof_ws.detectorInfo().detectorIDs()[det] - detID.append(detector) + detID[workspaceIndex] = detectors[workspaceIndex] + + fig, ax = plt.subplots() + ax.set_xlabel("det IDs") + ax.set_ylabel("Pearson correlation coefficient (TOF, d)") ax.plot(detID, r_vals, marker="x", linestyle="None") -- GitLab