Struggling to use LinePlot with GADGET-4 data
Hi all, I am very new to YT and I have been trying to create a line plot for my GADGET-4 simulation output, but I keep running into a problem. I try to do a similar plot as that found here: https://yt-project.org/doc/cookbook/simple_plots.html#simple-1d-line-plottin.... I want to be able to 'draw' an arbitrary line and see how a quantity such as density changes along that line. My script and an example snapshot is linked below with the error I am getting following after. The code: http://paste.yt-project.org/show/392/ The snapshot and code: http://use.yt/upload/6dd0e0b8 YT version: 4.0.4 I keep getting this traceback error: " Traceback (most recent call last): File ~/PATH/yt_analysis.py:85 in <module> plot = yt.LinePlot(ds, "Density", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), 1000) File ~/.local/lib/python3.9/site-packages/yt/visualization/line_plot.py:174 in __init__ self._setup_plots() File ~/.local/lib/python3.9/site-packages/yt/visualization/line_plot.py:308 in _setup_plots x, y = self.ds.coordinates.pixelize_line( File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:284 in pixelize_line arc_length, plot_values = _sample_ray(ray, npoints, field) File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:47 in _sample_ray ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:47 in <listcomp> ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:258 in __getitem__ self.get_data(f) File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:211 in get_data self._generate_fields(fields_to_generate) File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:232 in _generate_fields fd = self._generate_field(field) File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:299 in _generate_field tr = self._generate_fluid_field(field) File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:318 in _generate_fluid_field rv = finfo(gen_obj) File ~/.local/lib/python3.9/site-packages/yt/fields/derived_field.py:294 in __call__ dd = self._function(self, data) File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/coordinate_handler.py:24 in _coords rv = data.ds.arr(data.fcoords[..., axi].copy(), units) File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:418 in fcoords return self._current_chunk.fcoords File ~/.local/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:255 in cached_func tr = self._accumulate_values(n[1:]) File ~/.local/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:292 in _accumulate_values arrs.append(f(self.dobj)) File ~/.local/lib/python3.9/site-packages/yt/data_objects/index_subobjects/particle_container.py:17 in _func_non_indexed raise YTNonIndexedDataContainer(self) YTNonIndexedDataContainer: The data container (<class 'yt.data_objects.index_subobjects.particle_container.ParticleContainer'>) is an unindexed type. Operations such as ires, icoords, fcoords and fwidth will not work on it." Help with this would be highly appreciated. Kind regards, Christian
Hi Christian, If I am following Slack right, I think this got resolved -- or is there more we should do to help out? On Tue, Jul 26, 2022 at 7:55 AM Christian van der Merwe via yt-users < yt-users@python.org> wrote:
Hi all,
I am very new to YT and I have been trying to create a line plot for my GADGET-4 simulation output, but I keep running into a problem.
I try to do a similar plot as that found here: https://yt-project.org/doc/cookbook/simple_plots.html#simple-1d-line-plottin.... I want to be able to 'draw' an arbitrary line and see how a quantity such as density changes along that line. My script and an example snapshot is linked below with the error I am getting following after.
The code: http://paste.yt-project.org/show/392/ The snapshot and code: http://use.yt/upload/6dd0e0b8 YT version: 4.0.4
I keep getting this traceback error:
" Traceback (most recent call last):
File ~/PATH/yt_analysis.py:85 in <module> plot = yt.LinePlot(ds, "Density", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), 1000)
File ~/.local/lib/python3.9/site-packages/yt/visualization/line_plot.py:174 in __init__ self._setup_plots()
File ~/.local/lib/python3.9/site-packages/yt/visualization/line_plot.py:308 in _setup_plots x, y = self.ds.coordinates.pixelize_line(
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:284 in pixelize_line arc_length, plot_values = _sample_ray(ray, npoints, field)
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:47 in _sample_ray ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:47 in <listcomp> ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T
File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:258 in __getitem__ self.get_data(f)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:211 in get_data self._generate_fields(fields_to_generate)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:232 in _generate_fields fd = self._generate_field(field)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:299 in _generate_field tr = self._generate_fluid_field(field)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:318 in _generate_fluid_field rv = finfo(gen_obj)
File ~/.local/lib/python3.9/site-packages/yt/fields/derived_field.py:294 in __call__ dd = self._function(self, data)
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/coordinate_handler.py:24 in _coords rv = data.ds.arr(data.fcoords[..., axi].copy(), units)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:418 in fcoords return self._current_chunk.fcoords
File ~/.local/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:255 in cached_func tr = self._accumulate_values(n[1:])
File ~/.local/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:292 in _accumulate_values arrs.append(f(self.dobj))
File ~/.local/lib/python3.9/site-packages/yt/data_objects/index_subobjects/particle_container.py:17 in _func_non_indexed raise YTNonIndexedDataContainer(self)
YTNonIndexedDataContainer: The data container (<class 'yt.data_objects.index_subobjects.particle_container.ParticleContainer'>) is an unindexed type. Operations such as ires, icoords, fcoords and fwidth will not work on it."
Help with this would be highly appreciated.
Kind regards, Christian _______________________________________________ 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
Christian, While LinePlot doesn't seem to do what you're trying to, since it doesn't work for SPH datasets, you can try this alternative way to determine properties along a line through your simulation's volume. (Note to other devs, this might be a good way to fix the problem with LinePlot not working on SPH datasets, since the ray object does work with SPH datasets). Replace your final line's call to `LinePlot` with the lines below for creating a ray and then manually plotting the fields along that ray ('t' field is just a parametric length along the ray). Here are some notes on ray objects: https://yt-project.org/docs/dev/analyzing/objects.html?highlight=ortho_ray#m... https://yt-project.org/docs/dev/faq/index.html#why-are-the-values-in-my-ray-... import yt import matplotlib.pyplot as plt import numpy as np #Load the dataset and create the ray ds = yt.load(YOUR_DATASET) ray = ds.ray((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)) #start and end coords of line through data #Order the density field along its trajectory using "t" field (parametric length) ray_sort = np.argsort(ray["t"]) density = ray["gas", "density"][ray_sort] t = ray["t"][ray_sort] #Plot density vs "t"--the length along the field plt.plot(t, density) plt.yscale('log') plt.savefig('line_plot.png') On Mon, Aug 8, 2022 at 10:58 AM Matthew Turk <matthewturk@gmail.com> wrote:
Hi Christian,
If I am following Slack right, I think this got resolved -- or is there more we should do to help out?
On Tue, Jul 26, 2022 at 7:55 AM Christian van der Merwe via yt-users < yt-users@python.org> wrote:
Hi all,
I am very new to YT and I have been trying to create a line plot for my GADGET-4 simulation output, but I keep running into a problem.
I try to do a similar plot as that found here: https://yt-project.org/doc/cookbook/simple_plots.html#simple-1d-line-plottin.... I want to be able to 'draw' an arbitrary line and see how a quantity such as density changes along that line. My script and an example snapshot is linked below with the error I am getting following after.
The code: http://paste.yt-project.org/show/392/ The snapshot and code: http://use.yt/upload/6dd0e0b8 YT version: 4.0.4
I keep getting this traceback error:
" Traceback (most recent call last):
File ~/PATH/yt_analysis.py:85 in <module> plot = yt.LinePlot(ds, "Density", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), 1000)
File ~/.local/lib/python3.9/site-packages/yt/visualization/line_plot.py:174 in __init__ self._setup_plots()
File ~/.local/lib/python3.9/site-packages/yt/visualization/line_plot.py:308 in _setup_plots x, y = self.ds.coordinates.pixelize_line(
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:284 in pixelize_line arc_length, plot_values = _sample_ray(ray, npoints, field)
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:47 in _sample_ray ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/cartesian_coordinates.py:47 in <listcomp> ray_coordinates = uvstack([ray[("index", d)] for d in "xyz"]).T
File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:258 in __getitem__ self.get_data(f)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:211 in get_data self._generate_fields(fields_to_generate)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:232 in _generate_fields fd = self._generate_field(field)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:299 in _generate_field tr = self._generate_fluid_field(field)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/data_containers.py:318 in _generate_fluid_field rv = finfo(gen_obj)
File ~/.local/lib/python3.9/site-packages/yt/fields/derived_field.py:294 in __call__ dd = self._function(self, data)
File ~/.local/lib/python3.9/site-packages/yt/geometry/coordinates/coordinate_handler.py:24 in _coords rv = data.ds.arr(data.fcoords[..., axi].copy(), units)
File ~/.local/lib/python3.9/site-packages/yt/data_objects/selection_objects/data_selection_objects.py:418 in fcoords return self._current_chunk.fcoords
File ~/.local/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:255 in cached_func tr = self._accumulate_values(n[1:])
File ~/.local/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:292 in _accumulate_values arrs.append(f(self.dobj))
File ~/.local/lib/python3.9/site-packages/yt/data_objects/index_subobjects/particle_container.py:17 in _func_non_indexed raise YTNonIndexedDataContainer(self)
YTNonIndexedDataContainer: The data container (<class 'yt.data_objects.index_subobjects.particle_container.ParticleContainer'>) is an unindexed type. Operations such as ires, icoords, fcoords and fwidth will not work on it."
Help with this would be highly appreciated.
Kind regards, Christian _______________________________________________ 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
_______________________________________________ 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: chummels@gmail.com
-- Cameron Hummels Computational Astrophysicist California Institute of Technology http://chummels.org
participants (3)
-
Cameron Hummels
-
christianvdm@saao.ac.za
-
Matthew Turk