lsst.pipe.tasks g540474b770+e2881a99e2
Loading...
Searching...
No Matches
lsst.pipe.tasks.prettyPictureMaker._task Namespace Reference

Classes

class  PrettyMosaicConfig
 
class  PrettyMosaicConnections
 
class  PrettyMosaicTask
 
class  PrettyPictureBackgroundFixerConnections
 
class  PrettyPictureConnections
 
class  PrettyPictureStarFixerConfig
 
class  PrettyPictureStarFixerConnections
 
class  PrettyPictureStarFixerTask
 

Functions

Struct run (self, Mapping[str, Exposure] images, Projection[Any]|None image_wcs=None, Box|None image_box=None)
 
None runQuantum (self, QuantumContext butlerQC, InputQuantizedConnection inputRefs, OutputQuantizedConnection outputRefs)
 
dict[str, ExposuremakeInputsFromRefs (self, Iterable[DatasetRef] refs, Butler|QuantumContext butler)
 
dict[str, DeferredDatasetHandle] makeInputsFromArrays (self, **kwargs)
 
dict[int, DeferredDatasetHandle] makeInputsFromExposures (self, **kwargs)
 
 fixBackground (self, image, detection_mask=None)
 
 run (self, Exposure inputCoadd)
 

Variables

 doWrite
 
 r
 
 g
 
 b
 
 array : `numpy.array`
 
 mean : `float`
 
 sigma : `float`
 
tuple lower_pos = (array - mu) < sigma
 
 sigma_ratio = min_sig / sigma
 
 arr : `numyp.ndarray`
 
 maxLikely = np.median(image, axis=None)
 
 mask = image < maxLikely
 
tuple initial_std = (image[mask] - maxLikely).std()
 
 mu_hat
 
 sigma_hat
 
 threshhold = mu_hat + pos_sigma_mult * sigma_hat
 
tuple image_mask = (image < threshhold) * (image > (mu_hat - 5 * sigma_hat))
 

Function Documentation

◆ fixBackground()

lsst.pipe.tasks.prettyPictureMaker._task.fixBackground ( self,
image,
detection_mask = None )
Estimate and subtract the background from an image.

This function estimates the background level in an image using a median-based
approach combined with Gaussian fitting and radial basis function interpolation.
It aims to provide a more accurate background estimation than a simple median
filter, especially in images with varying background levels.

Parameters
----------
image : `numpy.ndarray`
    The input image as a NumPy array.

Returns
-------
numpy.ndarray
    An array representing the estimated background level across the image.

Definition at line 817 of file _task.py.

◆ makeInputsFromArrays()

dict[str, DeferredDatasetHandle] lsst.pipe.tasks.prettyPictureMaker._task.makeInputsFromArrays ( self,
** kwargs )
Make valid inputs for the run method from numpy arrays.

Parameters
----------
kwargs : `numpy.ndarray`
    This is standard python kwargs where the left side of the equals
    is the data band, and the right side is the corresponding `numpy.ndarray`
    array.

Returns
-------
sortedImages : `dict` of `str` to \
        `~lsst.daf.butler.DeferredDatasetHandle`
    A dictionary of `~lsst.daf.butlger.DeferredDatasetHandle`\ s keyed
    by the band they correspond to.

Definition at line 587 of file _task.py.

◆ makeInputsFromExposures()

dict[int, DeferredDatasetHandle] lsst.pipe.tasks.prettyPictureMaker._task.makeInputsFromExposures ( self,
** kwargs )
Make valid inputs for the run method from `Exposure` objects.

Parameters
----------
kwargs : `Exposure`
    This is standard python kwargs where the left side of the equals
    is the data band, and the right side is the corresponding
    `Exposure`.

Returns
-------
sortedImages : `dict` of `int` to \
        `~lsst.daf.butler.DeferredDatasetHandle`
    A dictionary of `~lsst.daf.butler.DeferredDatasetHandle`\ s keyed
    by the band they correspond to.

Definition at line 612 of file _task.py.

◆ makeInputsFromRefs()

dict[str, Exposure] lsst.pipe.tasks.prettyPictureMaker._task.makeInputsFromRefs ( self,
Iterable[DatasetRef] refs,
Butler | QuantumContext butler )
Make valid inputs for the run method from butler references.

Parameters
----------
refs : `Iterable` of `DatasetRef`
    Some `Iterable` container of `Butler` `DatasetRef`\ s
butler : `Butler` or `QuantumContext`
    This is the object that fetches the input data.

Returns
-------
sortedImages : `dict` of `str` to `Exposure`
    A dictionary of `Exposure`\ s keyed by the band they
    correspond to.

Definition at line 562 of file _task.py.

◆ run() [1/2]

lsst.pipe.tasks.prettyPictureMaker._task.run ( self,
Exposure inputCoadd )
Estimate a background for an input Exposure and remove it.

Parameters
----------
inputCoadd : `Exposure`
    The exposure the background will be removed from.

Returns
-------
result : `Struct`
    A `Struct` that contains the exposure with the background removed.
    This `Struct` will have an attribute named ``outputCoadd``.

Definition at line 881 of file _task.py.

◆ run() [2/2]

Struct lsst.pipe.tasks.prettyPictureMaker._task.run ( self,
Mapping[str, Exposure] images,
Projection[Any] | None image_wcs = None,
Box | None image_box = None )
Turns the input arguments in arguments into an RGB array.

Parameters
----------
images : `Mapping` of `str` to `Exposure`
    A mapping of input images and the band they correspond to.
image_wcs : `~lsst.images.Projection`, optional
    A projection describing the sky coordinate of each pixel.
image_box : `~lsst.images.Box`, optional
    A box that defines this image as part of a larger region.

Returns
-------
result : `Struct`
    A struct with the corresponding RGB image, and mask used in
    RGB image construction. The struct will have the attributes
    outputRGB and outputRGBMask. Each of the outputs will
    be a `~lsst.images.ColorImage` object.

Notes
-----
Construction of input images are made easier by use of the
makeInputsFrom* methods.

Definition at line 380 of file _task.py.

◆ runQuantum()

None lsst.pipe.tasks.prettyPictureMaker._task.runQuantum ( self,
QuantumContext butlerQC,
InputQuantizedConnection inputRefs,
OutputQuantizedConnection outputRefs )

Definition at line 531 of file _task.py.

Variable Documentation

◆ arr

lsst.pipe.tasks.prettyPictureMaker._task.arr : `numyp.ndarray`
_DefaultName = "prettyPictureBackgroundFixer"
ConfigClass = PrettyPictureBackgroundFixerConfig

config: ConfigClass

def _tile_slices(self, arr, R, C):

Definition at line 698 of file _task.py.

◆ array

lsst.pipe.tasks.prettyPictureMaker._task.array : `numpy.array`
r = Field[float](doc="The amount of red contained in this channel")
g = Field[float](doc="The amount of green contained in this channel")
b = Field[float](doc="The amount of blue contained in this channel")


class PrettyPictureConfig(PipelineTaskConfig, pipelineConnections=PrettyPictureConnections):
channelConfig = ConfigDictField(
    doc="A dictionary that maps band names to their rgb channel configurations",
    keytype=str,
    itemtype=ChannelRGBConfig,
    default={},
)
cieWhitePoint = ListField[float](
    doc="The white point of the input arrays in ciexz coordinates", maxLength=2, default=[0.28, 0.28]
)
arrayType = ChoiceField[str](
    doc="The dataset type for the output image array",
    default="uint8",
    allowed={
        "uint8": "Use 8 bit arrays, 255 max",
        "uint16": "Use 16 bit arrays, 65535 max",
        "half": "Use 16 bit float arrays, 1 max",
        "float": "Use 32 bit float arrays, 1 max",
    },
)
recenterNoise = Field[float](
    doc="Recenter the noise away from zero. Supplied value is in units of sigma",
    optional=True,
    default=None,
)
noiseSearchThreshold = Field[float](
    doc=(
        "Flux threshold below which most flux will be considered noise, used to estimate noise properties"
    ),
    default=10,
)
doPsfDeconvolve = Field[bool](
    doc="Use the PSF in a Richardson-Lucy deconvolution on the luminance channel.", default=False
)
doPSFDeconcovlve = Field[bool](
    doc="Use the PSF in a Richardson-Lucy deconvolution on the luminance channel.",
    default=False,
    deprecated="This field will be removed in v32. Use doPsfDeconvolve instead.",
    optional=True,
)
doRemapGamut = Field[bool](
    doc="Apply a color correction to unrepresentable colors; if False, clip them.", default=True
)
doExposureBrackets = Field[bool](
    doc="Apply exposure bracketing to aid in dynamic range compression", default=True
)
doLocalContrast = Field[bool](doc="Apply local contrast optimizations to luminance.", default=True)

imageRemappingConfig = ConfigurableActionField[BoundsRemapper](
    doc="Action controlling normalization process"
)
luminanceConfig = ConfigurableActionField[LumCompressor](
    doc="Action controlling luminance scaling when making an RGB image"
)
localContrastConfig = ConfigurableActionField[LocalContrastEnhancer](
    doc="Action controlling the local contrast correction in RGB image production"
)
colorConfig = ConfigurableActionField[ColorScaler](
    doc="Action to control the color scaling process in RGB image production"
)
exposureBracketerConfig = ConfigurableActionField[ExposureBracketer](
    doc=(
        "Exposure scaling action used in creating multiple exposures with different scalings which will "
        "then be fused into a final image"
    ),
)
gamutMapperConfig = ConfigurableActionField[GamutFixer](
    doc="Action to fix pixels which lay outside RGB color gamut"
)

exposureBrackets = ListField[float](
    doc=(
        "Exposure scaling factors used in creating multiple exposures with different scalings which will "
        "then be fused into a final image"
    ),
    optional=True,
    default=[1.25, 1, 0.75],
    deprecated=(
        "This field will stop working in v31 and be removed in v32, "
        "please set exposureBracketerConfig.exposureBrackets"
    ),
)
gamutMethod = ChoiceField[str](
    doc="If doRemapGamut is True this determines the method",
    default="inpaint",
    allowed={
        "mapping": "Use a mapping function",
        "inpaint": "Use surrounding pixels to determine likely value",
    },
    deprecated="This field will stop working in v31 and be removed in v32, please set gamutMapperConfig",
)

def setDefaults(self):
    self.channelConfig["i"] = ChannelRGBConfig(r=1, g=0, b=0)
    self.channelConfig["r"] = ChannelRGBConfig(r=0, g=1, b=0)
    self.channelConfig["g"] = ChannelRGBConfig(r=0, g=0, b=1)
    return super().setDefaults()

def _handle_deprecated(self):
# check if gamutMethod is set
if len(self._history["gamutMethod"]) > 1:
    # This has been set in config, update it in the new location
    self.gamutMapperConfig.gamutMethod = self.gamutMethod

if len(self._history["exposureBrackets"]) > 1:
    self.exposureBracketerConfig.exposureBrackets = self.exposureBrackets
    if self.exposureBrackets is None:
        self.doExposureBrackets = False

if len(self.localContrastConfig._history["doLocalContrast"]) > 1:
    self.doLocalContrast = self.localContrastConfig.doLocalContrast

# Handle doPsfDeconcovlve typo fix
if len(self._history["doPSFDeconcovlve"]) > 1:
    self.doPsfDeconvolve = self.doPSFDeconcovlve

def freeze(self):
# ensure this is not already frozen
if self._frozen is not True:
    self._handle_deprecated()
super().freeze()


class PrettyPictureTask(PipelineTask):
_DefaultName = "prettyPicture"
ConfigClass = PrettyPictureConfig

config: ConfigClass

def _find_normal_stats(self, array):

Definition at line 299 of file _task.py.

◆ b

lsst.pipe.tasks.prettyPictureMaker._task.b

Definition at line 134 of file _task.py.

◆ doWrite

lsst.pipe.tasks.prettyPictureMaker._task.doWrite

Definition at line 100 of file _task.py.

◆ g

lsst.pipe.tasks.prettyPictureMaker._task.g

Definition at line 134 of file _task.py.

◆ image_mask

tuple lsst.pipe.tasks.prettyPictureMaker._task.image_mask = (image < threshhold) * (image > (mu_hat - 5 * sigma_hat))

Definition at line 814 of file _task.py.

◆ initial_std

tuple lsst.pipe.tasks.prettyPictureMaker._task.initial_std = (image[mask] - maxLikely).std()

Definition at line 800 of file _task.py.

◆ lower_pos

tuple lsst.pipe.tasks.prettyPictureMaker._task.lower_pos = (array - mu) < sigma
# Extract negative values efficiently
values_noise = array[array < self.config.noiseSearchThreshold]

# find the mode
center = mode(np.round(values_noise, 2)).mode

# extract the negative values
values_neg = array[array < center]

# Return infinity if no negative values found
if values_neg.size == 0:
    return 0, np.inf

try:
    # Fit half-normal distribution to absolute negative values
    mu, sigma = halfnorm.fit(np.abs(values_neg))
except (ValueError, RuntimeError):
    # Handle fitting failures (e.g., constant data, optimization issues)
    return 0, np.inf

return center, sigma

def _match_sigmas_and_recenter(self, *arrays, factor=1):

Definition at line 368 of file _task.py.

◆ mask

lsst.pipe.tasks.prettyPictureMaker._task.mask = image < maxLikely

Definition at line 799 of file _task.py.

◆ maxLikely

lsst.pipe.tasks.prettyPictureMaker._task.maxLikely = np.median(image, axis=None)

Definition at line 794 of file _task.py.

◆ mean

lsst.pipe.tasks.prettyPictureMaker._task.mean : `float`

Definition at line 304 of file _task.py.

◆ mu_hat

lsst.pipe.tasks.prettyPictureMaker._task.mu_hat

Definition at line 806 of file _task.py.

◆ r

lsst.pipe.tasks.prettyPictureMaker._task.r

Definition at line 133 of file _task.py.

◆ sigma

lsst.pipe.tasks.prettyPictureMaker._task.sigma : `float`

Definition at line 306 of file _task.py.

◆ sigma_hat

lsst.pipe.tasks.prettyPictureMaker._task.sigma_hat

Definition at line 806 of file _task.py.

◆ sigma_ratio

lsst.pipe.tasks.prettyPictureMaker._task.sigma_ratio = min_sig / sigma

Definition at line 375 of file _task.py.

◆ threshhold

lsst.pipe.tasks.prettyPictureMaker._task.threshhold = mu_hat + pos_sigma_mult * sigma_hat

Definition at line 813 of file _task.py.