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-7261: Port to Python 3 #3

Merged
merged 8 commits into from
Aug 20, 2016
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_build.*
.sconsign.dblite
config.log
.sconf_temp
Expand All @@ -14,6 +15,8 @@ doc/html
doc/*.tag
doc/*.inc
doc/doxygen.conf
doc/xml
Copy link
Member Author

Choose a reason for hiding this comment

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

Also tests/.cache I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I should add that. Oddly enough when I run py.test I don't see this; I'm not sure why

tests/.tests
tests/.cache
version.py

47 changes: 24 additions & 23 deletions examples/makeNoiseCoadd.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
#!/usr/bin/env python

#
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import with_statement
"""Make a coadd from gaussian noise images
"""
from __future__ import print_function
Copy link
Member Author

Choose a reason for hiding this comment

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

We usually put the __future__ lines before other imports.

import os
import sys

import numpy
from builtins import range
import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.image.testUtils as afwTestUtils
import lsst.coadd.chisquared as coaddChiSq
from noiseCoaddConfig import NoiseCoaddConfig

if __name__ == "__main__":
# pexLog.Trace.setVerbosity('lsst.coadd', 5)
# pexLog.Trace.setVerbosity('lsst.coadd', 5)
helpStr = """Usage: makeCoadd.py coaddPath numImages

where:
Expand All @@ -48,12 +49,12 @@
Run the resulting coadd through makeHistogram to see this.
"""
if len(sys.argv) != 3:
print helpStr
print(helpStr)
sys.exit(0)

coaddPath = sys.argv[1]
weightPath = os.path.splitext(coaddPath)[0] + "_weight.fits"

numImages = int(sys.argv[2])

config = NoiseCoaddConfig()
Expand All @@ -65,31 +66,31 @@
imageSigma = %0.1f
variance = %0.1f
""" % (coaddPath, numImages, config.imageShape, config.imageSigma, config.variance))
numpy.random.seed(0)

np.random.seed(0)

coadd = None
for imInd in range(numImages):
print >> sys.stderr, "Create exposure %d" % (imInd,)
print("Create exposure %d" % (imInd,), file=sys.stderr)
maskedImage = afwTestUtils.makeGaussianNoiseMaskedImage(
dimensions=config.imageShape, sigma=config.imageSigma, variance=config.variance)
# the WCS doesn't matter; the default will do
wcs = afwImage.Wcs()
exposure = afwImage.ExposureF(maskedImage, wcs)

if not coadd:
print >> sys.stderr, "Create coadd"
print("Create coadd", file=sys.stderr)
coadd = coaddChiSq.Coadd.fromConfig(
bbox = exposure.getBBox(),
wcs = exposure.getWcs(),
config = config.coadd)
print >> sys.stderr, "badPixelMask=", coadd.getBadPixelMask()
bbox=exposure.getBBox(),
wcs=exposure.getWcs(),
config=config.coadd)
print("badPixelMask=", coadd.getBadPixelMask(), file=sys.stderr)

coadd.addExposure(exposure)

print >> sys.stderr, "Save weight map as %s" % (weightPath,)
print("Save weight map as %s" % (weightPath,), file=sys.stderr)
weightMap = coadd.getWeightMap()
weightMap.writeFits(weightPath)
coaddExposure = coadd.getCoadd()
print >> sys.stderr, "Save coadd as %s" % (coaddPath,)
print("Save coadd as %s" % (coaddPath,), file=sys.stderr)
coaddExposure.writeFits(coaddPath)
75 changes: 38 additions & 37 deletions examples/makeWarpedNoiseCoadd.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#!/usr/bin/env python

#
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import with_statement
"""Make a coadd from warped gaussian noise images
"""
from __future__ import print_function
import os
import sys
import traceback

import numpy
import numpy as np

import lsst.pex.logging as pexLog
import lsst.afw.image as afwImage
Expand Down Expand Up @@ -59,15 +59,15 @@
The intent is to see how correlated noise affects the statistics of a pure noise coadd.
"""
if len(sys.argv) != 3:
print helpStr
print(helpStr)
sys.exit(0)

coaddPath = sys.argv[1]
if os.path.exists(coaddPath):
print >> sys.stderr, "Coadd file %s already exists" % (coaddPath,)
print("Coadd file %s already exists" % (coaddPath,), file=sys.stderr)
sys.exit(1)
weightPath = os.path.splitext(coaddPath)[0] + "_weight.fits"

indata = sys.argv[2]

config = NoiseCoaddConfig()
Expand All @@ -78,8 +78,8 @@
variance = %0.1f
saveDebugImages = %s
""" % (coaddPath, config.imageSigma, config.variance, config.saveDebugImages))
numpy.random.seed(0)

np.random.seed(0)

# process exposures
coadd = None
Expand All @@ -93,55 +93,56 @@
continue
exposurePath = line
expNum += 1

try:
print >> sys.stderr, "Processing exposure %s" % (exposurePath,)
print("Processing exposure %s" % (exposurePath,), file=sys.stderr)
inputExposure = afwImage.ExposureF(exposurePath)
print >> sys.stderr, "Create Gaussian noise exposure"

print("Create Gaussian noise exposure", file=sys.stderr)
maskedImage = afwTestUtils.makeGaussianNoiseMaskedImage(
dimensions = inputExposure.getDimensions(),
sigma = config.imageSigma,
variance = config.variance,
dimensions=inputExposure.getDimensions(),
sigma=config.imageSigma,
variance=config.variance,
)
exposure = afwImage.ExposureF(maskedImage, inputExposure.getWcs())

if config.saveDebugImages:
exposure.writeFits("exposure%d.fits" % (expNum,))

if not coadd:
print >> sys.stderr, "Create warper and coadd with size and WCS matching the first exposure"
print("Create warper and coadd with size and WCS matching the first exposure",
file=sys.stderr)
warper = afwMath.Warper.fromConfig(config.warp)
coadd = coaddChiSq.Coadd.fromConfig(
bbox = exposure.getBBox(),
wcs = exposure.getWcs(),
config = config.coadd,
bbox=exposure.getBBox(),
wcs=exposure.getWcs(),
config=config.coadd,
)
print >> sys.stderr, "badPixelMask=", coadd.getBadPixelMask()
print("badPixelMask=", coadd.getBadPixelMask(), file=sys.stderr)

coadd.addExposure(exposure)
else:
print >> sys.stderr, "Warp exposure"
print("Warp exposure", file=sys.stderr)
warpedExposure = warper.warpExposure(
destWcs = coadd.getWcs(),
srcExposure = exposure,
maxBBox = coadd.getBBox(),
destWcs=coadd.getWcs(),
srcExposure=exposure,
maxBBox=coadd.getBBox(),
)

coadd.addExposure(warpedExposure)

if config.saveDebugImages:
warpedExposure.writeFits("warped%d.fits" % (expNum,))

numExposuresInCoadd += 1
except Exception, e:
print >> sys.stderr, "Exposure %s failed: %s" % (exposurePath, e)
except Exception as e:
print("Exposure %s failed: %s" % (exposurePath, e), file=sys.stderr)
if os.path.exists(exposurePath):
traceback.print_exc(file=sys.stderr)
numExposuresFailed += 1
continue

print >> sys.stderr, "Coadded %d exposures and failed %d" % (numExposuresInCoadd, numExposuresFailed)
print("Coadded %d exposures and failed %d" % (numExposuresInCoadd, numExposuresFailed), file=sys.stderr)
weightMap = coadd.getWeightMap()
weightMap.writeFits(weightPath)
coaddExposure = coadd.getCoadd()
Expand Down
47 changes: 24 additions & 23 deletions examples/noiseCoaddConfig.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/usr/bin/env python

#
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
"""Config for making coadds of images of pure noise
Expand All @@ -27,33 +27,34 @@
import lsst.afw.math as afwMath
import lsst.coadd.chisquared as coaddChiSq


class NoiseCoaddConfig(pexConfig.Config):
saveDebugImages = pexConfig.Field(
dtype = bool,
doc = "Save warped intermediate images?",
default = False,
dtype=bool,
doc="Save warped intermediate images?",
default=False,
)
imageShape = pexConfig.ListField(
dtype = int,
doc = "Constant value of variance pixels",
length = 2,
default = (256, 256),
dtype=int,
doc="Constant value of variance pixels",
length=2,
default=(256, 256),
)
imageSigma = pexConfig.Field(
dtype = float,
doc = "Sigma of Gaussian noise for image pixels",
default = 1.0,
dtype=float,
doc="Sigma of Gaussian noise for image pixels",
default=1.0,
)
variance = pexConfig.Field(
dtype = float,
doc = "Constant value of variance pixels",
default = 1.0,
dtype=float,
doc="Constant value of variance pixels",
default=1.0,
)
warp = pexConfig.ConfigField(
dtype = afwMath.Warper.ConfigClass,
doc = "Policy to control warping.",
dtype=afwMath.Warper.ConfigClass,
doc="Policy to control warping.",
)
coadd = pexConfig.ConfigField(
dtype = coaddChiSq.Coadd.ConfigClass,
doc = "Policy to control coadd.",
dtype=coaddChiSq.Coadd.ConfigClass,
doc="Policy to control coadd.",
)