Ejemplo n.º 1
0
    def evaluate(self, x, y, z, lon0, lat0, rdiff0, rinj, delta, b, piv, piv2):

        lon, lat = x, y
        energy = z

        # energy in kev -> TeV.
        # NOTE: the use of piv2 is necessary to preserve dimensional correctness: the logarithm can only be taken
        # of a dimensionless quantity, so there must be a pivot there.

        e_energy_piv2 = 17. * \
            np.power(old_div(energy, piv2), 0.54 + 0.046 *
                     np.log10(old_div(energy, piv2)))
        e_piv_piv2 = 17. * \
            np.power(old_div(piv, piv2), 0.54 + 0.046 *
                     np.log10(old_div(piv, piv2)))

        rdiff_c = rdiff0 * np.power(old_div(e_energy_piv2, e_piv_piv2), old_div((delta - 1.), 2.)) * \
            np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / \
            np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 *
                    np.power(1. + 0.0107 * e_energy_piv2, -1.5))

        rdiff_i = rdiff0 * rinj * \
            np.power(old_div(e_energy_piv2, e_piv_piv2), old_div(delta, 2.))

        rdiff = np.minimum(rdiff_c, rdiff_i)

        angsep = angular_distance_fast(lon, lat, lon0, lat0)

        pi = np.pi

        rdiffs, angseps = np.meshgrid(rdiff, angsep)

        return np.power(old_div(180.0, pi), 2) * 1.2154 / (pi * np.sqrt(pi) * rdiffs * (angseps + 0.06 * rdiffs)) * \
            np.exp(old_div(-np.power(angseps, 2), rdiffs ** 2))
Ejemplo n.º 2
0
    def evaluate(self, x, y, z, lon0, lat0, rdiff0, delta, b, piv, piv2, incl, elongation):

        lon, lat = x, y
        energy = z

        # energy in kev -> TeV.
        # NOTE: the use of piv2 is necessary to preserve dimensional correctness: the logarithm can only be taken
        # of a dimensionless quantity, so there must be a pivot there.

        e_energy_piv2 = 17. * \
            np.power(old_div(energy, piv2), 0.54 + 0.046 *
                     np.log10(old_div(energy, piv2)))
        e_piv_piv2 = 17. * \
            np.power(old_div(piv, piv2), 0.54 + 0.046 *
                     np.log10(old_div(piv, piv2)))

        try:

            rdiff_a = rdiff0 * np.power(old_div(e_energy_piv2, e_piv_piv2), old_div((delta - 1.), 2.)) * \
                np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / \
                np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 *
                        np.power(1. + 0.0107 * e_energy_piv2, -1.5))

        except ValueError:

            # This happens when using units, because astropy.units fails with the message:
            # "ValueError: Quantities and Units may only be raised to a scalar power"

            # Work around the problem with this loop, which is slow but using units is only for testing purposes or
            # single calls, so it shouldn't matter too much
            rdiff_a = np.array([(rdiff0 * np.power(old_div(e_energy_piv2, e_piv_piv2), x)).value for x in (delta - 1.) / 2. * np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) /
                                np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_energy_piv2, -1.5))]) * rdiff0.unit

        rdiff_b = rdiff_a * elongation

        pi = np.pi

        angsep = angular_distance_fast(lon, lat, lon0, lat0)
        ang = np.arctan2(lat - lat0, (lon - lon0) *
                         np.cos(lat0 * np.pi / 180.))

        theta = np.arctan2(old_div(np.sin(ang-incl*np.pi/180.),
                                   elongation), np.cos(ang-incl*np.pi/180.))

        rdiffs_a, thetas = np.meshgrid(rdiff_a, theta)
        rdiffs_b, angseps = np.meshgrid(rdiff_b, angsep)

        rdiffs = np.sqrt(rdiffs_a ** 2 * np.cos(thetas) **
                         2 + rdiffs_b ** 2 * np.sin(thetas) ** 2)

        results = np.power(old_div(180.0, pi), 2) * 1.22 / (pi * np.sqrt(pi) * rdiffs_a * np.sqrt(
            elongation) * (angseps + 0.06 * rdiffs)) * np.exp(old_div(-np.power(angseps, 2), rdiffs ** 2))

        return results
Ejemplo n.º 3
0
    def evaluate(self, x, y, z, lon0, lat0, rdiff0, delta, uratio, piv, piv2):

        lon, lat = x, y
        energy = z

        # energy in kev -> TeV.
        # NOTE: the use of piv2 is necessary to preserve dimensional correctness: the logarithm can only be taken
        # of a dimensionless quantity, so there must be a pivot there.

        e_energy_piv2 = 17. * np.power(
            old_div(energy, piv2),
            0.54 + 0.046 * np.log10(old_div(energy, piv2)))
        e_piv_piv2 = 17. * np.power(
            old_div(piv, piv2), 0.54 + 0.046 * np.log10(old_div(piv, piv2)))

        try:

            rdiff = rdiff0 * np.power(old_div(e_energy_piv2, e_piv_piv2), old_div((delta - 1.), 2.)) * \
                    np.sqrt(1. + uratio * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / \
                    np.sqrt(1. + uratio * np.power(1. + 0.0107 * e_energy_piv2, -1.5))

        except ValueError:

            # This happens when using units, because astropy.units fails with the message:
            # "ValueError: Quantities and Units may only be raised to a scalar power"

            # Work around the problem with this loop, which is slow but using units is only for testing purposes or
            # single calls, so it shouldn't matter too much
            rdiff = np.array([
                (rdiff0 *
                 np.power(old_div(e_energy_piv2, e_piv_piv2), x)).value
                for x in (delta - 1.) / 2. *
                np.sqrt(1. +
                        uratio * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) /
                np.sqrt(1. +
                        uratio * np.power(1. + 0.0107 * e_energy_piv2, -1.5))
            ]) * rdiff0.unit

        angsep = angular_distance_fast(lon, lat, lon0, lat0)

        pi = np.pi

        rdiffs, angseps = np.meshgrid(rdiff, angsep)

        return np.power(old_div(180.0, pi), 2) * 1.2154 / (pi * np.sqrt(pi) * rdiffs * (angseps + 0.06 * rdiffs)) * \
               np.exp(old_div(-np.power(angseps, 2), rdiffs ** 2))
Ejemplo n.º 4
0
    def evaluate(self, x, y, z, K, lon0, lat0, *args):

        lons = x
        lats = y
        energies = z

        angsep = angular_distance_fast(lon0, lat0, lons, lats)

        #if only one energy is passed, make sure we can iterate just once
        if not isinstance(energies, np.ndarray):

            energies = np.array(energies)

        #transform energy from keV to MeV
        #galprop likes MeV, 3ML likes keV
        log_energies = np.log10(energies) - np.log10((u.MeV.to("keV")/u.keV).value)

        #A = np.multiply(K, self._interpolate(lons, lats, log_energies, args)/(10**convert_val))
        A = np.multiply(K, self._interpolate(log_energies, lons, lats, args)) #if templates are normalized no need to convert back

        return A