LSSTApplications  17.0+10,17.0+51,17.0+88,18.0.0+10,18.0.0+15,18.0.0+34,18.0.0+4,18.0.0+6,18.0.0-2-ge43143a+6,18.1.0-1-g0001055+2,18.1.0-1-g0896a44+10,18.1.0-1-g1349e88+9,18.1.0-1-g2505f39+7,18.1.0-1-g380d4d4+9,18.1.0-1-g5e4b7ea+2,18.1.0-1-g7e8fceb,18.1.0-1-g85f8cd4+7,18.1.0-1-g9a6769a+3,18.1.0-1-ga1a4c1a+6,18.1.0-1-gc037db8+2,18.1.0-1-gd55f500+3,18.1.0-1-ge10677a+7,18.1.0-10-g73b8679e+12,18.1.0-12-gf30922b,18.1.0-13-g451e75588,18.1.0-13-gbfe7f7f,18.1.0-2-g31c43f9+7,18.1.0-2-g9c63283+9,18.1.0-2-gdf0b915+9,18.1.0-2-gf03bb23+2,18.1.0-3-g52aa583+3,18.1.0-3-g8f4a2b1+1,18.1.0-3-g9cb968e+8,18.1.0-4-g7bbbad0,18.1.0-5-g510c42a+8,18.1.0-5-ga46117f,18.1.0-5-gaeab27e+9,18.1.0-6-gdda7f3e+11,18.1.0-8-g4084bf03+1,w.2019.34
LSSTDataManagementBasePackage
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 378 of file background.py.

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

◆ 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 417 of file background.py.

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

◆ 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 19 of file background.py.

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

◆ 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 851 of file background.py.

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