Skip to content

Commit

Permalink
Merge pull request #27 from lsst/tickets/DM-34082
Browse files Browse the repository at this point in the history
DM-34082: Handle empty arrays
  • Loading branch information
arunkannawadi committed Mar 16, 2022
2 parents e8198aa + ada0e75 commit aa635fc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
3 changes: 3 additions & 0 deletions python/lsst/analysis/drp/colorColorFitPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ def colorColorFitPlot(self, catPlot, plotInfo, fitParams):
ys = catPlot[self.config.axisLabels["y"]].values
mags = catPlot[self.config.axisLabels["mag"]].values

if len(xs) == 0 or len(ys) == 0:
return fig

# Points to use for the fit
fitPoints = np.where((xs > fitParams["xMin"]) & (xs < fitParams["xMax"])
& (ys > fitParams["yMin"]) & (ys < fitParams["yMax"]))[0]
Expand Down
54 changes: 32 additions & 22 deletions python/lsst/analysis/drp/colorColorPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,19 @@ def colorColorPlot(self, catPlot, plotInfo):
ysStars = catPlot.loc[stars, yCol]
zsStars = catPlot.loc[stars, zCol]

[vminGals, vmaxGals] = np.nanpercentile(zsGalaxies, [1, 99])
[vminStars, vmaxStars] = np.nanpercentile(zsStars, [1, 99])
galPoints = ax.scatter(xsGalaxies, ysGalaxies, c=zsGalaxies, cmap=newReds, label="Galaxies",
s=0.5, vmin=vminGals, vmax=vmaxGals)
starPoints = ax.scatter(xsStars, ysStars, c=zsStars, cmap=newBlues, label="Stars", s=0.5,
vmin=vminStars, vmax=vmaxStars)
if len(zsGalaxies) > 0:
[vminGals, vmaxGals] = np.nanpercentile(zsGalaxies, [1, 99])
galPoints = ax.scatter(xsGalaxies, ysGalaxies, c=zsGalaxies, cmap=newReds, label="Galaxies",
s=0.5, vmin=vminGals, vmax=vmaxGals)
else:
galPoints = None

if len(zsStars) > 0:
[vminStars, vmaxStars] = np.nanpercentile(zsStars, [1, 99])
starPoints = ax.scatter(xsStars, ysStars, c=zsStars, cmap=newBlues, label="Stars", s=0.5,
vmin=vminStars, vmax=vmaxStars)
else:
starPoints = None

# Add text details
galBBox = dict(facecolor="lemonchiffon", alpha=0.5, edgecolor="none")
Expand All @@ -205,28 +212,31 @@ def colorColorPlot(self, catPlot, plotInfo):
fig.text(0.70, 0.96, "Num. Stars: {}".format(stars.sum()), bbox=starBBox, fontsize=8)

# Add colorbars
galCbAx = fig.add_axes([0.85, 0.11, 0.04, 0.75])
plt.colorbar(galPoints, cax=galCbAx, extend="both")
galCbAx.yaxis.set_ticks_position("left")
starCbAx = fig.add_axes([0.89, 0.11, 0.04, 0.75])
plt.colorbar(starPoints, cax=starCbAx, extend="both")
magLabel = self.config.axisLabels["z"]
galText = galCbAx.text(0.5, 0.5, magLabel + ": Galaxies", color="k", rotation="vertical",
transform=galCbAx.transAxes, ha="center", va="center", fontsize=10)
galText.set_path_effects([pathEffects.Stroke(linewidth=3, foreground="w"), pathEffects.Normal()])
starText = starCbAx.text(0.5, 0.5, magLabel + ": Stars", color="k", rotation="vertical",
transform=starCbAx.transAxes, ha="center", va="center", fontsize=10)
starText.set_path_effects([pathEffects.Stroke(linewidth=3, foreground="w"), pathEffects.Normal()])
if galPoints:
galCbAx = fig.add_axes([0.85, 0.11, 0.04, 0.75])
plt.colorbar(galPoints, cax=galCbAx, extend="both")
galCbAx.yaxis.set_ticks_position("left")
galText = galCbAx.text(0.5, 0.5, magLabel + ": Galaxies", color="k", rotation="vertical",
transform=galCbAx.transAxes, ha="center", va="center", fontsize=10)
galText.set_path_effects([pathEffects.Stroke(linewidth=3, foreground="w"), pathEffects.Normal()])
if starPoints:
starCbAx = fig.add_axes([0.89, 0.11, 0.04, 0.75])
plt.colorbar(starPoints, cax=starCbAx, extend="both")
starText = starCbAx.text(0.5, 0.5, magLabel + ": Stars", color="k", rotation="vertical",
transform=starCbAx.transAxes, ha="center", va="center", fontsize=10)
starText.set_path_effects([pathEffects.Stroke(linewidth=3, foreground="w"), pathEffects.Normal()])

ax.set_xlabel(self.config.axisLabels["x"])
ax.set_ylabel(self.config.axisLabels["y"])

# Set useful axis limits
starPercsX = np.nanpercentile(xsStars, [1, 99.5])
starPercsY = np.nanpercentile(ysStars, [1, 99.5])
pad = (starPercsX[1] - starPercsX[0])/10
ax.set_xlim(starPercsX[0] - pad, starPercsX[1] + pad)
ax.set_ylim(starPercsY[0] - pad, starPercsY[1] + pad)
if len(xsStars) > 0:
starPercsX = np.nanpercentile(xsStars, [1, 99.5])
starPercsY = np.nanpercentile(ysStars, [1, 99.5])
pad = (starPercsX[1] - starPercsX[0])/10
ax.set_xlim(starPercsX[0] - pad, starPercsX[1] + pad)
ax.set_ylim(starPercsY[0] - pad, starPercsY[1] + pad)

fig = addPlotInfo(plt.gcf(), plotInfo)

Expand Down
1 change: 0 additions & 1 deletion python/lsst/analysis/drp/quiverPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class QuiverPlotTaskConfig(SkyPlotTaskConfig):

def setDefaults(self):
super().setDefaults()
self.plotOutlines = False


class QuiverPlotTask(SkyPlotTask):
Expand Down
9 changes: 3 additions & 6 deletions python/lsst/analysis/drp/scatterPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def scatterPlotWithTwoHists(self, catPlot, plotInfo, sumStats, yLims=False, xLim
label=r"$\sigma_{MAD}$: " + f"{sigMads[0]:0.2f}")
ax.plot(xs, meds - 1.0*sigMads, color, alpha=0.8)
linesForLegend.append(sigMadLine)
histIm = None

# Set the scatter plot limits
if len(ysStars) > 0:
Expand All @@ -500,11 +501,7 @@ def scatterPlotWithTwoHists(self, catPlot, plotInfo, sumStats, yLims=False, xLim
plotMed = np.nanmedian(ysGalaxies)
if yLims:
ax.set_ylim(yLims[0], yLims[1])
else:
if len(ysStars) > 0:
[ys1, ys99] = np.nanpercentile(ysStars, [1, 99])
else:
[ys1, ys99] = np.nanpercentile(ysGalaxies, [1, 99])

numSig = 4
yLimMin = plotMed - numSig*sigMadYs
yLimMax = plotMed + numSig*sigMadYs
Expand Down Expand Up @@ -576,7 +573,7 @@ def scatterPlotWithTwoHists(self, catPlot, plotInfo, sumStats, yLims=False, xLim

sideHist.axes.get_yaxis().set_visible(False)
sideHist.set_xlabel("Number", fontsize=8)
if self.config.plot2DHist:
if self.config.plot2DHist and histIm is not None:
divider = make_axes_locatable(sideHist)
cax = divider.append_axes("right", size="8%", pad=0)
plt.colorbar(histIm, cax=cax, orientation="vertical", label="Number of Points Per Bin")
Expand Down

0 comments on commit aa635fc

Please sign in to comment.