LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Functions
lsst.afw.image.disableArithmetic Namespace Reference

Functions

def wrapNotImplemented (cls, attr)
 
def disableImageArithmetic (cls)
 
def disableMaskArithmetic (cls)
 

Function Documentation

◆ disableImageArithmetic()

def lsst.afw.image.disableArithmetic.disableImageArithmetic (   cls)
Add helpful error messages about image arithmetic

Definition at line 45 of file disableArithmetic.py.

45 def disableImageArithmetic(cls):
46  """Add helpful error messages about image arithmetic"""
47  for attr in ("__add__", "__sub__", "__mul__", "__truediv__",
48  "__radd__", "__rsub__", "__rmul__", "__rtruediv__"):
49  setattr(cls, attr, wrapNotImplemented(cls, attr))
50 
51 

◆ disableMaskArithmetic()

def lsst.afw.image.disableArithmetic.disableMaskArithmetic (   cls)
Add helpful error messages about mask arithmetic

Definition at line 52 of file disableArithmetic.py.

52 def disableMaskArithmetic(cls):
53  """Add helpful error messages about mask arithmetic"""
54  for attr in ("__or__", "__and__", "__xor__",
55  "__ror__", "__rand__", "__rxor__"):
56  setattr(cls, attr, wrapNotImplemented(cls, attr))

◆ wrapNotImplemented()

def lsst.afw.image.disableArithmetic.wrapNotImplemented (   cls,
  attr 
)
Wrap a method providing a helpful error message about image arithmetic

Parameters
----------
cls : `type`
    Class in which the method is to be defined.
attr : `str`
    Name of the method.

Returns
-------
method : callable
    Wrapped method.

Definition at line 6 of file disableArithmetic.py.

6 def wrapNotImplemented(cls, attr):
7  """Wrap a method providing a helpful error message about image arithmetic
8 
9  Parameters
10  ----------
11  cls : `type`
12  Class in which the method is to be defined.
13  attr : `str`
14  Name of the method.
15 
16  Returns
17  -------
18  method : callable
19  Wrapped method.
20  """
21  existing = getattr(cls, attr, None)
22 
23  def notImplemented(self, other):
24  """Provide a helpful error message about image arithmetic
25 
26  Unless we're operating on an ImageSlice, in which case it might be
27  defined.
28 
29  Parameters
30  ----------
31  self : subclass of `lsst.afw.image.ImageBase`
32  Image someone's attempting to do arithmetic with.
33  other : anything
34  The operand of the arithmetic operation.
35  """
36  if existing is not None and isinstance(other, (ImageSliceF, ImageSliceD)):
37  return existing(self, other)
38  raise NotImplementedError("This arithmetic operation is not implemented, in order to prevent the "
39  "accidental proliferation of temporaries. Please use the in-place "
40  "arithmetic operations (e.g., += instead of +) or operate on the "
41  "underlying arrays.")
42  return notImplemented
43 
44