Creating a regular grid using SPH kernel
Hello, I apologize in advance for any ignorant questions. I am new to YT and am really struggling with this problem. I am trying to use YT (version 3.5.1) to grid my SPH simulation box to a regular grid with 1024^3 cells. The box itself has sides of 300 Mpc/h and the data consists of pre-loaded numpy arrays for positions (in Mpc/h), mass (in 10^10 Msun/h), density (in 10^10 Msun/h /(Mpc/h)^3 ), particle smoothing length (in Mpc/h) and an optical depth tau. How can I properly load this into a YT dataset and how can I then get YT to create the regular grid for the optical depth tau or the density with an SPH kernel, such as Wendland2? Also, is it possible to output the grids as an array that could then be saved to file or used with other scripts? To hopefully clarify what I am trying to do, below you can find the YT part of my current script. Thank you in advance for any help you could give. Robin Kooistra
import numpy as np import yt .................... density, m, tau, smooth and pos are numpy arrays .................... data = dict(particle_density = density, particle_mass = m, particle_tau = tau, particle_smoothing_length = smooth, particle_position_x = pos[:,0], particle_position_y = pos[:,1], particle_position_z = pos[:,2] )
ds = yt.load_particles(data,bbox=n.array([[0.,300.],[0.,300.],[0.,300.]]))
yt.fields.particle_fields.add_volume_weighted_smoothed_field(ptype='io', coord_name='particle_position', mass_name='particle_mass', smoothing_length_name='particle_smoothing_length', density_name='particle_density', smoothed_field='particle_tau',registry=ds.field_info, nneighbors=58,kernel_name='wendland2')
ag = ds.arbitrary_grid(ds.domain_left_edge,ds.domain_right_edge,dims=[1024,1024,1024]) mesh = ag['deposit','io_wendland2_smoothed_particle_tau']
Hi Robin,
I think you're going to have a lot more luck using the still in-development
yt-4.0 branch, where we have done some major changes to improve support for
SPH data.
For example, here is a pull request from Bili Dong that makes the sort of
workflow you're trying to do much more straightforward:
https://github.com/yt-project/yt/pull/2186
And you can see some documentation we've written on transitioning from
yt-3.0 to yt-4.0:
https://github.com/yt-project/yt/blob/yt-4.0/doc/source/yt4differences.rst
There's also the talk I gave with Meagan Lang at SciPy 2017:
https://www.youtube.com/watch?v=pkZgQIGac6I
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjn5pK5uMjhAhVGs6wKHVc_DecQtwIwAHoECDEQAQ&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpkZgQIGac6I&usg=AOvVaw3JFLgbI7iX7GOOQ55FT5V_
To install, you'll need to create a virtualenv (or conda env or whatever)
with numpy and cython installed, clone the yt repo, check out the yt-4.0
branch, and use the pip associated with the environment to install with
"pip install -e .".
Sorry this doesn't work out of the box with the current stable version of
yt. We're very much aware that the current support for SPH data could be
massively improved and are eager to get the 4.0 release of yt out the door.
-Nathan
On Thu, Apr 11, 2019 at 9:12 AM
Hello,
I apologize in advance for any ignorant questions. I am new to YT and am really struggling with this problem.
I am trying to use YT (version 3.5.1) to grid my SPH simulation box to a regular grid with 1024^3 cells. The box itself has sides of 300 Mpc/h and the data consists of pre-loaded numpy arrays for positions (in Mpc/h), mass (in 10^10 Msun/h), density (in 10^10 Msun/h /(Mpc/h)^3 ), particle smoothing length (in Mpc/h) and an optical depth tau. How can I properly load this into a YT dataset and how can I then get YT to create the regular grid for the optical depth tau or the density with an SPH kernel, such as Wendland2? Also, is it possible to output the grids as an array that could then be saved to file or used with other scripts?
To hopefully clarify what I am trying to do, below you can find the YT part of my current script.
Thank you in advance for any help you could give. Robin Kooistra
import numpy as np import yt .................... density, m, tau, smooth and pos are numpy arrays .................... data = dict(particle_density = density, particle_mass = m, particle_tau = tau, particle_smoothing_length = smooth, particle_position_x = pos[:,0], particle_position_y = pos[:,1], particle_position_z = pos[:,2] )
ds = yt.load_particles(data,bbox=n.array([[0.,300.],[0.,300.],[0.,300.]]))
yt.fields.particle_fields.add_volume_weighted_smoothed_field(ptype='io', coord_name='particle_position', mass_name='particle_mass', smoothing_length_name='particle_smoothing_length', density_name='particle_density', smoothed_field='particle_tau',registry=ds.field_info, nneighbors=58,kernel_name='wendland2')
ag = ds.arbitrary_grid(ds.domain_left_edge,ds.domain_right_edge,dims=[1024,1024,1024]) mesh = ag['deposit','io_wendland2_smoothed_particle_tau']
yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
For reference, I've assembled detailed instructions on how to install the
yt-4 branch here:
https://nbviewer.jupyter.org/url/trident-project.org/notebooks/trident_demes...
It also includes instructions at the end for installing the relevant
version of Trident, a synthetic observation package, but that may be
irrelevant for your analysis so you can just ignore that.
Good luck!
Cameron
On Thu, Apr 11, 2019 at 9:20 AM Nathan Goldbaum
Hi Robin,
I think you're going to have a lot more luck using the still in-development yt-4.0 branch, where we have done some major changes to improve support for SPH data.
For example, here is a pull request from Bili Dong that makes the sort of workflow you're trying to do much more straightforward:
https://github.com/yt-project/yt/pull/2186
And you can see some documentation we've written on transitioning from yt-3.0 to yt-4.0:
https://github.com/yt-project/yt/blob/yt-4.0/doc/source/yt4differences.rst
There's also the talk I gave with Meagan Lang at SciPy 2017: https://www.youtube.com/watch?v=pkZgQIGac6I https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjn5pK5uMjhAhVGs6wKHVc_DecQtwIwAHoECDEQAQ&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpkZgQIGac6I&usg=AOvVaw3JFLgbI7iX7GOOQ55FT5V_
To install, you'll need to create a virtualenv (or conda env or whatever) with numpy and cython installed, clone the yt repo, check out the yt-4.0 branch, and use the pip associated with the environment to install with "pip install -e .".
Sorry this doesn't work out of the box with the current stable version of yt. We're very much aware that the current support for SPH data could be massively improved and are eager to get the 4.0 release of yt out the door.
-Nathan
On Thu, Apr 11, 2019 at 9:12 AM
wrote: Hello,
I apologize in advance for any ignorant questions. I am new to YT and am really struggling with this problem.
I am trying to use YT (version 3.5.1) to grid my SPH simulation box to a regular grid with 1024^3 cells. The box itself has sides of 300 Mpc/h and the data consists of pre-loaded numpy arrays for positions (in Mpc/h), mass (in 10^10 Msun/h), density (in 10^10 Msun/h /(Mpc/h)^3 ), particle smoothing length (in Mpc/h) and an optical depth tau. How can I properly load this into a YT dataset and how can I then get YT to create the regular grid for the optical depth tau or the density with an SPH kernel, such as Wendland2? Also, is it possible to output the grids as an array that could then be saved to file or used with other scripts?
To hopefully clarify what I am trying to do, below you can find the YT part of my current script.
Thank you in advance for any help you could give. Robin Kooistra
import numpy as np import yt .................... density, m, tau, smooth and pos are numpy arrays .................... data = dict(particle_density = density, particle_mass = m, particle_tau = tau, particle_smoothing_length = smooth, particle_position_x = pos[:,0], particle_position_y = pos[:,1], particle_position_z = pos[:,2] )
ds = yt.load_particles(data,bbox=n.array([[0.,300.],[0.,300.],[0.,300.]]))
yt.fields.particle_fields.add_volume_weighted_smoothed_field(ptype='io', coord_name='particle_position', mass_name='particle_mass', smoothing_length_name='particle_smoothing_length', density_name='particle_density', smoothed_field='particle_tau',registry=ds.field_info, nneighbors=58,kernel_name='wendland2')
ag =
ds.arbitrary_grid(ds.domain_left_edge,ds.domain_right_edge,dims=[1024,1024,1024])
mesh = ag['deposit','io_wendland2_smoothed_particle_tau']
yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
-- Cameron Hummels NSF Postdoctoral Fellow Department of Astronomy California Institute of Technology http://chummels.org
Thank you both, this helped a lot. So I switched to YT 4.0.dev0 and I think I found how to get it to run with the pixelize_sph_kernel_arbitrary_grid function (following the example in https://ashkelly.github.io/gsoc-blog//2018-06-01-getting-started/). However, when I compare the values in the gridded volume to that of the SPH particles directly (e.g. the temperature or density), I find that there seems to be an increase in the gridded version. For example, the highest temperature particle in the box would have a temperature of ~10^8 K, but when this field is gridded I get many grid cells with temperatures of ~10^9 K or even ~10^10 K. Is that normal or is the normalization not implemented properly? Also, is there a way to set how many nearest neighbors are used for the smoothing? Best regards, Robin
On Sun, Apr 14, 2019 at 10:42 PM
Thank you both, this helped a lot. So I switched to YT 4.0.dev0 and I think I found how to get it to run with the pixelize_sph_kernel_arbitrary_grid function (following the example in https://ashkelly.github.io/gsoc-blog//2018-06-01-getting-started/).
The main user-facing API in yt is ds.arbitrary_grid, you might want to use that instead. The function you are using is a low-level function that is called by the arbitrary_grid data object and is not intended to be used directly outside of yt’s internals.
However, when I compare the values in the gridded volume to that of the SPH particles directly (e.g. the temperature or density), I find that there seems to be an increase in the gridded version. For example, the highest temperature particle in the box would have a temperature of ~10^8 K, but when this field is gridded I get many grid cells with temperatures of ~10^9 K or even ~10^10 K. Is that normal or is the normalization not implemented properly?
Hard to say without an example to look at. If you can make a runnable example demonstrating this behavior using either fake in-memory data or a public dataset (e.g. the ones on yt-project.org/data) that would make this discussion more concrete. It might also make sense to continue this discussion in a github issue in yt’s repository: github.com/yt-project/yt/issues/new You might also try using “gather” smoothing: ds.sph_smoothing_style = “gather” Note that you will likely need to use ds.arbitrary_grid rather than the low-level function you are using for this to work correctly.
Also, is there a way to set how many nearest neighbors are used for the smoothing?
Yup: ds.num_neighbors = 12
Best regards, Robin _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
participants (3)
-
Cameron Hummels
-
Nathan Goldbaum
-
robin.kooistra@ipmu.jp