LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
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)