LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Classes | Functions
lsst.ip.diffim.dcrModel Namespace Reference

Classes

class  DcrModel
 

Functions

def applyDcr (image, dcr, useInverse=False, splitSubfilters=False, kwargs)
 
def calculateDcr (visitInfo, wcs, filterInfo, dcrNumSubfilters, splitSubfilters=False)
 
def calculateImageParallacticAngle (visitInfo, wcs)
 
def wavelengthGenerator (filterInfo, dcrNumSubfilters)
 

Function Documentation

◆ applyDcr()

def lsst.ip.diffim.dcrModel.applyDcr (   image,
  dcr,
  useInverse = False,
  splitSubfilters = False,
  kwargs 
)
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
kwargs
    Additional keyword parameters to pass in to
    `scipy.ndimage.interpolation.shift`

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

Definition at line 582 of file dcrModel.py.

582 def applyDcr(image, dcr, useInverse=False, splitSubfilters=False, **kwargs):
583  """Shift an image along the X and Y directions.
584 
585  Parameters
586  ----------
587  image : `numpy.ndarray`
588  The input image to shift.
589  dcr : `tuple`
590  Shift calculated with ``calculateDcr``.
591  Uses numpy axes ordering (Y, X).
592  If ``splitSubfilters`` is set, each element is itself a `tuple`
593  of two `float`, corresponding to the DCR shift at the two wavelengths.
594  Otherwise, each element is a `float` corresponding to the DCR shift at
595  the effective wavelength of the subfilter.
596  useInverse : `bool`, optional
597  Apply the shift in the opposite direction. Default: False
598  splitSubfilters : `bool`, optional
599  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
600  instead of at the midpoint. Default: False
601  kwargs
602  Additional keyword parameters to pass in to
603  `scipy.ndimage.interpolation.shift`
604 
605  Returns
606  -------
607  shiftedImage : `numpy.ndarray`
608  A copy of the input image with the specified shift applied.
609  """
610  if splitSubfilters:
611  if useInverse:
612  shift = [-1.*s for s in dcr[0]]
613  shift1 = [-1.*s for s in dcr[1]]
614  else:
615  shift = dcr[0]
616  shift1 = dcr[1]
617  shiftedImage = ndimage.interpolation.shift(image, shift, **kwargs)
618  shiftedImage += ndimage.interpolation.shift(image, shift1, **kwargs)
619  shiftedImage /= 2.
620  else:
621  if useInverse:
622  shift = [-1.*s for s in dcr]
623  else:
624  shift = dcr
625  shiftedImage = ndimage.interpolation.shift(image, shift, **kwargs)
626  return shiftedImage
627 
628 
def applyDcr(image, dcr, useInverse=False, splitSubfilters=False, kwargs)
Definition: dcrModel.py:582

◆ calculateDcr()

def lsst.ip.diffim.dcrModel.calculateDcr (   visitInfo,
  wcs,
  filterInfo,
  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.
filterInfo : `lsst.afw.image.Filter`
    The filter definition, set in the current instruments' obs package.
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 629 of file dcrModel.py.

629 def calculateDcr(visitInfo, wcs, filterInfo, dcrNumSubfilters, splitSubfilters=False):
630  """Calculate the shift in pixels of an exposure due to DCR.
631 
632  Parameters
633  ----------
634  visitInfo : `lsst.afw.image.VisitInfo`
635  Metadata for the exposure.
636  wcs : `lsst.afw.geom.SkyWcs`
637  Coordinate system definition (wcs) for the exposure.
638  filterInfo : `lsst.afw.image.Filter`
639  The filter definition, set in the current instruments' obs package.
640  dcrNumSubfilters : `int`
641  Number of sub-filters used to model chromatic effects within a band.
642  splitSubfilters : `bool`, optional
643  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
644  instead of at the midpoint. Default: False
645 
646  Returns
647  -------
648  dcrShift : `tuple` of two `float`
649  The 2D shift due to DCR, in pixels.
650  Uses numpy axes ordering (Y, X).
651  """
652  rotation = calculateImageParallacticAngle(visitInfo, wcs)
653  dcrShift = []
654  weight = [0.75, 0.25]
655  lambdaEff = filterInfo.getFilterProperty().getLambdaEff()
656  for wl0, wl1 in wavelengthGenerator(filterInfo, dcrNumSubfilters):
657  # Note that diffRefractAmp can be negative, since it's relative to the midpoint of the full band
658  diffRefractAmp0 = differentialRefraction(wavelength=wl0, wavelengthRef=lambdaEff,
659  elevation=visitInfo.getBoresightAzAlt().getLatitude(),
660  observatory=visitInfo.getObservatory(),
661  weather=visitInfo.getWeather())
662  diffRefractAmp1 = differentialRefraction(wavelength=wl1, wavelengthRef=lambdaEff,
663  elevation=visitInfo.getBoresightAzAlt().getLatitude(),
664  observatory=visitInfo.getObservatory(),
665  weather=visitInfo.getWeather())
666  if splitSubfilters:
667  diffRefractPix0 = diffRefractAmp0.asArcseconds()/wcs.getPixelScale().asArcseconds()
668  diffRefractPix1 = diffRefractAmp1.asArcseconds()/wcs.getPixelScale().asArcseconds()
669  diffRefractArr = [diffRefractPix0*weight[0] + diffRefractPix1*weight[1],
670  diffRefractPix0*weight[1] + diffRefractPix1*weight[0]]
671  shiftX = [diffRefractPix*np.sin(rotation.asRadians()) for diffRefractPix in diffRefractArr]
672  shiftY = [diffRefractPix*np.cos(rotation.asRadians()) for diffRefractPix in diffRefractArr]
673  dcrShift.append(((shiftY[0], shiftX[0]), (shiftY[1], shiftX[1])))
674  else:
675  diffRefractAmp = (diffRefractAmp0 + diffRefractAmp1)/2.
676  diffRefractPix = diffRefractAmp.asArcseconds()/wcs.getPixelScale().asArcseconds()
677  shiftX = diffRefractPix*np.sin(rotation.asRadians())
678  shiftY = diffRefractPix*np.cos(rotation.asRadians())
679  dcrShift.append((shiftY, shiftX))
680  return dcrShift
681 
682 
def calculateImageParallacticAngle(visitInfo, wcs)
Definition: dcrModel.py:683
def wavelengthGenerator(filterInfo, dcrNumSubfilters)
Definition: dcrModel.py:714
def differentialRefraction(wavelength, wavelengthRef, elevation, observatory, weather=None)
Definition: refraction.py:95
def calculateDcr(visitInfo, wcs, filterInfo, dcrNumSubfilters, splitSubfilters=False)
Definition: dcrModel.py:629

◆ 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 683 of file dcrModel.py.

683 def calculateImageParallacticAngle(visitInfo, wcs):
684  """Calculate the total sky rotation angle of an exposure.
685 
686  Parameters
687  ----------
688  visitInfo : `lsst.afw.image.VisitInfo`
689  Metadata for the exposure.
690  wcs : `lsst.afw.geom.SkyWcs`
691  Coordinate system definition (wcs) for the exposure.
692 
693  Returns
694  -------
695  `lsst.geom.Angle`
696  The rotation of the image axis, East from North.
697  Equal to the parallactic angle plus any additional rotation of the
698  coordinate system.
699  A rotation angle of 0 degrees is defined with
700  North along the +y axis and East along the +x axis.
701  A rotation angle of 90 degrees is defined with
702  North along the +x axis and East along the -y axis.
703  """
704  parAngle = visitInfo.getBoresightParAngle().asRadians()
705  cd = wcs.getCdMatrix()
706  if wcs.isFlipped:
707  cdAngle = (np.arctan2(-cd[0, 1], cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
708  else:
709  cdAngle = (np.arctan2(cd[0, 1], -cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
710  rotAngle = (cdAngle + parAngle)*radians
711  return rotAngle
712 
713 
def calculateImageParallacticAngle(visitInfo, wcs)
Definition: dcrModel.py:683

◆ wavelengthGenerator()

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

Parameters
----------
filterInfo : `lsst.afw.image.Filter`
    The filter definition, set in the current instruments' obs package.
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 nm.

Definition at line 714 of file dcrModel.py.

714 def wavelengthGenerator(filterInfo, dcrNumSubfilters):
715  """Iterate over the wavelength endpoints of subfilters.
716 
717  Parameters
718  ----------
719  filterInfo : `lsst.afw.image.Filter`
720  The filter definition, set in the current instruments' obs package.
721  dcrNumSubfilters : `int`
722  Number of sub-filters used to model chromatic effects within a band.
723 
724  Yields
725  ------
726  `tuple` of two `float`
727  The next set of wavelength endpoints for a subfilter, in nm.
728  """
729  lambdaMin = filterInfo.getFilterProperty().getLambdaMin()
730  lambdaMax = filterInfo.getFilterProperty().getLambdaMax()
731  wlStep = (lambdaMax - lambdaMin)/dcrNumSubfilters
732  for wl in np.linspace(lambdaMin, lambdaMax, dcrNumSubfilters, endpoint=False):
733  yield (wl, wl + wlStep)
734 
def wavelengthGenerator(filterInfo, dcrNumSubfilters)
Definition: dcrModel.py:714