示例#1
0
    def go(self):
        pi = self.progress.indicator
        nstates = len(self.state_labels)
        if self.interface == 'matplotlib':
            with pi:
                if 'state_pop_evolution' in self.stateprobs_file:
                    pi.new_operation('plotting populations', nstates)
                    for istate in range(nstates):
                        self.plot_pop(istate)
                        pi.progress += 1

                if 'color_prob_evolution' in self.stateprobs_file:
                    pi.new_operation('plotting ensemble populations', nstates)
                    for istate in range(nstates):
                        self.plot_color(istate)
                        pi.progress += 1
                else:
                    print('population evolution not available')
        else:
            plotter = Plotter(self.stateprobs_file,
                              'state_pop_evolution',
                              iteration=-1,
                              interface='text')
            for istate in range(nstates):
                plotter.plot(istate)
            plotter = Plotter(self.stateprobs_file,
                              'color_prob_evolution',
                              iteration=-1,
                              interface='text')
            for istate in range(nstates):
                plotter.plot(istate)
示例#2
0
文件: ploterr.py 项目: westpa/westpa
    def go(self):
        pi = self.progress.indicator
        nstates = len(self.state_labels)
        if self.interface == 'matplotlib':
            with pi:
                if 'state_pop_evolution' in self.stateprobs_file:
                    pi.new_operation('plotting populations', nstates)
                    for istate in xrange(nstates):
                        self.plot_pop(istate)
                        pi.progress += 1

                if 'color_prob_evolution' in self.stateprobs_file:
                    pi.new_operation('plotting ensemble populations', nstates)
                    for istate in xrange(nstates):
                        self.plot_color(istate)
                        pi.progress += 1
                else:
                    print('population evolution not available')
        else:
            plotter = Plotter(self.stateprobs_file, 'state_pop_evolution', iteration=-1, interface='text')
            for istate in xrange(nstates):
                    plotter.plot(istate)
            plotter = Plotter(self.stateprobs_file, 'color_prob_evolution', iteration=-1, interface='text')
            for istate in xrange(nstates):
                    plotter.plot(istate)
示例#3
0
文件: ploterr.py 项目: westpa/westpa
 def go(self):
     pi = self.progress.indicator
     nstates = len(self.state_labels)
     if self.interface == 'matplotlib':
         with pi:
             # if --evolution-mode wasn't specified, neither of these exist:
             if 'target_flux_evolution' in self.kinavg_file:
                 pi.new_operation('plotting fluxes', nstates)
                 for istate in xrange(nstates):
                     self.plot_flux(istate)
                     pi.progress += 1
             
             # if --evolution-mode wasn't specified, we won't get this either
             if 'rate_evolution' in self.kinavg_file:
                 pi.new_operation('plotting rates', nstates*nstates)
                 for istate in xrange(nstates):
                     for jstate in xrange(nstates):
                         self.plot_rate(istate, jstate)
                         pi.progress += 1
             else:
                 print('rate evolution not available')
     else:
         plotter = Plotter(self.kinavg_file, 'rate_evolution', iteration=-1, interface='text')
         for istate in xrange(nstates):
             for jstate in xrange(nstates):
                 if istate != jstate:
                     plotter.plot(istate, jstate)
         plotter = Plotter(self.kinavg_file, 'conditional_flux_evolution', iteration=-1, interface='text')
         for istate in xrange(nstates):
             for jstate in xrange(nstates):
                 if istate != jstate:
                     plotter.plot(istate, jstate)
示例#4
0
 def __1D_with_error__(self, h5key, index, assign):
     self.step_iter = (self.h5file[h5key]['iter_stop'][0] - self.h5file[h5key]['iter_start'][0])[1]
     value = ((index-self.h5file.attrs['iter_start']) // self.step_iter)
     if value < 0:
         value = 0
     raw = self.h5file[h5key][value, :]
     error = (raw['ci_ubound'] - raw['ci_lbound']) / (2*raw['expected'])
     expected = raw['expected']
     raw = self.__custom_dataset__(raw, assign, h5key)
     raw.error = error
     raw.plotter = Plotter(self.h5file, h5key, iteration=value, interface='text')
     raw.plot = raw.plotter.plot
     return raw
示例#5
0
文件: wipi.py 项目: chemlove/westpa
    def __getitem__(self, value):
        '''
        Responsible for handling whether this is treated like a dictionary of data sets, or an array of walker data.
        '''
        # Check to see if we're indexing via any of the active string types.  We should probably break it down via string or int, instead of 'what exists and what doesn't', but it works for now.
        active_items = [
            'kinavg', 'statepops', 'weights', 'pcoord', 'auxdata', 'parents',
            'summary', 'seg_id', 'walkers', 'states', 'bins', 'populations',
            'plot', 'instant_matrix', 'kinrw', 'matrix', 'rwstatepops'
        ]
        #if value in active_items:
        if type(value) is str:
            # This should handle everything.  Otherwise...
            try:
                return self.raw[value]
            except:
                print('{} is not a valid data structure.'.format(value))
        elif type(value) is int or type(value) is np.int64:
            # Otherwise, we assume they're trying to index for a seg_id.
            if value < self.walkers:
                current = {}
                current['plotter'] = {}
                for i in ['pcoord']:
                    current[i] = WIPIDataset(raw=self.raw[i][value, :, :],
                                             key=i)
                    current[i].plotter = Plotter(self.raw[i][value, :, :],
                                                 i,
                                                 iteration=self.iteration,
                                                 interface='text')
                    current[i].plot = current[i].plotter.plot

                current['states'] = self.raw['states'][value, :]
                current['bins'] = self.raw['bins'][value, :]
                current['parents'] = self.raw['parents'][value]
                current['seg_id'] = self.raw['seg_id'][value]
                current['weights'] = self.raw['weights'][value]
                try:
                    current['auxdata'] = {}
                    for key in self.raw['auxdata'].keys():
                        current['auxdata'][key] = self.raw['auxdata'][key][
                            value]
                except:
                    pass
                current = WIPIDataset(
                    current,
                    'Segment {} in Iter {}'.format(value, self.iteration))
                return current
            else:
                print('INVALID SEG_ID {}.  SEG_ID should be less than {}.'.
                      format(value, self.walkers))
示例#6
0
 def __2D_with_error__(self, h5key, index, assign):
     # Check the start and stop, calculate the block size, and index appropriately.
     # While we could try and automatically generate this above, it's a little more consistent to try it here.
     # This should show the first block for which the current iteration has contributed data.
     self.step_iter = (self.h5file[h5key]['iter_stop'][0] - self.h5file[h5key]['iter_start'][0])[1,0]
     value = ((index-self.h5file.attrs['iter_start']) // self.step_iter)
     if value < 0:
         value = 0
     raw = self.h5file[h5key][value, :, :]
     error = (raw['ci_ubound'] - raw['ci_lbound']) / (2*raw['expected'])
     expected = raw['expected']
     raw = self.__custom_dataset__(raw, assign, h5key)
     raw.error = error
     raw.plotter = Plotter(self.h5file, h5key, iteration=value, interface='text')
     raw.plot = raw.plotter.plot
     return raw
示例#7
0
    def go(self):
        pi = self.progress.indicator
        nstates = len(self.state_labels)
        if self.interface == 'matplotlib':
            with pi:
                # if --evolution-mode wasn't specified, neither of these exist:
                if 'target_flux_evolution' in self.kinavg_file:
                    pi.new_operation('plotting fluxes', nstates)
                    for istate in range(nstates):
                        self.plot_flux(istate)
                        pi.progress += 1

                # if --evolution-mode wasn't specified, we won't get this either
                if 'rate_evolution' in self.kinavg_file:
                    pi.new_operation('plotting rates', nstates * nstates)
                    for istate in range(nstates):
                        for jstate in range(nstates):
                            self.plot_rate(istate, jstate)
                            pi.progress += 1
                else:
                    print('rate evolution not available')
        else:
            plotter = Plotter(self.kinavg_file,
                              'rate_evolution',
                              iteration=-1,
                              interface='text')
            for istate in range(nstates):
                for jstate in range(nstates):
                    if istate != jstate:
                        plotter.plot(istate, jstate)
            plotter = Plotter(self.kinavg_file,
                              'conditional_flux_evolution',
                              iteration=-1,
                              interface='text')
            for istate in range(nstates):
                for jstate in range(nstates):
                    if istate != jstate:
                        plotter.plot(istate, jstate)
示例#8
0
    def trace(self, seg_id):
        '''
        Runs a trace on a seg_id within the current iteration, all the way back to the beginning,
        returning a dictionary containing all interesting information:

            seg_id, pcoord, states, bins, weights, iteration, auxdata (optional)

        sorted in chronological order.


        Call with a seg_id.
        '''
        if seg_id >= self.current.walkers:
            print("Walker seg_id # {} is beyond the max count of {} walkers.".format(seg_id, self.current.walkers))
            return 1
        pi = self.progress.indicator
        with pi:
            pi.new_operation('Tracing scheme:iter:seg_id {}:{}:{}'.format(self.scheme, self.iteration, seg_id), self.iteration)
            current = { 'seg_id': [], 'pcoord': [], 'states': [], 'weights': [], 'iteration': [], 'bins': [] }
            keys = []
            try:
                current['auxdata'] = {}
                for key in list(self.current['auxdata'].keys()):
                    current['auxdata'][key] = []
                    key = []
            except:
                pass
            for iter in reversed(list(range(1, self.iteration+1))):
                iter_group = self.data_reader.get_iter_group(iter)
                particles = self.data_reader.data_manager.get_iter_summary(int(iter))['n_particles']
                current['pcoord'].append(iter_group['pcoord'][seg_id, :, :])
                current['states'].append(self.assign['trajlabels'][iter-1, seg_id,:])
                current['bins'].append(self.assign['assignments'][iter-1, seg_id,:])
                current['seg_id'].append(seg_id)
                current['weights'].append(iter_group['seg_index']['weight'][seg_id])
                current['iteration'].append(iter)
                try:
                    for key in keys:
                        current['auxdata'][key].append(iter_group['auxdata'][key][seg_id])
                except:
                    pass
                seg_id = iter_group['seg_index']['parent_id'][seg_id]
                if seg_id < 0:
                    # Necessary for steady state simulations.  This means they started in that iteration.
                    break
                pi.progress += 1
        current['seg_id'] = list(reversed(current['seg_id']))
        current['iteration'] = list(reversed(current['iteration']))
        current['states'] = np.concatenate(np.array(list(reversed(current['states']))))
        current['bins'] = np.concatenate(np.array(list(reversed(current['bins']))))
        current['weights'] = np.array(list(reversed(current['weights'])))
        current['pcoord'] = np.concatenate(np.array(list(reversed(current['pcoord']))))
        try:
            for key in keys():
                current['auxdata'][key] = np.concatenate(np.array(list(reversed(current['auxdata'][key]))))
        except:
            pass
        current['state_labels'] = self.assign['state_labels']
        for i in ['pcoord', 'states', 'bins', 'weights']:
            current[i] = WIPIDataset(raw=current[i], key=i)
            if i == 'weights':
                current[i].plotter = Plotter(np.log10(current[i].raw), str('log10 of ' + str(i)), iteration=current[i].raw.shape[0], interface=self.interface)
            else:
                current[i].plotter = Plotter(current[i].raw, i, iteration=current[i].raw.shape[0], interface=self.interface)
            current[i].plot = current[i].plotter.plot
        return WIPIDataset(raw=current, key=seg_id)