Skip to content

Commit

Permalink
Merge pull request #119 from lsst/tickets/DM-14253
Browse files Browse the repository at this point in the history
DM-14253: Modernize python in meas_base and meas_algorithms
  • Loading branch information
r-owen committed May 3, 2018
2 parents 306a561 + 04672f3 commit 4b67208
Show file tree
Hide file tree
Showing 67 changed files with 278 additions and 431 deletions.
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
7 changes: 2 additions & 5 deletions examples/measAlgTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import print_function
from builtins import range
import os
import sys
import numpy as np
Expand Down Expand Up @@ -71,7 +69,7 @@ def run(display=False):
config = SingleFrameMeasurementTask.ConfigClass()

config.algorithms.names = ["base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux"]
config.algorithms["base_CircularApertureFlux"].radii = [1, 2, 4, 8, 16] # pixels
config.algorithms["base_CircularApertureFlux"].radii = [1, 2, 4, 8, 16] # pixels

config.slots.instFlux = None
config.slots.modelFlux = None
Expand Down Expand Up @@ -107,7 +105,6 @@ def run(display=False):
for i in range(s.get("flux.aperture.nProfile")):
ds9.dot('o', *xy, size=radii[i], ctype=ds9.YELLOW, frame=frame)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

if __name__ == "__main__":
import argparse
Expand All @@ -120,7 +117,7 @@ def run(display=False):

if args.debug:
try:
import debug
import debug # noqa F401
except ImportError as e:
print(e, file=sys.stderr)

Expand Down
1 change: 0 additions & 1 deletion examples/subtractBackgroundExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#
"""Example use of SubtractBackgroundTask
"""
from __future__ import absolute_import, division, print_function
import os.path

import lsst.utils
Expand Down
2 changes: 1 addition & 1 deletion lib/libmeas_algorithms.so-gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
if printerDir not in sys.path:
sys.path.append(printerDir)

import meas.algorithms.printers
import meas.algorithms.printers # noqa E402

meas.algorithms.printers.register(gdb.current_objfile())
13 changes: 4 additions & 9 deletions python/lsst/gdb/meas/algorithms/printers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from __future__ import print_function
from builtins import object
import gdb
import re
import sys

try:
import gdb.printing

class CRPixelPrinter(object):
class CRPixelPrinter:
"Print a CRPixel"

def __init__(self, val):
Expand All @@ -27,8 +24,6 @@ def register(obj):
for p in printers:
gdb.printing.register_pretty_printer(obj, p)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

def build_meas_algorithms_dictionary():
printer = gdb.printing.RegexpCollectionPrettyPrinter("meas_algorithms")

Expand All @@ -39,9 +34,9 @@ def build_meas_algorithms_dictionary():
printers.append(build_meas_algorithms_dictionary())

except ImportError as e:
def register(*args, **kwargs):
print("Your version of gdb is too old to load the meas.algorithms python pretty printers: %s" % (
e), file=sys.stderr)
def register(*args, exception=e, **kwargs):
print("Your version of gdb is too old to load the meas.algorithms python pretty printers: %s" %
(exception,), file=sys.stderr)
pass

pass
13 changes: 6 additions & 7 deletions python/lsst/meas/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#
#
# LSST Data Management System
#
# Copyright 2008-2017 AURA/LSST.
#
#
# 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 <https://www.lsstcorp.org/LegalNotices/>.
#
"""lsst.meas.algorithms
"""
from __future__ import absolute_import

import lsst.afw.image
import lsst.afw.math
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/meas/algorithms/astrometrySourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function

import numpy as np

Expand Down Expand Up @@ -124,7 +123,8 @@ def _hasCentroid_vector(self, sourceCat):
"""Return True for each source that has a valid centroid"""
def checkNonfiniteCentroid():
"""Return True for sources with non-finite centroids."""
return ~np.isfinite(sourceCat.get(self.centroidXKey)) | ~np.isfinite(sourceCat.get(self.centroidYKey))
return ~np.isfinite(sourceCat.get(self.centroidXKey)) | \
~np.isfinite(sourceCat.get(self.centroidYKey))
assert ~checkNonfiniteCentroid().any(), \
"Centroids not finite for %d unflagged sources." % (checkNonfiniteCentroid().sum())
return np.isfinite(sourceCat.get(self.centroidXSigmaKey)) \
Expand Down
13 changes: 6 additions & 7 deletions python/lsst/meas/algorithms/coaddPsf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
#
#
# LSST Data Management System
#
# Copyright 2008-2017 AURA/LSST.
#
#
# 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 <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import

from .coaddPsf import *
from .coaddPsfContinued import *
4 changes: 1 addition & 3 deletions python/lsst/meas/algorithms/coaddPsf/coaddPsfContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import

__all__ = ["CoaddPsfConfig"]

from lsst.utils import continueClass
from .coaddPsf import CoaddPsfControl
from lsst.pex.config import makeConfigClass

makeConfigClass(CoaddPsfControl, "CoaddPsfConfig")
CoaddPsfConfig = makeConfigClass(CoaddPsfControl, "CoaddPsfConfig")
12 changes: 6 additions & 6 deletions python/lsst/meas/algorithms/debugger.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#
#
# LSST Data Management System
#
# Copyright 2008-2017 AURA/LSST.
#
#
# 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 <https://www.lsstcorp.org/LegalNotices/>.
#
"""This is a useful module for debugging measurements.
Expand Down

0 comments on commit 4b67208

Please sign in to comment.