Exemplo n.º 1
0
    def load(self, file_name):
        """ Loads a snapshot storage

        Args:
            file_name: Can be either a directory with numbered .csv files, or a
            numpy pickle (.pkl)
        """
        if not self.in_memory:
            raise IOError("Can't load from file because in-memory storage is disabled.")

        if not os.path.exists(file_name):
            raise IOError("Specified file does not exist.")

        if file_name.endswith(".pkl"):
            self._snapshots = np.load(file_name)
        else:
            self._snapshots = util.load_snapshots(file_name)
        
        self.snapshot_shape = self._snapshots.shape[1:]
        self.max_snapshots = self._snapshots.shape[0]
        self._reserved_length = self.max_snapshots
        self._current_index = self.max_snapshots
        self.snapshot_count = self.max_snapshots
Exemplo n.º 2
0
    parser = argparse.ArgumentParser(description="Render nbody simulation results.")
    parser.add_argument("directory", help="directory with all of the simulation files in a .csv format, or a pickled snapshot file")
    parser.add_argument("-c", "--color", type=str, help="specifies in what color to draw the bodies. If not set all bodies are drawn in different colors", choices=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'])
    parser.add_argument("-s", "--speed", metavar="fps", type=int, default=20)
    parser.add_argument("-t", "--timesteps", metavar="num", type=int, default=1, help="displays previous body states up to the amount specified. Set to 0 to display all states")
    parser.add_argument("-f", "--fade", action="store_true", help="specifies whether bodies from previous time steps should fade")
    parser.add_argument("-o", "--out", metavar="path", type=str, help="if specified will output video to file")
    parser.add_argument("-v", "--verbose", action="store_true", help="prints the current frame number to the terminal while drawing")
    
    args = parser.parse_args()
    
    bodies = None
    if args.directory.endswith(".pkl"):
        bodies = cPickle.load(args.directory)
    else:
        bodies = util.load_snapshots(args.directory)

    color = cm.get_cmap()
    if args.color:
        color = args.color

    verbose_level = 1
    if args.verbose:
        verbose_level = 2

    body_renderer = SnapshotRenderer(bodies, line_style="-", marker_style=".", 
                                     history_length=args.timesteps, fade=args.fade, 
                                     color=color, fps=args.speed, verbose=verbose_level)
    body_renderer.run(out_file=args.out)

    '''