示例#1
0
    def GroupBy(self, variable='Z'):
        """
        GroupBy(variable='Z')
        
        create instance.datagrouped dictionary
        finds unique values of variable and groups all the 
        data that has that value of variable

        e.g.
        GroupBy()   # default is 'Z'
        instance.datagrouped is dict with:
        0.000: array of (nparticles x allother variables)
        1.202: similar but different number of particles maybe
        ... etc
        """
        self.datagrouped = Data.AsciiData()

        #find unique values of variable
        uniquevalues = sorted(list(set(_np.round(self.data[variable], 2))))

        #remove the variable from the subset
        #find it's index in keys list
        indexofvariabletoremove = self.keyslist.index(variable)
        for value in uniquevalues:
            mask = _np.round(self.data[variable], 2) == value
            dcopy = self.dataarray[mask]
            dcopydict = dict(
                zip(self.keyslist,
                    [dcopy[:, i] for i in range(_np.shape(dcopy)[1])]))

            #dcopydict = Data.AsciiData(zip(self.data.keyslist,[dcopy[:,i] for i in range(_np.shape(dcopy)[1])]))
            dcopydict['nparticles'] = _np.shape(dcopy)[0]
            self.datagrouped[value] = dcopydict
        self.keysgrouped = list(_np.sort(self.datagrouped.keys()))