LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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