コード例 #1
0
ファイル: test_transforms.py プロジェクト: sweverett/GalSim
def test_gsparams():
    """Test withGSParams with some non-default gsparams
    """
    obj = galsim.Exponential(half_light_radius=1.7)
    gsp = galsim.GSParams(folding_threshold=1.e-4, maxk_threshold=1.e-4, maximum_fft_size=1.e4)
    gsp2 = galsim.GSParams(folding_threshold=1.e-2, maxk_threshold=1.e-2)

    tr = obj.shear(g1=0.2, g2=0.3)
    jac = galsim.Shear(g1=0.2, g2=0.3).getMatrix()
    tr1 = tr.withGSParams(gsp)
    assert tr.gsparams == galsim.GSParams()
    assert tr1.gsparams == gsp
    assert tr1.original.gsparams == gsp

    tr2 = galsim.Transformation(obj.withGSParams(gsp), jac=jac)
    tr3 = galsim.Transformation(galsim.Exponential(half_light_radius=1.7, gsparams=gsp), jac=jac)
    tr4 = galsim.Transform(obj, jac=jac, gsparams=gsp)
    assert tr != tr1
    assert tr1 == tr2
    assert tr1 == tr3
    assert tr1 == tr4
    print('stepk = ',tr.stepk, tr1.stepk)
    assert tr1.stepk < tr.stepk
    print('maxk = ',tr.maxk, tr1.maxk)
    assert tr1.maxk > tr.maxk

    tr5 = galsim.Transform(obj, jac=jac, gsparams=gsp, propagate_gsparams=False)
    assert tr5 != tr4
    assert tr5.gsparams == gsp
    assert tr5.original.gsparams == galsim.GSParams()

    tr6 = tr5.withGSParams(gsp2)
    assert tr6 != tr5
    assert tr6.gsparams == gsp2
    assert tr6.original.gsparams == galsim.GSParams()
コード例 #2
0
def test_ne():
    """ Check that inequality works as expected."""
    gal1 = galsim.Gaussian(fwhm=1)
    gal2 = galsim.Gaussian(fwhm=2)
    gsp = galsim.GSParams(maxk_threshold=1.1e-3, folding_threshold=5.1e-3)

    # Transforms using the callables below will produce galsim.ChromaticTransformation objects
    # instead of galsim.Transformation objects, but they should still compare unequal so we go ahead
    # and test them too.
    jac = lambda w: [[w, 0], [0, 1]]
    offset = lambda w: (0, w)
    flux_ratio = lambda w: w

    objs = [
        galsim.Transform(gal1),
        galsim.Transform(gal2),
        galsim.Transform(gal1, jac=(1, 0.5, 0.5, 1)),
        galsim.Transform(gal1, jac=jac),
        galsim.Transform(gal1, offset=galsim.PositionD(2, 2)),
        galsim.Transform(gal1, offset=offset),
        galsim.Transform(gal1, flux_ratio=1.1),
        galsim.Transform(gal1, flux_ratio=flux_ratio),
        galsim.Transform(gal1, gsparams=gsp)
    ]
    all_obj_diff(objs)
コード例 #3
0
    def __mul__(self, other):
        # Watch out for 5 types of `other`:
        # 1.  SED: Check that not both spectral densities.
        # 2.  GSObject: return a ChromaticObject().
        # 3.  Bandpass: return an SED, but carefully propagate blue/red limit and wave_list.
        # 4.  Callable: return an SED
        # 5.  Scalar: return an SED
        #
        # Additionally, check for shortcuts when self._const

        # Product of two SEDs
        if isinstance(other, galsim.SED):
            if self.spectral and other.spectral:
                raise TypeError(
                    "Cannot multiply two spectral densities together.")

            if other._const:
                return self.__mul__(
                    other._spec(42.0))  # const, so can eval anywhere.
            elif self._const:
                return other.__mul__(self._spec(42.0))

            if self.spectral:
                redshift = self.redshift
            elif other.spectral:
                redshift = other.redshift
            else:
                redshift = 0.0

            fast = self.fast and other.fast

            wave_list, blue_limit, red_limit = galsim.utilities.combine_wave_list(
                self, other)
            if fast:
                # Make sure _fast_spec exists in both
                self._make_fast_spec()
                other._make_fast_spec()
                zfactor1 = (1. + redshift) / (1. + self.redshift)
                zfactor2 = (1. + redshift) / (1. + other.redshift)
                spec = lambda w: self._fast_spec(
                    w * zfactor1) * other._fast_spec(w * zfactor2)
            else:
                spec = lambda w: self(w *
                                      (1. + redshift)) * other(w *
                                                               (1. + redshift))
            _spectral = self.spectral or other.spectral
            return SED(spec,
                       'nm',
                       'fphotons',
                       redshift=redshift,
                       fast=fast,
                       _blue_limit=blue_limit,
                       _red_limit=red_limit,
                       _wave_list=wave_list,
                       _spectral=_spectral)

        # Product of SED and achromatic GSObject is a `ChromaticTransformation`.
        if isinstance(other, galsim.GSObject):
            return galsim.Transform(other, flux_ratio=self)

        # Product of SED and Bandpass is (filtered) SED.  The `redshift` attribute is retained.
        if isinstance(other, galsim.Bandpass):
            wave_list, blue_limit, red_limit = galsim.utilities.combine_wave_list(
                self, other)
            zfactor = (1.0 + self.redshift) * other.wave_factor
            if self.fast:
                self._make_fast_spec()
                spec = lambda w: self._fast_spec(w) * other._tp(w * zfactor)
            else:
                spec = lambda w: self(w * (1.0 + self.redshift)) * other._tp(
                    w * zfactor)
            return SED(spec,
                       'nm',
                       'fphotons',
                       redshift=self.redshift,
                       fast=self.fast,
                       _blue_limit=blue_limit,
                       _red_limit=red_limit,
                       _wave_list=wave_list,
                       _spectral=self.spectral)

        # Product of SED with generic callable is also a (filtered) SED, with retained `redshift`.
        if hasattr(other, '__call__'):
            if self.fast:
                self._make_fast_spec()
                spec = lambda w: self._fast_spec(w) * other(w * (1.0 + self.
                                                                 redshift))
            else:
                spec = lambda w: self(w * (1.0 + self.redshift)) * other(w * (
                    1.0 + self.redshift))
            flux_type = 'fphotons' if self.spectral else '1'
            return SED(spec,
                       'nm',
                       flux_type,
                       redshift=self.redshift,
                       fast=self.fast,
                       _blue_limit=self.blue_limit,
                       _red_limit=self.red_limit,
                       _wave_list=self.wave_list,
                       _spectral=self.spectral)

        if isinstance(other, (int, float)):
            # If other is a scalar and self._spec a LookupTable, then remake that LookupTable.
            if isinstance(self._spec, galsim.LookupTable):
                wave_type = self.wave_type
                flux_type = self.flux_type
                x = self._spec.getArgs()
                f = [val * other for val in self._spec.getVals()]
                spec = galsim.LookupTable(x,
                                          f,
                                          x_log=self._spec.x_log,
                                          f_log=self._spec.f_log,
                                          interpolant=self._spec.interpolant)
            elif self._const:
                spec = self._spec(42.0) * other
                wave_type = 'nm'
                flux_type = '1'
            else:
                wave_type = 'nm'
                flux_type = 'fphotons' if self.spectral else '1'
                if self.fast:
                    self._make_fast_spec()
                    spec = lambda w: self._fast_spec(w) * other
                else:
                    spec = lambda w: self(w * (1.0 + self.redshift)) * other
            return SED(spec,
                       wave_type,
                       flux_type,
                       redshift=self.redshift,
                       fast=self.fast,
                       _blue_limit=self.blue_limit,
                       _red_limit=self.red_limit,
                       _wave_list=self.wave_list,
                       _spectral=self.spectral)
コード例 #4
0
ファイル: test_transforms.py プロジェクト: sweverett/GalSim
def test_ne():
    """ Check that inequality works as expected."""
    gal1 = galsim.Gaussian(fwhm=1)
    gal2 = galsim.Gaussian(fwhm=2)
    gsp = galsim.GSParams(maxk_threshold=1.1e-3, folding_threshold=5.1e-3)

    # Transforms using the callables below will produce galsim.ChromaticTransformation objects
    # instead of galsim.Transformation objects, but they should still compare unequal so we go ahead
    # and test them too.
    jac = lambda w: [[w, 0], [0, 1]]
    offset = lambda w: (0, w)
    flux_ratio = lambda w: w

    objs = [galsim.Transform(gal1),
            galsim.Transform(gal2),
            galsim.Transform(gal1, jac=(1, 0.5, 0.5, 1)),
            galsim.Transform(gal1, jac=(1, 1, 1, 1)),
            galsim.Transform(gal1, jac=jac),
            galsim.Transform(gal1, offset=galsim.PositionD(2, 2)),
            galsim.Transform(gal1, offset=offset),
            galsim.Transform(gal1, flux_ratio=1.1),
            galsim.Transform(gal1, flux_ratio=flux_ratio),
            galsim.Transform(gal1, gsparams=gsp),
            galsim.Transform(gal1, gsparams=gsp, propagate_gsparams=False)]
    all_obj_diff(objs)

    # The degenerate jacobian will build fine, but will raise an exception when used.
    degen = galsim.Transform(gal1, jac=(1, 1, 1, 1))
    with assert_raises(galsim.GalSimError):
        sbp = degen._sbp

    assert_raises(TypeError, galsim.Transform, jac)