Skip to content

Commit

Permalink
Modernize the python code
Browse files Browse the repository at this point in the history
Use `from __future__ import absolute_import, division, print_function`
and check all existing use of division.
Fix flake8 warnings.
Note: one file uses two undefined variables; I will file a ticket.
  • Loading branch information
r-owen committed Feb 7, 2017
1 parent e22bb26 commit 331e3f4
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion python/lsst/obs/decam/decamCpIsr.py
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
#
# LSST Data Management System
#
Expand All @@ -21,6 +20,7 @@
# 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

from lsst.ip.isr import biasCorrection, flatCorrection
from lsst.meas.algorithms.detection import SourceDetectionTask
Expand Down
23 changes: 13 additions & 10 deletions python/lsst/obs/decam/decamMapper.py
@@ -1,4 +1,3 @@
from builtins import map
#
# LSST Data Management System
# Copyright 2012-2016 LSST Corporation.
Expand All @@ -20,9 +19,12 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import os
import re

import numpy as np

from lsst.utils import getPackageDir
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
Expand All @@ -40,14 +42,15 @@ class DecamMapper(CameraMapper):

MakeRawVisitInfoClass = MakeDecamRawVisitInfo

detectorNames = {1: 'S29', 2: 'S30', 3: 'S31', 4: 'S25', 5: 'S26', 6: 'S27', 7: 'S28', 8: 'S20', 9: 'S21',
10: 'S22', 11: 'S23', 12: 'S24', 13: 'S14', 14: 'S15', 15: 'S16', 16: 'S17', 17: 'S18',
18: 'S19', 19: 'S8', 20: 'S9', 21: 'S10', 22: 'S11', 23: 'S12', 24: 'S13', 25: 'S1', 26: 'S2',
27: 'S3', 28: 'S4', 29: 'S5', 30: 'S6', 31: 'S7', 32: 'N1', 33: 'N2', 34: 'N3', 35: 'N4',
36: 'N5', 37: 'N6', 38: 'N7', 39: 'N8', 40: 'N9', 41: 'N10', 42: 'N11', 43: 'N12', 44: 'N13',
45: 'N14', 46: 'N15', 47: 'N16', 48: 'N17', 49: 'N18', 50: 'N19', 51: 'N20', 52: 'N21',
53: 'N22', 54: 'N23', 55: 'N24', 56: 'N25', 57: 'N26', 58: 'N27', 59: 'N28', 60: 'N29',
62: 'N31'}
detectorNames = {
1: 'S29', 2: 'S30', 3: 'S31', 4: 'S25', 5: 'S26', 6: 'S27', 7: 'S28', 8: 'S20', 9: 'S21',
10: 'S22', 11: 'S23', 12: 'S24', 13: 'S14', 14: 'S15', 15: 'S16', 16: 'S17', 17: 'S18',
18: 'S19', 19: 'S8', 20: 'S9', 21: 'S10', 22: 'S11', 23: 'S12', 24: 'S13', 25: 'S1', 26: 'S2',
27: 'S3', 28: 'S4', 29: 'S5', 30: 'S6', 31: 'S7', 32: 'N1', 33: 'N2', 34: 'N3', 35: 'N4',
36: 'N5', 37: 'N6', 38: 'N7', 39: 'N8', 40: 'N9', 41: 'N10', 42: 'N11', 43: 'N12', 44: 'N13',
45: 'N14', 46: 'N15', 47: 'N16', 48: 'N17', 49: 'N18', 50: 'N19', 51: 'N20', 52: 'N21',
53: 'N22', 54: 'N23', 55: 'N24', 56: 'N25', 57: 'N26', 58: 'N27', 59: 'N28', 60: 'N29',
62: 'N31'}

def __init__(self, inputPolicy=None, **kwargs):
policyFile = pexPolicy.DefaultPolicyFile(self.packageName, "DecamMapper.paf", "policy")
Expand Down Expand Up @@ -165,7 +168,7 @@ def translate_dqmask(self, dqmask):
def translate_wtmap(self, wtmap):
wtmArr = wtmap.getArray()
idxUndefWeight = np.where(wtmArr <= 0)
#Reassign weights to be finite but small:
# Reassign weights to be finite but small:
wtmArr[idxUndefWeight] = min(1e-14, np.min(wtmArr[np.where(wtmArr > 0)]))
var = 1.0 / wtmArr
varim = afwImage.ImageF(var)
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/obs/decam/decamNullIsr.py
Expand Up @@ -20,6 +20,8 @@
# 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 lsst.pipe.base as pipeBase
import lsst.pex.config as pexConfig

Expand Down
14 changes: 10 additions & 4 deletions python/lsst/obs/decam/ingest.py
@@ -1,4 +1,3 @@
from builtins import zip
#
# LSST Data Management System
# Copyright 2012,2015 LSST Corporation.
Expand All @@ -20,8 +19,12 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import os
import re

from builtins import zip

import lsst.afw.image as afwImage
from lsst.pipe.tasks.ingest import ParseTask, IngestTask, IngestArgumentParser

Expand Down Expand Up @@ -56,11 +59,14 @@ def run(self, args):
fileInfo, hduInfoList = self.parse.getInfo(infile, args.filetype)
if len(hduInfoList) > 0:
outfileInstcal = os.path.join(root, self.parse.getDestination(args.butler,
hduInfoList[0], infile, "instcal"))
hduInfoList[0],
infile, "instcal"))
outfileDqmask = os.path.join(root, self.parse.getDestination(args.butler,
hduInfoList[0], infile, "dqmask"))
hduInfoList[0], infile,
"dqmask"))
outfileWtmap = os.path.join(root, self.parse.getDestination(args.butler,
hduInfoList[0], infile, "wtmap"))
hduInfoList[0], infile,
"wtmap"))

ingestedInstcal = self.ingest(fileInfo["instcal"], outfileInstcal,
mode=args.mode, dryrun=args.dryrun)
Expand Down
3 changes: 3 additions & 0 deletions python/lsst/obs/decam/ingestCalibs.py
@@ -1,5 +1,8 @@
from __future__ import absolute_import, division, print_function

import collections
import re

from lsst.pipe.tasks.ingestCalibs import CalibsParseTask


Expand Down
1 change: 1 addition & 0 deletions python/lsst/obs/decam/isr.py
Expand Up @@ -19,6 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function

import lsst.afw.geom as afwGeom
import lsst.afw.table as afwTable
Expand Down
3 changes: 3 additions & 0 deletions python/lsst/obs/decam/makeCamera.py
@@ -1,4 +1,7 @@
from __future__ import absolute_import, division, print_function

from builtins import range

import lsst.afw.geom as afwGeom
import lsst.afw.cameraGeom as cameraGeom

Expand Down
6 changes: 3 additions & 3 deletions python/lsst/obs/decam/selectDecamImages.py
Expand Up @@ -20,7 +20,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import print_function
from __future__ import absolute_import, division, print_function
from builtins import range
import MySQLdb
import os
Expand Down Expand Up @@ -163,7 +163,7 @@ def run(self, coordList, filter):
if not columnNames:
raise RuntimeError("Bug: no column names")
queryStr = "select %s " % (", ".join(columnNames),)
dataTuple = () # tuple(columnNames)
dataTuple = () # tuple(columnNames)

if coordList is not None:
# look for exposures that overlap the specified region
Expand All @@ -174,7 +174,7 @@ def run(self, coordList, filter):
coordStr = ", ".join(coordStrList)
coordCmd = "call scisql.scisql_s2CPolyRegion(scisql_s2CPolyToBin(%s), 10)" % (coordStr,)
cursor.execute(coordCmd)
cursor.nextset() # ignore one-line result of coordCmd
cursor.nextset() # ignore one-line result of coordCmd

queryStr += """
from %s as ccdExp,
Expand Down
3 changes: 2 additions & 1 deletion tests/testButler.py
@@ -1,4 +1,3 @@
from __future__ import print_function
#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
Expand All @@ -20,10 +19,12 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function

import os
import unittest
import warnings

import lsst.daf.persistence as dafPersist
import lsst.pex.exceptions as pexExcept
import lsst.utils.tests
Expand Down
3 changes: 2 additions & 1 deletion tests/testGetId.py
Expand Up @@ -19,10 +19,11 @@
# 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 unittest
import lsst.utils.tests

import lsst.utils.tests
import lsst.daf.persistence as dafPersist
from lsst.obs.decam import DecamMapper

Expand Down
2 changes: 1 addition & 1 deletion tests/testGetInstcal.py
@@ -1,4 +1,3 @@
from __future__ import print_function
#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
Expand All @@ -20,6 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function

import math
import os
Expand Down
1 change: 1 addition & 0 deletions tests/testGetRaw.py
Expand Up @@ -20,6 +20,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function

import math
import os
Expand Down
2 changes: 1 addition & 1 deletion tests/testProcessCcd.py
Expand Up @@ -19,7 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions tests/testWcsCards.py
Expand Up @@ -19,6 +19,7 @@
# 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 os
import unittest
Expand Down

0 comments on commit 331e3f4

Please sign in to comment.