LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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)