def anim(sername, simname): sim = Simulation(sername, simname) # https://github.com/matplotlib/matplotlib/issues/16965 anim_fn = os.path.join(CACHEDIR, "graphics", sername, simname, f"{simname}.gif") os.makedirs(os.path.dirname(anim_fn), exist_ok=True) base_fn = sim.data_fn() if flask.request.values.get("maxind"): max_data_index = int(flask.request.values.get("maxind")) else: max_data_index = sim.status()['dataFileCounter'] datafiles = [f"{base_fn}.{ind}" for ind in range(max_data_index)] if (flask.request.values.get("nocache") or need_to_regenerate(anim_fn, datafiles)): ani = create_animation(sername, simname, maxframes=max_data_index, samplesize=3000) ani.save(anim_fn, writer="imagemagick") # ani.save(anim_fn, writer="ffmpeg") if flask.request.values.get("format") == "webm": clip = mp.VideoFileClip(anim_fn) webm_fn = f"{anim_fn}.webm" clip.write_videofile(webm_fn) with open(webm_fn, "rb") as webm_f: return Response(webm_f.read(), mimetype="video/webm") else: with open(anim_fn, "rb") as anim_f: return Response(anim_f.read(), mimetype="image/gif")
def showdataplot_page(sername, simname, ind): """A page that contains a .data file's plot.""" sim = Simulation(sername, simname) simstatus = sim.status() max_data_index = simstatus['dataFileCounter'] - 1 data_df, dimensions, headline = read_data_file(sim.data_fn(ind)) num, time, xmin, ymin, zmin, xmax, ymax, zmax = headline if dimensions == 2: return render_template("results/data2d_plot.html", sername=sername, simname=simname, ind=ind, time=time, dt=simstatus['timeStep'] * simstatus['dataFileSaveCount'], lines=data_df, mdi=max_data_index) elif dimensions == 3: return render_template("results/data3d_plot.html", sername=sername, simname=simname, ind=ind, time=time, dt=simstatus['timeStep'] * simstatus['dataFileSaveCount'], lines=data_df, mdi=max_data_index) else: raise ValueError("Number of dimensions should be 2 or 3.")
def showdatafile(sername, simname, ind): sim = Simulation(sername, simname) simstatus = sim.status() max_data_index = simstatus['dataFileCounter'] - 1 max_fstat_index = simstatus['fStatFileCounter'] - 1 ind = int(ind) if ind > max_data_index: return f"The index {ind} is greater than the maximum index {max_data_index} so far", 400 try: data_df, dimensions, headline = read_data_file(sim.data_fn(ind)) except FileNotFoundError: return f"{sim.data_fn(ind)} not found" num, time, xmin, ymin, zmin, xmax, ymax, zmax = headline if dimensions == 2: return render_template("results/data2d.html", sername=sername, simname=simname, ind=ind, time=time, dt=simstatus['timeStep'] * simstatus['dataFileSaveCount'], lines=data_df, mdi=max_data_index) if dimensions == 3: return render_template("results/data3d.html", sername=sername, simname=simname, ind=ind, time=time, dt=simstatus['timeStep'] * simstatus['dataFileSaveCount'], lines=data_df, mdi=max_data_index)
def simulation_view(sername, simname): """Serve a page showing some summary statistics of this simulation, as well as links to more details such as individual files, and logs. """ sim = Simulation(sername, simname) if not os.path.isdir(sim.simdir()): raise SimulationNotFoundError(sername, simname) simstatus = sim.status() print(simstatus) max_data_index = simstatus['dataFileCounter'] - 1 print(max_data_index) max_fstat_index = simstatus['fStatFileCounter'] - 1 return render_template('simulation.html', sername=sername, simname=simname, simstatus=simstatus, dt=simstatus['timeStep'] * simstatus['dataFileSaveCount'], mdi=max_data_index, mfi=max_fstat_index, ind=0)