LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
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)
 
 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, wcs)
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 )
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 843 of file dcrModel.py.

843def calculateImageParallacticAngle(visitInfo, wcs):
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`
851 Coordinate system definition (wcs) for the exposure.
852
853 Returns
854 -------
855 `lsst.geom.Angle`
856 The rotation of the image axis, East from North.
857 Equal to the parallactic angle plus any additional rotation of the
858 coordinate system.
859 A rotation angle of 0 degrees is defined with
860 North along the +y axis and East along the +x axis.
861 A rotation angle of 90 degrees is defined with
862 North along the +x axis and East along the -y axis.
863 """
864 parAngle = visitInfo.getBoresightParAngle().asRadians()
865 cd = wcs.getCdMatrix()
866 if wcs.isFlipped:
867 cdAngle = (np.arctan2(-cd[0, 1], cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
868 rotAngle = (cdAngle + parAngle)*geom.radians
869 else:
870 cdAngle = (np.arctan2(cd[0, 1], -cd[0, 0]) + np.arctan2(cd[1, 0], cd[1, 1]))/2.
871 rotAngle = (cdAngle - parAngle)*geom.radians
872 return rotAngle
873
874

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

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