Loading [MathJax]/extensions/tex2jax.js
LSST Applications g04a91732dc+7fec47d7bc,g07dc498a13+5ab4d22ec3,g0fba68d861+565de8e5d5,g1409bbee79+5ab4d22ec3,g1a7e361dbc+5ab4d22ec3,g1fd858c14a+11200c7927,g20f46db602+25d63fd678,g35bb328faa+fcb1d3bbc8,g4d2262a081+61302e889d,g4d39ba7253+d05e267ece,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g60b5630c4e+d05e267ece,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8048e755c2+a1301e4c20,g8852436030+163ceb82d8,g89139ef638+5ab4d22ec3,g89e1512fd8+fbb808ebce,g8d6b6b353c+d05e267ece,g9125e01d80+fcb1d3bbc8,g989de1cb63+5ab4d22ec3,g9f33ca652e+8abe617c77,ga9baa6287d+d05e267ece,gaaedd4e678+5ab4d22ec3,gabe3b4be73+1e0a283bba,gb1101e3267+fefe9ce5b1,gb58c049af0+f03b321e39,gb90eeb9370+824c420ec4,gc741bbaa4f+77ddc33078,gcf25f946ba+163ceb82d8,gd315a588df+0f88d5218e,gd6cbbdb0b4+c8606af20c,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+e6bd566e97,ge278dab8ac+932305ba37,ge82c20c137+76d20ab76d,w.2025.10
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
lsst.pipe.tasks.background Namespace Reference

Classes

class  BackgroundConfig
 
class  FocalPlaneBackground
 
class  FocalPlaneBackgroundConfig
 
class  MaskObjectsConfig
 
class  MaskObjectsTask
 
class  SkyMeasurementConfig
 
class  SkyMeasurementTask
 
class  SkyStatsConfig
 

Functions

 robustMean (array, rej=3.0)
 
 interpolate1D (method, xSample, ySample, xInterp)
 
 interpolateBadPixels (array, isBad, interpolationStyle)
 
 smoothArray (array, bad, sigma)
 
 _create_module_child (name)
 

Variables

 pipe_drivers = _create_module_child("lsst.pipe.drivers")
 
 pipe_drivers_background = _create_module_child("lsst.pipe.drivers.background")
 

Function Documentation

◆ _create_module_child()

lsst.pipe.tasks.background._create_module_child ( name)
protected
Create an empty module attached to the relevant parent.

Definition at line 909 of file background.py.

909def _create_module_child(name):
910 """Create an empty module attached to the relevant parent."""
911 parent, child = name.rsplit(".", 1)
912 spec = importlib.machinery.ModuleSpec(name, None)
913 newmod = importlib.util.module_from_spec(spec)
914 setattr(sys.modules[parent], child, newmod)
915 sys.modules[name] = newmod
916 return newmod
917
918
919# This module used to be located in pipe_drivers as
920# lsst.pipe.drivers.background. All pickled datasets using this name
921# require that it still exists as that name. Therefore we create a faked
922# version of lsst.pipe.drivers if that package is not around.

◆ interpolate1D()

lsst.pipe.tasks.background.interpolate1D ( method,
xSample,
ySample,
xInterp )
Interpolate in one dimension

Interpolates the curve provided by `xSample` and `ySample` at
the positions of `xInterp`. Automatically backs off the
interpolation method to achieve successful interpolation.

Parameters
----------
method : `lsst.afw.math.Interpolate.Style`
    Interpolation method to use.
xSample : `numpy.ndarray`
    Vector of ordinates.
ySample : `numpy.ndarray`
    Vector of coordinates.
xInterp : `numpy.ndarray`
    Vector of ordinates to which to interpolate.

Returns
-------
yInterp : `numpy.ndarray`
    Vector of interpolated coordinates.

Definition at line 393 of file background.py.

393def interpolate1D(method, xSample, ySample, xInterp):
394 """Interpolate in one dimension
395
396 Interpolates the curve provided by `xSample` and `ySample` at
397 the positions of `xInterp`. Automatically backs off the
398 interpolation method to achieve successful interpolation.
399
400 Parameters
401 ----------
402 method : `lsst.afw.math.Interpolate.Style`
403 Interpolation method to use.
404 xSample : `numpy.ndarray`
405 Vector of ordinates.
406 ySample : `numpy.ndarray`
407 Vector of coordinates.
408 xInterp : `numpy.ndarray`
409 Vector of ordinates to which to interpolate.
410
411 Returns
412 -------
413 yInterp : `numpy.ndarray`
414 Vector of interpolated coordinates.
415
416 """
417 if len(xSample) == 0:
418 return numpy.ones_like(xInterp)*numpy.nan
419 try:
420 return afwMath.makeInterpolate(xSample.astype(float), ySample.astype(float),
421 method).interpolate(xInterp.astype(float))
422 except Exception:
423 if method == afwMath.Interpolate.CONSTANT:
424 # We've already tried the most basic interpolation and it failed
425 return numpy.ones_like(xInterp)*numpy.nan
426 newMethod = afwMath.lookupMaxInterpStyle(len(xSample))
427 if newMethod == method:
428 newMethod = afwMath.Interpolate.CONSTANT
429 return interpolate1D(newMethod, xSample, ySample, xInterp)
430
431
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for 'n' points.
std::shared_ptr< Interpolate > makeInterpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=Interpolate::AKIMA_SPLINE)
A factory function to make Interpolate objects.

◆ interpolateBadPixels()

lsst.pipe.tasks.background.interpolateBadPixels ( array,
isBad,
interpolationStyle )
Interpolate bad pixels in an image array

The bad pixels are modified in the array.

Parameters
----------
array : `numpy.ndarray`
    Image array with bad pixels.
isBad : `numpy.ndarray` of type `bool`
    Boolean array indicating which pixels are bad.
interpolationStyle : `str`
    Style for interpolation (see `lsst.afw.math.Background`);
    supported values are CONSTANT, LINEAR, NATURAL_SPLINE,
    AKIMA_SPLINE.

Definition at line 432 of file background.py.

432def interpolateBadPixels(array, isBad, interpolationStyle):
433 """Interpolate bad pixels in an image array
434
435 The bad pixels are modified in the array.
436
437 Parameters
438 ----------
439 array : `numpy.ndarray`
440 Image array with bad pixels.
441 isBad : `numpy.ndarray` of type `bool`
442 Boolean array indicating which pixels are bad.
443 interpolationStyle : `str`
444 Style for interpolation (see `lsst.afw.math.Background`);
445 supported values are CONSTANT, LINEAR, NATURAL_SPLINE,
446 AKIMA_SPLINE.
447 """
448 if numpy.all(isBad):
449 raise RuntimeError("No good pixels in image array")
450 height, width = array.shape
451 xIndices = numpy.arange(width, dtype=float)
452 yIndices = numpy.arange(height, dtype=float)
453 method = afwMath.stringToInterpStyle(interpolationStyle)
454 isGood = ~isBad
455 for y in range(height):
456 if numpy.any(isBad[y, :]) and numpy.any(isGood[y, :]):
457 array[y][isBad[y]] = interpolate1D(method, xIndices[isGood[y]], array[y][isGood[y]],
458 xIndices[isBad[y]])
459
460 isBad = numpy.isnan(array)
461 isGood = ~isBad
462 for x in range(width):
463 if numpy.any(isBad[:, x]) and numpy.any(isGood[:, x]):
464 array[:, x][isBad[:, x]] = interpolate1D(method, yIndices[isGood[:, x]],
465 array[:, x][isGood[:, x]], yIndices[isBad[:, x]])
466
467
Interpolate::Style stringToInterpStyle(std::string const &style)
Conversion function to switch a string to an Interpolate::Style.

◆ robustMean()

lsst.pipe.tasks.background.robustMean ( array,
rej = 3.0 )
Measure a robust mean of an array

Parameters
----------
array : `numpy.ndarray`
    Array for which to measure the mean.
rej : `float`
    k-sigma rejection threshold.

Returns
-------
mean : `array.dtype`
    Robust mean of `array`.

Definition at line 51 of file background.py.

51def robustMean(array, rej=3.0):
52 """Measure a robust mean of an array
53
54 Parameters
55 ----------
56 array : `numpy.ndarray`
57 Array for which to measure the mean.
58 rej : `float`
59 k-sigma rejection threshold.
60
61 Returns
62 -------
63 mean : `array.dtype`
64 Robust mean of `array`.
65 """
66 q1, median, q3 = numpy.percentile(array, [25.0, 50.0, 100.0])
67 good = numpy.abs(array - median) < rej*0.74*(q3 - q1)
68 return array[good].mean()
69
70

◆ smoothArray()

lsst.pipe.tasks.background.smoothArray ( array,
bad,
sigma )
Gaussian-smooth an array while ignoring bad pixels

It's not sufficient to set the bad pixels to zero, as then they're treated
as if they are zero, rather than being ignored altogether. We need to apply
a correction to that image that removes the effect of the bad pixels.

Parameters
----------
array : `numpy.ndarray` of floating-point
    Array to smooth.
bad : `numpy.ndarray` of `bool`
    Flag array indicating bad pixels.
sigma : `float`
    Gaussian sigma.

Returns
-------
convolved : `numpy.ndarray`
    Smoothed image.

Definition at line 883 of file background.py.

883def smoothArray(array, bad, sigma):
884 """Gaussian-smooth an array while ignoring bad pixels
885
886 It's not sufficient to set the bad pixels to zero, as then they're treated
887 as if they are zero, rather than being ignored altogether. We need to apply
888 a correction to that image that removes the effect of the bad pixels.
889
890 Parameters
891 ----------
892 array : `numpy.ndarray` of floating-point
893 Array to smooth.
894 bad : `numpy.ndarray` of `bool`
895 Flag array indicating bad pixels.
896 sigma : `float`
897 Gaussian sigma.
898
899 Returns
900 -------
901 convolved : `numpy.ndarray`
902 Smoothed image.
903 """
904 convolved = gaussian_filter(numpy.where(bad, 0.0, array), sigma, mode="constant", cval=0.0)
905 denominator = gaussian_filter(numpy.where(bad, 0.0, 1.0), sigma, mode="constant", cval=0.0)
906 return convolved/denominator
907
908

Variable Documentation

◆ pipe_drivers

lsst.pipe.tasks.background.pipe_drivers = _create_module_child("lsst.pipe.drivers")

Definition at line 927 of file background.py.

◆ pipe_drivers_background

lsst.pipe.tasks.background.pipe_drivers_background = _create_module_child("lsst.pipe.drivers.background")

Definition at line 930 of file background.py.