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-14001: Make afw pep8 compliant and enable auto testing #341

Merged
merged 8 commits into from
Apr 5, 2018
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
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sudo: false
language: python
matrix:
include:
- python: '3.6'
install:
- pip install flake8
script: flake8
5 changes: 2 additions & 3 deletions bin.src/showCamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
import argparse

parser = argparse.ArgumentParser(description='Show the layout of CCDs in a camera.',
epilog=
'The corresponding obs-package must be setup (e.g. obs_decam ' +
epilog='The corresponding obs-package must be setup (e.g. obs_decam ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the + needed? (I know you didn't add it).

'if you want to see DECam)'
)
parser.add_argument(
Expand All @@ -52,7 +51,7 @@

try:
__import__(obsPackageName)
except:
except Exception:
print("Unable to import %s -- is it setup?" %
(obsPackageName,), file=sys.stderr)
sys.exit(1)
Expand Down
12 changes: 1 addition & 11 deletions doc/doxygen.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@ EXAMPLE_PATH = examples
INPUT += examples/imageDisplay.ipynb
EXCLUDE += include/lsst/afw/detection/FootprintArray.cc
EXCLUDE += include/lsst/afw/detection/detail/dgPsf.cc
EXCLUDE += src/math/Stack.cc
EXCLUDE += src/image/Utils.cc
EXCLUDE += src/image/TanWcs.cc
EXCLUDE += src/math/FunctionLibrary.cc
EXCLUDE += src/table
EXCLUDE += src/geom
EXCLUDE += src/geom/ellipses
EXCLUDE += src/detection/Psf.cc
EXCLUDE += src/detection/DoubleGaussianPsf.cc
EXCLUDE += src/fits.cc
EXCLUDE += src/fitsCompression.cc
EXCLUDE_PATTERNS += */src/*/*.cc
EXCLUDE_SYMBOLS += _swig_property
1 change: 0 additions & 1 deletion doc/imageAlgorithm.dox
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace lsst { namespace afw { namespace image {
/**
\page afwSecImageAlgorithm How to use algorithms to manipulate Images
\section afwSecImageAlgorithm How to use algorithms to manipulate Images

All of these algorithms require the inclusion of <TT>lsst/afw/image/ImageAlgorithm.h</TT>, and are in namespace @c lsst::afw::image.

Expand Down
1 change: 0 additions & 1 deletion doc/imageDisplay.dox
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace lsst { namespace afw { namespace image {
/**
\page afwSecDisplay How to display images
\section afwSecDisplay How to display images

- \ref afwSecImageDisplay
- \ref afwSecImageTypes
Expand Down
2 changes: 1 addition & 1 deletion doc/imagePython.dox
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace lsst { namespace afw { namespace image {
/**
\page afwSecPyImage How to manipulate images from python
\page afwSecPyImagePage How to manipulate images from python
\section afwSecPyImage How to manipulate images from python

You can use the C++ APIs to manipulate images and bits of images from python, e.g.
Expand Down
6 changes: 2 additions & 4 deletions doc/mainpage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ by an image processing system. In particular:

namespace lsst { namespace afw { namespace image {
/**
\page afwSecImage Images
\page afwSecImagePage Images

\section afwSecImage Images

Expand Down Expand Up @@ -213,7 +213,7 @@ previous APIs)

namespace lsst { namespace afw { namespace image {
/**
\page afwSecImageIO Image I/O
\page afwSecImageIOPage Image/Mask/MaskedImage I/O
\section afwSecImageIO Image/Mask/MaskedImage I/O

Reading Image%s, Mask%s, and MaskedImage%s from FITS files is achieved via their
Expand Down Expand Up @@ -288,7 +288,6 @@ but \b not possible to read it back from a non-default HDU.
namespace lsst { namespace afw { namespace math {
/**
\page afwSecMath Mathematical Operations
\section afwSecMath Mathematical Operations

- Statistics.
Annotated examples are available for \link StatisticsExample Statistics\endlink.
Expand All @@ -308,7 +307,6 @@ Annotated examples are available for \link BackgroundExample Background Estimati
namespace lsst { namespace afw { namespace detection {
/**
\page afwSecDetection Detection
\section afwSecDetection Detection

Detected pixels are manipulated using the following classes:
- Footprint : A set of pixels above (or below) a Threshold
Expand Down
4 changes: 0 additions & 4 deletions examples/ellipsePixelRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ def main():
transX = mgt[0, 0] * allX + mgt[0, 1] * allY + mgt[0, 2]
transY = mgt[1, 0] * allX + mgt[1, 1] * allY + mgt[1, 2]
allR = (transX**2 + transY**2)**0.5
for span in region:
for point in span:
transPoint = gt(lsst.afw.geom.Point2D(point))
r = (transPoint.getX()**2 + transPoint.getY()**2)**0.5
pyplot.plot(ellX, ellY, 'ro', markeredgewidth=0, alpha=0.5)
pyplot.plot(allX[allR < 1], allY[allR < 1], '+')
pyplot.plot(allX[allR > 1], allY[allR > 1], 'x')
Expand Down
5 changes: 0 additions & 5 deletions examples/estimateBackground.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def simpleBackground(image):

bkgd = afwMath.makeBackground(image, bctrl)

statsImage = bkgd.getStatsImage()

image -= bkgd.getImageF(afwMath.Interpolate.NATURAL_SPLINE)

return bkgd
Expand Down Expand Up @@ -82,9 +80,6 @@ def complexBackground(image):
statsImage = bkgd.getStatsImage()
ds9.mtv(statsImage.getVariance())

bkdgImages = dict(SPLINE = bkgd.getImageF(afwMath.Interpolate.NATURAL_SPLINE),
LINEAR = bkgd.getImageF(afwMath.Interpolate.LINEAR))

return bkgd


Expand Down
10 changes: 5 additions & 5 deletions examples/statisticsNaN.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def main():
inImage = afwImage.ImageF(afwGeom.Extent2I(100, 100))
inImage.set(1)
if disp:
ds9.mtv(inImage, frame = 0)
ds9.mtv(inImage, frame=0)

# works
outImage = afwImage.ImageF(afwGeom.Extent2I(100, 100))
afwMath.convolve(outImage, inImage, gaussKernel, False, True)
if disp:
ds9.mtv(outImage, frame = 1)
ds9.mtv(outImage, frame=1)
print("Should be a number: ", afwMath.makeStatistics(
outImage, afwMath.MEAN).getValue())
print("Should be a number: ", afwMath.makeStatistics(
Expand All @@ -59,7 +59,7 @@ def main():
outImage = afwImage.ImageF(afwGeom.Extent2I(100, 100))
afwMath.convolve(outImage, inImage, gaussKernel, False, False)
if disp:
ds9.mtv(outImage, frame = 2)
ds9.mtv(outImage, frame=2)
print("Should be a number: ", afwMath.makeStatistics(
outImage, afwMath.MEAN).getValue())
print("Should be a number: ", afwMath.makeStatistics(
Expand All @@ -68,8 +68,8 @@ def main():
# This will print nan
sctrl = afwMath.StatisticsControl()
sctrl.setNanSafe(False)
print ("Should be a nan (nanSafe set to False): " +
str(afwMath.makeStatistics(outImage, afwMath.MEAN, sctrl).getValue()))
print("Should be a nan (nanSafe set to False): " +
str(afwMath.makeStatistics(outImage, afwMath.MEAN, sctrl).getValue()))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions examples/timeLeastSquares.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import numpy
from matplotlib import pyplot
from lsst.afw.math import LeastSquares
from lsst.afw.math import LeastSquares # noqa F401

nDataList = 2**numpy.arange(4, 14, 2, dtype=int)
dimensionList = 2**numpy.arange(1, 8, dtype=int)
Expand Down Expand Up @@ -37,7 +37,7 @@ def run(number=10):
for j, dimension in enumerate(dimensionList):
if dimension <= nData:
results[method][i, j] = timeit.timeit(statement % method, setup % (nData, dimension),
number = number) / number
number=number) / number
progress += 1
else:
results[method][i, j] = float("NaN")
Expand Down
14 changes: 7 additions & 7 deletions examples/timeWarpExposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ def run():
interpLength,
)
destWcs = makeWcs(
projName = "TAN",
destCtrInd = destCtrInd,
skyOffset = skyOffset,
rotAng = rotAng,
scaleFac = scaleFac,
srcWcs = srcWcs,
srcCtrInd = srcCtrInd,
projName="TAN",
destCtrInd=destCtrInd,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@r-owen r-owen Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the original version did not pass flake8 linter using our standard published flake8 configuration, which had fewer things disabled than my own settings. Sigh. I wish our standard was at least optional, but as it stands there is no simple way to reconcile our published list of flake8 ignores and our style guide. I filed RFC-471

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do think we should use PEP8 here. I don't understand the motivation for the space. It seems to me that if you have a longish line, and then add a new keyword and have to go on a new line, that you suddenly need to add spaces everywhere.

skyOffset=skyOffset,
rotAng=rotAng,
scaleFac=scaleFac,
srcWcs=srcWcs,
srcCtrInd=srcCtrInd,
)
destExposure.setWcs(destWcs)
dTime, nIter, goodPix = timeWarp(
Expand Down
2 changes: 1 addition & 1 deletion examples/warpExposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():
help="kernel type: bilinear or lancszosN where N = order; default=%s" % (DefKernel,))
parser.add_option("-v", "--verbosity",
type=int, default=DefVerbosity,
help="verbosity of diagnostic trace messages; 1 for just TRACE1, more for more" +
help="verbosity of diagnostic trace messages; 1 for just TRACE1, more for more"
" information; default=%s" % (DefVerbosity,))

(opt, args) = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/afw/image/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Filter {
* @param metadata Metadata to process (e.g. a IFITS header)
* @param force Allow us to construct an unknown Filter
*/
explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const>, bool const force = false);
explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const> metadata, bool const force = false);

Filter(Filter const&) = default;
Filter(Filter&&) = default;
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/afw/math/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Random {
* @throws lsst::pex::exceptions::InvalidParameterError
* Thrown if the requested algorithm is not supported.
*/
void initialize(std::string const &);
void initialize(std::string const & algorithm);
};

/*
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/afw/math/detail/Convolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage, lsst::afw
template <typename OutImageT, typename InImageT>
void basicConvolve(OutImageT& convolvedImage, InImageT const& inImage,
lsst::afw::math::DeltaFunctionKernel const& kernel,
lsst::afw::math::ConvolutionControl const&);
lsst::afw::math::ConvolutionControl const& convolutionControl);

/**
* A version of basicConvolve that should be used when convolving a LinearCombinationKernel
Expand Down
3 changes: 2 additions & 1 deletion lib/libafw.so-gdb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os, os.path, sys
import os
import sys
import lsst.utils
import gdb
#
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/afw/cameraGeom/assembleImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def assembleAmplifierImage(destImage, rawImage, amplifier):
"""
if not amplifier.getHasRawInfo():
raise RuntimeError("amplifier must contain raw amplifier info")
if type(destImage.Factory) != type(rawImage.Factory):
if type(destImage.Factory) != type(rawImage.Factory): # noqa E721
raise RuntimeError("destImage type = %s != %s = rawImage type" %
type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
inView = rawImage.Factory(rawImage, amplifier.getRawDataBBox())
Expand All @@ -95,7 +95,7 @@ def assembleAmplifierRawImage(destImage, rawImage, amplifier):
"""
if not amplifier.getHasRawInfo():
raise RuntimeError("amplifier must contain raw amplifier info")
if type(destImage.Factory) != type(rawImage.Factory):
if type(destImage.Factory) != type(rawImage.Factory): # noqa E721
raise RuntimeError("destImage type = %s != %s = rawImage type" %
type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
inBBox = amplifier.getRawBBox()
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/cameraGeom/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class Camera(DetectorCollection):
"""!A collection of Detectors plus additional coordinate system support

Camera.transform transforms points from one camera coordinate system to another.

Camera.getTransform returns a transform between camera coordinate systems.
Expand Down
14 changes: 7 additions & 7 deletions python/lsst/afw/cameraGeom/cameraConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class DetectorConfig(pexConfig.Config):
"x offset from the origin of the camera in mm in the transposed system.", float)
offset_y = pexConfig.Field(
"y offset from the origin of the camera in mm in the transposed system.", float)
refpos_x = pexConfig.Field("x position of the reference point in the detector in pixels " +
refpos_x = pexConfig.Field("x position of the reference point in the detector in pixels "
"in transposed coordinates.", float)
refpos_y = pexConfig.Field("y position of the reference point in the detector in pixels " +
refpos_y = pexConfig.Field("y position of the reference point in the detector in pixels "
"in transposed coordinates.", float)
yawDeg = pexConfig.Field("yaw (rotation about z) of the detector in degrees. " +
"This includes any necessary rotation to go from " +
"detector coordinates to camera coordinates " +
yawDeg = pexConfig.Field("yaw (rotation about z) of the detector in degrees. "
"This includes any necessary rotation to go from "
"detector coordinates to camera coordinates "
"after optional transposition.", float)
pitchDeg = pexConfig.Field(
"pitch (rotation about y) of the detector in degrees", float)
Expand All @@ -59,8 +59,8 @@ def getCrosstalk(self, numAmps):
return None
try:
return np.array(self.crosstalk, dtype=np.float32).reshape((numAmps, numAmps))
except:
raise RuntimeError("Cannot reshape 'crosstalk' coefficients to square matrix")
except Exception as e:
raise RuntimeError("Cannot reshape 'crosstalk' coefficients to square matrix: %s" % (e,))


class CameraConfig(pexConfig.Config):
Expand Down
14 changes: 7 additions & 7 deletions python/lsst/afw/cameraGeom/cameraFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToField):

tanPixSys = CameraSys(TAN_PIXELS, detectorConfig.name)
transforms[tanPixSys] = makePixelToTanPixel(
bbox = bbox,
orientation = orientation,
focalPlaneToField = focalPlaneToField,
pixelSizeMm = pixelSizeMm,
bbox=bbox,
orientation=orientation,
focalPlaneToField=focalPlaneToField,
pixelSizeMm=pixelSizeMm,
)

args = [
Expand Down Expand Up @@ -154,9 +154,9 @@ def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict,
ampInfoCatalog = ampInfoCatDict[detectorConfig.name]

detectorList.append(makeDetector(
detectorConfig = detectorConfig,
ampInfoCatalog = ampInfoCatalog,
focalPlaneToField = focalPlaneToField,
detectorConfig=detectorConfig,
ampInfoCatalog=ampInfoCatalog,
focalPlaneToField=focalPlaneToField,
))

return Camera(cameraConfig.name, detectorList, transformMap, pupilFactoryClass)
8 changes: 4 additions & 4 deletions python/lsst/afw/cameraGeom/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def __init__(self,
0.0, self.radialDistortion/pScaleRad]
focalPlaneToField = afwGeom.makeRadialTransform(radialDistortCoeffs)
pixelToTanPixel = makePixelToTanPixel(
bbox = self.bbox,
orientation = self.orientation,
focalPlaneToField = focalPlaneToField,
pixelSizeMm = self.pixelSize,
bbox=self.bbox,
orientation=self.orientation,
focalPlaneToField=focalPlaneToField,
pixelSizeMm=self.pixelSize,
)

self.transMap = {
Expand Down
12 changes: 6 additions & 6 deletions python/lsst/afw/cameraGeom/transformConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class TransformMapConfig(pexConfig.Config):
transforms = pexConfig.ConfigDictField(
doc = "Dict of coordinate system name: TransformConfig",
keytype = str,
itemtype = TransformConfig,
doc="Dict of coordinate system name: TransformConfig",
keytype=str,
itemtype=TransformConfig,
)
nativeSys = pexConfig.Field(
doc = "Name of reference coordinate system",
dtype = str,
optional = False,
doc="Name of reference coordinate system",
dtype=str,
optional=False,
)
2 changes: 1 addition & 1 deletion python/lsst/afw/cameraGeom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def plotFocalPlane(camera, fieldSizeDeg_x=0, fieldSizeDeg_y=None, dx=0.1, dy=0.1


def makeImageFromAmp(amp, imValue=None, imageFactory=afwImage.ImageU, markSize=10, markValue=0,
scaleGain = lambda gain: (gain*1000)//10):
scaleGain=lambda gain: (gain*1000)//10):
"""!Make an image from an amp object

Since images are integer images by default, the gain needs to be scaled to give enough dynamic range
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/afw/detection/footprintMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def getMergedSourceCatalog(self, catalogs, filters,
# if peak is not an array, create an array the size of catalogs
try:
len(samePeakDist)
except:
except TypeError:
samePeakDist = [samePeakDist] * len(catalogs)

try:
len(peakDist)
except:
except TypeError:
peakDist = [peakDist] * len(catalogs)

if len(peakDist) != len(catalogs):
Expand Down