Exemple #1
0
    def _TEST_derotate_field(self):
        from import_toolkit.cluster import Cluster
        from testing import angular_momentum

        cluster = Cluster(simulation_name='celr_e',
                          clusterID=0,
                          redshift='z000p000')
        mass = cluster.particle_masses('gas')

        coords, vel = angular_momentum.derotate(cluster,
                                                align='gas',
                                                cluster_rest_frame=True,
                                                derotate_block=True)
        angular_momentum_vector_GADGET, _ = cluster.angular_momentum(
            mass, vel, coords)

        coords, vel = angular_momentum.derotate(cluster,
                                                align='gas',
                                                cluster_rest_frame=True,
                                                derotate_block=False)
        angular_momentum_vector_DEROT, _ = cluster.angular_momentum(
            mass, vel, coords)

        self.plot_angularmomentum_vectors(
            np.vstack((angular_momentum_vector_GADGET,
                       angular_momentum_vector_DEROT)),
            labels=None,
            axes=None,
            plot_unitSphere=True,
            normalise_length=False,
            make_all_unitary=True,
        )
Exemple #2
0
    def _TEST_CELR_yrkSZ_field(self):

        from import_toolkit.cluster import Cluster
        from testing import angular_momentum

        cluster = Cluster(simulation_name='celr_e',
                          clusterID=0,
                          redshift='z000p000')
        r500 = cluster.group_r500()
        mass = cluster.particle_masses('gas')

        coords, vel = angular_momentum.derotate(cluster,
                                                align='gas',
                                                aperture_radius=r500,
                                                cluster_rest_frame=True)

        from unyt import hydrogen_mass, speed_of_light, thompson_cross_section
        plot_limit = 3 * r500
        nbins = 100
        bins = np.linspace(-plot_limit, plot_limit, nbins)
        pixel_area = (bins[1] - bins[0])**2
        kSZ = np.multiply((vel.T * mass).T, (-1) * thompson_cross_section /
                          (pixel_area * speed_of_light * hydrogen_mass * 1.16))

        self.xyz_projections(
            xyzdata=coords,
            weights=kSZ,
            weights_labels=[r'$y_{kSZ} / \mathrm{Mpc}^2$'] * 3,
            plot_limit=plot_limit,
            nbins=nbins,
            colorbar_type=('symlog', 1e-6),
            circle_pars=[[0, 0, 0, r500], [0, 0, 0, 5 * r500]],
            circle_labels=[r'$R_{500}$', r'$5\times R_{500}$'],
            special_markers_pars=[0, 0, 0],
            special_markers_labels=r'CoM')
Exemple #3
0
    def test_software_rotvel_alignment_GAS(self):
        print(f"{' SOFTWARE TEST ':*^60}")
        data_required = {
            'partType0':
            ['mass', 'coordinates', 'velocity', 'temperature', 'sphdensity'],
            'partType1': ['mass', 'coordinates', 'velocity'],
            'partType4': ['mass', 'coordinates', 'velocity'],
            'partType5': ['mass', 'coordinates', 'velocity']
        }

        for sim in ['celr_e', 'celr_b', 'macsis']:

            cluster = Cluster(simulation_name=sim,
                              clusterID=0,
                              redshift='z000p000',
                              comovingframe=False,
                              requires=data_required)

            # cluster.info()

            print(f"\n {sim}{' | halo 0 | z=0 ':-^60}")
            pec_velocity = cluster.group_zero_momentum_frame()
            ang_momentum = cluster.group_angular_momentum()
            angle = cluster.angle_between_vectors(pec_velocity, ang_momentum)
            print(f"pec_velocity = {pec_velocity}")
            print(f"ang_momentum = {ang_momentum}")
            print(f"angle = {angle}")
Exemple #4
0
    def _TEST_CELR_velocity_field(self):

        from import_toolkit.cluster import Cluster
        from testing import angular_momentum

        cluster = Cluster(simulation_name='celr_b',
                          clusterID=0,
                          redshift='z000p000')
        r500 = cluster.group_r500()
        mass = cluster.particle_masses('gas')

        coords, vel = angular_momentum.derotate(cluster,
                                                align='gas',
                                                aperture_radius=r500,
                                                cluster_rest_frame=True)
        momentum_lineOfSight = (vel.T * mass).T

        cbarlabel = [
            r'$\sum_{i} m_i v_{z, i} / \sum_{i} m_i \ [\mathrm{km\ s^{-1}}]$',
            r'$\sum_{i} m_i v_{x, i} / \sum_{i} m_i \ [\mathrm{km\ s^{-1}}]$',
            r'$\sum_{i} m_i v_{y, i} / \sum_{i} m_i \ [\mathrm{km\ s^{-1}}]$'
        ]

        self.xyz_projections(
            xyzdata=coords,
            weights=momentum_lineOfSight,
            plot_limit=3 * r500,
            weights_labels=cbarlabel,
            nbins=100,
            colorbar_type='midpointLinear',
            circle_pars=[[0, 0, 0, r500], [0, 0, 0, 5 * r500]],
            circle_labels=[r'$R_{500}$', r'$5\times R_{500}$'],
            special_markers_pars=[0, 0, 0],
            special_markers_labels=r'CoM')
Exemple #5
0
def test_loop_apertures(i):
    # Create a cluster object
    cluster = Cluster(simulation_name='ceagle', clusterID=i, redshift='z000p000')
    apertures = cluster.generate_apertures()

    for aperture in apertures:
        # Create a PhaseDiagram object and link it to the cluster object
        t_rho_diagram = PhaseDiagram(cluster, aperture=aperture)
        t_rho_diagram.info()

        # Test the map output
        t_rho_diagram.setup_plot()
 def get_matterLambda_equality_z(self) -> float:
     cluster = Cluster(simulation_name=self.simulation.simulation_name,
                       clusterID=0,
                       redshift='z000p000')
     omega_lambda = cluster.OmegaLambda
     omega_matter = cluster.Omega0
     return (omega_matter / (2 * omega_lambda))**(-1 / 3) - 1
Exemple #7
0
def gen_data():
    """
    Generates the dynamical index and thermodynamical index
    for different C-EAGLE clusters.
    :return:
    Dictionary containing two arrays of floats.
    """

    z = 0.101
    merg_indices = {'dynamical_index': [], 'thermodynamic_index': []}
    for ID in range(0, 1):
        cluster = Cluster(clusterID=int(ID), redshift=z, subject='groups')
        dyn_idx = dynamical_index(cluster)
        therm_idx = thermal_index(cluster)
        print('Process cluster', ID, '\t\tdyn: ', dyn_idx, '\t\ttherm: ',
              therm_idx)
        merg_indices['dynamical_index'].append(dyn_idx)
        merg_indices['thermodynamic_index'].append(therm_idx)

    # Create a trigger that allows the save operation to proceed
    trigger = False
    if (len(merg_indices['dynamical_index']) == ceagle.totalClusters and len(
            merg_indices['thermodynamic_index']) == ceagle.totalClusters
            and np.all(np.isfinite(merg_indices['dynamical_index'])) == True
            and np.all(np.isfinite(
                merg_indices['thermodynamic_index'])) == True):

        trigger = True

    else:
        raise ('Generated data have something wrong.')

    return merg_indices, trigger
Exemple #8
0
def test_loop_redshifts(i):

    simulation = Simulation(simulation_name='celr_b')
    redshifts = simulation.redshiftAllowed

    for z in redshifts:
        # Create a cluster object
        cluster = Cluster(simulation_name='celr_b', clusterID=i, redshift=z)
        cluster.info()

        # Create a PhaseDiagram object and link it to the cluster object
        t_rho_diagram = PhaseDiagram(cluster)
        # t_rho_diagram.info()

        # Test the map output
        t_rho_diagram.setup_plot()
Exemple #9
0
    def test():
        cluster = Cluster(simulation_name='celr_e',
                          clusterID=0,
                          redshift='z000p000')
        matrix = CorrelationMatrix(cluster)
        data = matrix.get_data()
        aperture = matrix.get_apertures()

        matrix.plot_matrix(data[15], aperture[15])
Exemple #10
0
 def from_cluster(self):
     print(inspect.stack()[0][3])
     from import_toolkit.cluster import Cluster
     cluster = Cluster(simulation_name='celr_e',
                       clusterID=0,
                       redshift='z000p000',
                       comovingframe=False,
                       requires=self.data_required)
     scheduler = SchedulerMPI.from_cluster(cluster)
     scheduler.info()
     print('[ UNIT TEST ]\t==> ', self.quick_build() == scheduler)
Exemple #11
0
def test_simple():

    # Create a cluster object
    cluster = Cluster(simulation_name='macsis', clusterID=0, redshift='z000p000')
    # cluster.info()

    # Create a PhaseDiagram object and link it to the cluster object
    t_rho_diagram = PhaseDiagram(cluster)
    # t_rho_diagram.info()

    # Test the map output
    t_rho_diagram.setup_plot()
Exemple #12
0
def check_dirs(simulation_obj) -> np.ndarray:
    """
    Loops over all listed clusters and redshifts and returns a boolean for what clusters and redshifts
    are present in the simulation archive.
    :return:
    """
    iterator = itertools.product(simulation_obj.clusterIDAllowed,
                                 simulation_obj.redshiftAllowed)
    check_matrix = np.zeros((len(
        simulation_obj.clusterIDAllowed), len(simulation_obj.redshiftAllowed)),
                            dtype=np.bool)
    for process_n, (halo_id, halo_z) in enumerate(list(iterator)):
        cluster = Cluster(simulation_name=simulation_obj.simulation_name,
                          clusterID=halo_id,
                          redshift=halo_z)
        test = cluster.is_cluster() * cluster.is_redshift()
        check_matrix[halo_id][simulation_obj.redshiftAllowed.index(
            halo_z)] = test
        if not test:
            print(process_n, halo_id, halo_z)
    return check_matrix
Exemple #13
0
    def __init__(self,
                 cluster: Cluster,
                 resolution: int = 200,
                 aperture: float = None,
                 plotlimits: float = None):
        """

        :param cluster:
        :param resolution:
        :param aperture:
        :param plotlimits:
        """

        # Impose cluste             r requirements
        cluster.set_requires(self.REQUIRES)
        cluster.import_requires()

        # Initialise the KSZ map fields
        self.cluster = cluster
        self.resolution = resolution
        self.aperture = cluster.r500 if aperture == None else aperture
        self.plotlimits = 3 * cluster.r500 if plotlimits == None else plotlimits
Exemple #14
0
    def __init__(self,
                 cluster: Cluster,
                 resolution: int = 300,
                 aperture: float = None,
                 density_bounds: list = None,
                 temperature_bounds: list = None):
        """

        :param cluster:
        :param resolution:
        :param aperture:
        :param plotlimits:
        """

        # Impose cluster requirements
        cluster.set_requires(self.REQUIRES)
        cluster.import_requires()

        # Initialise the KSZ map fields
        self.cluster = cluster
        self.resolution = resolution
        self.aperture = 5*cluster.r200 if aperture == None else aperture
        self.density_bounds = [1e-8, 1e5] if density_bounds == None else density_bounds
        self.temperature_bounds = [1e3, 1e11] if temperature_bounds == None else temperature_bounds
Exemple #15
0
 def test():
     cluster = Cluster(simulation_name='celr_e',
                       clusterID=0,
                       redshift='z000p000')
     out = FOFDatagen(cluster)
     out.push_R_crit()
     out.push_apertures()
     out.push_mass()
     out.push_centre_of_mass()
     out.push_peculiar_velocity()
     out.push_angular_momentum()
     out.push_dynamical_merging_index()
     out.push_kinetic_energy()
     out.push_thermal_energy()
     out.push_thermodynamic_merging_index()
     out.push_substructure_merging_index()
Exemple #16
0
    def make_simstats(self):
        assert self.simulation is not None
        z_master = np.array(
            [redshift_str2num(z) for z in self.simulation.redshiftAllowed])
        z_master = z_master[z_master < 1.8]

        print(
            f"{'':<30s} {' process ID ':^25s} | {' halo ID ':^15s} | {' halo redshift ':^20s}\n"
        )
        angle_master = np.zeros(
            (self.simulation.totalClusters, len(z_master), 2), dtype=np.float)
        iterator = itertools.product(self.simulation.clusterIDAllowed,
                                     self.simulation.redshiftAllowed)

        for process_n, (halo_id, halo_z) in enumerate(list(iterator)):
            print(
                f"{'Processing...':<30s} {process_n:^25d} | {halo_id:^15d} | {halo_z:^20s}"
            )
            if self.simulation.sample_completeness[
                    halo_id,
                    self.simulation.redshiftAllowed.index(halo_z)]:
                cluster = Cluster(
                    simulation_name=self.simulation.simulation_name,
                    clusterID=halo_id,
                    redshift=halo_z,
                    fastbrowsing=True)
                read = pull.FOFRead(cluster)
                angle = read.pull_rot_vel_angle_between(
                    'ParType0_angmom', 'ParType4_angmom')[self.aperture_id]
                angle_master[halo_id,
                             self.simulation.redshiftAllowed.index(halo_z),
                             0] = redshift_str2num(halo_z)
                angle_master[halo_id,
                             self.simulation.redshiftAllowed.index(halo_z),
                             1] = angle

        print(
            f"Saving npy files: redshift_rot0vel4_simstats_aperture_{self.aperture_id}.npy"
        )
        np.save(
            os.path.join(
                self.path,
                f'redshift_rot0vel4_simstats_aperture_{self.aperture_id}.npy'),
            angle_master)
Exemple #17
0
    def wrapper(*args, **kwargs):

        # Checks that the essential paremeters are there
        assert not kwargs['out_allPartTypes'] is None
        assert not kwargs['simulation_name'] is None

        # Generate a simulation object and oush it to **kwargs
        sim = Simulation(simulation_name=kwargs['simulation_name'])
        kwargs['simulation'] = sim

        # Set-up the MPI allocation schedule
        process = 0
        process_iterator = itertools.product(sim.clusterIDAllowed,
                                             sim.redshiftAllowed)

        for halo_num, redshift in process_iterator:

            if process % size == rank:

                cluster_obj = Cluster(clusterID=int(halo_num),
                                      redshift=redshift_str2num(redshift))
                file_name = sim.cluster_prefix + sim.halo_Num(
                    halo_num) + redshift
                fileCompletePath = sim.pathSave + '/' + sim.simulation + '_output/collective_output/' + file_name + '.hdf5'

                kwargs['cluster'] = cluster_obj
                kwargs['fileCompletePath'] = fileCompletePath

                print(
                    'CPU ({}/{}) is processing halo {} @ z = {} ------ process ID: {}'
                    .format(rank, size, cluster_obj.clusterID,
                            cluster_obj.redshift, process))
                # Each CPU loops over all apertures - this avoids concurrence in file reading
                # The loop over apertures is defined explicitly in the wrapped function.
                function(*args, **kwargs)

            process += 1
Exemple #18
0
    def all_clusters(apertureidx):
        simulation = Simulation(simulation_name='celr_b')
        matrix_list = []
        aperture_list = []
        aperture_self_similar = []
        for id in simulation.clusterIDAllowed:
            cluster = Cluster(simulation_name='celr_e',
                              clusterID=id,
                              redshift='z000p101')
            print(f'Analysing cluster {cluster.clusterID}')
            matrix = CorrelationMatrix(cluster)
            data = matrix.get_data()[apertureidx]
            aperture = matrix.get_apertures()[apertureidx]
            matrix_list.append(data)
            aperture_list.append(aperture)
            aperture_self_similar.append(aperture / cluster.r500)

        if not os.path.exists(
                os.path.join(simulation.pathSave, simulation.simulation_name,
                             'rotvel_correlation')):
            os.makedirs(
                os.path.join(simulation.pathSave, simulation.simulation_name,
                             'rotvel_correlation'))

        average_aperture = np.mean(aperture_self_similar, axis=0)

        matrix.plot_matrix(matrix_list, average_aperture)
        print(
            f"Saving matrix | aperture {apertureidx} | redshift {cluster.redshift}"
        )
        plt.savefig(
            os.path.join(
                simulation.pathSave, simulation.simulation_name,
                'rotvel_correlation',
                f'{simulation.simulation_name}_meanPMstd_{cluster.redshift}_aperture'
                f'_{apertureidx}.png'))
Exemple #19
0
    def plot_z_trends(self, axis: Axes = None) -> None:

        if axis is None:
            axis = self.figure.add_subplot(111)

        cluster = Cluster(simulation_name=self.simulation.simulation_name,
                          clusterID=0,
                          redshift='z000p000')
        aperture_float = self.get_apertures(cluster)[
            self.aperture_id] / cluster.r200

        if not os.path.isfile(
                os.path.join(
                    self.path,
                    f'redshift_rot0rot4_bootstrap_aperture_{self.aperture_id}.npy'
                )):
            warnings.warn(
                f"File redshift_rot0rot4_bootstrap_aperture_{self.aperture_id}.npy not found."
            )
            print("self.make_simbootstrap() activated.")
            self.make_simbootstrap()

        print(
            f"Retrieving npy files: redshift_rot0rot4_bootstrap_aperture_{self.aperture_id}.npy"
        )
        sim_bootstrap = np.load(os.path.join(
            self.path, f'redshift_rot0rot4_bootstrap_aperture_'
            f'{self.aperture_id}.npy'),
                                allow_pickle=True)
        sim_bootstrap = np.asarray(sim_bootstrap)

        items_labels = f""" REDSHIFT TRENDS
							Number of clusters: {self.simulation.totalClusters:d}
							$z$ = 0.0 - 1.8
							Aperture radius = {aperture_float:.2f} $R_{{200\ true}}$"""
        print(items_labels)

        sim_colors = {
            'ceagle': 'pink',
            'celr_e': 'lime',
            'celr_b': 'orange',
            'macsis': 'aqua',
        }

        axis.axhline(90, linestyle='--', color='k', alpha=0.5, linewidth=2)

        axis.plot(sim_bootstrap[0, 0],
                  sim_bootstrap[3, 0],
                  color=sim_colors[self.simulation.simulation_name],
                  alpha=1,
                  linestyle='none',
                  marker='^',
                  markersize=10)
        axis.plot(sim_bootstrap[0, 0],
                  sim_bootstrap[2, 0],
                  color=sim_colors[self.simulation.simulation_name],
                  alpha=1,
                  linestyle='none',
                  marker='o',
                  markersize=10)
        axis.plot(sim_bootstrap[0, 0],
                  sim_bootstrap[1, 0],
                  color=sim_colors[self.simulation.simulation_name],
                  alpha=1,
                  linestyle='none',
                  marker='v',
                  markersize=10)

        for marker_index in range(len(sim_bootstrap[0, 0])):

            if marker_index is 0:
                align_toggle = 'edge'
                x_edge_left = sim_bootstrap[0, 0][marker_index]
                x_edge_right = sim_bootstrap[
                    0, 0][marker_index] + sim_bootstrap[0, 1][marker_index]
            else:
                align_toggle = 'center'
                x_edge_left = sim_bootstrap[
                    0, 0][marker_index] - sim_bootstrap[0, 1][marker_index] / 2
                x_edge_right = sim_bootstrap[
                    0, 0][marker_index] + sim_bootstrap[0, 1][marker_index] / 2

            axis.plot([x_edge_left, x_edge_right], [
                sim_bootstrap[3, 0][marker_index],
                sim_bootstrap[3, 0][marker_index]
            ],
                      color=sim_colors[self.simulation.simulation_name],
                      alpha=0.8,
                      linestyle='--',
                      lw=1.5)

            axis.plot([x_edge_left, x_edge_right], [
                sim_bootstrap[2, 0][marker_index],
                sim_bootstrap[2, 0][marker_index]
            ],
                      color=sim_colors[self.simulation.simulation_name],
                      alpha=0.8,
                      linestyle='-',
                      lw=1.5)

            axis.plot([x_edge_left, x_edge_right], [
                sim_bootstrap[1, 0][marker_index],
                sim_bootstrap[1, 0][marker_index]
            ],
                      color=sim_colors[self.simulation.simulation_name],
                      alpha=0.8,
                      linestyle='-.',
                      lw=1.5)

            axis.bar(sim_bootstrap[0, 0][marker_index],
                     2 * sim_bootstrap[3, 1][marker_index],
                     bottom=sim_bootstrap[3, 0][marker_index] -
                     sim_bootstrap[3, 1][marker_index],
                     width=sim_bootstrap[0, 1][marker_index],
                     align=align_toggle,
                     color=sim_colors[self.simulation.simulation_name],
                     alpha=0.2,
                     edgecolor='none',
                     linewidth=0)
            axis.bar(sim_bootstrap[0, 0][marker_index],
                     2 * sim_bootstrap[2, 1][marker_index],
                     bottom=sim_bootstrap[2, 0][marker_index] -
                     sim_bootstrap[2, 1][marker_index],
                     width=sim_bootstrap[0, 1][marker_index],
                     align=align_toggle,
                     color=sim_colors[self.simulation.simulation_name],
                     alpha=0.2,
                     edgecolor='none',
                     linewidth=0)
            axis.bar(sim_bootstrap[0, 0][marker_index],
                     2 * sim_bootstrap[1, 1][marker_index],
                     bottom=sim_bootstrap[1, 0][marker_index] -
                     sim_bootstrap[1, 1][marker_index],
                     width=sim_bootstrap[0, 1][marker_index],
                     align=align_toggle,
                     color=sim_colors[self.simulation.simulation_name],
                     alpha=0.2,
                     edgecolor='none',
                     linewidth=0)

        perc84 = Line2D([], [],
                        color='k',
                        marker='^',
                        linestyle='--',
                        markersize=10,
                        label=r'$84^{th}$ percentile')
        perc50 = Line2D([], [],
                        color='k',
                        marker='o',
                        linestyle='-',
                        markersize=10,
                        label=r'median')
        perc16 = Line2D([], [],
                        color='k',
                        marker='v',
                        linestyle='-.',
                        markersize=10,
                        label=r'$16^{th}$ percentile')
        patch_ceagle = Patch(facecolor=sim_colors['ceagle'],
                             label='C-EAGLE',
                             edgecolor='k',
                             linewidth=1)
        patch_celre = Patch(facecolor=sim_colors['celr_e'],
                            label='CELR-E',
                            edgecolor='k',
                            linewidth=1)
        patch_celrb = Patch(facecolor=sim_colors['celr_b'],
                            label='CELR-B',
                            edgecolor='k',
                            linewidth=1)
        patch_macsis = Patch(facecolor=sim_colors['macsis'],
                             label='MACSIS',
                             edgecolor='k',
                             linewidth=1)

        leg1 = axis.legend(handles=[perc84, perc50, perc16],
                           loc='lower right',
                           handlelength=3,
                           fontsize=20)
        leg2 = axis.legend(
            handles=[patch_ceagle, patch_celre, patch_celrb, patch_macsis],
            loc='lower left',
            handlelength=1,
            fontsize=20)
        axis.add_artist(leg1)
        axis.add_artist(leg2)
        axis.text(0.03,
                  0.97,
                  items_labels,
                  horizontalalignment='left',
                  verticalalignment='top',
                  transform=axis.transAxes,
                  size=15)

        axis.set_xlabel(r"$z$", size=25)
        axis.set_ylabel(
            r"$\Delta \theta \equiv (\mathbf{L},\mathrm{\widehat{CoP}},\mathbf{v_{pec}})$\quad[degrees]",
            size=25)
        axis.set_ylim(0, 180)
Exemple #20
0
    for z in redshifts:
        # Create a cluster object
        cluster = Cluster(simulation_name='celr_b', clusterID=i, redshift=z)
        cluster.info()

        # Create a PhaseDiagram object and link it to the cluster object
        t_rho_diagram = PhaseDiagram(cluster)
        # t_rho_diagram.info()

        # Test the map output
        t_rho_diagram.setup_plot()




if __name__ == '__main__':
    # test_simple()
    exec(open('visualisation/light_mode.py').read())
    for sim in ['celr_e', 'celr_b', 'macsis', 'ceagle']:

        cluster = Cluster(simulation_name=sim, clusterID=0, redshift='z000p000')
        t_rho_diagram = PhaseDiagram(cluster)
        t_rho_diagram.setup_plot()

    # from mpi4py import MPI
    #
    # comm = MPI.COMM_WORLD
    # size = comm.Get_size()
    # rank = comm.Get_rank()
    # test_loop_apertures(rank)
    # test_loop_redshifts(rank)
Exemple #21
0
    def test_particle_subgroup_number(self):
        # Read in celr_e | halo 0 | z=0
        path = '/cosma5/data/dp004/dc-pear3/data/eagle/halo_00/data/particledata_029_z000p000'
        with h5.File(
                os.path.join(path,
                             'eagle_subfind_particles_029_z000p000.0.hdf5'),
                'r') as f:
            hd5set = f['/PartType1/SubGroupNumber']
            subgroup_number = hd5set[...]
            print(f"\n{' celr_e | halo 0 | z=0 ':-^60}")
            print(
                f"Particles with subgroup number < 0: {len(np.where(subgroup_number<0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 0: {len(np.where(subgroup_number==0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 1: {len(np.where(subgroup_number==1)[0])} particles found."
            )

        # Read in celr_b | halo 0 | z=0
        path = '/cosma5/data/dp004/dc-pear3/data/bahamas/halo_00/data/particledata_029'
        with h5.File(os.path.join(path, 'eagle_subfind_particles_029.0.hdf5'),
                     'r') as f:
            hd5set = f['/PartType1/SubGroupNumber']
            subgroup_number = hd5set[...]
            print(f"\n{' celr_b | halo 0 | z=0 ':-^60}")
            print(
                f"Particles with subgroup number < 0: {len(np.where(subgroup_number < 0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 0: {len(np.where(subgroup_number == 0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 1: {len(np.where(subgroup_number == 1)[0])} particles found."
            )

        # Read in macsis | halo 0 | z=0
        path = '/cosma5/data/dp004/dc-hens1/macsis/macsis_gas/halo_0000/data/particledata_022'
        with h5.File(os.path.join(path, 'eagle_subfind_particles_022.0.hdf5'),
                     'r') as f:
            hd5set = f['/PartType1/SubGroupNumber']
            subgroup_number = hd5set[...]
            print(f"\n{' macsis | halo 0 | z=0 ':-^60}")
            print(
                f"Particles with subgroup number < 0: {len(np.where(subgroup_number < 0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 0: {len(np.where(subgroup_number == 0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 1: {len(np.where(subgroup_number == 1)[0])} particles found."
            )

        # Read in ceagle | halo 0 | z=0
        path = '/cosma5/data/dp004/C-EAGLE/Complete_Sample/CE_00/data/particledata_029_z000p000'
        subgroup_number = np.zeros(0, dtype=np.int)
        file_index = 0

        while file_index > -1:
            try:
                with h5.File(
                        os.path.join(
                            path,
                            f'eagle_subfind_particles_029_z000p000.{str(file_index)}.hdf5'
                        ), 'r') as f:
                    hd5set = f['/PartType1/SubGroupNumber']
                    subgroup_number = np.concatenate(
                        (subgroup_number, hd5set[...]), axis=0)
                    file_index += 1
            except:
                file_index = -1

        print(f"\n{' ceagle | halo 0 | z=0 ':-^60}")
        print(
            f"Particles with subgroup number < 0: {len(np.where(subgroup_number < 0)[0])} particles found."
        )
        print(
            f"Particles with subgroup number = 0: {len(np.where(subgroup_number == 0)[0])} particles found."
        )
        print(
            f"Particles with subgroup number = 1: {len(np.where(subgroup_number == 1)[0])} particles found."
        )

        print(f"{' SOFTWARE TEST ':=^60}")
        for sim in ['celr_e', 'celr_b', 'macsis', 'ceagle']:
            cluster = Cluster(simulation_name=sim,
                              clusterID=0,
                              redshift='z000p000')
            print(f"\n {sim}{' | halo 0 | z=0 ':-^60}")

            subgroup_number = cluster.subgroup_number_part('1')

            print(
                f"Particles with subgroup number < 0: {len(np.where(subgroup_number < 0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 0: {len(np.where(subgroup_number == 0)[0])} particles found."
            )
            print(
                f"Particles with subgroup number = 1: {len(np.where(subgroup_number == 1)[0])} particles found."
            )
Exemple #22
0
    def test_substructure_mass(self):
        print(f"{' SOFTWARE TEST ':=^60}")

        data_required = {
            'partType0': [
                'mass', 'coordinates', 'velocity', 'subgroupnumber',
                'temperature', 'sphdensity'
            ],
            'partType1': ['mass', 'coordinates', 'velocity', 'subgroupnumber'],
            'partType4': ['mass', 'coordinates', 'velocity', 'subgroupnumber'],
            'partType5': ['mass', 'coordinates', 'velocity', 'subgroupnumber']
        }

        for sim in ['celr_e', 'celr_b', 'macsis', 'ceagle']:
            cluster = Cluster(simulation_name=sim,
                              clusterID=0,
                              redshift='z000p000',
                              requires=data_required)
            print(f"\n {sim} {' | halo 0 | z=0 ':->60}")
            warnings.filterwarnings("ignore")
            print(f"{' out_allPartTypes=False ':^60}")
            print("cluster.group_thermal_energy",
                  cluster.group_thermal_energy())
            print("cluster.group_kinetic_energy",
                  cluster.group_kinetic_energy())
            print("cluster.group_substructure_mass",
                  cluster.group_substructure_mass())
            print("cluster.group_dynamical_merging_index",
                  cluster.group_dynamical_merging_index())
            print("cluster.group_thermodynamic_merging_index",
                  cluster.group_thermodynamic_merging_index())
            print("cluster.group_substructure_fraction",
                  cluster.group_substructure_fraction())
            print(f"{' out_allPartTypes=True ':^60}")
            print("cluster.group_thermal_energy",
                  cluster.group_thermal_energy())
            print("cluster.group_kinetic_energy",
                  cluster.group_kinetic_energy(out_allPartTypes=True))
            print("cluster.group_substructure_mass",
                  cluster.group_substructure_mass(out_allPartTypes=True))
            print("cluster.group_dynamical_merging_index",
                  cluster.group_dynamical_merging_index(out_allPartTypes=True))
            print("cluster.group_thermodynamic_merging_index",
                  cluster.group_thermodynamic_merging_index())
            print("cluster.group_substructure_fraction",
                  cluster.group_substructure_fraction(out_allPartTypes=True))
            print('\n\n')
import h5py
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.lines as mlines
from matplotlib.collections import EllipseCollection

# exec(open(os.path.abspath(os.path.join(
# 		os.path.dirname(__file__), os.path.pardir, 'visualisation', 'light_mode.py'))).read())
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
warnings.filterwarnings("ignore")
from import_toolkit.cluster import Cluster

cluster = Cluster(simulation_name='bahamas',
                  clusterID=0,
                  redshift='z000p000',
                  comovingframe=False,
                  fastbrowsing=True)

filepath = "/local/scratch/altamura/analysis_results/"
filename = f"bahamas-box-5r200spheres.jpg"

fig = plt.figure(figsize=(15, 15))
ax = fig.add_subplot(111)
ax.set_aspect('equal')
# ax.set_xlim([0, 400])
# ax.set_ylim([0, 400])
ax.set_xlabel(r'$x$ \quad [cMpc]')
ax.set_ylabel(r'$y$ \quad [cMpc]')

n_largeM = 0
Exemple #24
0
    def plot_z_trend_histogram(self,
                               axis: Axes = None,
                               polar: bool = True,
                               normed: bool = True) -> None:

        if axis is None:
            axis = self.figure.add_subplot(111)

        cluster = Cluster(simulation_name=self.simulation.simulation_name,
                          clusterID=0,
                          redshift='z000p000')
        aperture_float = self.get_apertures(cluster)[
            self.aperture_id] / cluster.r200

        if not os.path.isfile(
                os.path.join(
                    self.path,
                    f'redshift_rot0rot4_histogram_aperture_{self.aperture_id}.npy'
                )):
            warnings.warn(
                f"File redshift_rot0rot4_histogram_aperture_{self.aperture_id}.npy not found."
            )
            print("self.make_simhist() activated.")
            self.make_simhist()

        print(
            f"Retrieving npy files: redshift_rot0rot4_histogram_aperture_{self.aperture_id}.npy"
        )
        sim_hist = np.load(os.path.join(
            self.path,
            f'redshift_rot0rot4_histogram_aperture_{self.aperture_id}.npy'),
                           allow_pickle=True)
        sim_hist = np.asarray(sim_hist)

        if normed:
            norm_factor = np.sum(self.simulation.sample_completeness)
            sim_hist[2] /= norm_factor
            sim_hist[3] /= norm_factor
            y_label = r"Sample fraction"
        else:
            y_label = r"Number of samples"

        items_labels = f""" REDSHIFT TRENDS - HISTOGRAM
							Number of clusters: {self.simulation.totalClusters:d}
							$z$ = 0.0 - 1.8
							Total samples: {np.sum(self.simulation.sample_completeness):d} $\equiv N_\mathrm{{clusters}} \cdot N_\mathrm{{redshifts}}$
							Aperture radius = {aperture_float:.2f} $R_{{200\ true}}$"""
        print(items_labels)

        sim_colors = {
            'ceagle': 'pink',
            'celr_e': 'lime',
            'celr_b': 'orange',
            'macsis': 'aqua',
        }

        axis.axvline(90, linestyle='--', color='k', alpha=0.5, linewidth=2)
        axis.step(sim_hist[0],
                  sim_hist[2],
                  color=sim_colors[self.simulation.simulation_name],
                  where='mid')
        axis.fill_between(sim_hist[0],
                          sim_hist[2] + sim_hist[3],
                          sim_hist[2] - sim_hist[3],
                          step='mid',
                          color=sim_colors[self.simulation.simulation_name],
                          alpha=0.2,
                          edgecolor='none',
                          linewidth=0)

        axis.set_ylabel(y_label, size=25)
        axis.set_xlabel(
            r"$\Delta \theta \equiv (\mathbf{L}_\mathrm{gas},\mathrm{\widehat{CoP}},\mathbf{L}_\mathrm{stars})$\quad[degrees]",
            size=25)
        axis.set_xlim(0, 180)
        axis.set_ylim(0, 0.1)
        axis.text(0.03,
                  0.97,
                  items_labels,
                  horizontalalignment='left',
                  verticalalignment='top',
                  transform=axis.transAxes,
                  size=15)

        if polar:
            inset_axis = self.figure.add_axes([0.75, 0.65, 0.25, 0.25],
                                              projection='polar')
            inset_axis.patch.set_alpha(0)  # Transparent background
            inset_axis.set_theta_zero_location('N')
            inset_axis.set_thetamin(0)
            inset_axis.set_thetamax(180)
            inset_axis.set_xticks(np.pi / 180. *
                                  np.linspace(0, 180, 5, endpoint=True))
            inset_axis.set_yticks([])
            inset_axis.step(sim_hist[0] / 180 * np.pi,
                            sim_hist[2],
                            color=sim_colors[self.simulation.simulation_name],
                            where='mid')
            inset_axis.fill_between(
                sim_hist[0] / 180 * np.pi,
                sim_hist[2] + sim_hist[3],
                sim_hist[2] - sim_hist[3],
                step='mid',
                color=sim_colors[self.simulation.simulation_name],
                alpha=0.2,
                edgecolor='none',
                linewidth=0)

        patch_ceagle = Patch(facecolor=sim_colors['ceagle'],
                             label='C-EAGLE',
                             edgecolor='k',
                             linewidth=1)
        patch_celre = Patch(facecolor=sim_colors['celr_e'],
                            label='CELR-E',
                            edgecolor='k',
                            linewidth=1)
        patch_celrb = Patch(facecolor=sim_colors['celr_b'],
                            label='CELR-B',
                            edgecolor='k',
                            linewidth=1)
        patch_macsis = Patch(facecolor=sim_colors['macsis'],
                             label='MACSIS',
                             edgecolor='k',
                             linewidth=1)

        leg2 = axis.legend(
            handles=[patch_ceagle, patch_celre, patch_celrb, patch_macsis],
            loc='lower center',
            handlelength=1,
            fontsize=20)
        axis.add_artist(leg2)
Exemple #25
0
    # Set-up the MPI allocation schedule
    sim = Simulation(simulation_name='ceagle')
    iterator = itertools.product(sim.clusterIDAllowed, sim.redshiftAllowed)
    print(f"{sim.simulation:=^100s}")
    print(
        f"{' CPU (rank/size) ':^30s} | {' CPU process ID ':^25s} | {' halo ID ':^15s} | "
        f"{' halo redshift ':^20s}\n")

    for process_n, (halo_id, halo_z) in enumerate(list(iterator)):
        if ((sim.sample_completeness[halo_id,
                                     sim.redshiftAllowed.index(halo_z)])
                and (process_n % size is rank)):

            cluster = Cluster(simulation_name=sim.simulation_name,
                              clusterID=halo_id,
                              redshift=halo_z,
                              comovingframe=False,
                              requires=data_required)

            out = FOFDatagen(cluster)
            out.push_R_crit()
            out.push_M_crit()
            out.push_apertures()
            out.push_mass()
            out.push_centre_of_mass()
            out.push_peculiar_velocity()
            out.push_angular_momentum()
            out.push_kinetic_energy()
            out.push_thermal_energy()
            out.push_substructure_mass()
            out.push_dynamical_merging_index()
            ang_momentum = ang_momenta[1]
        elif align == 'stars' or align == '4':
            ang_momentum = ang_momenta[4]
        elif align == 'black_holes' or align == '5':
            ang_momentum = ang_momenta[5]

        z_axis_unit_vector = [0, 0, 1]
        rot_matrix = cluster.rotation_matrix_from_vectors(
            ang_momentum, z_axis_unit_vector)
        coords = cluster.apply_rotation_matrix(rot_matrix, coords)
        vel = cluster.apply_rotation_matrix(rot_matrix, vel)

        return coords, vel


if __name__ == "__main__":

    from visualisation.rendering import plot_angularmomentum_vectors

    cluster = Cluster(clusterID=0, redshift=0.)
    angmom, masses = cluster.group_angular_momentum(out_allPartTypes=True)
    m = angular_momentum_PartType_alignment_matrix(cluster)
    print(m)
    plot_angularmomentum_vectors(
        angmom,
        axes=None,
        plot_unitSphere=False,
        normalise_length=False,
        make_all_unitary=False,
    )
    plt.show()
        return fig


filepath = "/local/scratch/altamura/analysis_results/"
filename = f"bahamas-clustermap-5r200.jpg"
data_required = {
    'partType0': [
        'groupnumber', 'mass', 'coordinates', 'velocity', 'temperature',
        'sphdensity'
    ],
    'partType1': ['groupnumber', 'mass', 'coordinates', 'velocity'],
    'partType4': ['groupnumber', 'mass', 'coordinates', 'velocity']
}
cluster = Cluster(simulation_name='bahamas',
                  clusterID=0,
                  redshift='z003p000',
                  comovingframe=False,
                  fastbrowsing=False,
                  requires=data_required)

coords = cluster.partType0_coordinates
x0, y0, z0 = cluster.centre_of_potential
morphology = cluster.group_morphology(aperture_radius=cluster.r200)
eigenvalues = morphology['eigenvalues'][1]
eigenvectors = morphology['eigenvectors'][1].reshape((3, 3))

# Sort eigenvalues from largest to smallest
eigenvalues = [x for x, _ in sorted(zip(eigenvalues, eigenvectors))][::-1]
eigenvectors = [x for _, x in sorted(zip(eigenvalues, eigenvectors))][::-1]

a_val, b_val, c_val = np.sqrt(eigenvalues)
a_vec, b_vec, c_vec = eigenvectors
Exemple #28
0
        vectors = [[0, 1, 1], [2, 5, 6], [-3, -2, 0]]
        labels = [
            r'$\mathbf{L}_\mathrm{gas}$', r'$\mathbf{L}_\mathrm{DM}$',
            r'$\mathbf{L}_\mathrm{stars}$'
        ]
        observer.plot_angularmomentum_vectors(vectors,
                                              labels=labels,
                                              plot_unitSphere=True,
                                              normalise_length=False,
                                              make_all_unitary=True)

        observer.draw_legend(ax)


if __name__ == '__main__':
    exec(open('visualisation/light_mode.py').read())

    # Create a cluster object
    cluster = Cluster(simulation_name='ceagle',
                      clusterID=0,
                      redshift='z000p000')

    # Create a KSZMAP object and link it to the cluster object
    test_map = KSZMAP(cluster,
                      resolution=300,
                      aperture=cluster.r2500,
                      plotlimits=3 * cluster.r2500)
    test_map.info()
    # Test the map output
    test_map.make_plot()
    plt.show()
Exemple #29
0
    def test_filenames(self):
        # Read in celr_e | halo 0 | z=0
        path = '/cosma5/data/dp004/dc-pear3/data/eagle'
        exists_dir = os.path.isdir(
            os.path.join(path, 'halo_00/data/particledata_029_z000p000'))
        exists_file = os.path.isfile(
            os.path.join(path, 'halo_00/data/particledata_029_z000p000',
                         'eagle_subfind_particles_029_z000p000.0.hdf5'))

        print(f"\n{' celr_e | halo 0 | z=0 ':-^60}")
        print(f"Data directory exists: {exists_dir}.")
        print(f"Data file exists: {exists_file}.")

        # Read in celr_b | halo 0 | z=0
        path = '/cosma5/data/dp004/dc-pear3/data/bahamas'
        exists_dir = os.path.isdir(
            os.path.join(path, 'halo_00/data/particledata_029'))
        exists_file = os.path.isfile(
            os.path.join(path, 'halo_00/data/particledata_029',
                         'eagle_subfind_particles_029.0.hdf5'))

        print(f"\n{' celr_b | halo 0 | z=0 ':-^60}")
        print(f"Data directory exists: {exists_dir}.")
        print(f"Data file exists: {exists_file}.")

        # Read in macsis | halo 0 | z=0
        path = '/cosma5/data/dp004/dc-hens1/macsis/macsis_gas'
        exists_dir = os.path.isdir(
            os.path.join(path, 'halo_0000/data/particledata_022'))
        exists_file = os.path.isfile(
            os.path.join(path, 'halo_0000/data/particledata_022',
                         'eagle_subfind_particles_022.0.hdf5'))

        print(f"\n{' macsis | halo 0 | z=0 ':-^60}")
        print(f"Data directory exists: {exists_dir}.")
        print(f"Data file exists: {exists_file}.")

        # Read in ceagle | halo 0 | z=0
        path = '/cosma5/data/dp004/C-EAGLE/Complete_Sample'
        exists_dir = os.path.isdir(
            os.path.join(path, 'CE_00/data/particledata_029_z000p000'))
        print(f"\n{' ceagle | halo 0 | z=0 ':-^60}")
        print(f"Data directory exists: {exists_dir}.")
        collection_exists_file = []
        file_index = 0
        exists_file = True

        while exists_file:
            exists_file = os.path.isfile(
                os.path.join(
                    path, f'CE_00/data/particledata_029_z000p000',
                    f'eagle_subfind_particles_029_z000p000.{str(file_index)}.hdf5'
                ))
            collection_exists_file.append(exists_file)
            print(f"Data file {file_index:03d} exists: {exists_file}.")
            file_index += 1

        print(f"{' SOFTWARE TEST ':=^60}")
        for sim in ['celr_e', 'celr_b', 'macsis', 'ceagle']:
            cluster = Cluster(simulation_name=sim,
                              clusterID=0,
                              redshift='z000p000')
            print(f"\n {sim}{' | halo 0 | z=0 ':-^60}")
            # print("cluster.groups_filePaths", cluster.groups_filePaths(), sep='\n')
            # Check the files exist
            for file in cluster.groups_filePaths():
                print(os.path.isfile(file), file)

            # print("cluster.partdata_filePaths", cluster.partdata_filePaths(), sep='\n')
            # Check the files exist
            for file in cluster.partdata_filePaths():
                print(os.path.isfile(file), file)
Exemple #30
0
    fname = cluster.partdata_filePaths()[0]  # dataset to load
    CoP = cluster.group_centre_of_potential()
    print(fname)

    unit_base = {
        'UnitLength_in_cm': 3.08568e+21,
        'UnitMass_in_g': 1.989e+43,
        'UnitVelocity_in_cm_per_s': 100000
    }

    bbox_lim = 1e5  # kpc

    bbox = [[-bbox_lim, bbox_lim], [-bbox_lim, bbox_lim],
            [-bbox_lim, bbox_lim]]

    ds = yt.load(fname, unit_base=unit_base, bounding_box=bbox)
    ad = ds.all_data()
    density = ad[("PartType0", "density")]
    wdens = np.where(density == np.max(density))
    coordinates = ad[("PartType0", "Coordinates")]
    center = coordinates[wdens][0]

    # Create density slices of several fields along the x axis
    yt.SlicePlot(ds,
                 'z', [('gas', 'density'), ('gas', 'temperature')],
                 width=(15 * r200, 'Mpc'),
                 center=center).save()


cluster = Cluster(clusterID=4, redshift=0.101)
YT_plot_gas_density(cluster)