Exemple #1
0
    def __init__(self,
                 sim_file,
                 groups_file,
                 group_ids_file,
                 n=1,
                 reverse=False,
                 bins=51,
                 reconstruct=True,
                 test=False,
                 basis_test=False,
                 n_test=51,
                 int_test=False,
                 x_max=1.0,
                 bases=[[0, 0, 0]]):
        """
        Read in a sim-file for use with the shapelet analysis.
        
        PARAMETERS:
        sim_file: file containing the simulation snapshot
        groups_file: file containing the location of groups
        group_ids_file: file containing the ids of the group members
        
        n: optional, default 1, number of groups to retain for further analysis (from largest to smallest)
        reverse: optional, default False, whether to use the n SMALLEST groups rather than largest.
        """
        self.n = n
        self.int_test = int_test
        if basis_test:
            self.test_bases(n_test)
            return

        self.test = test
        simops.readsim(sim_file)
        simops.find_groups(groups_file, group_ids_file)

        self.groups_pos = []
        for i in range(n):
            if not reverse:
                self.groups_pos = self.groups_pos + [
                    np.asfortranarray(simops.pos[:,
                                                 simops.group_number == i + 1])
                ]
            else:
                self.groups_pos = self.groups_pos + [
                    np.asfortranarray(
                        simops.pos[:, simops.group_number ==
                                   np.max(simops.group_number) - i])
                ]

            simops.centre(self.groups_pos[i], mode=1)
            simops.rotate(self.groups_pos[i], self.groups_pos[i],
                          [0.0, 0.0, 0.0], 0.0)

        self.make_directories(sim_file)

        if not self.test:
            self.shapelets_main(bins, reconstruct)
        else:
            self.shapelets_test(x_max, bins, bases)
    def __init__(self,sim_file,groups_file,group_ids_file, n=1,reverse=False,bins=51,reconstruct=True,
                 test=False,basis_test=False,n_test=51,int_test=False,x_max=1.0,bases=[[0,0,0]]):
        """
        Read in a sim-file for use with the shapelet analysis.
        
        PARAMETERS:
        sim_file: file containing the simulation snapshot
        groups_file: file containing the location of groups
        group_ids_file: file containing the ids of the group members
        
        n: optional, default 1, number of groups to retain for further analysis (from largest to smallest)
        reverse: optional, default False, whether to use the n SMALLEST groups rather than largest.
        """
        self.n = n
        self.int_test = int_test
        if basis_test:
            self.test_bases(n_test)
            return
            
        self.test = test
        simops.readsim(sim_file)
        simops.find_groups(groups_file,group_ids_file)
        
        self.groups_pos = []
        for i in range(n):
            if not reverse:
                self.groups_pos = self.groups_pos + [np.asfortranarray(simops.pos[:,simops.group_number == i+1])]
            else:
                self.groups_pos = self.groups_pos + [np.asfortranarray(simops.pos[:,simops.group_number == np.max(simops.group_number)-i])]
            
            simops.centre(self.groups_pos[i],mode=1)
            simops.rotate(self.groups_pos[i],self.groups_pos[i],[0.0,0.0,0.0],0.0)
            
        self.make_directories(sim_file)

        if not self.test:
            self.shapelets_main(bins, reconstruct)
        else:
            self.shapelets_test(x_max, bins, bases)
Exemple #3
0
    def __init__(self,filename,group_filename=None,ids_filename=None,n_groups=1,reverse=False,centring_mode=None,loud=False,subgroup_filename=None):
        """
        Imports the simulation and detects groups and subgroups if specified.
        """
        #Set the FORTRAN module parameter whether to write out extra information.
        fsims.loud = loud
        
        # readsim reads in the simulation and defines fsims.pos and fsims.vel amongst others.
        fsims.readsim(filename)

        # find_groups locates groups in the simulation and saves the array fsmims.group_number,
        # which contains the number of the group for each particle.  
        if group_filename:
            fsims.find_groups(group_filename,ids_filename)
            
            # Modify the number of groups to work with in the stats part.
            if n_groups is 'all':
                self.n_groups = fsims.ngroups
            else:
                self.n_groups = n_groups
             
            #If a subgroup filename was given, read in all the subgroups, saving a flagged subgroup number to each particle.   
            if subgroup_filename:
                fsims.read_subgroupv(subgroup_filename)
                self.subgroups_pos = []
            
            #Initialize all variables for later use.    
            self.groups_pos = []
            self.groups_vel = []
            self.groups_pos_f = []
            self.groups_vel_f = []
            self.axis_b = []
            self.axis_c = []
            self.axis_d = []
            self.original_group_centres = []
            
            for i in range(self.n_groups):
                #Save the particles to their respective groups
                group_pos, group_vel = fsims.specify_groups(i+1,fsims.grouplen[i])
                self.groups_vel = self.groups_vel + [np.asfortranarray(group_vel)]
                self.groups_pos = self.groups_pos + [np.asfortranarray(group_pos)]
                
                #Save the original group centre (the first particle position of each group)
                self.original_group_centres = self.original_group_centres + [np.array(group_pos[:,0])]

                # Recentre each group around its first particle
                fsims.centre(self.groups_pos[i],centring_mode)
                
                #Rotate each group so its longest axis is the x-axis.
                fsims.rotate(self.groups_pos[i],np.asfortranarray(self.groups_vel[i]),[0.0,0.0,0.0],0.0)

                #Save axis ratios for further use.
                self.axis_b.append(float(fsims.axis_ratio_b))
                self.axis_c.append(float(fsims.axis_ratio_c))
                self.axis_d.append(float(fsims.axis_ratio_d))
                 
                #Locate subgroups.Particles are in no particular order though!
                self.subgroups_pos = self.subgroups_pos + [[]]
                
                #Arrange the subgroup numbers contained in each group in descending order so that non-grouped particles are last.
                indices = list(set(fsims.subgroup_number[fsims.group_number == i+1]))
                indices.sort(reverse=True)
                for index in indices:
                    self.subgroups_pos[i] = self.subgroups_pos[i] + [np.array(self.groups_pos[i])[:,fsims.subgroup_number[fsims.group_number == i+1]== index]]


        #Make the directory structure that files will be saved to.        
        self.make_directories(filename)
Exemple #4
0
    def __init__(self,
                 filename,
                 group_filename=None,
                 ids_filename=None,
                 n_groups=1,
                 reverse=False,
                 centring_mode=None,
                 loud=False,
                 subgroup_filename=None):
        """
        Imports the simulation and detects groups and subgroups if specified.
        """
        #Set the FORTRAN module parameter whether to write out extra information.
        fsims.loud = loud

        # readsim reads in the simulation and defines fsims.pos and fsims.vel amongst others.
        fsims.readsim(filename)

        # find_groups locates groups in the simulation and saves the array fsmims.group_number,
        # which contains the number of the group for each particle.
        if group_filename:
            fsims.find_groups(group_filename, ids_filename)

            # Modify the number of groups to work with in the stats part.
            if n_groups is 'all':
                self.n_groups = fsims.ngroups
            else:
                self.n_groups = n_groups

            #If a subgroup filename was given, read in all the subgroups, saving a flagged subgroup number to each particle.
            if subgroup_filename:
                fsims.read_subgroupv(subgroup_filename)
                self.subgroups_pos = []

            #Initialize all variables for later use.
            self.groups_pos = []
            self.groups_vel = []
            self.groups_pos_f = []
            self.groups_vel_f = []
            self.axis_b = []
            self.axis_c = []
            self.axis_d = []
            self.original_group_centres = []

            for i in range(self.n_groups):
                #Save the particles to their respective groups
                group_pos, group_vel = fsims.specify_groups(
                    i + 1, fsims.grouplen[i])
                self.groups_vel = self.groups_vel + [
                    np.asfortranarray(group_vel)
                ]
                self.groups_pos = self.groups_pos + [
                    np.asfortranarray(group_pos)
                ]

                #Save the original group centre (the first particle position of each group)
                self.original_group_centres = self.original_group_centres + [
                    np.array(group_pos[:, 0])
                ]

                # Recentre each group around its first particle
                fsims.centre(self.groups_pos[i], centring_mode)

                #Rotate each group so its longest axis is the x-axis.
                fsims.rotate(self.groups_pos[i],
                             np.asfortranarray(self.groups_vel[i]),
                             [0.0, 0.0, 0.0], 0.0)

                #Save axis ratios for further use.
                self.axis_b.append(float(fsims.axis_ratio_b))
                self.axis_c.append(float(fsims.axis_ratio_c))
                self.axis_d.append(float(fsims.axis_ratio_d))

                #Locate subgroups.Particles are in no particular order though!
                self.subgroups_pos = self.subgroups_pos + [[]]

                #Arrange the subgroup numbers contained in each group in descending order so that non-grouped particles are last.
                indices = list(
                    set(fsims.subgroup_number[fsims.group_number == i + 1]))
                indices.sort(reverse=True)
                for index in indices:
                    self.subgroups_pos[i] = self.subgroups_pos[i] + [
                        np.array(self.groups_pos[i])[:, fsims.subgroup_number[
                            fsims.group_number == i + 1] == index]
                    ]

        #Make the directory structure that files will be saved to.
        self.make_directories(filename)