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-14842: Fix deprecation warnings from PropertyList/Set.get #96

Merged
merged 5 commits into from
Jun 22, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ config.log
*_wrap.cc
*Lib.py
.cache
.pytest_cache
.coverage
doc/html
doc/*.tag
doc/*.inc
Expand Down
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
1 change: 0 additions & 1 deletion python/lsst/obs/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down
4 changes: 1 addition & 3 deletions python/lsst/obs/base/butler_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function
from future.utils import with_metaclass
#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
Expand Down Expand Up @@ -29,7 +27,7 @@
__all__ = ["ButlerGetTests"]


class ButlerGetTests(with_metaclass(abc.ABCMeta)):
class ButlerGetTests(metaclass=abc.ABCMeta):
"""
Tests of obs_* Butler get() functionality.

Expand Down
7 changes: 3 additions & 4 deletions python/lsst/obs/base/cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from builtins import str
import copy
import os
import pyfits # required by _makeDefectsDict until defects are written as AFW tables
Expand Down Expand Up @@ -495,7 +494,7 @@ def querySubClosure(key, format, dataId, mapping=mapping):
setMethods("len", bypassImpl=lambda datasetType, pythonType, location, dataId:
readMetadata(os.path.join(location.getStorage().root,
location.getLocations()[0]),
hdu=1).get("NAXIS2"))
hdu=1).getScalar("NAXIS2"))

# Schema of catalog
if not datasetType.endswith("_schema") and datasetType + "_schema" not in datasets:
Expand Down Expand Up @@ -895,7 +894,7 @@ def search(filename, description):
try:
self.log.info("Loading Posix %s registry from %s", description, storage.root)
registry = dafPersist.PosixRegistry(storage.root)
except:
except Exception:
registry = None

return registry
Expand Down Expand Up @@ -1220,7 +1219,7 @@ def getImageCompressionSettings(self, datasetType, dataId):
recipe = self._writeRecipes[storageType][recipeName].deepCopy()
seed = hash(tuple(dataId.items())) % 2**31
for plane in ("image", "mask", "variance"):
if recipe.exists(plane + ".scaling.seed") and recipe.get(plane + ".scaling.seed") == 0:
if recipe.exists(plane + ".scaling.seed") and recipe.getScalar(plane + ".scaling.seed") == 0:
recipe.set(plane + ".scaling.seed", seed)
return recipe

Expand Down
4 changes: 1 addition & 3 deletions python/lsst/obs/base/camera_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function
from future.utils import with_metaclass
#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
Expand Down Expand Up @@ -31,7 +29,7 @@
__all__ = ["CameraTests"]


class CameraTests(with_metaclass(abc.ABCMeta)):
class CameraTests(metaclass=abc.ABCMeta):
"""
Tests that the butler returns a useable Camera.

Expand Down
1 change: 0 additions & 1 deletion python/lsst/obs/base/exposureIdInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from builtins import object
from past.builtins import long

__all__ = ["ExposureIdInfo"]
Expand Down
11 changes: 4 additions & 7 deletions python/lsst/obs/base/makeRawVisitInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
import numpy as np

Expand Down Expand Up @@ -215,14 +212,14 @@ def popItem(self, md, key, default=None):
Returns
-------
`object`
The value of the specified key, using whatever type md.get(key)
The value of the specified key, using whatever type md.getScalar(key)
returns.
"""
try:
if not md.exists(key):
self.log.warn("Key=\"{}\" not in metadata".format(key))
return default
val = md.get(key)
val = md.getScalar(key)
md.remove(key)
return val
except Exception as e:
Expand Down Expand Up @@ -302,7 +299,7 @@ def popIsoDate(self, md, key, timesys=None):
if isoDateStr is not None:
try:
if timesys is None:
timesys = md.get("TIMESYS") if md.exists("TIMESYS") else "UTC"
timesys = md.getScalar("TIMESYS") if md.exists("TIMESYS") else "UTC"
if isoDateStr.endswith("Z"): # illegal in FITS
isoDateStr = isoDateStr[0:-1]
astropyTime = astropy.time.Time(isoDateStr, scale=timesys.lower(), format="fits")
Expand Down Expand Up @@ -336,7 +333,7 @@ def popMjdDate(self, md, key, timesys=None):
mjdDate = self.popFloat(md, key)
try:
if timesys is None:
timesys = md.get("TIMESYS") if md.exists("TIMESYS") else "UTC"
timesys = md.getScalar("TIMESYS") if md.exists("TIMESYS") else "UTC"
astropyTime = astropy.time.Time(mjdDate, format="mjd", scale=timesys.lower())
# DateTime uses nanosecond resolution, regardless of the resolution of the original date
astropyTime.precision = 9
Expand Down
13 changes: 7 additions & 6 deletions python/lsst/obs/base/mapper_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function
from future.utils import with_metaclass
#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
Expand Down Expand Up @@ -33,7 +31,7 @@
__all__ = ["MapperTests"]


class MapperTests(with_metaclass(abc.ABCMeta)):
class MapperTests(metaclass=abc.ABCMeta):
"""
Generic tests of obs_* package mapper functionality.

Expand Down Expand Up @@ -124,7 +122,8 @@ def test_map_config_data(self):
self.assertEqual(self.mapper.root, butlerLocation.getStorage().root)
self.assertEqual(butlerLocation.getLocations(), [processCcd_path])
for k, v in dataId.items():
self.assertEqual(butlerLocation.getAdditionalData().get(k), v, msg="Failed for key={}".format(k))
self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
msg="Failed for key={}".format(k))

def test_map_metadata_data(self):
dataId = self.dataIds['raw']
Expand All @@ -134,7 +133,8 @@ def test_map_metadata_data(self):
self.assertEqual(butlerLocation.getStorageName(), "BoostStorage")
self.assertEqual(butlerLocation.getLocations(), [self.mapper_data.metadata_output_path])
for k, v in dataId.items():
self.assertEqual(butlerLocation.getAdditionalData().get(k), v, msg="Failed for key={}".format(k))
self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
msg="Failed for key={}".format(k))

def test_keys(self):
self.assertEqual(set(self.mapper.keys()), self.mapper_data.keys)
Expand All @@ -160,7 +160,8 @@ def _test_map(self, butlerLocation, dataId):
fileName = os.path.basename(locationList[0])
self.assertEqual(fileName, self.mapper_data.raw_filename)
for k, v in dataId.items():
self.assertEqual(butlerLocation.getAdditionalData().get(k), v, msg="Failed for key={}".format(k))
self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
msg="Failed for key={}".format(k))

def test_map(self):
dataId = self.dataIds['raw']
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/obs/base/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from builtins import zip
from builtins import object
from collections import OrderedDict
import os
import re
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/obs/base/test/compositeMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import lsst.daf.persistence as dafPersist
from lsst.obs.base import CameraMapper
from lsst.utils import getPackageDir
import os

__all__ = ["CompositeMapper"]

Expand Down
2 changes: 0 additions & 2 deletions python/lsst/obs/base/yamlCamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import division, print_function
from builtins import zip
import yaml

import numpy as np
Expand Down
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 110
ignore = E133, E226, E228, N802, N803, N806
exclude = __init__.py, tests/camera/camera.py

[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806
2 changes: 1 addition & 1 deletion tests/SConscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.tests()
scripts.BasicSConscript.tests(pyList=[])
42 changes: 19 additions & 23 deletions tests/test_cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import print_function
from builtins import range
import collections
import gc
import os
import sqlite3
Expand Down Expand Up @@ -145,8 +142,8 @@ def checkCompression(testCase, additionalData):
"scaling.bscale",
"scaling.bzero",
):
additionalData.get(plane + "." + entry)
testCase.assertNotEqual(additionalData.get(plane + ".scaling.seed"), 0)
additionalData.getScalar(plane + "." + entry)
testCase.assertNotEqual(additionalData.getScalar(plane + ".scaling.seed"), 0)


class Mapper1TestCase(unittest.TestCase):
Expand Down Expand Up @@ -195,7 +192,6 @@ def testStandardize(self):
self.assertEqual(result, 3.14)

def testNames(self):
name = MinMapper1.getCameraName()
self.assertEqual(MinMapper1.getCameraName(), "min")
self.assertEqual(MinMapper1.getPackageName(), "larry")

Expand Down Expand Up @@ -230,7 +226,7 @@ def testMap(self):
self.assertEqual(loc.getStorageName(), "FitsStorage")
self.assertEqual(loc.getLocations(), ["foo-13.fits"])
self.assertEqual(loc.getStorage().root, ROOT)
self.assertEqual(loc.getAdditionalData().get("ccd"), 13)
self.assertEqual(loc.getAdditionalData().getScalar("ccd"), 13)
checkCompression(self, loc.getAdditionalData())

def testSubMap(self):
Expand All @@ -249,11 +245,11 @@ def testSubMap(self):
self.assertEqual(loc.getStorageName(), "FitsStorage")
self.assertEqual(loc.getLocations(), ["foo-13.fits"])
self.assertEqual(loc.getStorage().root, ROOT)
self.assertEqual(loc.getAdditionalData().get("ccd"), 13)
self.assertEqual(loc.getAdditionalData().get("width"), 300)
self.assertEqual(loc.getAdditionalData().get("height"), 400)
self.assertEqual(loc.getAdditionalData().get("llcX"), 200)
self.assertEqual(loc.getAdditionalData().get("llcY"), 100)
self.assertEqual(loc.getAdditionalData().getScalar("ccd"), 13)
self.assertEqual(loc.getAdditionalData().getScalar("width"), 300)
self.assertEqual(loc.getAdditionalData().getScalar("height"), 400)
self.assertEqual(loc.getAdditionalData().getScalar("llcX"), 200)
self.assertEqual(loc.getAdditionalData().getScalar("llcY"), 100)
checkCompression(self, loc.getAdditionalData())

loc = mapper.map("raw_sub", {"ccd": 13, "bbox": bbox, "imageOrigin": "PARENT"}, write=True)
Expand All @@ -262,12 +258,12 @@ def testSubMap(self):
self.assertEqual(loc.getStorageName(), "FitsStorage")
self.assertEqual(loc.getLocations(), ["foo-13.fits"])
self.assertEqual(loc.getStorage().root, ROOT)
self.assertEqual(loc.getAdditionalData().get("ccd"), 13)
self.assertEqual(loc.getAdditionalData().get("width"), 300)
self.assertEqual(loc.getAdditionalData().get("height"), 400)
self.assertEqual(loc.getAdditionalData().get("llcX"), 200)
self.assertEqual(loc.getAdditionalData().get("llcY"), 100)
self.assertEqual(loc.getAdditionalData().get("imageOrigin"), "PARENT")
self.assertEqual(loc.getAdditionalData().getScalar("ccd"), 13)
self.assertEqual(loc.getAdditionalData().getScalar("width"), 300)
self.assertEqual(loc.getAdditionalData().getScalar("height"), 400)
self.assertEqual(loc.getAdditionalData().getScalar("llcX"), 200)
self.assertEqual(loc.getAdditionalData().getScalar("llcY"), 100)
self.assertEqual(loc.getAdditionalData().getScalar("imageOrigin"), "PARENT")
checkCompression(self, loc.getAdditionalData())

def testCatalogExtras(self):
Expand All @@ -288,7 +284,7 @@ def testCatalogExtras(self):
self.assertEqual(butler.get("someCatalog_schema", dataId), schema)
self.assertEqual(butler.get("someCatalog_len", dataId), size)
header = butler.get("someCatalog_md", dataId)
self.assertEqual(header.get("NAXIS2"), size)
self.assertEqual(header.getScalar("NAXIS2"), size)
finally:
try:
os.remove(filename)
Expand Down Expand Up @@ -388,10 +384,10 @@ def testCalib(self):
expectedLocations = ["flat-05Am03-fi.fits"]
self.assertEqual(loc.getStorage().root, expectedRoot)
self.assertEqual(loc.getLocations(), expectedLocations)
self.assertEqual(loc.getAdditionalData().get("ccd"), 13)
self.assertEqual(loc.getAdditionalData().get("visit"), 787650)
self.assertEqual(loc.getAdditionalData().get("derivedRunId"), "05Am03")
self.assertEqual(loc.getAdditionalData().get("filter"), "i")
self.assertEqual(loc.getAdditionalData().getScalar("ccd"), 13)
self.assertEqual(loc.getAdditionalData().getScalar("visit"), 787650)
self.assertEqual(loc.getAdditionalData().getScalar("derivedRunId"), "05Am03")
self.assertEqual(loc.getAdditionalData().getScalar("filter"), "i")
checkCompression(self, loc.getAdditionalData())

def testNames(self):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import gc
import os
import shutil
import unittest
Expand Down Expand Up @@ -215,7 +214,7 @@ def setUp(self):
# setter names inferred by component name.
},
# "generic assembler default constructor pair"
'gaDefCtorPair': { # dataset defition that uses the default ctor
'gaDefCtorPair': { # dataset defition that uses the default ctor
'python': 'lsst.daf.persistence.test.TestObjectPair',
'composite': {
# note that the component names are the same as the argument
Expand Down
3 changes: 1 addition & 2 deletions tests/test_exposureFromImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# 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 unittest

import lsst.utils.tests
Expand All @@ -46,7 +45,7 @@ def testDecoratedImage(self):
exposure = exposureFromImage(decoImage)
self.assertImagesEqual(exposure.getMaskedImage().getImage(), image)
md = exposure.getMetadata()
self.assertEqual(md.get("FOO"), "BAR")
self.assertEqual(md.getScalar("FOO"), "BAR")

def testExposure(self):
inExposure = afwImage.ExposureF(self.maskedImage)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_findParentMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import shutil
import unittest
import tempfile

import lsst.utils.tests
from lsst.utils import getPackageDir
import lsst.daf.persistence as dafPersist

ROOT = os.path.abspath(os.path.dirname(__file__))
Expand Down
1 change: 0 additions & 1 deletion tests/test_makeRawVisitInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# 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 unittest

Expand Down
6 changes: 2 additions & 4 deletions tests/test_outputRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from future import standard_library
standard_library.install_aliases()
import unittest
import tempfile
import shutil
import lsst.utils.tests
import pickle
import os
import subprocess

import lsst.utils.tests
import lsst.afw.geom as afwGeom
import lsst.pex.policy as pexPolicy
import lsst.daf.persistence as dafPersist
Expand Down