yt-project / yt

Main yt repository
http://yt-project.org
Other
468 stars 277 forks source link

Create derived field which contains some field values averaged along one axis #2112

Open jisuoqing opened 5 years ago

jisuoqing commented 5 years ago

It would be nice to obtain some averaged field along one axis only via a derived field.

Say, if the simulation data has field field[x,y,z], then create the new derived field of the average along z axis: new_field = np.average(field, axis=2)[...,None].

This is particularly useful for computing fluctuations relative some mean background in plane-parallel or non-axisymmetric components, etc.

neutrinoceros commented 4 years ago

This is the kind of stuff that I really miss right now in yt, I'd be interested in making this a thing. Unfortunately this is a lot less trivial than calling np.average but I think the machinery is already present in yt.ProjectionPlot. We could build a ds.add_average_fields() method by imitating the logic in ds.add_gradient_fields(). Ideally the new method would also accept an arbitrary axis as an argument (just like ProjectionPlot !), though it may not be necessary for a first version.