-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-34082: Handle empty arrays #27
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,12 +191,18 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a style choice, I think a blank line would be nice here. But not necessary of course. |
||
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") | ||
|
@@ -205,28 +211,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't have any stars, what happens to the limits? (Though better than crashing!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example case I had had both stars and galaxies list empty. So the axis limits were [0,1] in both directions. I suppose matplotlib still autoscales the limits so they are not going to be totally useless. |
||
|
||
fig = addPlotInfo(plt.gcf(), plotInfo) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -502,9 +503,12 @@ def scatterPlotWithTwoHists(self, catPlot, plotInfo, sumStats, yLims=False, xLim | |
ax.set_ylim(yLims[0], yLims[1]) | ||
else: | ||
if len(ysStars) > 0: | ||
[ys1, ys99] = np.nanpercentile(ysStars, [1, 99]) | ||
[ys1, ys99] = np.nanpercentile(ysStars, [1, 99]) # noqa: F841 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These variables are not used anywhere and makes flake8 unhappy. I could remove this, but I don't want to since I don't know what is was intended for, and I just want to get it in by tonight. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry @erykoff , the force push was introducing these noqa comments since the linting failed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, just delete the whole section then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And how did this ever pass linting? Anyway, these should be deleted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out if you defined something like [ys1, ys99] = [blah, blah], then it's okay according to F841. But if I made it ys1, ys99 = blah, blah (as I do now) and don't use ys1 and ys99, then flake8 is unhappy. That's how it passed the linting previously. |
||
elif len(ysGalaxies) > 0: | ||
[ys1, ys99] = np.nanpercentile(ysGalaxies, [1, 99]) # noqa: F841 | ||
else: | ||
[ys1, ys99] = np.nanpercentile(ysGalaxies, [1, 99]) | ||
ys1, ys99 = np.nan, np.nan # noqa: F841 | ||
|
||
numSig = 4 | ||
yLimMin = plotMed - numSig*sigMadYs | ||
yLimMax = plotMed + numSig*sigMadYs | ||
|
@@ -576,7 +580,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") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fail to see how the length of
xs
andys
could differ, but I guess it doesn't hurt to check both.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't either, but this is the first time I am seeing this code, so I am being extra cautious.