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
maskedImageContinued.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008-2017 LSST/AURA.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 __all__ = ["MaskedImage", "VariancePixel"]
24 
25 import numpy as np
26 
27 from lsst.utils import TemplateMeta
28 from lsst.utils.deprecated import deprecate_pybind11
29 
30 from ..image.fitsIoWithOptions import imageReadFitsWithOptions, exposureWriteFitsWithOptions
31 from ..slicing import supportSlicing
32 from ..disableArithmetic import disableImageArithmetic
33 from .maskedImage import MaskedImageI, MaskedImageF, MaskedImageD, MaskedImageU, MaskedImageL
34 
35 
36 VariancePixel = np.float32
37 
38 
39 class MaskedImage(metaclass=TemplateMeta):
40 
41  def set(self, value, mask=None, variance=None):
42  """Assign a tuple of scalars to the entirety of all three planes.
43  """
44  if mask is None and variance is None:
45  try:
46  value, mask, variance = value
47  except TypeError:
48  pass
49  if mask is None:
50  mask = 0
51  if variance is None:
52  variance = 0.0
53  self.image.set(value)
54  self.mask.set(mask)
55  self.variance.set(variance)
56 
57  def _set(self, index, value, origin):
58  """Set the pixel at the given index to a triple (value, mask, variance).
59 
60  Parameters
61  ----------
62  index : `geom.Point2I`
63  Position of the pixel to assign to.
64  value : `tuple`
65  A tuple of (value, mask, variance) scalars.
66  origin : `ImageOrigin`
67  Coordinate system of ``index`` (`PARENT` or `LOCAL`).
68  """
69  self.image[index, origin] = value[0]
70  self.mask[index, origin] = value[1]
71  self.variance[index, origin] = value[2]
72 
73  def _get(self, index, origin):
74  """Return a triple (value, mask, variance) at the given index.
75 
76  Parameters
77  ----------
78  index : `geom.Point2I`
79  Position of the pixel to assign to.
80  origin : `ImageOrigin`
81  Coordinate system of ``index`` (`PARENT` or `LOCAL`).
82  """
83  return (self.image[index, origin],
84  self.mask[index, origin],
85  self.variance[index, origin])
86 
87  def getArrays(self):
88  """Return a tuple (value, mask, variance) numpy arrays."""
89  return (self.image.array if self.image else None,
90  self.mask.array if self.mask else None,
91  self.variance.array if self.variance else None)
92 
93  def convertF(self):
94  return MaskedImageF(self, True)
95 
96  def convertD(self):
97  return MaskedImageD(self, True)
98 
99  def __reduce__(self):
100  from lsst.afw.fits import reduceToFits
101  return reduceToFits(self)
102 
103  def __str__(self):
104  string = "image={},\nmask={}, maskPlaneDict={}\nvariance={}, bbox={}"
105  return string.format(self.image.array,
106  self.mask.array,
107  self.mask.getMaskPlaneDict(),
108  self.variance.array,
109  self.getBBox())
110 
111  def __repr__(self):
112  return "{}.{}=({})".format(self.__module__, self.__class__.__name__, str(self))
113 
114  readFitsWithOptions = classmethod(imageReadFitsWithOptions)
115 
116  writeFitsWithOptions = exposureWriteFitsWithOptions
117 
118 
119 MaskedImage.register(np.int32, MaskedImageI)
120 MaskedImage.register(np.float32, MaskedImageF)
121 MaskedImage.register(np.float64, MaskedImageD)
122 MaskedImage.register(np.uint16, MaskedImageU)
123 MaskedImage.register(np.uint64, MaskedImageL)
124 MaskedImage.alias("I", MaskedImageI)
125 MaskedImage.alias("F", MaskedImageF)
126 MaskedImage.alias("D", MaskedImageD)
127 MaskedImage.alias("U", MaskedImageU)
128 MaskedImage.alias("L", MaskedImageL)
129 
130 for cls in set(MaskedImage.values()):
131  supportSlicing(cls)
133  cls.__ilshift__ = deprecate_pybind11(cls.__ilshift__,
134  reason="Use `assign` instead. To be removed after 20.0.0.")
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
def deprecate_pybind11(obj, reason, category=FutureWarning)
Definition: deprecated.py:26