LSST Applications g0da5cf3356+25b44625d0,g17e5ecfddb+50a5ac4092,g1c76d35bf8+585f0f68a2,g295839609d+8ef6456700,g2e2c1a68ba+cc1f6f037e,g38293774b4+62d12e78cb,g3b44f30a73+2891c76795,g48ccf36440+885b902d19,g4b2f1765b6+0c565e8f25,g5320a0a9f6+bd4bf1dc76,g56364267ca+403c24672b,g56b687f8c9+585f0f68a2,g5c4744a4d9+78cd207961,g5ffd174ac0+bd4bf1dc76,g6075d09f38+3075de592a,g667d525e37+cacede5508,g6f3e93b5a3+da81c812ee,g71f27ac40c+cacede5508,g7212e027e3+eb621d73aa,g774830318a+18d2b9fa6c,g7985c39107+62d12e78cb,g79ca90bc5c+fa2cc03294,g881bdbfe6c+cacede5508,g91fc1fa0cf+82a115f028,g961520b1fb+2534687f64,g96f01af41f+f2060f23b6,g9ca82378b8+cacede5508,g9d27549199+78cd207961,gb065e2a02a+ad48cbcda4,gb1df4690d6+585f0f68a2,gb35d6563ee+62d12e78cb,gbc3249ced9+bd4bf1dc76,gbec6a3398f+bd4bf1dc76,gd01420fc67+bd4bf1dc76,gd59336e7c4+c7bb92e648,gf46e8334de+81c9a61069,gfed783d017+bd4bf1dc76,v25.0.1.rc3
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions
lsst.pipe.drivers.background Namespace Reference

Classes

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

Functions

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

Function Documentation

◆ interpolate1D()

def lsst.pipe.drivers.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 377 of file background.py.

377def interpolate1D(method, xSample, ySample, xInterp):
378 """Interpolate in one dimension
379
380 Interpolates the curve provided by `xSample` and `ySample` at
381 the positions of `xInterp`. Automatically backs off the
382 interpolation method to achieve successful interpolation.
383
384 Parameters
385 ----------
386 method : `lsst.afw.math.Interpolate.Style`
387 Interpolation method to use.
388 xSample : `numpy.ndarray`
389 Vector of ordinates.
390 ySample : `numpy.ndarray`
391 Vector of coordinates.
392 xInterp : `numpy.ndarray`
393 Vector of ordinates to which to interpolate.
394
395 Returns
396 -------
397 yInterp : `numpy.ndarray`
398 Vector of interpolated coordinates.
399
400 """
401 if len(xSample) == 0:
402 return numpy.ones_like(xInterp)*numpy.nan
403 try:
404 return afwMath.makeInterpolate(xSample.astype(float), ySample.astype(float),
405 method).interpolate(xInterp.astype(float))
406 except Exception:
407 if method == afwMath.Interpolate.CONSTANT:
408 # We've already tried the most basic interpolation and it failed
409 return numpy.ones_like(xInterp)*numpy.nan
410 newMethod = afwMath.lookupMaxInterpStyle(len(xSample))
411 if newMethod == method:
412 newMethod = afwMath.Interpolate.CONSTANT
413 return interpolate1D(newMethod, xSample, ySample, xInterp)
414
415
Interpolate::Style lookupMaxInterpStyle(int const n)
Get the highest order Interpolation::Style available for 'n' points.
Definition: Interpolate.cc:279
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.
Definition: Interpolate.cc:347

◆ interpolateBadPixels()

def lsst.pipe.drivers.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 416 of file background.py.

416def interpolateBadPixels(array, isBad, interpolationStyle):
417 """Interpolate bad pixels in an image array
418
419 The bad pixels are modified in the array.
420
421 Parameters
422 ----------
423 array : `numpy.ndarray`
424 Image array with bad pixels.
425 isBad : `numpy.ndarray` of type `bool`
426 Boolean array indicating which pixels are bad.
427 interpolationStyle : `str`
428 Style for interpolation (see `lsst.afw.math.Background`);
429 supported values are CONSTANT, LINEAR, NATURAL_SPLINE,
430 AKIMA_SPLINE.
431 """
432 if numpy.all(isBad):
433 raise RuntimeError("No good pixels in image array")
434 height, width = array.shape
435 xIndices = numpy.arange(width, dtype=float)
436 yIndices = numpy.arange(height, dtype=float)
437 method = afwMath.stringToInterpStyle(interpolationStyle)
438 isGood = ~isBad
439 for y in range(height):
440 if numpy.any(isBad[y, :]) and numpy.any(isGood[y, :]):
441 array[y][isBad[y]] = interpolate1D(method, xIndices[isGood[y]], array[y][isGood[y]],
442 xIndices[isBad[y]])
443
444 isBad = numpy.isnan(array)
445 isGood = ~isBad
446 for x in range(width):
447 if numpy.any(isBad[:, x]) and numpy.any(isGood[:, x]):
448 array[:, x][isBad[:, x]] = interpolate1D(method, yIndices[isGood[:, x]],
449 array[:, x][isGood[:, x]], yIndices[isBad[:, x]])
450
451
A virtual base class to evaluate image background levels.
Definition: Background.h:235
Interpolate::Style stringToInterpStyle(std::string const &style)
Conversion function to switch a string to an Interpolate::Style.
Definition: Interpolate.cc:261

◆ robustMean()

def lsst.pipe.drivers.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 18 of file background.py.

18def robustMean(array, rej=3.0):
19 """Measure a robust mean of an array
20
21 Parameters
22 ----------
23 array : `numpy.ndarray`
24 Array for which to measure the mean.
25 rej : `float`
26 k-sigma rejection threshold.
27
28 Returns
29 -------
30 mean : `array.dtype`
31 Robust mean of `array`.
32 """
33 q1, median, q3 = numpy.percentile(array, [25.0, 50.0, 100.0])
34 good = numpy.abs(array - median) < rej*0.74*(q3 - q1)
35 return array[good].mean()
36
37

◆ smoothArray()

def lsst.pipe.drivers.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 856 of file background.py.

856def smoothArray(array, bad, sigma):
857 """Gaussian-smooth an array while ignoring bad pixels
858
859 It's not sufficient to set the bad pixels to zero, as then they're treated
860 as if they are zero, rather than being ignored altogether. We need to apply
861 a correction to that image that removes the effect of the bad pixels.
862
863 Parameters
864 ----------
865 array : `numpy.ndarray` of floating-point
866 Array to smooth.
867 bad : `numpy.ndarray` of `bool`
868 Flag array indicating bad pixels.
869 sigma : `float`
870 Gaussian sigma.
871
872 Returns
873 -------
874 convolved : `numpy.ndarray`
875 Smoothed image.
876 """
877 convolved = gaussian_filter(numpy.where(bad, 0.0, array), sigma, mode="constant", cval=0.0)
878 denominator = gaussian_filter(numpy.where(bad, 0.0, 1.0), sigma, mode="constant", cval=0.0)
879 return convolved/denominator