extracting data from LinePlot or SlicePlot
Hi yt users, Is any ways to extract data from LinePlot or SlicePlot and put data into numpy array? thanks.
Hello Tseng,
I think if you create a Slice plot in FITS format you can achieve it with
any number of pixels and pixels size (say 4024*4024). This could be the
easy way to do, but it will convert the slice plot (the final image itself)
into a numpy array (FITS format)
For more details, you can visit this link:
https://yt-project.org/doc/visualizing/writing_fits_images.html
I hope this will help you if I get you correctly.
Regards,
-Prateek
On Wed, Oct 16, 2019 at 6:30 AM Tseng, Po-Hsun
Please remove this duplicate post. _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
Both SlicePlot and LinePlot have an "frb" attribute that can do this. "frb" is short for fixed resolution buffer, you can also create a FixedResolutionBuffer object directly if you don't want to go through a plot first. But to answer your question:
import yt ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030') plot = yt.SlicePlot(ds, 'z', ('gas', 'density')) image = plot.frb['gas', 'density'] image ImageArray([[4.91956679e-31, 4.91956679e-31, 4.91956679e-31, ..., 4.91953429e-31, 4.91953429e-31, 4.91953429e-31], [4.91956679e-31, 4.91956679e-31, 4.91956679e-31, ..., 4.91953429e-31, 4.91953429e-31, 4.91953429e-31], [4.91956679e-31, 4.91956679e-31, 4.91956679e-31, ..., 4.91953429e-31, 4.91953429e-31, 4.91953429e-31], ..., [4.91956021e-31, 4.91956021e-31, 4.91956021e-31, ..., 4.91951824e-31, 4.91951824e-31, 4.91951824e-31], [4.91956021e-31, 4.91956021e-31, 4.91956021e-31, ..., 4.91951824e-31, 4.91951824e-31, 4.91951824e-31], [4.91956021e-31, 4.91956021e-31, 4.91956021e-31, ..., 4.91951824e-31, 4.91951824e-31, 4.91951824e-31]]) g/cm**3
You could also do e.g. np.array(image) to get back a plain numpy array without units. You can control the resolution of the image by calling plot.set_buff_size. See the docstrings and documentation for more info. For LinePlot it's similar, except since it supports plotting multiple lines at the same time, it has an attribute called 'lines' that holds a list of LineBuffer objects:
p = yt.LinePlot(ds, ('gas', 'density'), [0, 0, 0], [1, 1, 1], 100) p.lines [
] l = p.lines[0] l['gas', 'density'] YTArray([4.92775113e-31, 4.92775113e-31, 4.92775113e-31, 4.92775113e-31, 4.96987919e-31, 4.96987919e-31, 4.96987919e-31, 4.97023179e-31, 4.97023179e-31, 4.97023179e-31, 4.97023632e-31, 4.97023632e-31, 4.97023632e-31, 4.97024002e-31, 4.97024002e-31, 4.97024002e-31, 4.97024866e-31, 4.97024866e-31, 4.97024866e-31, 4.97026718e-31, 4.97026718e-31, 4.97026718e-31, 4.97029844e-31, 4.97029844e-31, 4.97029844e-31, 4.97886419e-31, 4.97886419e-31, 4.97062801e-31, 5.24180988e-31, 5.04485900e-31, 4.97426883e-31, 4.97034411e-31, 4.97035934e-31, 4.93452054e-31, 5.13882260e-31, 4.97194338e-31, 4.97091025e-31, 4.97140357e-31, 4.97624662e-31, 5.20128850e-31, 3.07842369e-30, 7.38727627e-30, 2.64390638e-29, 2.61299513e-29, 2.20546348e-29, 7.35661360e-29, 9.36134319e-29, 2.11825925e-28, 8.91401066e-28, 5.36897290e-27, 3.77679792e-27, 5.19837507e-28, 1.68498658e-28, 1.22250288e-28, 4.89956291e-29, 5.38828391e-29, 3.30081098e-29, 5.19947043e-30, 6.39781169e-30, 5.51930167e-30, 7.06063703e-31, 4.97779610e-31, 4.97131511e-31, 4.97092136e-31, 4.97065681e-31, 4.97041159e-31, 4.97010013e-31, 4.97056629e-31, 4.97035152e-31, 4.97029844e-31, 4.97013839e-31, 4.96973642e-31, 4.97018283e-31, 4.96881109e-31, 4.96881109e-31, 4.97029721e-31, 4.97029721e-31, 4.97029721e-31, 4.97026718e-31, 4.97026718e-31, 4.97026718e-31, 4.97024907e-31, 4.97024907e-31, 4.97024907e-31, 4.97024084e-31, 4.97024084e-31, 4.97024084e-31, 4.97023591e-31, 4.97023591e-31, 4.97023591e-31, 4.97023220e-31, 4.97023220e-31, 4.97023220e-31, 4.96989811e-31, 4.96989811e-31, 4.96989811e-31, 4.92762688e-31, 4.92762688e-31, 4.92762688e-31, 4.92762688e-31]) g/cm**3
Again, you could do np.array(l['gas', 'density']) if you wanted a plain
numpy array.
Hope that's helpful.
On Wed, Oct 16, 2019 at 1:39 AM Prateek Gupta
Hello Tseng,
I think if you create a Slice plot in FITS format you can achieve it with any number of pixels and pixels size (say 4024*4024). This could be the easy way to do, but it will convert the slice plot (the final image itself) into a numpy array (FITS format)
For more details, you can visit this link: https://yt-project.org/doc/visualizing/writing_fits_images.html
I hope this will help you if I get you correctly.
Regards, -Prateek
On Wed, Oct 16, 2019 at 6:30 AM Tseng, Po-Hsun
wrote: Please remove this duplicate post. _______________________________________________ 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
participants (3)
-
Nathan
-
Prateek Gupta
-
Tseng, Po-Hsun