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

Merged
merged 15 commits into from
Nov 4, 2016
2 changes: 1 addition & 1 deletion bin.src/assembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--legacyCoadd', action='store_true', default=False)
parser.add_argument('-h','--help', action='store_true',default=False)
parser.add_argument('-h', '--help', action='store_true', default=False)
result, extra = parser.parse_known_args(sys.argv)

legacy_message = '''
Expand Down
23 changes: 13 additions & 10 deletions bin.src/dumpTaskMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#
"""Select images and report which tracts and patches they are in
"""
from __future__ import print_function
import collections
import itertools
import re
Expand All @@ -32,31 +33,32 @@
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase

__all__ = ["DumpTaskMetadataTask",]
__all__ = ["DumpTaskMetadataTask", ]


class DumpTaskMetadataConfig(pexConfig.Config):
"""Config for DumpTaskMetadataTask
"""
showTimingData = pexConfig.Field(dtype=bool, default=True,
doc = "Show timing data?")
doc="Show timing data?")


class DumpTaskMetadataTask(pipeBase.CmdLineTask):
"""Report which tracts and patches are needed for coaddition
"""
ConfigClass = DumpTaskMetadataConfig
_DefaultName = "DumpTaskMetadata"

@pipeBase.timeMethod
def run(self, dataRef):
"""Report task metadata
"""
print "%s for dataId=%s" % (dataRef.butlerSubset.datasetType, dataRef.dataId)
print("%s for dataId=%s" % (dataRef.butlerSubset.datasetType, dataRef.dataId))
TimerSuffixList = ("CpuTime", "InBlock", "MajFlt", "MaxRss",
"MinFlt", "NIvCsw", "NVCsw", "OuBlock", "STime", "UTime", "Utc")
"MinFlt", "NIvCsw", "NVCsw", "OuBlock", "STime", "UTime", "Utc")

taskMetadata = dataRef.get()
nameList = list(taskMetadata.names(False)) # hierarchical names
nameList = list(taskMetadata.names(False)) # hierarchical names
nameList.sort()
for name in nameList:
if not self.config.showTimingData:
Expand All @@ -67,20 +69,21 @@ def run(self, dataRef):
if isinstance(data, dafBase.PropertySet):
# this same data will come up again in nameList
continue
print "%s %s" % (name, data)
print("%s %s" % (name, data))

@classmethod
def _makeArgumentParser(cls):
"""Create an argument parser
"""
return pipeBase.InputOnlyArgumentParser(name=cls._DefaultName,
datasetType=pipeBase.DatasetArgument(help="dataset type for task metadata"))

datasetType=pipeBase.DatasetArgument(
help="dataset type for task metadata"))

def _getConfigName(self):
"""Don't persist config, so return None
"""
return None

def _getMetadataName(self):
"""Don't persist metadata, so return None
"""
Expand Down
67 changes: 34 additions & 33 deletions bin.src/reportImagesInPatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#
"""Select images for a given coadd patch
"""
from __future__ import print_function
import numpy

import lsst.pex.config as pexConfig
Expand All @@ -31,19 +32,20 @@
from lsst.pipe.tasks.makeSkyMap import MakeSkyMapTask
from lsst.pipe.tasks.selectImages import WcsSelectImagesTask

__all__ = ["ReportImagesInPatchTask",]
__all__ = ["ReportImagesInPatchTask", ]


class ReportImagesInPatchConfig(pexConfig.Config):
"""Config for ReportImagesInPatchTask
"""
coaddName = pexConfig.Field(
doc = "coadd name: one of deep or goodSeeing",
dtype = str,
default = "deep",
doc="coadd name: one of deep or goodSeeing",
dtype=str,
default="deep",
)
select = pexConfig.ConfigurableField(
doc = "image selection subtask",
target = WcsSelectImagesTask,
doc="image selection subtask",
target=WcsSelectImagesTask,
)


Expand All @@ -52,17 +54,17 @@ class ReportImagesInPatchTask(pipeBase.CmdLineTask):
"""
ConfigClass = ReportImagesInPatchConfig
_DefaultName = "reportImagesInPatch"

def __init__(self, *args, **kwargs):
pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
self.makeSubtask("select")

@pipeBase.timeMethod
def run(self, patchRef):
"""Select images for a region and report how many are in each tract and patch
Also report quartiles of FWHM

Also report quartiles of FWHM

@param patchRef: data reference for coadd patch.
@return: a pipeBase.Struct with fields:
- exposureInfoList: a list of exposure info objects, as returned by the select subtask
Expand All @@ -80,44 +82,42 @@ def run(self, patchRef):
skyPosList = [coord.getPosition(afwGeom.degrees) for coord in coordList]
skyPosStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
skyPosStr = ", ".join(skyPosStrList)
print "PatchId=%s; corner RA/Dec (deg)=%s" % (patchRef.dataId, skyPosStr)
print("PatchId=%s; corner RA/Dec (deg)=%s" % (patchRef.dataId, skyPosStr))

exposureInfoList = self.select.runDataRef(
dataRef = patchRef,
coordList = coordList,
makeDataRefList = False,
dataRef=patchRef,
coordList=coordList,
makeDataRefList=False,
).exposureInfoList
print "Found %d suitable exposures" % (len(exposureInfoList),)

print("Found %d suitable exposures" % (len(exposureInfoList),))
if len(exposureInfoList) < 1:
return

fwhmList = [exposureInfo.fwhm for exposureInfo in exposureInfoList]
fwhmList = numpy.array(fwhmList, dtype=float)
print "FWHM Q1=%0.2f Q2=%0.2f Q3=%0.2f" % (
print("FWHM Q1=%0.2f Q2=%0.2f Q3=%0.2f" % (
numpy.percentile(fwhmList, 25.0),
numpy.percentile(fwhmList, 50.0),
numpy.percentile(fwhmList, 75.0),
)
print "Image IDs:"
))

print("Image IDs:")
if len(exposureInfoList) > 0:
idKeys = sorted(exposureInfoList[0].dataId.keys())
for exposureInfo in exposureInfoList:
idStr = " ".join("%s=%s" % (key, exposureInfo.dataId[key]) for key in idKeys)
skyPosList = [coord.getPosition(afwGeom.degrees) for coord in exposureInfo.coordList]
skyPosStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
skyPosStr = ", ".join(skyPosStrList)
print "dataId=%s; corner RA/Dec (deg)=%s" % (idStr, skyPosStr)

return pipeBase.Struct(
exposureInfoList = exposureInfoList,
)
print("dataId=%s; corner RA/Dec (deg)=%s" % (idStr, skyPosStr))

return pipeBase.Struct(exposureInfoList=exposureInfoList)

@classmethod
def _makeArgumentParser(cls):
"""Create an argument parser

Use datasetType="deepCoadd" to get the right keys (even chi-squared coadds
need filter information for this particular task).
"""
Expand All @@ -130,34 +130,35 @@ def _getConfigName(self):
"""Don't persist config, so return None
"""
return None

def _getMetadataName(self):
"""Don't persist metadata, so return None
"""
return None


class ReportImagesInPatchDataIdContainer(pipeBase.DataIdContainer):
"""A version of lsst.pipe.base.DataIdContainer specialized for reporting images.

Required because butler.subset cannot handle this dataset type.
"""

def makeDataRefList(self, namespace):
"""Make self.refList from self.idList"""
datasetType = namespace.config.coaddName + "Coadd"

for dataId in self.idList:
dataRef = namespace.butler.dataRef(
datasetType = datasetType,
dataId = dataId,
datasetType=datasetType,
dataId=dataId,
)
self.refList.append(dataRef)


def _getBox2DCorners(bbox):
"""Return the four corners of a bounding box (Box2I or Box2D) as four afwGeom Point2D
"""
bbox = afwGeom.Box2D(bbox) # mak
bbox = afwGeom.Box2D(bbox) # mak
return (
bbox.getMin(),
afwGeom.Point2D(bbox.getMaxX(), bbox.getMinY()),
Expand Down