예제 #1
0
    def test_project_2d_random(self):
        r = 1
        R, x, y = velocity_util.project2d_random(r=r)
        assert R <= r

        r = np.linspace(0, 10, 100)
        R, x, y = velocity_util.project2d_random(r=r)
        assert len(R) == 100
예제 #2
0
    def test_project_2d_random(self):
        r = 1
        R, x, y = velocity_util.project2d_random(r=r)
        assert R <= r

        num = 100000
        r = np.ones(num)
        R, x, y = velocity_util.project2d_random(r=r)
        assert len(R) == num
예제 #3
0
    def test_draw_light_3d(self):
        lightProfile = LightProfile(profile_list=['HERNQUIST'],
                                    min_interpolate=0.0001,
                                    max_interpolate=100.)
        kwargs_profile = [{'amp': 1., 'Rs': 0.5}]
        r_list = lightProfile.draw_light_3d(kwargs_profile,
                                            n=100000,
                                            new_compute=False)
        print(r_list, 'r_list')
        # project it
        R, x, y = velocity_util.project2d_random(r_list)
        # test with draw light 2d profile routine

        bins = np.linspace(0.1, 1, 10)
        hist, bins_hist = np.histogram(r_list, bins=bins, density=True)
        bins_plot = (bins_hist[1:] + bins_hist[:-1]) / 2.
        light3d = lightProfile.light_3d(r=bins_plot,
                                        kwargs_list=kwargs_profile)
        light3d *= bins_plot**2
        light3d /= np.sum(light3d)
        hist /= np.sum(hist)
        #import matplotlib.pyplot as plt
        #plt.plot(bins_plot , light3d/light3d[5], label='3d reference')
        #plt.plot(bins_plot, hist / hist[5], label='hist')
        #plt.legend()
        #plt.show()
        print(light3d / hist)
        npt.assert_almost_equal(light3d[5] / hist[5], 1, decimal=1)
예제 #4
0
    def draw_light(self, kwargs_light):
        """

        :param kwargs_light: keyword argument (list) of the light model
        :return: 3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate
        """
        r = self.lightProfile.draw_light_3d(kwargs_light, n=1)[0]
        R, x, y = util.project2d_random(r)
        return r, R, x, y
예제 #5
0
    def draw_light(kwargs_light):
        """

        :param kwargs_light: keyword argument (list) of the light model
        :return: 3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate
        """
        if 'a' not in kwargs_light:
            kwargs_light['a'] = 0.551 * kwargs_light['r_eff']
        a = kwargs_light['a']
        r = vel_util.draw_hernquist(a)
        R, x, y = vel_util.project2d_random(r)
        return r, R, x, y
예제 #6
0
    def test_draw_light_3d_hernquist(self):
        lightProfile = LightProfile(profile_list=['HERNQUIST'], min_interpolate=0.0001, max_interpolate=1000.)
        kwargs_profile = [{'amp': 1., 'Rs': 0.5}]
        r_list = lightProfile.draw_light_3d(kwargs_profile, n=1000000, new_compute=False)
        print(r_list, 'r_list')
        # project it

        # test with draw light 2d profile routine
        # compare with 3d analytical solution vs histogram binned
        bins = np.linspace(0.0, 10, 20)
        hist, bins_hist = np.histogram(r_list, bins=bins, density=True)
        bins_plot = (bins_hist[1:] + bins_hist[:-1]) / 2.
        light3d = lightProfile.light_3d(r=bins_plot, kwargs_list=kwargs_profile)
        light3d *= bins_plot ** 2
        light3d /= np.sum(light3d)
        hist /= np.sum(hist)
        #import matplotlib.pyplot as plt
        #plt.plot(bins_plot , light3d/light3d[5], label='3d reference Hernquist')
        #plt.plot(bins_plot, hist / hist[5], label='hist')
        #plt.legend()
        #plt.show()
        print(light3d / hist)
        #npt.assert_almost_equal(light3d / hist, 1, decimal=1)

        # compare with 2d analytical solution vs histogram binned
        #bins = np.linspace(0.1, 1, 10)
        R, x, y = velocity_util.project2d_random(np.array(r_list))
        hist_2d, bins_hist = np.histogram(R, bins=bins, density=True)
        hist_2d /= np.sum(hist_2d)
        bins_plot = (bins_hist[1:] + bins_hist[:-1]) / 2.
        light2d = lightProfile.light_2d(R=bins_plot, kwargs_list=kwargs_profile)
        light2d *= bins_plot ** 1
        light2d /= np.sum(light2d)

        light2d_finite = lightProfile.light_2d_finite(R=bins_plot, kwargs_list=kwargs_profile)
        light2d_finite *= bins_plot ** 1
        light2d_finite /= np.sum(light2d_finite)
        hist /= np.sum(hist)
        #import matplotlib.pyplot as plt
        #plt.plot(bins_plot, light2d/light2d[5], '--', label='2d reference Hernquist')
        #plt.plot(bins_plot, light2d_finite / light2d_finite[5], '-.', label='2d reference Hernquist finite')
        #plt.plot(bins_plot, hist_2d / hist_2d[5], label='hist')
        #plt.legend()
        #plt.show()
        print(light2d / hist_2d)

        #plt.plot(R, r_list, '.', label='test')
        #plt.legend()
        #plt.xlim([0, 0.2])
        #plt.ylim([0, 0.2])
        #plt.show()

        npt.assert_almost_equal(light2d / hist_2d, 1, decimal=1)
예제 #7
0
    def draw_light(self, kwargs_light):
        """

        :param kwargs_light: keyword argument (list) of the light model
        :return: 3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate
        """
        r = self.lightProfile.draw_light_3d(kwargs_light, n=1)[0]
        R, x, y = util.project2d_random(r)

        # this code is a remnant of the 2d-only rendering
        # (can be used when accurate luminosity-weighted integrated velocity dispersion predictions are made)
        # R = self.lightProfile.draw_light_2d(kwargs_light, n=1)[0]
        # x, y = util.draw_xy(R)
        # r = None
        return r, R, x, y
예제 #8
0
    def test_draw_light_3d_power_law(self):
        lightProfile = LightProfile(profile_list=['POWER_LAW'], min_interpolate=0.0001, max_interpolate=1000.)
        kwargs_profile = [{'amp': 1., 'gamma': 2, 'e1': 0, 'e2': 0}]
        r_list = lightProfile.draw_light_3d(kwargs_profile, n=1000000, new_compute=False)
        print(r_list, 'r_list')
        # project it
        R, x, y = velocity_util.project2d_random(r_list)
        # test with draw light 2d profile routine

        # compare with 3d analytical solution vs histogram binned
        bins = np.linspace(0.1, 10, 10)
        hist, bins_hist = np.histogram(r_list, bins=bins, density=True)
        bins_plot = (bins_hist[1:] + bins_hist[:-1]) / 2.
        light3d = lightProfile.light_3d(r=bins_plot, kwargs_list=kwargs_profile)
        light3d *= bins_plot ** 2
        light3d /= np.sum(light3d)
        hist /= np.sum(hist)
        #import matplotlib.pyplot as plt
        #plt.plot(bins_plot , light3d/light3d[5], label='3d reference power-law')
        #plt.plot(bins_plot, hist / hist[5], label='hist')
        #plt.legend()
        #plt.show()
        print(light3d / hist)
        npt.assert_almost_equal(light3d / hist, 1, decimal=1)

        # compare with 2d analytical solution vs histogram binned
        #bins = np.linspace(0.1, 1, 10)
        hist, bins_hist = np.histogram(R, bins=bins, density=True)
        bins_plot = (bins_hist[1:] + bins_hist[:-1]) / 2.
        light2d = lightProfile.light_2d_finite(R=bins_plot, kwargs_list=kwargs_profile)
        light2d *= bins_plot ** 1
        light2d /= np.sum(light2d)
        hist /= np.sum(hist)
        #import matplotlib.pyplot as plt
        #plt.plot(bins_plot , light2d/light2d[5], label='2d reference power-law')
        #plt.plot(bins_plot, hist / hist[5], label='hist')
        #plt.legend()
        #plt.show()
        print(light2d / hist)
        npt.assert_almost_equal(light2d / hist, 1, decimal=1)