コード例 #1
0
 def applyRotation(self, theta):
     if not isinstance(theta, galsim.Angle):
         raise TypeError("Input theta should be an Angle")
     sigma = self.SBProfile.getSigma()
     bvec = self.SBProfile.getBVec().copy()
     bvec.rotate(theta)
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #2
0
 def setBVec(self, bvec):
     sigma = self.SBProfile.getSigma()
     order = self.SBProfile.getBVec().order
     bvec_size = galsim.LVectorSize(order)
     if len(bvec) != bvec_size:
         raise ValueError("bvec is the wrong size for the Shapelet order")
     import numpy
     bvec = galsim.LVector(order, numpy.array(bvec))
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #3
0
 def setOrder(self, order):
     curr_bvec = self.SBProfile.getBVec()
     curr_order = curr_bvec.order
     if curr_order == order: return
     # Preserve the existing values as much as possible.
     sigma = self.SBProfile.getSigma()
     if curr_order > order:
         bvec = galsim.LVector(order,
                               curr_bvec.array[0:galsim.LVectorSize(order)])
     else:
         import numpy
         a = numpy.zeros(galsim.LVectorSize(order))
         a[0:len(curr_bvec.array)] = curr_bvec.array
         bvec = galsim.LVector(order, a)
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #4
0
    def fitImage(self, image, center=None, normalization='flux'):
        """Fit for a shapelet decomposition of a given image

        The optional normalization parameter mirrors the parameter in the GSObject `draw` method.
        If the fitted shapelet is drawn with the same normalization value as was used when it 
        was fit, then the resulting image should be an approximate match to the original image.

        For example:

            image = ...
            shapelet = galsim.Shapelet(sigma, order)
            shapelet.fitImage(image,normalization='sb')
            shapelet.draw(image=image2, dx=image.scale, normalization='sb')

        Then image2 and image should be as close to the same as possible for the given
        sigma and order.  Increasing the order can improve the fit, as can having sigma match
        the natural scale size of the image.  However, it should be noted that some images
        are not well fit by a shapelet for any (reasonable) order.

        @param image          The Image for which to fit the shapelet decomposition
        @param center         The position in pixels to use for the center of the decomposition.
                              [Default: use the image center (`image.bounds.trueCenter()`)]
        @param normalization  The normalization to assume for the image. 
                              (Default `normalization = "flux"`)
        """
        if not center:
            center = image.bounds.trueCenter()
        # convert from PositionI if necessary
        center = galsim.PositionD(center.x, center.y)

        if not normalization.lower() in ("flux", "f", "surface brightness",
                                         "sb"):
            raise ValueError((
                "Invalid normalization requested: '%s'. Expecting one of 'flux', "
                + "'f', 'surface brightness' or 'sb'.") % normalization)

        sigma = self.SBProfile.getSigma()
        bvec = self.SBProfile.getBVec().copy()

        galsim.ShapeletFitImage(sigma, bvec, image, center)

        if normalization.lower() == "flux" or normalization.lower() == "f":
            bvec /= image.scale**2

        # SBShapelet, like all SBProfiles, is immutable, so we need to reinitialize with a
        # new Shapelet object.
        GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #5
0
    def __init__(self, sigma, order, bvec=None, gsparams=None):
        # Make sure order and sigma are the right type:
        order = int(order)
        sigma = float(sigma)

        # Make bvec if necessary
        if bvec is None:
            bvec = galsim.LVector(order)
        else:
            bvec_size = galsim.LVectorSize(order)
            if len(bvec) != bvec_size:
                raise ValueError(
                    "bvec is the wrong size for the provided order")
            import numpy
            bvec = galsim.LVector(order, numpy.array(bvec))

        GSObject.__init__(self, galsim.SBShapelet(sigma, bvec, gsparams))
コード例 #6
0
 def applyMagnification(self, mu):
     import numpy
     sigma = self.SBProfile.getSigma() * numpy.sqrt(mu)
     bvec = self.SBProfile.getBVec() * mu
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #7
0
 def applyDilation(self, scale):
     sigma = self.SBProfile.getSigma() * scale
     bvec = self.SBProfile.getBVec()
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #8
0
 def scaleFlux(self, fluxRatio):
     # More efficient to change the bvector rather than add a transformation layer above
     # the SBShapelet, which is what the normal setFlux method does.
     sigma = self.SBProfile.getSigma()
     bvec = self.SBProfile.getBVec() * fluxRatio
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #9
0
 def setPQ(self, p, q, re, im=0.):
     sigma = self.SBProfile.getSigma()
     bvec = self.SBProfile.getBVec().copy()
     bvec.setPQ(p, q, re, im)
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
コード例 #10
0
 def setSigma(self, sigma):
     bvec = self.SBProfile.getBVec()
     GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))