Skip to content

Commit 1864ea4

Browse files
committed
final touches
1 parent 3a808ed commit 1864ea4

File tree

1 file changed

+57
-28
lines changed

1 file changed

+57
-28
lines changed

python/lsst/summit/extras/plotting/psfPlotting.py

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def makeFigureAndAxes(nrows=2) -> tuple[Figure, Any]:
356356
The created axes.
357357
"""
358358
# Note, tuning params here manually. Be careful if adjusting.
359-
fig = make_figure(figsize=(10, 8))
359+
fig = make_figure(figsize=(10, 3 * nrows))
360360

361361
scatterSpec = GridSpec(
362362
nrows=nrows,
@@ -417,14 +417,7 @@ def plotData(
417417
e1 = table[prefix + "e1"]
418418
e2 = table[prefix + "e2"]
419419
e = table["e"]
420-
coma1 = table["coma1"]
421-
coma2 = table["coma2"]
422-
coma = table["coma"]
423-
trefoil1 = table["trefoil1"]
424-
trefoil2 = table["trefoil2"]
425-
trefoil = table["trefoil"]
426420
fwhm = table["FWHM"]
427-
kurtosis = table["kurtosis"]
428421

429422
# Quiver plot
430423
quiver_kwargs = {
@@ -498,14 +491,30 @@ def plotData(
498491

499492

500493
def plot_triangle(ax, center=(0, 0), size=1.0, angle_deg=0.0, color='blue'):
494+
"""
495+
Plot an equilateral triangle
496+
497+
Parameters
498+
----------
499+
ax : `~matplotlib.axes.Axes`
500+
The pane to plot on.
501+
center : `tuple [`float`]`, optional
502+
The (x, y) coordinates of the triangle center.
503+
size : `float`, optional
504+
The size of the triangle.
505+
angle_deg : `float`, optional
506+
The rotation angle of the triangle in degrees.
507+
color : `str`, optional
508+
The color of the triangle.
509+
"""
501510
# Define an equilateral triangle centered at origin
502511
theta = np.deg2rad(angle_deg)
503512

504513
# Base triangle points (pointing upward, unit size)
505514
triangle = np.array([
506515
[0, 1],
507-
[-np.sqrt(3)/2, -0.5],
508-
[ np.sqrt(3)/2, -0.5]
516+
[-0.5 * np.sqrt(3), -0.5],
517+
[0.5 * np.sqrt(3), -0.5]
509518
])
510519

511520
# Scale
@@ -533,6 +542,19 @@ def plotHigherOrderMomentsData(
533542
prefix: str = "",
534543
bin_spacing: float = 0.06,
535544
):
545+
"""Plot coma, trefoil and kurtosis from the table on the provided axes.
546+
547+
Parameters
548+
----------
549+
axs : `numpy.ndarray`
550+
The array of axes objects to plot on.
551+
table : `Table`
552+
The table containing the data to plot.
553+
prefix : `str`, optional
554+
The prefix to use for the column names in the table.
555+
bin_spacing : `float`, optional
556+
The spacing between arrows and triangles in the plot.
557+
"""
536558
x = table[prefix + "x"]
537559
y = table[prefix + "y"]
538560
kurtosis = table["kurtosis"]
@@ -555,14 +577,14 @@ def plotHigherOrderMomentsData(
555577

556578
mean_coma_angle = np.arctan2(mean_coma[2], mean_coma[1])
557579
mean_coma_amplitude = np.hypot(mean_coma[2], mean_coma[2])
558-
Q_coma = axs[2, 0].quiver(
580+
Q_coma = axs[0].quiver(
559581
binning.coords0[:, 0],
560582
binning.coords0[:, 1],
561583
mean_coma_amplitude * np.cos(mean_coma_angle),
562584
mean_coma_amplitude * np.sin(mean_coma_angle),
563585
**quiver_kwargs,
564586
)
565-
axs[2, 0].quiverkey(Q_coma, X=0.1, Y=0.88, U=0.05, label="0.05", labelpos="S")
587+
axs[0].quiverkey(Q_coma, X=0.1, Y=0.88, U=0.05, label="0.05", labelpos="S")
566588

567589
mean_trefoil = {}
568590
for i in (1, 2):
@@ -574,17 +596,23 @@ def plotHigherOrderMomentsData(
574596
mean_trefoil_angle = np.arctan2(mean_trefoil[2], mean_trefoil[1]) / 3 # spin-3
575597
mean_trefoil_amplitude = np.hypot(mean_trefoil[2], mean_trefoil[1])
576598
SCALE_TRIANGLE = 0.5
577-
plot_triangle(axs[2, 1], center=(1.8, 1.7), size=0.1*SCALE_TRIANGLE, angle_deg=0.0, color='black')
578-
axs[2, 1].text(1.6, 1.35, "0.1")
599+
plot_triangle(axs[1], center=(1.8, 1.7), size=0.1 * SCALE_TRIANGLE, angle_deg=0.0, color='black')
600+
axs[1].text(1.6, 1.35, "0.1")
579601
for idx in range(len(mean_trefoil_amplitude)):
580602
_t = mean_trefoil_amplitude[idx]
581603
_ta = mean_trefoil_angle[idx]
582604
_xcen = binning.coords0[idx, 0]
583605
_ycen = binning.coords0[idx, 1]
584-
plot_triangle(axs[2, 1], center=(_xcen, _ycen), size=_t*SCALE_TRIANGLE, angle_deg=_ta*180/np.pi, color='black')
606+
plot_triangle(
607+
axs[1],
608+
center=(_xcen, _ycen),
609+
size=_t * SCALE_TRIANGLE,
610+
angle_deg=_ta * 180.0 / np.pi,
611+
color='black',
612+
)
585613

586-
pos = axs[2, 1].get_position() # get current position [left, bottom, width, height]
587-
axs[2, 1].set_position([pos.x0, pos.y0, pos.width*0.931, pos.height])
614+
pos = axs[1].get_position() # get current position [left, bottom, width, height]
615+
axs[1].set_position([pos.x0, pos.y0, pos.width * 0.931, pos.height])
588616

589617
textKwargs = {
590618
"x": 0.95,
@@ -596,23 +624,23 @@ def plotHigherOrderMomentsData(
596624
}
597625

598626
# Kurtosis hist
599-
axs[2, 2].hist(kurtosis, bins=int(np.sqrt(len(table))), color="C3")
627+
axs[2].hist(kurtosis, bins=int(np.sqrt(len(table))), color="C3")
600628
kurtosisQuartiles = np.nanpercentile(kurtosis, [25, 50, 75])
601629
s = "Kurtosis\n"
602630
s += f"25%: {kurtosisQuartiles[0]:.3f}\n"
603631
s += f"50%: {kurtosisQuartiles[1]:.3f}\n"
604632
s += f"75%: {kurtosisQuartiles[2]:.3f}\n"
605-
axs[2, 2].text(
633+
axs[2].text(
606634
s=s,
607-
transform=axs[2, 2].transAxes,
635+
transform=axs[2].transAxes,
608636
**textKwargs,
609637
)
610-
axs[2, 2].axvline(kurtosisQuartiles[0], color="grey", lw=1)
611-
axs[2, 2].axvline(kurtosisQuartiles[1], color="k", lw=2)
612-
axs[2, 2].axvline(kurtosisQuartiles[2], color="grey", lw=1)
638+
axs[2].axvline(kurtosisQuartiles[0], color="grey", lw=1)
639+
axs[2].axvline(kurtosisQuartiles[1], color="k", lw=2)
640+
axs[2].axvline(kurtosisQuartiles[2], color="grey", lw=1)
613641

614-
axs[2, 0].text(0.05, 0.92, "coma", transform=axs[2, 0].transAxes, fontsize=10)
615-
axs[2, 1].text(0.82, 0.92, "trefoil", transform=axs[2, 1].transAxes, fontsize=10)
642+
axs[0].text(0.05, 0.92, "coma", transform=axs[0].transAxes, fontsize=10)
643+
axs[1].text(0.82, 0.92, "trefoil", transform=axs[1].transAxes, fontsize=10)
616644

617645

618646
def outlineDetectors(
@@ -945,7 +973,8 @@ def makeAzElPlot(
945973
if len(table) == 0:
946974
return
947975

948-
plotHigherOrderMomentsData(axs, table, prefix="aa_")
976+
if axs.shape[0] > 2:
977+
plotHigherOrderMomentsData(axs[2, :], table, prefix="aa_")
949978
table = randomRowsPerDetector(table, maxPointsPerDetector)
950979
plotData(axs[:2, :], table, prefix="aa_")
951980

@@ -955,9 +984,9 @@ def makeAzElPlot(
955984
for ax in axs[:3, :2].ravel():
956985
ax.set_xlim(-plotLimit, plotLimit)
957986
ax.set_ylim(-plotLimit, plotLimit)
958-
for ax in axs[2, :2]:
987+
for ax in axs[-1, :2]:
959988
ax.set_xlabel("$\\Delta$ Azimuth [deg]")
960-
for ax in axs[:3, 0]:
989+
for ax in axs[:, 0]:
961990
ax.set_ylabel("$\\Delta$ Elevation [deg]")
962991

963992
visitId = table.meta["LSST BUTLER DATAID VISIT"]

0 commit comments

Comments
 (0)