LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Classes | Functions
lsst.ip.diffim.dcrModel Namespace Reference

Classes

class  DcrModel
 

Functions

def applyDcr (image, dcr, useInverse=False, splitSubfilters=False, splitThreshold=0., doPrefilter=True, order=3)
 
def calculateDcr (visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilters, splitSubfilters=False)
 
def calculateImageParallacticAngle (visitInfo, wcs)
 
def wavelengthGenerator (effectiveWavelength, bandwidth, dcrNumSubfilters)
 

Function Documentation

◆ applyDcr()

def lsst.ip.diffim.dcrModel.applyDcr (   image,
  dcr,
  useInverse = False,
  splitSubfilters = False,
  splitThreshold = 0.,
  doPrefilter = True,
  order = 3 
)
Shift an image along the X and Y directions.

Parameters
----------
image : `numpy.ndarray`
    The input image to shift.
dcr : `tuple`
    Shift calculated with ``calculateDcr``.
    Uses numpy axes ordering (Y, X).
    If ``splitSubfilters`` is set, each element is itself a `tuple`
    of two `float`, corresponding to the DCR shift at the two wavelengths.
    Otherwise, each element is a `float` corresponding to the DCR shift at
    the effective wavelength of the subfilter.
useInverse : `bool`, optional
    Apply the shift in the opposite direction. Default: False
splitSubfilters : `bool`, optional
    Calculate DCR for two evenly-spaced wavelengths in each subfilter,
    instead of at the midpoint. Default: False
splitThreshold : `float`, optional
    Minimum DCR difference within a subfilter required to use
    ``splitSubfilters``
doPrefilter : `bool`, optional
    Spline filter the image before shifting, if set. Filtering is required,
    so only set to False if the image is already filtered.
    Filtering takes ~20% of the time of shifting, so if `applyDcr` will be
    called repeatedly on the same image it is more efficient to
    precalculate the filter.
order : `int`, optional
    The order of the spline interpolation, default is 3.

Returns
-------
shiftedImage : `numpy.ndarray`
    A copy of the input image with the specified shift applied.

Definition at line 693 of file dcrModel.py.

694  doPrefilter=True, order=3):
695  """Shift an image along the X and Y directions.
696 
697  Parameters
698  ----------
699  image : `numpy.ndarray`
700  The input image to shift.
701  dcr : `tuple`
702  Shift calculated with ``calculateDcr``.
703  Uses numpy axes ordering (Y, X).
704  If ``splitSubfilters`` is set, each element is itself a `tuple`
705  of two `float`, corresponding to the DCR shift at the two wavelengths.
706  Otherwise, each element is a `float` corresponding to the DCR shift at
707  the effective wavelength of the subfilter.
708  useInverse : `bool`, optional
709  Apply the shift in the opposite direction. Default: False
710  splitSubfilters : `bool`, optional
711  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
712  instead of at the midpoint. Default: False
713  splitThreshold : `float`, optional
714  Minimum DCR difference within a subfilter required to use
715  ``splitSubfilters``
716  doPrefilter : `bool`, optional
717  Spline filter the image before shifting, if set. Filtering is required,
718  so only set to False if the image is already filtered.
719  Filtering takes ~20% of the time of shifting, so if `applyDcr` will be
720  called repeatedly on the same image it is more efficient to
721  precalculate the filter.
722  order : `int`, optional
723  The order of the spline interpolation, default is 3.
724 
725  Returns
726  -------
727  shiftedImage : `numpy.ndarray`
728  A copy of the input image with the specified shift applied.
729  """
730  if doPrefilter:
731  prefilteredImage = ndimage.spline_filter(image, order=order)
732  else:
733  prefilteredImage = image
734  if splitSubfilters:
735  shiftAmp = np.max(np.abs([_dcr0 - _dcr1 for _dcr0, _dcr1 in zip(dcr[0], dcr[1])]))
736  if shiftAmp >= splitThreshold:
737  if useInverse:
738  shift = [-1.*s for s in dcr[0]]
739  shift1 = [-1.*s for s in dcr[1]]
740  else:
741  shift = dcr[0]
742  shift1 = dcr[1]
743  shiftedImage = ndimage.shift(prefilteredImage, shift, prefilter=False, order=order)
744  shiftedImage += ndimage.shift(prefilteredImage, shift1, prefilter=False, order=order)
745  shiftedImage /= 2.
746  return shiftedImage
747  else:
748  # If the difference in the DCR shifts is less than the threshold,
749  # then just use the average shift for efficiency.
750  dcr = (np.mean(dcr[0]), np.mean(dcr[1]))
751  if useInverse:
752  shift = [-1.*s for s in dcr]
753  else:
754  shift = dcr
755  shiftedImage = ndimage.shift(prefilteredImage, shift, prefilter=False, order=order)
756  return shiftedImage
757 
758 

◆ calculateDcr()

def lsst.ip.diffim.dcrModel.calculateDcr (   visitInfo,
  wcs,
  effectiveWavelength,
  bandwidth,
  dcrNumSubfilters,
  splitSubfilters = False 
)
Calculate the shift in pixels of an exposure due to DCR.

Parameters
----------
visitInfo : `lsst.afw.image.VisitInfo`
    Metadata for the exposure.
wcs : `lsst.afw.geom.SkyWcs`
    Coordinate system definition (wcs) for the exposure.
effectiveWavelength : `float`
    The effective wavelengths of the current filter, in nanometers.
bandwidth : `float`
    The bandwidth of the current filter, in nanometers.
dcrNumSubfilters : `int`
    Number of sub-filters used to model chromatic effects within a band.
splitSubfilters : `bool`, optional
    Calculate DCR for two evenly-spaced wavelengths in each subfilter,
    instead of at the midpoint. Default: False

Returns
-------
dcrShift : `tuple` of two `float`
    The 2D shift due to DCR, in pixels.
    Uses numpy axes ordering (Y, X).

Definition at line 759 of file dcrModel.py.

759 def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilters, splitSubfilters=False):
760  """Calculate the shift in pixels of an exposure due to DCR.
761 
762  Parameters
763  ----------
764  visitInfo : `lsst.afw.image.VisitInfo`
765  Metadata for the exposure.
766  wcs : `lsst.afw.geom.SkyWcs`
767  Coordinate system definition (wcs) for the exposure.
768  effectiveWavelength : `float`
769  The effective wavelengths of the current filter, in nanometers.
770  bandwidth : `float`
771  The bandwidth of the current filter, in nanometers.
772  dcrNumSubfilters : `int`
773  Number of sub-filters used to model chromatic effects within a band.
774  splitSubfilters : `bool`, optional
775  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
776  instead of at the midpoint. Default: False
777 
778  Returns
779  -------
780  dcrShift : `tuple` of two `float`
781  The 2D shift due to DCR, in pixels.
782  Uses numpy axes ordering (Y, X).
783  """
784  rotation = calculateImageParallacticAngle(visitInfo, wcs)
785  dcrShift = []
786  weight = [0.75, 0.25]
787  for wl0, wl1 in wavelengthGenerator(effectiveWavelength, bandwidth, dcrNumSubfilters):
788  # Note that diffRefractAmp can be negative, since it's relative to the
789  # midpoint of the full band
790  diffRefractAmp0 = differentialRefraction(wavelength=wl0, wavelengthRef=effectiveWavelength,
791  elevation=visitInfo.getBoresightAzAlt().getLatitude(),
792  observatory=visitInfo.getObservatory(),
793  weather=visitInfo.getWeather())
794  diffRefractAmp1 = differentialRefraction(wavelength=wl1, wavelengthRef=effectiveWavelength,
795  elevation=visitInfo.getBoresightAzAlt().getLatitude(),
796  observatory=visitInfo.getObservatory(),
797  weather=visitInfo.getWeather())
798  if splitSubfilters:
799  diffRefractPix0 = diffRefractAmp0.asArcseconds()/wcs.getPixelScale().asArcseconds()
800  diffRefractPix1 = diffRefractAmp1.asArcseconds()/wcs.getPixelScale().asArcseconds()
801  diffRefractArr = [diffRefractPix0*weight[0] + diffRefractPix1*weight[1],
802  diffRefractPix0*weight[1] + diffRefractPix1*weight[0]]
803  shiftX = [diffRefractPix*np.sin(rotation.asRadians()) for diffRefractPix in diffRefractArr]
804  shiftY = [diffRefractPix*np.cos(rotation.asRadians()) for diffRefractPix in diffRefractArr]
805  dcrShift.append(((shiftY[0], shiftX[0]), (shiftY[1], shiftX[1])))
806  else:
807  diffRefractAmp = (diffRefractAmp0 + diffRefractAmp1)/2.
808  diffRefractPix = diffRefractAmp.asArcseconds()/wcs.getPixelScale().asArcseconds()
809  shiftX = diffRefractPix*np.sin(rotation.asRadians())
810  shiftY = diffRefractPix*np.cos(rotation.asRadians())
811  dcrShift.append((shiftY, shiftX))
812  return dcrShift
813 
814 
def differentialRefraction(wavelength, wavelengthRef, elevation, observatory, weather=None)
Definition: _refraction.py:94
def wavelengthGenerator(effectiveWavelength, bandwidth, dcrNumSubfilters)
Definition: dcrModel.py:847
def calculateImageParallacticAngle(visitInfo, wcs)
Definition: dcrModel.py:815
def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilters, splitSubfilters=False)
Definition: dcrModel.py:759

◆ calculateImageParallacticAngle()

def lsst.ip.diffim.dcrModel.calculateImageParallacticAngle (   visitInfo,
  wcs 
)
Calculate the total sky rotation angle of an exposure.

Parameters
----------
visitInfo : `lsst.afw.image.VisitInfo`
    Metadata for the exposure.
wcs : `lsst.afw.geom.SkyWcs`
    Coordinate system definition (wcs) for the exposure.

Returns
-------
`lsst.geom.Angle`
    The rotation of the image axis, East from North.
    Equal to the parallactic angle plus any additional rotation of the
    coordinate system.
    A rotation angle of 0 degrees is defined with
    North along the +y axis and East along the +x axis.
    A rotation angle of 90 degrees is defined with
    North along the +x axis and East along the -y axis.

Definition at line 815 of file dcrModel.py.

815 def calculateImageParallacticAngle(visitInfo, wcs):
816  """Calculate the total sky rotation angle of an exposure.
817 
818  Parameters
819  ----------
820  visitInfo : `lsst.afw.image.VisitInfo`
821  Metadata for the exposure.
822  wcs : `lsst.afw.geom.SkyWcs`
823  Coordinate system definition (wcs) for the exposure.
824 
825  Returns
826  -------
827  `lsst.geom.Angle`
828  The rotation of the image axis, East from North.
829  Equal to the parallactic angle plus any additional rotation of the
830  coordinate system.
831  A rotation angle of 0 degrees is defined with
832  North along the +y axis and East along the +x axis.
833  A rotation angle of 90 degrees is defined with
834  North along the +x axis and East along the -y axis.
835  """
836  parAngle = visitInfo.getBoresightParAngle().asRadians()
837  cd = wcs.getCdMatrix()
838  if wcs.isFlipped:
839  cdAngle = (np.arctan2(-cd[0, 1], cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
840  rotAngle = (cdAngle + parAngle)*geom.radians
841  else:
842  cdAngle = (np.arctan2(cd[0, 1], -cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
843  rotAngle = (cdAngle - parAngle)*geom.radians
844  return rotAngle
845 
846 

◆ wavelengthGenerator()

def lsst.ip.diffim.dcrModel.wavelengthGenerator (   effectiveWavelength,
  bandwidth,
  dcrNumSubfilters 
)
Iterate over the wavelength endpoints of subfilters.

Parameters
----------
effectiveWavelength : `float`
    The effective wavelength of the current filter, in nanometers.
bandwidth : `float`
    The bandwidth of the current filter, in nanometers.
dcrNumSubfilters : `int`
    Number of sub-filters used to model chromatic effects within a band.

Yields
------
`tuple` of two `float`
    The next set of wavelength endpoints for a subfilter, in nanometers.

Definition at line 847 of file dcrModel.py.

847 def wavelengthGenerator(effectiveWavelength, bandwidth, dcrNumSubfilters):
848  """Iterate over the wavelength endpoints of subfilters.
849 
850  Parameters
851  ----------
852  effectiveWavelength : `float`
853  The effective wavelength of the current filter, in nanometers.
854  bandwidth : `float`
855  The bandwidth of the current filter, in nanometers.
856  dcrNumSubfilters : `int`
857  Number of sub-filters used to model chromatic effects within a band.
858 
859  Yields
860  ------
861  `tuple` of two `float`
862  The next set of wavelength endpoints for a subfilter, in nanometers.
863  """
864  lambdaMin = effectiveWavelength - bandwidth/2
865  lambdaMax = effectiveWavelength + bandwidth/2
866  wlStep = bandwidth/dcrNumSubfilters
867  for wl in np.linspace(lambdaMin, lambdaMax, dcrNumSubfilters, endpoint=False):
868  yield (wl, wl + wlStep)