LSSTApplications  20.0.0
LSSTDataManagementBasePackage
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, 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,
  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 637 of file dcrModel.py.

637 def applyDcr(image, dcr, useInverse=False, splitSubfilters=False, splitThreshold=0.,
638  doPrefilter=True, order=3):
639  """Shift an image along the X and Y directions.
640 
641  Parameters
642  ----------
643  image : `numpy.ndarray`
644  The input image to shift.
645  dcr : `tuple`
646  Shift calculated with ``calculateDcr``.
647  Uses numpy axes ordering (Y, X).
648  If ``splitSubfilters`` is set, each element is itself a `tuple`
649  of two `float`, corresponding to the DCR shift at the two wavelengths.
650  Otherwise, each element is a `float` corresponding to the DCR shift at
651  the effective wavelength of the subfilter.
652  useInverse : `bool`, optional
653  Apply the shift in the opposite direction. Default: False
654  splitSubfilters : `bool`, optional
655  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
656  instead of at the midpoint. Default: False
657  splitThreshold : `float`, optional
658  Minimum DCR difference within a subfilter required to use ``splitSubfilters``
659  doPrefilter : `bool`, optional
660  Spline filter the image before shifting, if set. Filtering is required,
661  so only set to False if the image is already filtered.
662  Filtering takes ~20% of the time of shifting, so if `applyDcr` will be
663  called repeatedly on the same image it is more efficient to precalculate
664  the filter.
665  order : `int`, optional
666  The order of the spline interpolation, default is 3.
667 
668  Returns
669  -------
670  shiftedImage : `numpy.ndarray`
671  A copy of the input image with the specified shift applied.
672  """
673  if doPrefilter:
674  prefilteredImage = ndimage.spline_filter(image, order=order)
675  else:
676  prefilteredImage = image
677  if splitSubfilters:
678  shiftAmp = np.max(np.abs([_dcr0 - _dcr1 for _dcr0, _dcr1 in zip(dcr[0], dcr[1])]))
679  if shiftAmp >= splitThreshold:
680  if useInverse:
681  shift = [-1.*s for s in dcr[0]]
682  shift1 = [-1.*s for s in dcr[1]]
683  else:
684  shift = dcr[0]
685  shift1 = dcr[1]
686  shiftedImage = ndimage.shift(prefilteredImage, shift, prefilter=False, order=order)
687  shiftedImage += ndimage.shift(prefilteredImage, shift1, prefilter=False, order=order)
688  shiftedImage /= 2.
689  return shiftedImage
690  else:
691  # If the difference in the DCR shifts is less than the threshold,
692  # then just use the average shift for efficiency.
693  dcr = (np.mean(dcr[0]), np.mean(dcr[1]))
694  if useInverse:
695  shift = [-1.*s for s in dcr]
696  else:
697  shift = dcr
698  shiftedImage = ndimage.shift(prefilteredImage, shift, prefilter=False, order=order)
699  return shiftedImage
700 
701 

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

702 def calculateDcr(visitInfo, wcs, filterInfo, dcrNumSubfilters, splitSubfilters=False):
703  """Calculate the shift in pixels of an exposure due to DCR.
704 
705  Parameters
706  ----------
707  visitInfo : `lsst.afw.image.VisitInfo`
708  Metadata for the exposure.
709  wcs : `lsst.afw.geom.SkyWcs`
710  Coordinate system definition (wcs) for the exposure.
711  filterInfo : `lsst.afw.image.Filter`
712  The filter definition, set in the current instruments' obs package.
713  dcrNumSubfilters : `int`
714  Number of sub-filters used to model chromatic effects within a band.
715  splitSubfilters : `bool`, optional
716  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
717  instead of at the midpoint. Default: False
718 
719  Returns
720  -------
721  dcrShift : `tuple` of two `float`
722  The 2D shift due to DCR, in pixels.
723  Uses numpy axes ordering (Y, X).
724  """
725  rotation = calculateImageParallacticAngle(visitInfo, wcs)
726  dcrShift = []
727  weight = [0.75, 0.25]
728  lambdaEff = filterInfo.getFilterProperty().getLambdaEff()
729  for wl0, wl1 in wavelengthGenerator(filterInfo, dcrNumSubfilters):
730  # Note that diffRefractAmp can be negative, since it's relative to the midpoint of the full band
731  diffRefractAmp0 = differentialRefraction(wavelength=wl0, wavelengthRef=lambdaEff,
732  elevation=visitInfo.getBoresightAzAlt().getLatitude(),
733  observatory=visitInfo.getObservatory(),
734  weather=visitInfo.getWeather())
735  diffRefractAmp1 = differentialRefraction(wavelength=wl1, wavelengthRef=lambdaEff,
736  elevation=visitInfo.getBoresightAzAlt().getLatitude(),
737  observatory=visitInfo.getObservatory(),
738  weather=visitInfo.getWeather())
739  if splitSubfilters:
740  diffRefractPix0 = diffRefractAmp0.asArcseconds()/wcs.getPixelScale().asArcseconds()
741  diffRefractPix1 = diffRefractAmp1.asArcseconds()/wcs.getPixelScale().asArcseconds()
742  diffRefractArr = [diffRefractPix0*weight[0] + diffRefractPix1*weight[1],
743  diffRefractPix0*weight[1] + diffRefractPix1*weight[0]]
744  shiftX = [diffRefractPix*np.sin(rotation.asRadians()) for diffRefractPix in diffRefractArr]
745  shiftY = [diffRefractPix*np.cos(rotation.asRadians()) for diffRefractPix in diffRefractArr]
746  dcrShift.append(((shiftY[0], shiftX[0]), (shiftY[1], shiftX[1])))
747  else:
748  diffRefractAmp = (diffRefractAmp0 + diffRefractAmp1)/2.
749  diffRefractPix = diffRefractAmp.asArcseconds()/wcs.getPixelScale().asArcseconds()
750  shiftX = diffRefractPix*np.sin(rotation.asRadians())
751  shiftY = diffRefractPix*np.cos(rotation.asRadians())
752  dcrShift.append((shiftY, shiftX))
753  return dcrShift
754 
755 

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

756 def calculateImageParallacticAngle(visitInfo, wcs):
757  """Calculate the total sky rotation angle of an exposure.
758 
759  Parameters
760  ----------
761  visitInfo : `lsst.afw.image.VisitInfo`
762  Metadata for the exposure.
763  wcs : `lsst.afw.geom.SkyWcs`
764  Coordinate system definition (wcs) for the exposure.
765 
766  Returns
767  -------
768  `lsst.geom.Angle`
769  The rotation of the image axis, East from North.
770  Equal to the parallactic angle plus any additional rotation of the
771  coordinate system.
772  A rotation angle of 0 degrees is defined with
773  North along the +y axis and East along the +x axis.
774  A rotation angle of 90 degrees is defined with
775  North along the +x axis and East along the -y axis.
776  """
777  parAngle = visitInfo.getBoresightParAngle().asRadians()
778  cd = wcs.getCdMatrix()
779  if wcs.isFlipped:
780  cdAngle = (np.arctan2(-cd[0, 1], cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
781  rotAngle = (cdAngle + parAngle)*geom.radians
782  else:
783  cdAngle = (np.arctan2(cd[0, 1], -cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
784  rotAngle = (cdAngle - parAngle)*geom.radians
785  return rotAngle
786 
787 

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

788 def wavelengthGenerator(filterInfo, dcrNumSubfilters):
789  """Iterate over the wavelength endpoints of subfilters.
790 
791  Parameters
792  ----------
793  filterInfo : `lsst.afw.image.Filter`
794  The filter definition, set in the current instruments' obs package.
795  dcrNumSubfilters : `int`
796  Number of sub-filters used to model chromatic effects within a band.
797 
798  Yields
799  ------
800  `tuple` of two `float`
801  The next set of wavelength endpoints for a subfilter, in nm.
802  """
803  lambdaMin = filterInfo.getFilterProperty().getLambdaMin()
804  lambdaMax = filterInfo.getFilterProperty().getLambdaMax()
805  wlStep = (lambdaMax - lambdaMin)/dcrNumSubfilters
806  for wl in np.linspace(lambdaMin, lambdaMax, dcrNumSubfilters, endpoint=False):
807  yield (wl, wl + wlStep)
lsst::afw::coord.refraction.differentialRefraction
def differentialRefraction(wavelength, wavelengthRef, elevation, observatory, weather=None)
Definition: refraction.py:95
lsst::ip::diffim.dcrModel.applyDcr
def applyDcr(image, dcr, useInverse=False, splitSubfilters=False, splitThreshold=0., doPrefilter=True, order=3)
Definition: dcrModel.py:637
lsst::ip::diffim.dcrModel.calculateImageParallacticAngle
def calculateImageParallacticAngle(visitInfo, wcs)
Definition: dcrModel.py:756
lsst::ip::diffim.dcrModel.calculateDcr
def calculateDcr(visitInfo, wcs, filterInfo, dcrNumSubfilters, splitSubfilters=False)
Definition: dcrModel.py:702
lsst::ip::diffim.dcrModel.wavelengthGenerator
def wavelengthGenerator(filterInfo, dcrNumSubfilters)
Definition: dcrModel.py:788