Dear all, I am a new yt user, working with idefix data. I was wondering if there is an easy way to do time averages in yt. For example, if I have two vtk files data.0.vtk and data.1.vtk that I can easily load with ds0=yt.load("data.0.vtk") and ds1=yt.load("data.1.vtk"). Is there an easy way to create a datafile dsmean where all fields are means of the fields in ds1 and ds2 ? Sorry if this question has already been asked, or if it's answered in the documentation, but I didn't see it. Thanks in advance, Best wishes, Thomas
Hi Thomas, I don’t know that there are builtin functionalities in yt to perform time averages, but you may be able to achieve what you need in a relatively straightforward manner. Here’s a short demonstration of two different ways you can get a time average either from raw data (taking advantage of the fact that idefix uses a time-fixed grid) or from yt fixed-resolution buffers (frb), i.e., images. import yt # step 0: create a time series (DatasetSeries object) ts = yt.load("tmp/vd/*.vtk", inifile="idefix.ini") ds0 = ts[0] time_span = ts[-1].current_time - ts[0].current_time field = ("gas", "density") # method 1: average on-disk data, taking advantage of the fact that grid is fixed buff = ds0.all_data()[field].copy() for ds in ts[1:]: buff += ds.all_data()[field] buff /= len(ts) cell_edges_shape = ds0.parameters["shape"] cell_centers_shape = tuple(max(x-1, 1) for x in cell_edges_shape) buff.shape = cell_centers_shape # ... custom viz, or reload into yt as an in-memory dataset ... # method 2 average images (robust to grid changes and ready to visualize) # warning: image may contain NaNs if plotting box is larger than simulation box p0 = yt.ProjectionPlot(ds0, (0,0,1), field) img = p0.frb[field].copy() for ds in ts[1:]: img += yt.ProjectionPlot(ds, (0,0,1), field).frb[field] img /= len(ts) Don’t hesitate to reach out to me on https://github.com/neutrinoceros/yt_idefix/ if you find anything not working as you’d expect, and have a nice one ! Clément
On 16 Apr 2024, at 18:44, taj30@cam.ac.uk wrote:
Dear all,
I am a new yt user, working with idefix data. I was wondering if there is an easy way to do time averages in yt. For example, if I have two vtk files data.0.vtk and data.1.vtk that I can easily load with ds0=yt.load("data.0.vtk") and ds1=yt.load("data.1.vtk"). Is there an easy way to create a datafile dsmean where all fields are means of the fields in ds1 and ds2 ? Sorry if this question has already been asked, or if it's answered in the documentation, but I didn't see it.
Thanks in advance,
Best wishes,
Thomas _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: clement.robert@protonmail.com
participants (2)
-
clement.robert@protonmail.com -
taj30@cam.ac.uk