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-18544: Add python-level deprecation warnings for Calib interface #448

Merged
merged 2 commits into from
Apr 13, 2019
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: 1 addition & 1 deletion examples/timeLeastSquares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import numpy
from matplotlib import pyplot
from lsst.afw.math import LeastSquares # noqa F401
from lsst.afw.math import LeastSquares # noqa: F401

nDataList = 2**numpy.arange(4, 14, 2, dtype=int)
dimensionList = 2**numpy.arange(1, 8, dtype=int)
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/afw/cameraGeom/assembleImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def assembleAmplifierImage(destImage, rawImage, amplifier):
"""
if not amplifier.getHasRawInfo():
raise RuntimeError("amplifier must contain raw amplifier info")
if type(destImage.Factory) != type(rawImage.Factory): # noqa E721
if type(destImage.Factory) != type(rawImage.Factory): # noqa: E721
raise RuntimeError("destImage type = %s != %s = rawImage type" %
type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
inView = rawImage.Factory(rawImage, amplifier.getRawDataBBox())
Expand Down Expand Up @@ -107,7 +107,7 @@ def assembleAmplifierRawImage(destImage, rawImage, amplifier):
"""
if not amplifier.getHasRawInfo():
raise RuntimeError("amplifier must contain raw amplifier info")
if type(destImage.Factory) != type(rawImage.Factory): # noqa E721
if type(destImage.Factory) != type(rawImage.Factory): # noqa: E721
raise RuntimeError("destImage type = %s != %s = rawImage type" %
type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
inBBox = amplifier.getRawBBox()
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/cameraGeom/camera/cameraContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .camera import Camera


@continueClass # noqa F811
@continueClass # noqa: F811
class Camera:

def getPupilFactory(self, visitInfo, pupilSize, npix, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/cameraGeom/detector/detectorContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
WAVEFRONT = DetectorType.WAVEFRONT


@continueClass # noqa F811
@continueClass # noqa: F811
class Detector:
def __iter__(self):
return (self[i] for i in range(len(self)))
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .detectorCollection import DetectorCollection


@continueClass # noqa F811
@continueClass # noqa: F811
class DetectorCollection:
"""!An immutable collection of Detectors that can be accessed by name or ID
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .footprintMerge import FootprintMergeList


@continueClass # noqa F811
@continueClass # noqa: F811
class FootprintMergeList:
def getMergedSourceCatalog(self, catalogs, filters,
peakDist, schema, idFactory, samePeakDist):
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/display/ds9.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lsst.afw.image as afwImage
from .interface import getDisplay as _getDisplay, getDefaultBackend, setDefaultBackend
# Backwards compatibility. Downstream code should be converted to use display.RED etc.
from .interface import BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE # noqa F401
from .interface import BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE # noqa: F401
try:
loaded
except NameError:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/display/rgb/rgbContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def writeRGB(fileName, rgbImage):
#


class asinhMappingF: # noqa N801
class asinhMappingF: # noqa: N801
"""Deprecated object used to support legacy API
"""

Expand Down
8 changes: 4 additions & 4 deletions python/lsst/afw/fits/fitsContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
compressionAlgorithmToString, scalingAlgorithmToString)


@continueClass # noqa F811
@continueClass # noqa: F811
class Fits:
def __enter__(self):
return self
Expand All @@ -14,21 +14,21 @@ def __exit__(self, cls, exc, traceback):
self.closeFile()


@continueClass # noqa F811
@continueClass # noqa: F811
class ImageWriteOptions:
def __repr__(self):
return "%s(compression=%r, scaling=%r)" % (self.__class__.__name__, self.compression, self.scaling)


@continueClass # noqa F811
@continueClass # noqa: F811
class ImageCompressionOptions:
def __repr__(self):
return ("%s(algorithm=%r, tiles=%r, quantizeLevel=%f" %
(self.__class__.__name__, compressionAlgorithmToString(self.algorithm),
self.tiles.tolist(), self.quantizeLevel))


@continueClass # noqa F811
@continueClass # noqa: F811
class ImageScalingOptions:
def __repr__(self):
return ("%s(algorithm=%r, bitpix=%d, maskPlanes=%s, seed=%d, quantizeLevel=%f, quantizePad=%f, "
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/angle/angle.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# provide backwards compatibility for pickle
from lsst.geom.angle import * # noqa F401
from lsst.geom.angle import * # noqa: F401, F403
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/coordinates/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# provide backwards compatibility for pickle
from lsst.geom.coordinates import * # noqa F401
from lsst.geom.coordinates import * # noqa: F401, F403
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/ellipses/axes/axesContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .axes import Axes


@continueClass # noqa F811
@continueClass # noqa: F811
class Axes:
def __repr__(self):
return "Axes(a=%r, b=%r, theta=%r)" % (self.getA(), self.getB(), self.getTheta())
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/ellipses/ellipse/ellipseContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .ellipse import Ellipse


@continueClass # noqa F811
@continueClass # noqa: F811
class Ellipse:
def __repr__(self):
return "Ellipse(%r, %r)" % (self.getCore(), self.getCenter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .quadrupole import Quadrupole


@continueClass # noqa F811
@continueClass # noqa: F811
class Quadrupole:
def __repr__(self):
return "Quadrupole(ixx=%r, iyy=%r, ixy=%r)" % (self.getIxx(), self.getIyy(), self.getIxy())
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/polygon/polygonContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .polygon import Polygon


@continueClass # noqa F811
@continueClass # noqa: F811
class Polygon:
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, [p for p in self.getVertices()])
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/geom/spherePoint/spherePoint.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# provide backwards compatibility for pickle
from lsst.geom.spherePoint import * # noqa F401
from lsst.geom.spherePoint import * # noqa: F401, F403
1 change: 1 addition & 0 deletions python/lsst/afw/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .exposureInfo import *
from .exposure import *
from .photoCalib import *
from .photoCalibContinued import *
from .imagePca import *
from .imageUtils import *
from .readMetadata import *
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/image/apCorrMap/apCorrMapContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .apCorrMap import ApCorrMap


@continueClass # noqa F811
@continueClass # noqa: F811
class ApCorrMap:

def keys(self):
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/afw/image/exposure/exposure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ PyExposure<PixelT> declareExposure(py::module &mod, const std::string &suffix) {
cls.def("setFilter", &ExposureT::setFilter, "filter"_a);

// Deprecated methods
cls.def("getCalib", &ExposureT::getCalib);
cls.def("setCalib", &ExposureT::setCalib, "photoCalib"_a);
cls.def("_getCalib", &ExposureT::getCalib);
cls.def("_setCalib", &ExposureT::setCalib, "photoCalib"_a);

cls.def("getPhotoCalib", &ExposureT::getPhotoCalib);
cls.def("setPhotoCalib", &ExposureT::setPhotoCalib, "photoCalib"_a);
Expand Down
15 changes: 7 additions & 8 deletions python/lsst/afw/image/exposure/exposureContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import numpy as np

# from deprecated.sphinx import deprecated
from deprecated.sphinx import deprecated

from lsst.utils import TemplateMeta

Expand Down Expand Up @@ -99,14 +99,13 @@ def setVariance(self, variance):

writeFitsWithOptions = exposureWriteFitsWithOptions

# TODO DM-18544: activate this once `deprecated` becomes available
# @deprecated(reason="Replaced with getPhotoCalib (will be removed in 18.0)", category=FutureWarning)
# def getCalib(self, *args, **kwargs):
# return self._getCalib(*args, **kwargs)
@deprecated(reason="Replaced with getPhotoCalib (will be removed after v18)", category=FutureWarning)
def getCalib(self, *args, **kwargs):
return self._getCalib(*args, **kwargs)

# @deprecated(reason="Replaced with setPhotoCalib (will be removed in 18.0)", category=FutureWarning)
# def setCalib(self, *args, **kwargs):
# return self._setCalib(*args, **kwargs)
@deprecated(reason="Replaced with setPhotoCalib (will be removed after v18)", category=FutureWarning)
def setCalib(self, *args, **kwargs):
self._setCalib(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Why force the wrapped methods to be all underscores instead of just following the style guide

setCalib = deprecated(reason="Replaced with setPhotoCalib (will be removed after v18)", category=FutureWarning)(setCalib)

You had to make a lot of changes in the C++ file...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because that doesn't work for methods on classes due to a docstring overwriting problem. @ktlim has what he thinks is a fix for upstream deprecate, but getting that into the stack is a problem because of upgrading the conda env being complicated.



Exposure.register(np.int32, ExposureI)
Expand Down
16 changes: 8 additions & 8 deletions python/lsst/afw/image/photoCalib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,20 @@ PYBIND11_MODULE(photoCalib, mod) {
"instFluxMag0Err"_a = false);

/* Deprecated Calib interface */
cls.def_static("setThrowOnNegativeFlux", &PhotoCalib::setThrowOnNegativeFlux);
cls.def_static("getThrowOnNegativeFlux", &PhotoCalib::getThrowOnNegativeFlux);
cls.def("getMagnitude", py::overload_cast<double>(&PhotoCalib::getMagnitude, py::const_), "instFlux"_a);
cls.def("getMagnitude", py::overload_cast<double, double>(&PhotoCalib::getMagnitude, py::const_),
cls.def_static("_setThrowOnNegativeFlux", &PhotoCalib::setThrowOnNegativeFlux);
cls.def_static("_getThrowOnNegativeFlux", &PhotoCalib::getThrowOnNegativeFlux);
cls.def("_getMagnitude", py::overload_cast<double>(&PhotoCalib::getMagnitude, py::const_), "instFlux"_a);
cls.def("_getMagnitude", py::overload_cast<double, double>(&PhotoCalib::getMagnitude, py::const_),
"instFlux"_a, "instFluxErr"_a);
cls.def("getMagnitude",
cls.def("_getMagnitude",
py::overload_cast<ndarray::Array<double const, 1> const &>(&PhotoCalib::getMagnitude, py::const_),
"instFlux"_a);
cls.def("getMagnitude",
cls.def("_getMagnitude",
py::overload_cast<ndarray::Array<double const, 1> const &,
ndarray::Array<double const, 1> const &>(&PhotoCalib::getMagnitude, py::const_),
"instFlux"_a, "instFluxErr"_a);
cls.def("getFlux", &PhotoCalib::getFlux, "instFlux"_a);
cls.def("getFluxMag0", &PhotoCalib::getFluxMag0);
cls.def("_getFlux", &PhotoCalib::getFlux, "instFlux"_a);
cls.def("_getFluxMag0", &PhotoCalib::getFluxMag0);
cls.def("setFluxMag0", &PhotoCalib::setFluxMag0, "instFluxMag0"_a, "instFluxMag0Err"_a = 0.0);

utils::python::addOutputOp(cls, "__str__");
Expand Down
62 changes: 62 additions & 0 deletions python/lsst/afw/image/photoCalibContinued.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# LSST Data Management System
# Copyright 2017 LSST/AURA.
#
# 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,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
"""This file only exists to provide deprecation warnings for the deprecated
Calib-style interface.
"""

__all__ = [] # import this module only for its side effects

from lsst.utils import continueClass

from deprecated.sphinx import deprecated

from .photoCalib import PhotoCalib


@continueClass # noqa: F811
class PhotoCalib:
@staticmethod
@deprecated("No-op: PhotoCalib never throws on negative instFlux (will be removed after v18).",
category=FutureWarning)
def setThrowOnNegativeFlux(raiseException):
PhotoCalib._setThrowOnNegativeFlux(raiseException)

@staticmethod
@deprecated("No-op: PhotoCalib never throws on negative instFlux (will be removed after v18).",
category=FutureWarning)
def getThrowOnNegativeFlux():
return PhotoCalib._getThrowOnNegativeFlux()

@deprecated("For backwards compatibility with Calib; use `instFluxToMagnitude` instead"
" (will be removed after v18).", category=FutureWarning)
def getMagnitude(self, *args, **kwargs):
return self._getMagnitude(*args, **kwargs)

@deprecated("For backwards compatibility with Calib; use `magnitudeToInstFlux` instead"
" (will be removed after v18).", category=FutureWarning)
def getFlux(self, *args, **kwargs):
return self._getFlux(*args, **kwargs)

@deprecated("For backwards compatibility with Calib: use `getCalibrationMean`, `getCalibrationErr`, or "
"`getInstFluxAtZeroMagnitude` (will be removed after v18).", category=FutureWarning)
def getFluxMag0(self):
return self._getFluxMag0()
2 changes: 1 addition & 1 deletion python/lsst/afw/math/background/backgroundContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
__all__ = [] # import this module only for its side effects


@continueClass # noqa F811
@continueClass # noqa: F811
class Background:
def __reduce__(self):
"""Pickling"""
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/table/aliasMap/aliasMapContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .aliasMap import AliasMap


@continueClass # noqa F811
@continueClass # noqa: F811
class AliasMap:

def keys(self):
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/afw/table/base/baseContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
__all__ = ["Catalog"]


@continueClass # noqa F811
@continueClass # noqa: F811
class BaseRecord:

def extract(self, *patterns, **kwds):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# base class, so we use the same naming convention we use for those.


@continueClass # noqa F811
@continueClass # noqa: F811
class _BaseColumnViewBase:

def getBits(self, keys=None):
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/afw/table/exposure/exposure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ PyExposureRecord declareExposureRecord(py::module &mod) {
cls.def("setPsf", &ExposureRecord::setPsf, "psf"_a);

// Deprecated methods
cls.def("getCalib", &ExposureRecord::getCalib);
cls.def("setCalib", &ExposureRecord::setCalib, "photoCalib"_a);
cls.def("_getCalib", &ExposureRecord::getCalib);
cls.def("_setCalib", &ExposureRecord::setCalib, "photoCalib"_a);

cls.def("getPhotoCalib", &ExposureRecord::getPhotoCalib);
cls.def("setPhotoCalib", &ExposureRecord::setPhotoCalib, "photoCalib"_a);
Expand Down
23 changes: 12 additions & 11 deletions python/lsst/afw/table/exposure/exposureContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@

__all__ = [] # import this module only for its side effects

# from deprecated.sphinx import deprecated
from deprecated.sphinx import deprecated

from lsst.utils import continueClass

from ..base import Catalog
from .exposure import ExposureCatalog
from .exposure import ExposureCatalog, ExposureRecord


# TODO DM-18544: activate this once `deprecated` becomes available
# @continueClass # noqa F811
# class ExposureRecord:
# @deprecated(reason="Replaced with getPhotoCalib (will be removed in 18.0)", category=FutureWarning)
# def getCalib(self, *args, **kwargs):
# return self._getCalib(*args, **kwargs)
@continueClass # noqa: F811
class ExposureRecord:
@deprecated(reason="Replaced with getPhotoCalib (will be removed after v18)", category=FutureWarning)
def getCalib(self, *args, **kwargs):
return self._getCalib(*args, **kwargs)

# @deprecated(reason="Replaced with setPhotoCalib (will be removed in 18.0)", category=FutureWarning)
# def setCalib(self, *args, **kwargs):
# return self._setCalib(*args, **kwargs)
@deprecated(reason="Replaced with setPhotoCalib (will be removed after v18)", category=FutureWarning)
def setCalib(self, *args, **kwargs):
self._setCalib(*args, **kwargs)


Catalog.register("Exposure", ExposureCatalog)