Skip to content
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-23173: Change W504 to W503 and fix flake8 warnings #156

Merged
merged 1 commit into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions python/lsst/ip/diffim/dipoleFitTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,9 @@ def measure(self, measRecord, exposure, posExp=None, negExp=None):

# Check if the footprint consists of a putative dipole - else don't fit it.
if (
(len(pks) <= 1) or # one peak in the footprint - not a dipole
(len(pks) > 1 and (np.sign(pks[0].getPeakValue()) ==
np.sign(pks[-1].getPeakValue()))) # peaks are same sign - not a dipole
(len(pks) <= 1) # one peak in the footprint - not a dipole
or (len(pks) > 1 and (np.sign(pks[0].getPeakValue())
== np.sign(pks[-1].getPeakValue()))) # peaks are same sign - not a dipole
):
measRecord.set(self.classificationFlagKey, False)
measRecord.set(self.classificationAttemptedFlagKey, False)
Expand Down Expand Up @@ -1132,8 +1132,8 @@ def measure(self, measRecord, exposure, posExp=None, negExp=None):
# Dia source flux: average of pos+neg
measRecord[self.fluxKey] = (abs(result.posFlux) + abs(result.negFlux))/2.
measRecord[self.orientationKey] = result.orientation
measRecord[self.separationKey] = np.sqrt((result.posCentroidX - result.negCentroidX)**2. +
(result.posCentroidY - result.negCentroidY)**2.)
measRecord[self.separationKey] = np.sqrt((result.posCentroidX - result.negCentroidX)**2.
+ (result.posCentroidY - result.negCentroidY)**2.)
measRecord[self.centroidKeyX] = result.centroidX
measRecord[self.centroidKeyY] = result.centroidY

Expand Down Expand Up @@ -1167,11 +1167,11 @@ def doClassify(self, measRecord, chi2val):

# Second, are the pos/neg fluxes greater than 1.0 and no more than 0.65 (param maxFluxRatio)
# of the total flux? By default this will never happen since posFlux = negFlux.
passesFluxPos = (abs(measRecord[self.posFluxKey]) /
(measRecord[self.fluxKey]*2.)) < self.config.maxFluxRatio
passesFluxPos = (abs(measRecord[self.posFluxKey])
/ (measRecord[self.fluxKey]*2.)) < self.config.maxFluxRatio
passesFluxPos &= (abs(measRecord[self.posFluxKey]) >= 1.0)
passesFluxNeg = (abs(measRecord[self.negFluxKey]) /
(measRecord[self.fluxKey]*2.)) < self.config.maxFluxRatio
passesFluxNeg = (abs(measRecord[self.negFluxKey])
/ (measRecord[self.fluxKey]*2.)) < self.config.maxFluxRatio
passesFluxNeg &= (abs(measRecord[self.negFluxKey]) >= 1.0)
allPass = (passesSn and passesFluxPos and passesFluxNeg) # and passesChi2)

Expand Down
8 changes: 4 additions & 4 deletions python/lsst/ip/diffim/imageDecorrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def run(self, exposure, templateExposure, subtractedExposure, psfMatchingKernel,
# exposure
if np.isnan(svar) or np.isnan(tvar):
# Double check that one of the exposures is all NaNs
if (np.all(np.isnan(exposure.getMaskedImage().getImage().getArray())) or
np.all(np.isnan(templateExposure.getMaskedImage().getImage().getArray()))):
if (np.all(np.isnan(exposure.getMaskedImage().getImage().getArray()))
or np.all(np.isnan(templateExposure.getMaskedImage().getImage().getArray()))):
self.log.warn('Template or science image is entirely NaNs: skipping decorrelation.')
outExposure = subtractedExposure.clone()
return pipeBase.Struct(correctedExposure=outExposure, correctionKernel=None)
Expand Down Expand Up @@ -648,8 +648,8 @@ def run(self, scienceExposure, templateExposure, subtractedExposure, psfMatching
tvar = self.computeVarianceMean(templateExposure)
if np.isnan(svar) or np.isnan(tvar): # Should not happen unless entire image has been masked.
# Double check that one of the exposures is all NaNs
if (np.all(np.isnan(scienceExposure.getMaskedImage().getImage().getArray())) or
np.all(np.isnan(templateExposure.getMaskedImage().getImage().getArray()))):
if (np.all(np.isnan(scienceExposure.getMaskedImage().getImage().getArray()))
or np.all(np.isnan(templateExposure.getMaskedImage().getImage().getArray()))):
self.log.warn('Template or science image is entirely NaNs: skipping decorrelation.')
if np.isnan(svar):
svar = 1e-9
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/ip/diffim/imageMapReduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def run(self, mapperResults, exposure, **kwargs):

for item in mapperResults:
item = item.subExposure # Expected named value in the pipeBase.Struct
if not (isinstance(item, afwImage.ExposureF) or isinstance(item, afwImage.ExposureI) or
isinstance(item, afwImage.ExposureU) or isinstance(item, afwImage.ExposureD)):
if not (isinstance(item, afwImage.ExposureF) or isinstance(item, afwImage.ExposureI)
or isinstance(item, afwImage.ExposureU) or isinstance(item, afwImage.ExposureD)):
raise TypeError("""Expecting an Exposure type, got %s.
Consider using `reduceOperation="none".""" % str(type(item)))
subExp = newExp.Factory(newExp, item.getBBox())
Expand Down Expand Up @@ -660,8 +660,8 @@ def _generateGrid(self, exposure, forceEvenSized=False, **kwargs):
if cellCentroidsX is None or len(cellCentroidsX) <= 0:
# Not given centroids; construct them from cellSize/gridStep

psfFwhm = (exposure.getPsf().computeShape().getDeterminantRadius() *
2.*np.sqrt(2.*np.log(2.)))
psfFwhm = (exposure.getPsf().computeShape().getDeterminantRadius()
* 2.*np.sqrt(2.*np.log(2.)))
if scaleByFwhm:
self.log.info("Scaling grid parameters by %f" % psfFwhm)

Expand Down
12 changes: 6 additions & 6 deletions python/lsst/ip/diffim/imagePsfMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,9 @@ def makeCandidateList(self, templateExposure, scienceExposure, kernelSize, candi
try:
candidateList[0].getSource()
except Exception as e:
raise RuntimeError("Candidate List is of type: %s. " % (type(candidateList[0])) +
"Can only make candidate list from list of afwTable.SourceRecords, " +
"measAlg.PsfCandidateF or other type with a getSource() method: %s" % (e))
raise RuntimeError(f"Candidate List is of type: {type(candidateList[0])} "
"Can only make candidate list from list of afwTable.SourceRecords, "
f"measAlg.PsfCandidateF or other type with a getSource() method: {e}")
candidateList = [c.getSource() for c in candidateList]

candidateList = diffimTools.sourceToFootprintList(candidateList,
Expand Down Expand Up @@ -953,9 +953,9 @@ def _validateWcs(self, templateExposure, scienceExposure):
if not (templateBBox.overlaps(scienceBBox)):
raise RuntimeError("Input images do not overlap at all")

if ((templateOrigin != scienceOrigin) or
(templateLimit != scienceLimit) or
(templateExposure.getDimensions() != scienceExposure.getDimensions())):
if ((templateOrigin != scienceOrigin)
or (templateLimit != scienceLimit)
or (templateExposure.getDimensions() != scienceExposure.getDimensions())):
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/diffim/kernelCandidateQa.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def makeMetricMap(self):
("D from K-S test of diffim pixels relative to Normal", ),
("Prob from K-S test of diffim pixels relative to Normal", "likelihood"),
("Anderson-Darling test statistic of diffim pixels relative to Normal", ),
("Critical values for the significance levels in KCDiffimADSig. If A2 is greater " +
("Critical values for the significance levels in KCDiffimADSig. If A2 is greater "
"than this number, hypothesis that the distributions are similar can be rejected.", 5),
("Anderson-Darling significance levels for the Normal distribution", 5),
("Reduced chi^2 of the residual.", "likelihood"),
Expand Down
20 changes: 10 additions & 10 deletions python/lsst/ip/diffim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,15 +698,15 @@ def plotPixelResiduals(exposure, warpedTemplateExposure, diffExposure, kernelCel
tsdiffim = sdiffim.Factory(sdiffim, bbox)

if origVariance:
candidateResids.append(np.ravel(tdiffim.getImage().getArray() /
np.sqrt(torig.getVariance().getArray())))
spatialResids.append(np.ravel(tsdiffim.getImage().getArray() /
np.sqrt(torig.getVariance().getArray())))
candidateResids.append(np.ravel(tdiffim.getImage().getArray()
/ np.sqrt(torig.getVariance().getArray())))
spatialResids.append(np.ravel(tsdiffim.getImage().getArray()
/ np.sqrt(torig.getVariance().getArray())))
else:
candidateResids.append(np.ravel(tdiffim.getImage().getArray() /
np.sqrt(tdiffim.getVariance().getArray())))
spatialResids.append(np.ravel(tsdiffim.getImage().getArray() /
np.sqrt(tsdiffim.getVariance().getArray())))
candidateResids.append(np.ravel(tdiffim.getImage().getArray()
/ np.sqrt(tdiffim.getVariance().getArray())))
spatialResids.append(np.ravel(tsdiffim.getImage().getArray()
/ np.sqrt(tsdiffim.getVariance().getArray())))

fullIm = diffExposure.getMaskedImage().getImage().getArray()
fullMask = diffExposure.getMaskedImage().getMask().getArray()
Expand Down Expand Up @@ -1055,8 +1055,8 @@ def detectDipoleSources(self, doMerge=True, diffim=None, detectSigma=5.5, grow=3
detectConfig.reEstimateBackground = True # if False, will fail often for faint sources on gradients?
detectConfig.thresholdType = "pixel_stdev"
# Test images are often quite small, so may need to adjust background binSize
while ((min(diffim.getWidth(), diffim.getHeight()))//detectConfig.background.binSize <
detectConfig.background.approxOrderX and detectConfig.background.binSize > minBinSize):
while ((min(diffim.getWidth(), diffim.getHeight()))//detectConfig.background.binSize
< detectConfig.background.approxOrderX and detectConfig.background.binSize > minBinSize):
detectConfig.background.binSize = max(minBinSize, detectConfig.background.binSize//2)

# Create the detection task. We pass the schema so the task can declare a few flag fields
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 110
ignore = E133, E226, E228, N802, N803, N806, E266, N812, N815, N816, W504
ignore = E133, E226, E228, N802, N803, N806, E266, N812, N815, N816, W503
# TODO: remove E266 when Task documentation is converted to rst in DM-14207.
exclude =
__init__.py,
Expand All @@ -9,7 +9,7 @@ exclude =

[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N815 N816 W504
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N815 N816 W503
# TODO: remove E266 lines when Task documentation is converted to rst in DM-14207.
diaCatalogSourceSelector.py E266
dipoleMeasurement.py E266
Expand Down
64 changes: 32 additions & 32 deletions tests/test_compareToHotpants.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def testSingleNoVariation(self):
# Hotpants centroids go from -1 to 1
# Only one passes
if xC > 150 and yC > 150:
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
self.kernelCellSet.insertCandidate(cand)

Expand Down Expand Up @@ -200,10 +200,10 @@ def testFourNoVariation(self):

# Hotpants centroids go from -1 to 1
if xC > 90 and yC > 90:
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)

self.kernelCellSet.insertCandidate(cand)
Expand Down Expand Up @@ -258,10 +258,10 @@ def testFourKernelVariation(self):

# Hotpants centroids go from -1 to 1
if xC > 90 and yC > 90:
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
self.kernelCellSet.insertCandidate(cand)

Expand Down Expand Up @@ -356,10 +356,10 @@ def testFourBgVariation(self):

# Hotpants centroids go from -1 to 1
if xC > 90 and yC > 90:
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
# print 'OBJECT', cand.getId(), 'AT', xC, yC, cand.getXCenter(), cand.getYCenter()
self.kernelCellSet.insertCandidate(cand)
Expand Down Expand Up @@ -418,10 +418,10 @@ def testFourVariation(self):

# Hotpants centroids go from -1 to 1
if xC > 90 and yC > 90:
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
self.kernelCellSet.insertCandidate(cand)

Expand Down Expand Up @@ -506,10 +506,10 @@ def testAllBgVariation2(self):
ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)

# Hotpants centroids go from -1 to 1
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
cands.append(cand)

Expand Down Expand Up @@ -577,10 +577,10 @@ def testAllKernelVariation2(self):
ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)

# Hotpants centroids go from -1 to 1
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
cands.append(cand)

Expand Down Expand Up @@ -692,10 +692,10 @@ def testAllVariation2(self):
ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)

# Hotpants centroids go from -1 to 1
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth()) /
(0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight()) /
(0.5 * self.smi.getHeight()),
cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
/ (0.5 * self.smi.getWidth()),
(yC - 0.5 * self.smi.getHeight())
/ (0.5 * self.smi.getHeight()),
tsmi, ssmi, self.ps)
cands.append(cand)

Expand Down