Esempio n. 1
0
def plot_hist_gasvx(rundir, snapnr, TimeBetSnapshot, ic=False):
    simulation = NumericalCluster(
        icdir=rundir + "ICs/",
        snapdir=rundir + "ICs/" if ic else rundir + "snaps/",
        logfile="runToycluster.log",
        icfile="IC_single_0" if ic else "snapshot_" + snapnr,
    )
    simulation.gas, simulation.dm = simulation.place_ic_data_in_datamodel(
        simulation.raw_data)

    pyplot.figure(figsize=(12, 9))
    amuse_plot.hist(simulation.gas.vx,
                    normed=True,
                    stacked=True,
                    bins=int(numpy.sqrt(simulation.raw_data.Ngas)))
    pyplot.xlabel("gas velocity x-direction")
    pyplot.ylabel("normalized count")
    pyplot.xlim(-2000, 1200)
    pyplot.suptitle("T = {0:04.2f} Gyr".format(TimeBetSnapshot * int(snapnr)),
                    color="black",
                    size=32,
                    y=1.01)
    pyplot.tight_layout()
    pyplot.savefig(rundir + "out/gasvx_" + snapnr)
    pyplot.close()
Esempio n. 2
0
    y1 = quantities.new_quantity(
        np.sin(np.arange(0, 1.5, 0.03)), 1e50*units.erg)
    y2 = -(1e43 | units.J) - y1
    native_plot.subplot(2, 2, 2)
    plot(x, y1, label='$E_\mathrm{kin}$')
    plot(x, y2, label='$E_\mathrm{pot}$')
    xlabel('t')
    ylabel('E')
    native_plot.legend()

    x = range(7) | units.day
    y1 = [0, 4, 2, 3, 2, 5, 1]
    y2 = [3, 0, 2, 2, 3, 0, 4]
    native_plot.subplot(2, 2, 3)
    plot(x, y1, 'ks', label='coffee')
    plot(x, y2, 'yo', label='tea')
    xlabel('time')
    ylabel('consumption / day')
    native_plot.legend()

    y1 = units.N.new_quantity(np.random.normal(0.0, 1.0, 100))
    x = units.N.new_quantity(np.arange(-3, 3, 0.1))
    y2 = np.exp(-np.arange(-3, 3, 0.1)**2)/np.sqrt(np.pi)
    native_plot.subplot(2, 2, 4)
    plot(x, y2, 'y--', label='model')
    hist(y1, bins=12, range=(-3, 3), normed=True, label='data')
    xlabel('force')
    ylabel('pdf')
    native_plot.legend()
    native_plot.show()
Esempio n. 3
0
def donnert_2014_figure1(analytical_P500=False):
    # Well, I will just eyeball the value of rho_0 in Figure 1 in Donnert (2014) and adopt this value, I suppose...
    # disturbed = InitialCluster(rho_0=(9e-27 | units.g/units.cm**3),
    #                            plot=False, do_print=False,
    #                            disturbed_cluster=True, cool_core_cluster=False)
    # coolcore = InitialCluster(rho_0=(3e-25 | units.g/units.cm**3),
    #                           plot=False, do_print=False,
    #                           disturbed_cluster=False, cool_core_cluster=True)
    # rickersarazin = InitialCluster(plot=False, do_print=False, disturbed_cluster=False, cool_core_cluster=False)

    r = VectorQuantity.arange(units.kpc(1), units.kpc(10000),
                              units.parsec(100))

    #fig, ((ax1, ax2), (ax3, ax4)) = pyplot.subplots(2, 2, figsize=(20, 20), dpi=500)
    fig, ((ax1, ax2), (ax3, ax4)) = pyplot.subplots(2, 2)

    # Plot the density situation
    pyplot.sca(ax1)
    amuse_plot.hist(r, bins=int(numpy.sqrt(len(r))), label="Hanky")
    # amuse_plot.loglog(coolcore.r, coolcore.rho_gas.as_quantity_in(units.g / units.cm**3),
    #                   c='k', ls='dotted', label="Gas, cool core")
    # amuse_plot.loglog(disturbed.r, disturbed.rho_gas.as_quantity_in(units.g / units.cm**3),
    #                   c='k', ls='dashed', label="Gas, disturbed")
    # amuse_plot.loglog(disturbed.r, disturbed.rho_dm.as_quantity_in(units.g / units.cm**3),
    #                   c='k', ls='solid', label="Dark Matter")
    amuse_plot.ylabel(r'$\rho$')
    amuse_plot.xlabel(r'$r$')
    pyplot.legend(loc=3, frameon=False, fontsize=12)

    ax1.set_ylim(ymin=1e-28, ymax=1e-23)

    # pyplot.axvline(x=disturbed.r_200.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.r_200.value_in(units.kpc), 7e-24, r'$r_{200}$', fontsize=12)
    # pyplot.axvline(x=disturbed.r_500.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.r_500.value_in(units.kpc), 7e-24, r'$r_{500}$', fontsize=12)

    # # a_hernq
    # intersect = disturbed.dm_density(disturbed.a)
    # ymin, ymax = ax1.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.g/units.cm**3)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=disturbed.a.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, c='k')
    # pyplot.text(disturbed.a.value_in(units.kpc), 5e-24, r'$a_{\rm Hernq}$', fontsize=12)

    # # r_core,dist
    # intersect = disturbed.gas_density(disturbed.r_c)
    # ymin, ymax = ax1.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.g/units.cm**3)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=disturbed.r_c.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, ls='--', c='k')
    # pyplot.text(disturbed.r_c.value_in(units.kpc), 5e-24, r'$r_{\rm core,dist}$', fontsize=12)

    # # r_core,cc
    # intersect = coolcore.gas_density(coolcore.r_c)
    # ymin, ymax = ax1.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.g/units.cm**3)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=coolcore.r_c.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, ls=':', c='k')
    # pyplot.text(coolcore.r_c.value_in(units.kpc), 5e-24, r'$r_{\rm core,cc}$', fontsize=12)

    # Plot the mass situation
    pyplot.sca(ax2)
    amuse_plot.hist(r, bins=int(numpy.sqrt(len(r))), label="Hanky")
    # amuse_plot.loglog(coolcore.r, coolcore.M_gas_below_r.as_quantity_in(units.MSun),
    #                   c='k', ls='dotted', label="Gas, cool core")
    # amuse_plot.loglog(disturbed.r, disturbed.M_gas_below_r.as_quantity_in(units.MSun),
    #                   c='k', ls='dashed', label="Gas, disturbed")
    # amuse_plot.loglog(disturbed.r, disturbed.M_dm_below_r.as_quantity_in(units.MSun),
    #                   c='k', ls='solid', label="Dark Matter")
    amuse_plot.ylabel(r'$M(<r)$')
    amuse_plot.xlabel(r'$r$')
    pyplot.legend(loc=8, frameon=False, fontsize=12)

    ax2.set_ylim(ymin=1e10, ymax=5e15)

    # pyplot.axvline(x=disturbed.r_200.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.r_200.value_in(units.kpc), 3e15, r'$r_{200}$', fontsize=12)
    # pyplot.axvline(x=disturbed.r_500.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.r_500.value_in(units.kpc), 3e15, r'$r_{500}$', fontsize=12)

    # # a_hernq
    # intersect = disturbed.dm_cummulative_mass(disturbed.a)
    # ymin, ymax = ax2.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.MSun)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=disturbed.a.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, c='k')
    # pyplot.text(disturbed.a.value_in(units.kpc), 2e15, r'$a_{\rm Hernq}$', fontsize=12)

    # # r_core,dist
    # intersect = disturbed.dm_cummulative_mass(disturbed.r_c)
    # ymin, ymax = ax2.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.MSun)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=disturbed.r_c.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, ls='--', c='k')
    # pyplot.text(disturbed.r_c.value_in(units.kpc), 2e15, r'$r_{\rm core,dist}$', fontsize=12)

    # # r_core,cc
    # intersect = coolcore.dm_cummulative_mass(coolcore.r_c)
    # ymin, ymax = ax2.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.MSun)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=coolcore.r_c.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, ls=':', c='k')
    # pyplot.text(coolcore.r_c.value_in(units.kpc), 2e15, r'$r_{\rm core,cc}$', fontsize=12)

    # Plot the temperature situation
    pyplot.sca(ax3)
    amuse_plot.hist(r, bins=int(numpy.sqrt(len(r))), label="Hanky")
    # amuse_plot.loglog(disturbed.r, disturbed.T_r.as_quantity_in(units.K),
    #                   c='k', ls='solid', label="disturbed")
    # amuse_plot.loglog(disturbed.r, disturbed.T_r_dm.as_quantity_in(units.K),
    #                   c='k', ls='dashdot', label="from DM, disturbed")
    # amuse_plot.loglog(disturbed.r, disturbed.T_r_gas.as_quantity_in(units.K),
    #                   c='k', ls='dashed', label="from Gas, disturbed")
    # amuse_plot.loglog(coolcore.r, coolcore.T_r.as_quantity_in(units.K),
    #                   c='k', ls='dotted', label="cool core")
    amuse_plot.ylabel(r'$T$')
    amuse_plot.xlabel(r'$r$')
    pyplot.legend(loc=10, frameon=False, fontsize=12)

    ax3.set_ylim(ymin=6e6, ymax=3e8)

    # pyplot.axvline(x=disturbed.r_200.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.r_200.value_in(units.kpc), 2.6e8, r'$r_{200}$', fontsize=12)
    # pyplot.axvline(x=disturbed.r_500.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.r_500.value_in(units.kpc), 2.6e8, r'$r_{500}$', fontsize=12)

    # pyplot.axvline(x=disturbed.a.value_in(units.kpc), lw=2, c='k')
    # pyplot.text(disturbed.a.value_in(units.kpc), 2.4e8, r'$a_{\rm Hernq}$', fontsize=12)

    # # r_core,dist
    # intersect = disturbed.temperature(disturbed.r_c)
    # ymin, ymax = ax3.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.K)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=disturbed.r_c.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, ls='--', c='k')
    # pyplot.text(disturbed.r_c.value_in(units.kpc), 2.4e8, r'$r_{\rm core,dist}$', fontsize=12)

    # # r_core,cc
    # intersect = coolcore.temperature(coolcore.r_c)
    # ymin, ymax = ax3.get_ylim()
    # ymin = (numpy.log(intersect.value_in(units.K)/ymin)) / (numpy.log(ymax/ymin))
    # pyplot.axvline(x=coolcore.r_c.value_in(units.kpc), ymin=ymin, ymax=1, lw=2, ls=':', c='k')
    # pyplot.text(coolcore.r_c.value_in(units.kpc), 2.4e8, r'$r_{\rm core,cc}$', fontsize=12)

    # TODO: pressure situation
    pyplot.sca(ax4)
    amuse_plot.hist(r, bins=int(numpy.sqrt(len(r))), label="Hanky")
    colours = [(255. / 255, 127. / 255, 0. / 255),
               (152. / 255, 78. / 255, 163. / 255),
               (77. / 255, 175. / 255, 74. / 255),
               (52. / 255, 126. / 255, 184. / 255),
               (228. / 255, 26. / 255, 28. / 255)]

    # print "Warning, the pressure plots make little sense because for each M_DM is the same but M_200 differs"
    # for i, M_200 in enumerate(VectorQuantity([3e15, 1.5e15, 1e15, 0.5e15, 0.1e15], units.MSun)):
    #     disturbed = InitialCluster(rho_0=(9e-27 | units.g/units.cm**3), M_200=M_200,
    #                                plot=False, do_print=False,
    #                                disturbed_cluster=True, cool_core_cluster=False)
    #     coolcore = InitialCluster(rho_0=(3e-25 | units.g/units.cm**3), M_200=M_200,
    #                               plot=False, do_print=False,
    #                               disturbed_cluster=False, cool_core_cluster=True)
    #     if analytical_P500:
    #         amuse_plot.loglog(disturbed.r/disturbed.r_500, (disturbed.P_gas/disturbed.find_p500_analytically()),
    #                           c=colours[i], ls='solid', label=r'{0} $M_\odot$'.format(disturbed.M_200.value_in(units.MSun)))
    #         amuse_plot.loglog(coolcore.r/coolcore.r_500, (coolcore.P_gas/coolcore.find_p500_analytically()),
    #                           c=colours[i], ls='dashed')
    #     else:
    #         amuse_plot.loglog(disturbed.r/disturbed.r_500, (disturbed.P_gas/disturbed.P_500),
    #                           c=colours[i], ls='solid', label=r'{0} $M_\odot$'.format(disturbed.M_200.value_in(units.MSun)))
    #         amuse_plot.loglog(coolcore.r/coolcore.r_500, (coolcore.P_gas/coolcore.P_500),
    #                           c=colours[i], ls='dashed')

    amuse_plot.ylabel(r'$P(r)/P_{500}$')
    amuse_plot.xlabel(r'$r/r_{500}$')
    legend = pyplot.legend(loc=3, frameon=False, fontsize=16)
    # Set the color situation
    # for colour, text in zip(colours, legend.get_texts()):
    #     text.set_color(colour)

    ax4.set_ylim(ymin=1e-2, ymax=1e3)
    ax4.set_xticks((0.01, 0.10, 1.00))
    ax4.set_xticklabels(("0.01", "0.10", "1.00"))
    ax4.set_xlim(xmin=0.01, xmax=2.0)
    ax4.minorticks_on()
    ax4.tick_params('both', length=10, width=2, which='major')
    ax4.tick_params('both', length=5, width=1, which='minor')
    ax4.text(0.015, 4, "disturbed", color="grey", fontsize=15)
    ax4.text(0.02, 110, "cool cores", color="grey", fontsize=15)
    ax4.text(0.2, 50, "Arnaud et al. 2010", color="black", fontsize=15)

    # Set the xticks situation
    for ax in [ax1, ax2, ax3]:
        ax.set_xscale("log")
        ax.set_yscale("log")
        ax.set_xticks((10, 100, 1000))
        ax.set_xticklabels(("10", "100", "1000"))
        ax.set_xlim(xmin=10, xmax=5000)
        ax.minorticks_on()
        ax.tick_params('both', length=10, width=2, which='major')
        ax.tick_params('both', length=5, width=1, which='minor')

    # pyplot.savefig("../img/Donnert2014_Figure1_by_TLRH.pdf", format="pdf", dpi=1000)
    pyplot.show()
Esempio n. 4
0
    y1 = quantities.new_quantity(
        np.sin(np.arange(0, 1.5, 0.03)), 1e50 * units.erg)
    y2 = -(1e43 | units.J) - y1
    native_plot.subplot(2, 2, 2)
    plot(x, y1, label='$E_\mathrm{kin}$')
    plot(x, y2, label='$E_\mathrm{pot}$')
    xlabel('t')
    ylabel('E')
    native_plot.legend()

    x = list(range(7)) | units.day
    y1 = [0, 4, 2, 3, 2, 5, 1]
    y2 = [3, 0, 2, 2, 3, 0, 4]
    native_plot.subplot(2, 2, 3)
    plot(x, y1, 'ks', label='coffee')
    plot(x, y2, 'yo', label='tea')
    xlabel('time')
    ylabel('consumption / day')
    native_plot.legend()

    y1 = units.N.new_quantity(np.random.normal(0.0, 1.0, 100))
    x = units.N.new_quantity(np.arange(-3, 3, 0.1))
    y2 = np.exp(-np.arange(-3, 3, 0.1)**2) / np.sqrt(np.pi)
    native_plot.subplot(2, 2, 4)
    plot(x, y2, 'y--', label='model')
    hist(y1, bins=12, range=(-3, 3), normed=True, label='data')
    xlabel('force')
    ylabel('pdf')
    native_plot.legend()
    native_plot.show()
Esempio n. 5
0
    def __init__(self, timestamp):
        debug = True
        """ First read IC output where two clusters live in the box.
        NB simulation to make distinction between `numerical' (has 1 cluster),
        and `simulation' where two clusters live in the box. """

        icdir = "../runs/{0}/ICs/".format(timestamp)
        outdir = "../runs/{0}/out/".format(timestamp)
        simulation = NumericalCluster(icdir=icdir,
                                      snapdir=icdir,
                                      logfile="runToycluster.log",
                                      icfile="IC_single_0")

        boxsize = simulation.toyclusterlog.systemsetup['Boxsize']\
            .value_in(units.kpc)

        # import os
        # tc_par_name = [file for file in os.listdir(icdir) if "par" in file][0]
        # NB simulation contains particles of both haloes
        gas, dm = simulation.place_ic_data_in_datamodel(simulation.raw_data)

        # Placeholders for now, will be filled with single-cluster data later
        # NB this is rather stupid but we cannot say halo0_numerical = simulation
        # because then id(halo0_numerical) = id(halo1_numerical) = id(simulation)
        halo0_numerical = NumericalCluster(icdir=icdir,
                                           snapdir=icdir,
                                           logfile="runToycluster.log",
                                           icfile="IC_single_0")

        halo1_numerical = NumericalCluster(icdir=icdir,
                                           snapdir=icdir,
                                           logfile="runToycluster.log",
                                           icfile="IC_single_0")
        """ Second, set up analytical models of both sampled clusters. """
        halo0_analytical = setup_analytical_cluster(simulation, i=0)
        halo1_analytical = setup_analytical_cluster(simulation, i=1)

        hist, edges = numpy.histogram(gas.x.value_in(units.kpc),
                                      bins=int(numpy.sqrt(len(gas.x))))
        if debug:
            pyplot.figure()
            pyplot.plot((edges[1:] + edges[:-1]) / 2, hist)
            pyplot.savefig(outdir + "world_01.png")
            #pyplot.show()
        # Domain contains indices of x values between -750 and 750
        # somewhere in this range there is a minimum x-value, which
        # is the center that we need to shift back the haloes.
        domain = numpy.where(numpy.logical_and(edges >= -1300, edges <= 1300))
        ymin_index = numpy.argmin(hist[domain])
        center = edges[domain][ymin_index]
        if debug:
            # numpy.amin(hist[domain])
            pyplot.figure()
            pyplot.plot(edges[domain], hist[domain])
            ymin = hist[domain][ymin_index]
            pyplot.axhline(ymin)
            pyplot.axvline(center)
            pyplot.savefig(outdir + "world_02.png")
            #pyplot.show()

        # Histogram of gas x-values is beautifully bimodal (y, z aint)
        if debug:
            pyplot.figure(figsize=(12, 12))
            amuse_plot.hist(gas.x, bins=int(numpy.sqrt(len(gas.x))))
            #pyplot.show()
            pyplot.savefig(outdir + "world_03.png")
        """ Third, split up particles in two haloes. Shift back to (0,0,0) """
        print "Splitting up haloes, halo0: x<{0}; halo1: x>{0}.".format(center)
        # The merger-axis is x. We know halo center x position, is D_CoM_0/1
        # TODO: can we assume the box is split in two at x=0?
        # halo0 lives on the left-hand side of the box (negative x)
        halo0gas = gas.select_array(lambda l: l < center | units.kpc, ["x"])
        halo0dm = dm.select_array(lambda l: l < center | units.kpc, ["x"])
        # halo1 lives on the left-hand side of the box (negative x)
        halo1gas = gas.select_array(lambda l: l > center | units.kpc, ["x"])
        halo1dm = dm.select_array(lambda l: l > center | units.kpc, ["x"])

        # TODO: check if this routine is valid only for -DCOMET ?
        # TODO: boxhalf is added in Shift_Origin, but then subtracted in
        # Apply_kinematics ?
        # NB, already corrected for in place_ic_data_in_datamodel
        boxhalf = simulation.toyclusterlog.systemsetup['Boxsize'] / 2

        # The x-position is shifted back from the CoM to the center (x=0)
        # TODO: properly shift back
        # d_clusters = 0.9 * (halo[0].R200 + halo[1].R200)
        # D_CoM_0 = -1 * d_clusters * halo[1].Mtotal200/param.Mtot200 (why?)
        # D_CoM_1 = d_clusters + D_CoM_0
        # dx =
        print "Shifting haloes, back to origin."
        halo0gas.x -= simulation.toyclusterlog.kinematics['D_CoM_0']
        halo0dm.x -= simulation.toyclusterlog.kinematics['D_CoM_0']
        halo1gas.x -= simulation.toyclusterlog.kinematics['D_CoM_1']
        halo1dm.x -= simulation.toyclusterlog.kinematics['D_CoM_1']

        # TODO: when an impact parameter is given, then y is also shifted!
        if not (-2**-14 < simulation.toyclusterlog.
                kinematics['Impact_Parameter'].value_in(units.kpc) < 2**-14):
            # TODO: properly shift back
            # b_CoM_0 = -1 * param.Impact_Param * halo[0].Mtotal200/param.Mtot200 (why?)
            # b_CoM_1 = param.Impact_Param + b_CoM_0
            #
            print "WARNING: correcting for impact parameter is untested"
            halo0gas.y -= simulation.toyclusterlog.kinematics['b_CoM_0']
            halo0dm.y -= simulation.toyclusterlog.kinematics['b_CoM_0']
            halo1gas.y -= simulation.toyclusterlog.kinematics['b_CoM_1']
            halo1dm.y -= simulation.toyclusterlog.kinematics['b_CoM_1']

        if debug:
            # Bimodality is gone; cluster now centered around x=0
            pyplot.figure(figsize=(12, 12))
            amuse_plot.hist(halo0gas.x, bins=int(numpy.sqrt(len(halo0gas.x))))
            pyplot.savefig(outdir + "world_04.png")
            #pyplot.show()

            pyplot.figure(figsize=(12, 12))
            amuse_plot.hist(halo1gas.x, bins=int(numpy.sqrt(len(halo1gas.x))))
            pyplot.savefig(outdir + "world_05.png")
            #pyplot.show()

        # recalculate r because now it is calculated with uncentered x, y values
        print "Recalculating halo radii."
        halo0gas.r = numpy.sqrt(
            p2(halo0gas.x.value_in(units.kpc)) +
            p2(halo0gas.y.value_in(units.kpc)) +
            p2(halo0gas.z.value_in(units.kpc))) | units.kpc
        halo0dm.r = numpy.sqrt(
            p2(halo0dm.x.value_in(units.kpc)) +
            p2(halo0dm.y.value_in(units.kpc)) +
            p2(halo0dm.z.value_in(units.kpc))) | units.kpc
        halo1gas.r = numpy.sqrt(
            p2(halo1gas.x.value_in(units.kpc)) +
            p2(halo1gas.y.value_in(units.kpc)) +
            p2(halo1gas.z.value_in(units.kpc))) | units.kpc
        halo1dm.r = numpy.sqrt(
            p2(halo1dm.x.value_in(units.kpc)) +
            p2(halo1dm.y.value_in(units.kpc)) +
            p2(halo1dm.z.value_in(units.kpc))) | units.kpc

        # Now fill the placeholders created earlier with the split up, reshifted haloes
        print "Filling AMUSE datamodel with particle properties."
        halo0_numerical.set_toycluster2_values(i=0)
        halo0_numerical.gas = halo0gas
        halo0_numerical.dm = halo0dm
        halo0_numerical.M_dm = halo0_numerical.Mass_in_DM
        halo0_numerical.M_gas = halo0_numerical.Mass_in_gas
        # Rather ugly hack, but ensures set_dm_density() method works
        halo0_numerical.raw_data.Ndm = len(halo0_numerical.dm)

        halo1_numerical.set_toycluster2_values(i=1)
        halo1_numerical.gas = halo1gas
        halo1_numerical.dm = halo1dm
        halo1_numerical.M_dm = halo1_numerical.Mass_in_DM
        halo1_numerical.M_gas = halo1_numerical.Mass_in_gas
        # Rather ugly hack, but ensures set_dm_density() method works
        halo1_numerical.raw_data.Ndm = len(halo1_numerical.dm)

        self.halo0_analytical = halo0_analytical
        self.halo0_numerical = halo0_numerical
        self.halo1_analytical = halo1_analytical
        self.halo1_numerical = halo1_numerical

        # To plot density profiles :-)...
        # self.halo0_numerical.get_gas_mass_via_density()
        # self.halo0_numerical.get_dm_mass_via_number_density()
        # self.halo0_numerical.set_dm_density()

        # self.halo1_numerical.get_gas_mass_via_density()
        # self.halo1_numerical.get_dm_mass_via_number_density()
        # self.halo1_numerical.set_dm_density()

        return

        # TODO: this can be used in plot_individual_cluster_density to sort
        # Sort subset of the particles by the radius such that we can
        # integrate in spherical shells to obtain the radial density profile
        sorted0gas = halo0gas.sorted_by_attribute('r')
        sorted1gas = halo1gas.sorted_by_attribute('r')
        sorted0dm = halo0dm.sorted_by_attribute('r')
        sorted1dm = halo1dm.sorted_by_attribute('r')
Esempio n. 6
0
    def perform_sanity_checks(self):

        # Let's see what the radius of the gas and dm looks like

        # Donnert (2014), Sec. 3: "The gas profile of one cluster is sampled to a maximal radius $R_{\rm max}$, which is half the box size"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.r,
                        bins=int(numpy.sqrt(self.raw_data.Ngas)),
                        label="Gas")
        amuse_plot.ylabel(r'$N$')
        amuse_plot.xlabel(r'$r$')
        pyplot.legend()

        # Donnert (2014), Sec. 3: "The clusters DM profile is sampled up to infinity"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.r,
                        bins=int(numpy.sqrt(self.raw_data.Ndm)),
                        label="DM")
        pyplot.legend()
        amuse_plot.ylabel(r'$N$')
        amuse_plot.xlabel(r'$r$')

        # Check the velocities of the gas (should only be zero) and of the dm (should follow Hernquist DF)
        for attr in ["vx", "vy", "vz"]:
            # NB, turn into numpy array using value_in method! VectorQuantity has no nonzero method
            v = getattr(self.gas, attr).value_in(units.kms)
            if len(v.nonzero()[0]) != 0:
                print "Error: gas {0} has nonzero values".format(attr)
            else:
                print "Passed: gas {0} only has nonzero values".format(attr)
            v = getattr(self.dm, attr).value_in(units.kms)
            if len(v.nonzero()[0]) == self.raw_data.Ndm:
                print "Passed: dm {0} has no nonzero values".format(attr)
            else:
                print "Error: dm {0} has nonzero values".format(attr)

        # Look at the gas velocity distribution (should only be zero)
        # Donnert (2014), Sec. 3: "The initial velocity of the gas particles is set to zero"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.vx, bins=int(numpy.sqrt(self.raw_data.Ngas)))
        pyplot.xlim(-1, 1)

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.vy, bins=int(numpy.sqrt(self.raw_data.Ngas)))
        pyplot.xlim(-1, 1)

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.vz, bins=int(numpy.sqrt(self.raw_data.Ngas)))
        pyplot.xlim(-1, 1)

        # Look at the dm velocity distribution (should follow Hernquist DF)
        # Donnert (2014), Sec. 3 "The velocity of the DM component is satisfied so the Hernquist DF, equation (5), is satisfied"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.vx, bins=int(numpy.sqrt(self.raw_data.Ndm)))

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.vy, bins=int(numpy.sqrt(self.raw_data.Ndm)))

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.vz, bins=int(numpy.sqrt(self.raw_data.Ndm)))