def run(no=None): '''Run a simulation. If no argument is given, run the current one; otherwise queries the buffer for the given simulation number. If the simulation has not been setup, does it before running. Optional arguments: no : Simulation number ''' #gets the correct simulation object from the buffer try: if no is None: sim = SimBuffer.get_current_sim() else: no = int(no) sim = SimBuffer.get_sim_no(no) except BufferError as e: handle(e) #setup the simulation if not sim.setup: sim.SetupSimulation() SimBuffer.load_live_snapshot(sim) while sim.t < sim.tend and sim.Nsteps < sim.Nstepsmax: #TODO: maybe some of these operations could be done in another thread, so that the computation is #not slowed down when compared to the stand-alone c++ executable #But need to think carefully, because of the GIL... (??) snap_list = sim.InteractiveRun() for snap in snap_list: SimBuffer.add_snapshot(snap, sim) SimBuffer.load_live_snapshot(sim) update("live")
def plot(x, y, type="default", snap="current", sim="current", overplot=False, autoscale=False, xunit="default", yunit="default", xaxis="linear", yaxis="linear", **kwargs): '''Plot particle data as a scatter plot. Creates a new plotting window if one does not already exist. Required arguments: x : Quantity on the x-axis. Must be a string. y : Quantity on the y-axis. Must be a string. Optional arguments: type : The type of the particles to plot (e.g. 'star' or 'sph'). snap : Number of the snapshot to plot. Defaults to 'current'. sim : Number of the simulation to plot. Defaults to 'current'. overplot : If True, overplots on the previous existing plot rather than deleting it. Defaults to False. autoscale : If True, the limits of the plot are set automatically. Can also be set to 'x' or 'y' to specify that only one of the axis has to use autoscaling. If False (default), autoscaling is not used. On an axis that does not have autoscaling turned on, global limits are used if defined for the plotted quantity. xunit : Specify the unit to use for the plotting for the quantity on the x-axis. yunit : Specify the unit to use for the plotting for the quantity on the y-axis. **kwargs : Extra keyword arguments will be passed to matplotlib. ''' simno = get_sim_no(sim) overplot=to_bool(overplot) # If we are plotting all particle species, call plot in turn if type=="all": sim = SimBuffer.get_sim_no(simno) snapobject = SimBuffer.get_snapshot_extended(sim, snap) nspecies = snapobject.GetNTypes() for ispecies in range(nspecies): plot(x,y,snapobject.GetSpecies(ispecies),snap,simno, (overplot or ispecies>0),autoscale,xunit,yunit, xaxis,yaxis,**kwargs) return command = Commands.ParticlePlotCommand(x, y, type, snap, simno, overplot, autoscale, xunit, yunit, xaxis, yaxis, **kwargs) data = command.prepareData(Singletons.globallimits) Singletons.queue.put([command, data]) sleep(0.001)
def snaps(simno): '''For the given simulation number, print a list of all the snapshots Required argument: simno : Simulation number from which to print the snapshot list. ''' simno = int(simno) sim = SimBuffer.get_sim_no(simno) print "The run_id of the requested simulation is " + sim.simparams.stringparams["run_id"] print "These are the snapshots that we know about for this simulation:" for num, snap in enumerate(sim.snapshots): #TODO: snap.t is set correctly only the first time that the snapshot is read from the disc, should be fixed print str(num) + ' ' + snap.filename + " " + str(snap.t) try: live = None live = sim.live except AttributeError: pass if live is not None: print "In addition, there is a live snapshot in memory, at time " + str(live.t)
def get_data(quantity, snap="current",type="default",sim="current",unit="default" ): '''Returns the array with the data for the given quantity. The data is returned scaled to the specified unit Required argument: quantity :The quantity required. Must be a string Optional arguments: type :The type of the particles (e.g. 'star') snap :Number of the snapshot. Defaults to 'current' sim :Number of the simulation. Defaults to 'current' unit :Specifies the unit to use to return the data ''' simno = get_sim_no(sim) sim = SimBuffer.get_sim_no(simno) snapobject = SimBuffer.get_snapshot_extended(sim, snap) nspecies = snapobject.GetNTypes() if type=="all": raise Exception("You requested all particle types to get_data, but we can return only one array!") fetcher=UserQuantity(quantity) unitinfo,data,scaling,label=fetcher.fetch(type=type,snap=snapobject,unit=unit) return data*scaling