23 __all__ = [
"MaskedImage",
"VariancePixel"]
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
36 VariancePixel = np.float32
41 def set(self, value, mask=None, variance=None):
42 """Assign a tuple of scalars to the entirety of all three planes.
44 if mask
is None and variance
is None:
46 value, mask, variance = value
55 self.variance.
set(variance)
57 def _set(self, index, value, origin):
58 """Set the pixel at the given index to a triple (value, mask, variance).
62 index : `geom.Point2I`
63 Position of the pixel to assign to.
65 A tuple of (value, mask, variance) scalars.
66 origin : `ImageOrigin`
67 Coordinate system of ``index`` (`PARENT` or `LOCAL`).
69 self.image[index, origin] = value[0]
70 self.mask[index, origin] = value[1]
71 self.variance[index, origin] = value[2]
73 def _get(self, index, origin):
74 """Return a triple (value, mask, variance) at the given index.
78 index : `geom.Point2I`
79 Position of the pixel to assign to.
80 origin : `ImageOrigin`
81 Coordinate system of ``index`` (`PARENT` or `LOCAL`).
83 return (self.image[index, origin],
84 self.mask[index, origin],
85 self.variance[index, origin])
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)
94 return MaskedImageF(self,
True)
97 return MaskedImageD(self,
True)
104 string =
"image={},\nmask={}, maskPlaneDict={}\nvariance={}, bbox={}"
105 return string.format(self.image.array,
107 self.mask.getMaskPlaneDict(),
112 return "{}.{}=({})".
format(self.__module__, self.__class__.__name__, str(self))
114 readFitsWithOptions = classmethod(imageReadFitsWithOptions)
116 writeFitsWithOptions = exposureWriteFitsWithOptions
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)
130 for cls
in set(MaskedImage.values()):
134 reason=
"Use `assign` instead. To be removed after 20.0.0.")