LSSTApplications  18.1.0
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 377 of file background.py.

377 def 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 
def interpolate1D(method, xSample, ySample, xInterp)
Definition: background.py:377
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 416 of file background.py.

416 def 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 
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:416
def interpolate1D(method, xSample, ySample, xInterp)
Definition: background.py:377

◆ 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.

18 def 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 
def robustMean(array, rej=3.0)
Definition: background.py:18

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

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