Extracting 3D data and position values

Hi all, I'm using yt to extract 3D data from a Ramses simulation cube. Specifically, I want to extract ("gas", "velocity_x") values from a smaller region within the cube. After this, I need to generate a set of (x,y,z) coordinates that correspond to the positions of those data values. So far I have tried doing this with ds.r and meshgrid (my code is given below). However, I'm uncertain if the ordering of my x,y,z coordinates matches the ordering of the data values? Is this the best method to do this? I question whether I should be using covering_grid instead, but am struggling to figure out how to use covering_grid to select out data for only a specific region within the simulation (the sim seems to extend between -300 to 300kpc in all dimensions, but I only want data between -15 to 15 kpc in all dimensions) Thanks for any help! Here is my code: sl = ds.r[(285, 'kpc'):(315, 'kpc'):400j, (285, 'kpc'):(315, 'kpc'):400j, (285, 'kpc'):(315, 'kpc'):400j)] x_ = np.linspace(-15,15,400) y_ = np.linspace(-15,15,400) z_ = np.linspace(-15,15,400) x,y,z = np.meshgrid(x_,y_,z_, indexing= 'ij')

Hi! Good question. The x values will indeed by the first dimension, then y, then z. The key thing to keep in mind is that the cell values are specified at the cell centers, so you'll need to offset the left edge and right edge by half a dx. You can either access the 'x' 'y' and 'z' fields on the object (sl in your case) or you can generate new fields like this: x = np.mgrid[sl.LeftEdge[0] + sl.dds[0]/2.0 : sl.RightEdge[0] - sl.dds[0]/2.0: N * 1j] etc. Your best bet might be to access the fields ("index", "x") , ("index", "y") and ("index", "z") though. Let me know if that helps! -Matt On Wed, Dec 15, 2021 at 4:21 PM hdav7324--- via yt-users <yt-users@python.org> wrote:
Hi all,
I'm using yt to extract 3D data from a Ramses simulation cube. Specifically, I want to extract ("gas", "velocity_x") values from a smaller region within the cube. After this, I need to generate a set of (x,y,z) coordinates that correspond to the positions of those data values. So far I have tried doing this with ds.r and meshgrid (my code is given below). However, I'm uncertain if the ordering of my x,y,z coordinates matches the ordering of the data values? Is this the best method to do this? I question whether I should be using covering_grid instead, but am struggling to figure out how to use covering_grid to select out data for only a specific region within the simulation (the sim seems to extend between -300 to 300kpc in all dimensions, but I only want data between -15 to 15 kpc in all dimensions)
Thanks for any help!
Here is my code: sl = ds.r[(285, 'kpc'):(315, 'kpc'):400j, (285, 'kpc'):(315, 'kpc'):400j, (285, 'kpc'):(315, 'kpc'):400j)]
x_ = np.linspace(-15,15,400) y_ = np.linspace(-15,15,400) z_ = np.linspace(-15,15,400)
x,y,z = np.meshgrid(x_,y_,z_, indexing= 'ij') _______________________________________________ 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: matthewturk@gmail.com
participants (2)
-
hdav7324@uni.sydney.edu.au
-
Matthew Turk