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 #379

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
20 changes: 10 additions & 10 deletions python/lsst/pipe/tasks/assembleCoadd.py
Expand Up @@ -1117,8 +1117,8 @@ def _makeArgumentParser(cls):
"""Create an argument parser.
"""
parser = pipeBase.ArgumentParser(name=cls._DefaultName)
parser.add_id_argument("--id", cls.ConfigClass().coaddName + "Coadd_" +
cls.ConfigClass().warpType + "Warp",
parser.add_id_argument("--id", cls.ConfigClass().coaddName + "Coadd_"
+ cls.ConfigClass().warpType + "Warp",
help="data ID, e.g. --id tract=12345 patch=1,2",
ContainerClass=AssembleCoaddDataIdContainer)
parser.add_id_argument("--selectId", "calexp", help="data ID, e.g. --selectId visit=6789 ccd=0..9",
Expand Down Expand Up @@ -1495,8 +1495,8 @@ def buildDifferenceImage(self, skyInfo, tempExpRefList, imageScalerList, weightL
# the same as AssembleCoaddConfig.connections, and the connections are not
# needed to run this task anyway.
configIntersection = {k: getattr(self.config, k)
for k, v in self.config.toDict().items() if (k in config.keys() and
k != "connections")}
for k, v in self.config.toDict().items()
if (k in config.keys() and k != "connections")}
config.update(**configIntersection)

# statistic MEAN copied from self.config.statistic, but for clarity explicitly assign
Expand Down Expand Up @@ -2186,8 +2186,8 @@ def findArtifacts(self, templateCoadd, tempExpRefList, imageScalerList):
warpDiffExp = self._readAndComputeWarpDiff(warpRef, imageScaler, templateCoadd)
if warpDiffExp is not None:
# This nImage only approximates the final nImage because it uses the PSF-matched mask
nImage.array += (numpy.isfinite(warpDiffExp.image.array) *
((warpDiffExp.mask.array & badPixelMask) == 0)).astype(numpy.uint16)
nImage.array += (numpy.isfinite(warpDiffExp.image.array)
* ((warpDiffExp.mask.array & badPixelMask) == 0)).astype(numpy.uint16)
fpSet = self.detect.detectFootprints(warpDiffExp, doSmooth=False, clearMask=True)
fpSet.positive.merge(fpSet.negative)
footprints = fpSet.positive
Expand Down Expand Up @@ -2301,12 +2301,12 @@ def filterArtifacts(self, spanSetList, epochCountImage, nImage, footprintsToExcl
totalN = nImage.array[yIdxLocal, xIdxLocal]

# effectiveMaxNumEpochs is broken line (fraction of N) with characteristic config.maxNumEpochs
effMaxNumEpochsHighN = (self.config.maxNumEpochs +
self.config.maxFractionEpochsHigh*numpy.mean(totalN))
effMaxNumEpochsHighN = (self.config.maxNumEpochs
+ self.config.maxFractionEpochsHigh*numpy.mean(totalN))
effMaxNumEpochsLowN = self.config.maxFractionEpochsLow * numpy.mean(totalN)
effectiveMaxNumEpochs = int(min(effMaxNumEpochsLowN, effMaxNumEpochsHighN))
nPixelsBelowThreshold = numpy.count_nonzero((outlierN > 0) &
(outlierN <= effectiveMaxNumEpochs))
nPixelsBelowThreshold = numpy.count_nonzero((outlierN > 0)
& (outlierN <= effectiveMaxNumEpochs))
percentBelowThreshold = nPixelsBelowThreshold / len(outlierN)
if percentBelowThreshold > self.config.spatialThreshold:
maskSpanSetList.append(span)
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/dcrAssembleCoadd.py
Expand Up @@ -649,8 +649,8 @@ def run(self, skyInfo, warpRefList, imageScalerList, weightList,
dcrNImages = None

subregionSize = geom.Extent2I(*self.config.subregionSize)
nSubregions = (ceil(skyInfo.bbox.getHeight()/subregionSize[1]) *
ceil(skyInfo.bbox.getWidth()/subregionSize[0]))
nSubregions = (ceil(skyInfo.bbox.getHeight()/subregionSize[1])
* ceil(skyInfo.bbox.getWidth()/subregionSize[0]))
subIter = 0
for subBBox in self._subBBoxIter(skyInfo.bbox, subregionSize):
modelIter = 0
Expand Down
47 changes: 23 additions & 24 deletions python/lsst/pipe/tasks/functors.py
Expand Up @@ -14,7 +14,7 @@ def init_fromDict(initDict, basePath='lsst.pipe.tasks.functors',
"""Initialize an object defined in a dictionary

The object needs to be importable as
'{0}.{1}'.format(basePath, initDict[typeKey])
f'{basePath}.{initDict[typeKey]}'
The positional and keyword arguments (if any) are contained in
"args" and "kwargs" entries in the dictionary, respectively.
This is used in `functors.CompositeFunctor.from_yaml` to initialize
Expand All @@ -34,7 +34,7 @@ def init_fromDict(initDict, basePath='lsst.pipe.tasks.functors',
"""
initDict = initDict.copy()
# TO DO: DM-21956 We should be able to define functors outside this module
pythonType = doImport('{0}.{1}'.format(basePath, initDict.pop(typeKey)))
pythonType = doImport(f'{basePath}.{initDict.pop(typeKey)}')
args = []
if 'args' in initDict:
args = initDict.pop('args')
Expand Down Expand Up @@ -133,8 +133,8 @@ def columns(self):

def multilevelColumns(self, parq):
if not set(parq.columnLevels) == set(self._columnLevels):
raise ValueError('ParquetTable does not have the expected column levels. ' +
'Got {0}; expected {1}.'.format(parq.columnLevels, self._columnLevels))
raise ValueError('ParquetTable does not have the expected column levels. '
f'Got {parq.columnLevels}; expected {self._columnLevels}.')

columnDict = {'column': self.columns,
'dataset': self.dataset}
Expand All @@ -143,10 +143,10 @@ def multilevelColumns(self, parq):
if self.dataset == 'ref':
columnDict['filter'] = parq.columnLevelNames['filter'][0]
else:
raise ValueError("'filt' not set for functor {}".format(self.name) +
"(dataset {}) ".format(self.dataset) +
"and ParquetTable " +
"contains multiple filters in column index. " +
raise ValueError(f"'filt' not set for functor {self.name}"
f"(dataset {self.dataset}) "
"and ParquetTable "
"contains multiple filters in column index. "
"Set 'filt' or set 'dataset' to 'ref'.")
else:
columnDict['filter'] = self.filt
Expand Down Expand Up @@ -395,7 +395,7 @@ def columns(self):
not_a_col = []
for c in flux_cols:
if not re.search('_instFlux$', c):
cols.append('{}_instFlux'.format(c))
cols.append(f'{c}_instFlux')
not_a_col.append(c)
else:
cols.append(c)
Expand Down Expand Up @@ -552,7 +552,7 @@ def _func(self, df):

@property
def name(self):
return 'mag_{0}'.format(self.col)
return f'mag_{self.col}'


class MagErr(Mag):
Expand Down Expand Up @@ -623,11 +623,11 @@ def _func(self, df):

@property
def name(self):
return '(mag_{0} - mag_{1})'.format(self.col1, self.col2)
return f'(mag_{self.col1} - mag_{self.col2})'

@property
def shortname(self):
return 'magDiff_{0}_{1}'.format(self.col1, self.col2)
return f'magDiff_{self.col1}_{self.col2}'


class Color(Functor):
Expand Down Expand Up @@ -694,12 +694,11 @@ def multilevelColumns(self, parq):

@property
def name(self):
return '{0} - {1} ({2})'.format(self.filt2, self.filt1, self.col)
return f'{self.filt2} - {self.filt1} ({self.col})'

@property
def shortname(self):
return '{0}_{1}m{2}'.format(self.col, self.filt2.replace('-', ''),
self.filt1.replace('-', ''))
return f"{self.col}_{self.filt2.replace('-', '')}m{self.filt1.replace('-', '')}"


class Labeller(Functor):
Expand Down Expand Up @@ -814,8 +813,8 @@ class HsmTraceSize(Functor):
"ext_shapeHSM_HsmSourceMoments_yy")

def _func(self, df):
srcSize = np.sqrt(0.5*(df["ext_shapeHSM_HsmSourceMoments_xx"] +
df["ext_shapeHSM_HsmSourceMoments_yy"]))
srcSize = np.sqrt(0.5*(df["ext_shapeHSM_HsmSourceMoments_xx"]
+ df["ext_shapeHSM_HsmSourceMoments_yy"]))
return srcSize


Expand All @@ -829,10 +828,10 @@ class PsfHsmTraceSizeDiff(Functor):
"ext_shapeHSM_HsmPsfMoments_yy")

def _func(self, df):
srcSize = np.sqrt(0.5*(df["ext_shapeHSM_HsmSourceMoments_xx"] +
df["ext_shapeHSM_HsmSourceMoments_yy"]))
psfSize = np.sqrt(0.5*(df["ext_shapeHSM_HsmPsfMoments_xx"] +
df["ext_shapeHSM_HsmPsfMoments_yy"]))
srcSize = np.sqrt(0.5*(df["ext_shapeHSM_HsmSourceMoments_xx"]
+ df["ext_shapeHSM_HsmSourceMoments_yy"]))
psfSize = np.sqrt(0.5*(df["ext_shapeHSM_HsmPsfMoments_xx"]
+ df["ext_shapeHSM_HsmPsfMoments_yy"]))
sizeDiff = 100*(srcSize - psfSize)/(0.5*(srcSize + psfSize))
return sizeDiff

Expand Down Expand Up @@ -970,8 +969,8 @@ def computeSkySeperation(self, ra1, dec1, ra2, dec2):
deltaRa = ra2 - ra1
return 2 * np.arcsin(
np.sqrt(
np.sin(deltaDec / 2) ** 2 +
np.cos(dec2) * np.cos(dec1) * np.sin(deltaRa / 2) ** 2))
np.sin(deltaDec / 2) ** 2
+ np.cos(dec2) * np.cos(dec1) * np.sin(deltaRa / 2) ** 2))

def getSkySeperationFromPixel(self, x1, y1, x2, y2, cd11, cd12, cd21, cd22):
"""Compute the distance on the sphere from x2, y1 to x1, y1.
Expand Down Expand Up @@ -1136,7 +1135,7 @@ def columns(self):

@property
def name(self):
return 'mag_{0}'.format(self.col)
return f'mag_{self.col}'

@classmethod
def hypot(cls, a, b):
Expand Down
32 changes: 16 additions & 16 deletions python/lsst/pipe/tasks/imageDifference.py
Expand Up @@ -738,29 +738,29 @@ def run(self, exposure=None, selectSources=None, templateExposure=None, template
cresiduals = [m.first.get(refCoordKey).getTangentPlaneOffset(
wcsResults.wcs.pixelToSky(
m.second.get(inCentroidKey))) for m in wcsResults.matches]
colors = numpy.array([-2.5*numpy.log10(srcToMatch[x].get("g")) +
2.5*numpy.log10(srcToMatch[x].get("r"))
colors = numpy.array([-2.5*numpy.log10(srcToMatch[x].get("g"))
+ 2.5*numpy.log10(srcToMatch[x].get("r"))
for x in sids if x in srcToMatch.keys()])
dlong = numpy.array([r[0].asArcseconds() for s, r in zip(sids, cresiduals)
if s in srcToMatch.keys()])
dlat = numpy.array([r[1].asArcseconds() for s, r in zip(sids, cresiduals)
if s in srcToMatch.keys()])
idx1 = numpy.where(colors < self.sourceSelector.config.grMin)
idx2 = numpy.where((colors >= self.sourceSelector.config.grMin) &
(colors <= self.sourceSelector.config.grMax))
idx2 = numpy.where((colors >= self.sourceSelector.config.grMin)
& (colors <= self.sourceSelector.config.grMax))
idx3 = numpy.where(colors > self.sourceSelector.config.grMax)
rms1Long = IqrToSigma*(
(numpy.percentile(dlong[idx1], 75) - numpy.percentile(dlong[idx1], 25)))
rms1Lat = IqrToSigma*(numpy.percentile(dlat[idx1], 75) -
numpy.percentile(dlat[idx1], 25))
rms1Lat = IqrToSigma*(numpy.percentile(dlat[idx1], 75)
- numpy.percentile(dlat[idx1], 25))
rms2Long = IqrToSigma*(
(numpy.percentile(dlong[idx2], 75) - numpy.percentile(dlong[idx2], 25)))
rms2Lat = IqrToSigma*(numpy.percentile(dlat[idx2], 75) -
numpy.percentile(dlat[idx2], 25))
rms2Lat = IqrToSigma*(numpy.percentile(dlat[idx2], 75)
- numpy.percentile(dlat[idx2], 25))
rms3Long = IqrToSigma*(
(numpy.percentile(dlong[idx3], 75) - numpy.percentile(dlong[idx3], 25)))
rms3Lat = IqrToSigma*(numpy.percentile(dlat[idx3], 75) -
numpy.percentile(dlat[idx3], 25))
rms3Lat = IqrToSigma*(numpy.percentile(dlat[idx3], 75)
- numpy.percentile(dlat[idx3], 25))
self.log.info("Blue star offsets'': %.3f %.3f, %.3f %.3f" %
(numpy.median(dlong[idx1]), rms1Long,
numpy.median(dlat[idx1]), rms1Lat))
Expand Down Expand Up @@ -1016,13 +1016,13 @@ def runDebug(self, exposure, subtractRes, selectSources, kernelSources, diaSourc
for s in diaSources:
x, y = s.getX() - x0, s.getY() - y0
ctype = "red" if s.get("flags_negative") else "yellow"
if (s.get("base_PixelFlags_flag_interpolatedCenter") or
s.get("base_PixelFlags_flag_saturatedCenter") or
s.get("base_PixelFlags_flag_crCenter")):
if (s.get("base_PixelFlags_flag_interpolatedCenter")
or s.get("base_PixelFlags_flag_saturatedCenter")
or s.get("base_PixelFlags_flag_crCenter")):
ptype = "x"
elif (s.get("base_PixelFlags_flag_interpolated") or
s.get("base_PixelFlags_flag_saturated") or
s.get("base_PixelFlags_flag_cr")):
elif (s.get("base_PixelFlags_flag_interpolated")
or s.get("base_PixelFlags_flag_saturated")
or s.get("base_PixelFlags_flag_cr")):
ptype = "+"
else:
ptype = "o"
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/interpImage.py
Expand Up @@ -69,8 +69,8 @@ class InterpImageConfig(pexConfig.Config):
def validate(self):
pexConfig.Config.validate(self)
if self.useFallbackValueAtEdge:
if (not self.negativeFallbackAllowed and self.fallbackValueType == "USER" and
self.fallbackUserValue < 0.0):
if (not self.negativeFallbackAllowed and self.fallbackValueType == "USER"
and self.fallbackUserValue < 0.0):
raise ValueError("User supplied fallbackValue is negative (%.2f) but "
"negativeFallbackAllowed is False" % self.fallbackUserValue)

Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/makeCoaddTempExp.py
Expand Up @@ -434,8 +434,8 @@ def run(self, calExpList, ccdIdList, skyInfo, visitId=0, dataIdList=None):
coaddTempExp = coaddTempExps[warpType]
if didSetMetadata[warpType]:
mimg = exposure.getMaskedImage()
mimg *= (coaddTempExp.getPhotoCalib().getInstFluxAtZeroMagnitude() /
exposure.getPhotoCalib().getInstFluxAtZeroMagnitude())
mimg *= (coaddTempExp.getPhotoCalib().getInstFluxAtZeroMagnitude()
/ exposure.getPhotoCalib().getInstFluxAtZeroMagnitude())
del mimg
numGoodPix[warpType] = coaddUtils.copyGoodPixels(
coaddTempExp.getMaskedImage(), exposure.getMaskedImage(), self.getBadPixelMask())
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/matchBackgrounds.py
Expand Up @@ -557,8 +557,8 @@ def _gridImage(self, maskedImage, binsize, statsFlag):
geom.PointI(int(x0 + xmax-1), int(y0 + ymax-1)))
subIm = afwImage.MaskedImageF(maskedImage, subBBox, afwImage.PARENT, False)
stats = afwMath.makeStatistics(subIm,
afwMath.MEAN | afwMath.MEANCLIP | afwMath.MEDIAN |
afwMath.NPOINT | afwMath.STDEV,
afwMath.MEAN | afwMath.MEANCLIP | afwMath.MEDIAN
| afwMath.NPOINT | afwMath.STDEV,
self.sctrl)
npoints, _ = stats.getResult(afwMath.NPOINT)
if npoints >= 2:
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/pipe/tasks/mergeDetections.py
Expand Up @@ -334,10 +334,10 @@ def cullPeaks(self, catalog):
familySize = len(oldPeaks)
totalPeaks += familySize
for rank, peak in enumerate(oldPeaks):
if ((rank < self.config.cullPeaks.rankSufficient) or
(sum([peak.get(k) for k in keys]) >= self.config.cullPeaks.nBandsSufficient) or
(rank < self.config.cullPeaks.rankConsidered and
rank < self.config.cullPeaks.rankNormalizedConsidered * familySize)):
if ((rank < self.config.cullPeaks.rankSufficient)
or (sum([peak.get(k) for k in keys]) >= self.config.cullPeaks.nBandsSufficient)
or (rank < self.config.cullPeaks.rankConsidered
and rank < self.config.cullPeaks.rankNormalizedConsidered * familySize)):
keptPeaks.append(peak)
else:
culledPeaks += 1
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/mergeMeasurements.py
Expand Up @@ -360,8 +360,8 @@ def run(self, catalogs):
if hasPseudoFilter:
bestRecord = priorityRecord
bestFlagKeys = priorityFlagKeys
elif (prioritySN < self.config.minSN and (maxSN - prioritySN) > self.config.minSNDiff and
maxSNRecord is not None):
elif (prioritySN < self.config.minSN and (maxSN - prioritySN) > self.config.minSNDiff
and maxSNRecord is not None):
bestRecord = maxSNRecord
bestFlagKeys = maxSNFlagKeys
elif priorityRecord is not None:
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/mocks/mockObservation.py
Expand Up @@ -173,8 +173,8 @@ def buildWcs(self, position, pa, detector):
"""
crval = position
pixelScale = (self.config.pixelScale * lsst.geom.arcseconds).asDegrees()
cd = (lsst.geom.LinearTransform.makeScaling(pixelScale) *
lsst.geom.LinearTransform.makeRotation(pa))
cd = (lsst.geom.LinearTransform.makeScaling(pixelScale)
* lsst.geom.LinearTransform.makeRotation(pa))
crpix = detector.transform(lsst.geom.Point2D(0, 0), FOCAL_PLANE, PIXELS)
wcs = lsst.afw.geom.makeSkyWcs(crpix=crpix, crval=crval, cdMatrix=cd.getMatrix())
return wcs
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/read_curated_calibs.py
Expand Up @@ -80,8 +80,8 @@ def check_metadata(obj, valid_start, instrument, chip_id, filepath, data_name):
finst = md['INSTRUME']
fchip_id = md['DETECTOR']
fdata_name = md['OBSTYPE']
if not ((finst.lower(), int(fchip_id), fdata_name) ==
(instrument.lower(), chip_id, data_name)):
if not ((finst.lower(), int(fchip_id), fdata_name)
== (instrument.lower(), chip_id, data_name)):
raise ValueError(f"Path and file metadata do not agree:\n"
f"Path metadata: {instrument} {chip_id} {data_name}\n"
f"File metadata: {finst} {fchip_id} {fdata_name}\n"
Expand Down