LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+9ce8016dbd,g1955dfad08+0bd186d245,g199a45376c+5137f08352,g1fd858c14a+a888a50aa2,g262e1987ae+45f9aba685,g29ae962dfc+1c7d47a24f,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+eed17d2c67,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+c4107e45b5,g67b6fd64d1+6dc8069a4c,g74acd417e5+f452e9c21a,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+2025e9ce17,g7cc15d900a+2d158402f9,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d4809ba88+c4107e45b5,g8d7436a09f+e96c132b44,g8ea07a8fe4+db21c37724,g98df359435+aae6d409c1,ga2180abaac+edbf708997,gac66b60396+966efe6077,gb632fb1845+88945a90f8,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gca7fc764a6+6dc8069a4c,gd7ef33dd92+6dc8069a4c,gda68eeecaf+7d1e613a8d,gdab6d2f7ff+f452e9c21a,gdbb4c4dda9+c4107e45b5,ge410e46f29+6dc8069a4c,ge41e95a9f2+c4107e45b5,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.ip.diffim.dcrModel Namespace Reference

Classes

class  DcrModel
 

Functions

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

Function Documentation

◆ applyDcr()

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

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

◆ calculateDcr()

lsst.ip.diffim.dcrModel.calculateDcr ( visitInfo,
wcs,
effectiveWavelength,
bandwidth,
dcrNumSubfilters,
splitSubfilters = False,
bbox = None )
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
bbox : `lsst.afw.geom.Box2I`, optional
    Bounding box for the region of interest for evaluating the local
    pixelScale (defaults to the Sky Origin of the ``wcs`` provided if
    ``bbox`` is None).

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

Definition at line 777 of file dcrModel.py.

778 bbox=None):
779 """Calculate the shift in pixels of an exposure due to DCR.
780
781 Parameters
782 ----------
783 visitInfo : `lsst.afw.image.VisitInfo`
784 Metadata for the exposure.
785 wcs : `lsst.afw.geom.SkyWcs`
786 Coordinate system definition (wcs) for the exposure.
787 effectiveWavelength : `float`
788 The effective wavelengths of the current filter, in nanometers.
789 bandwidth : `float`
790 The bandwidth of the current filter, in nanometers.
791 dcrNumSubfilters : `int`
792 Number of sub-filters used to model chromatic effects within a band.
793 splitSubfilters : `bool`, optional
794 Calculate DCR for two evenly-spaced wavelengths in each subfilter,
795 instead of at the midpoint. Default: False
796 bbox : `lsst.afw.geom.Box2I`, optional
797 Bounding box for the region of interest for evaluating the local
798 pixelScale (defaults to the Sky Origin of the ``wcs`` provided if
799 ``bbox`` is None).
800
801 Returns
802 -------
803 dcrShift : `tuple` of two `float`
804 The 2D shift due to DCR, in pixels.
805 Uses numpy axes ordering (Y, X).
806 """
807 rotation = calculateImageParallacticAngle(visitInfo)
808 dcrShift = []
809 weight = [0.75, 0.25]
810 for wl0, wl1 in wavelengthGenerator(effectiveWavelength, bandwidth, dcrNumSubfilters):
811 # Note that diffRefractAmp can be negative, since it's relative to the
812 # midpoint of the full band
813 diffRefractAmp0 = differentialRefraction(wavelength=wl0, wavelengthRef=effectiveWavelength,
814 elevation=visitInfo.getBoresightAzAlt().getLatitude(),
815 observatory=visitInfo.getObservatory(),
816 weather=visitInfo.getWeather())
817 diffRefractAmp1 = differentialRefraction(wavelength=wl1, wavelengthRef=effectiveWavelength,
818 elevation=visitInfo.getBoresightAzAlt().getLatitude(),
819 observatory=visitInfo.getObservatory(),
820 weather=visitInfo.getWeather())
821 if bbox is not None:
822 pixelScale = wcs.getPixelScale(bbox.getCenter()).asArcseconds()
823 else:
824 pixelScale = wcs.getPixelScale().asArcseconds()
825
826 if splitSubfilters:
827 diffRefractPix0 = diffRefractAmp0.asArcseconds()/pixelScale
828 diffRefractPix1 = diffRefractAmp1.asArcseconds()/pixelScale
829 diffRefractArr = [diffRefractPix0*weight[0] + diffRefractPix1*weight[1],
830 diffRefractPix0*weight[1] + diffRefractPix1*weight[0]]
831 shiftX = [diffRefractPix*np.sin(rotation.asRadians()) for diffRefractPix in diffRefractArr]
832 shiftY = [diffRefractPix*np.cos(rotation.asRadians()) for diffRefractPix in diffRefractArr]
833 dcrShift.append(((shiftY[0], shiftX[0]), (shiftY[1], shiftX[1])))
834 else:
835 diffRefractAmp = (diffRefractAmp0 + diffRefractAmp1)/2.
836 diffRefractPix = diffRefractAmp.asArcseconds()/pixelScale
837 shiftX = diffRefractPix*np.sin(rotation.asRadians())
838 shiftY = diffRefractPix*np.cos(rotation.asRadians())
839 dcrShift.append((shiftY, shiftX))
840 return dcrShift
841
842

◆ calculateImageParallacticAngle()

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

Parameters
----------
visitInfo : `lsst.afw.image.VisitInfo`
    Metadata for the exposure.
wcs : `lsst.afw.geom.SkyWcs`, optional
    Coordinate system definition (wcs) for the exposure.
    Deprecated, will be removed following v30.

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

843def calculateImageParallacticAngle(visitInfo, wcs=None):
844 """Calculate the total sky rotation angle of an exposure.
845
846 Parameters
847 ----------
848 visitInfo : `lsst.afw.image.VisitInfo`
849 Metadata for the exposure.
850 wcs : `lsst.afw.geom.SkyWcs`, optional
851 Coordinate system definition (wcs) for the exposure.
852 Deprecated, will be removed following v30.
853
854 Returns
855 -------
856 `lsst.geom.Angle`
857 The rotation of the image axis, East from North.
858 Equal to the parallactic angle plus any additional rotation of the
859 coordinate system.
860 A rotation angle of 0 degrees is defined with
861 North along the +y axis and East along the +x axis.
862 A rotation angle of 90 degrees is defined with
863 North along the +x axis and East along the -y axis.
864 """
865 rotAngle = visitInfo.boresightParAngle - visitInfo.boresightRotAngle
866 return rotAngle
867
868

◆ wavelengthGenerator()

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

869def wavelengthGenerator(effectiveWavelength, bandwidth, dcrNumSubfilters):
870 """Iterate over the wavelength endpoints of subfilters.
871
872 Parameters
873 ----------
874 effectiveWavelength : `float`
875 The effective wavelength of the current filter, in nanometers.
876 bandwidth : `float`
877 The bandwidth of the current filter, in nanometers.
878 dcrNumSubfilters : `int`
879 Number of sub-filters used to model chromatic effects within a band.
880
881 Yields
882 ------
883 `tuple` of two `float`
884 The next set of wavelength endpoints for a subfilter, in nanometers.
885 """
886 lambdaMin = effectiveWavelength - bandwidth/2
887 lambdaMax = effectiveWavelength + bandwidth/2
888 wlStep = bandwidth/dcrNumSubfilters
889 for wl in np.linspace(lambdaMin, lambdaMax, dcrNumSubfilters, endpoint=False):
890 yield (wl, wl + wlStep)