Annotating BH particles on SlicePlots
Hi all, I'm trying to annotate BH particles on top of a regular yt SlicePlot. I'm loading from an Enzo dataset and using yt version 3.3.1, the plot field and width in parsecs are given as command line arguments (I tried using density and 3.0). Here is the script I'm working with: import yt import sys from yt.units import pc, Msun, Myr import numpy as np yt.enable_parallelism() #get command line inputs, syntax is [field] [size] field = sys.argv[1] try : size = float(sys.argv[2]) except (TypeError, IndexError): print("Error, argument syntax is 'plot.py [field] [size]'") quit(0) ds = yt.load("DD0121/output_0121") time = '{:.3f}'.format(round(ds.current_time.in_units('Myr') - 194.608*Myr, 4)) val, loc = ds.find_max('density') plt = yt.SlicePlot(ds, 'z', field, center= loc, width= (size, 'pc')) plt.set_zlim(field, 1e-21, 1e-12) plt.annotate_particles(ds, size*pc, ptype= 8) #produces 1st error #plt.annotate_particles(ds, size*pc, p_size= 2.0, col= 'k', marker= 'o', stride= 1, ptype= 8, minimum_mass= None, alpha= 1.0) #produces 2nd error plt.annotate_text((0.05, 0.05), 't=' + time + 'Myr', coord_system= 'axis') plt.save("test.png") The script seems to run ok until attempting to save the plot, when I get the following error: Traceback (most recent call last): File "plot_yt.py", line 35, in <module> plt.save("test.png") File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_container.py", line 78, in newfunc args[0]._setup_plots() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 949, in _setup_plots self.run_callbacks() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1005, in run_callbacks sys.exc_info()[2]) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 999, in run_callbacks callback(cbw) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 53, in _check_geometry return func(self, plot) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 1575, in __call__ reg = self._get_region((x0,x1), (y0,y1), plot.data.axis, data) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 1639, in _get_region LE[zax] = data.center[zax].ndarray_view() - self.width*0.5 yt.utilities.exceptions.YTPlotCallbackError: annotate_particles callback failed with the following error: unsupported operand type(s) for *: 'EnzoDataset' and 'float' I've tried adding all the keyword arguments and their parameters to the annotate_particles call (switching the commented line on my script), but this produces: Traceback (most recent call last): File "plot_yt.py", line 35, in <module> plt.save("test.png") File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_container.py", line 78, in newfunc args[0]._setup_plots() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 949, in _setup_plots self.run_callbacks() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 997, in run_callbacks callback = CallbackMaker(*args[1:], **kwargs) TypeError: __init__() got multiple values for keyword argument 'p_size' Any help on getting this to work would be vastly appreciated. I was also wondering whether it was possible to use the annotate_particles callback on OffAxisSlicePlots and OffAxisProjectionPlots, I've tried both and neither seems to support this functionality. Many thanks, Sam Patrick
Hi Sam, I think you've run into a bug, I was able to reproduce the problem and have filed a github issue: https://github.com/yt-project/yt/issues/1839 Thanks for the report! I'll try to come up with a workaround for you but you may need to install yt from source to get the fix. I'll reply here when I have a pull request you can look at. -Nathan On Tue, Jun 19, 2018 at 8:40 AM, Sam Patrick <sam.patrick@port.ac.uk> wrote:
Hi all,
I'm trying to annotate BH particles on top of a regular yt SlicePlot. I'm loading from an Enzo dataset and using yt version 3.3.1, the plot field and width in parsecs are given as command line arguments (I tried using density and 3.0). Here is the script I'm working with:
import yt import sys from yt.units import pc, Msun, Myr import numpy as np
yt.enable_parallelism()
#get command line inputs, syntax is [field] [size] field = sys.argv[1] try : size = float(sys.argv[2]) except (TypeError, IndexError): print("Error, argument syntax is 'plot.py [field] [size]'") quit(0)
ds = yt.load("DD0121/output_0121") time = '{:.3f}'.format(round(ds.current_time.in_units('Myr') - 194.608*Myr, 4))
val, loc = ds.find_max('density') plt = yt.SlicePlot(ds, 'z', field, center= loc, width= (size, 'pc'))
plt.set_zlim(field, 1e-21, 1e-12) plt.annotate_particles(ds, size*pc, ptype= 8) #produces 1st error #plt.annotate_particles(ds, size*pc, p_size= 2.0, col= 'k', marker= 'o', stride= 1, ptype= 8, minimum_mass= None, alpha= 1.0) #produces 2nd error plt.annotate_text((0.05, 0.05), 't=' + time + 'Myr', coord_system= 'axis') plt.save("test.png")
The script seems to run ok until attempting to save the plot, when I get the following error:
Traceback (most recent call last): File "plot_yt.py", line 35, in <module> plt.save("test.png") File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_container.py", line 78, in newfunc args[0]._setup_plots() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 949, in _setup_plots self.run_callbacks() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1005, in run_callbacks sys.exc_info()[2]) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 999, in run_callbacks callback(cbw) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_modifications.py", line 53, in _check_geometry return func(self, plot) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_modifications.py", line 1575, in __call__ reg = self._get_region((x0,x1), (y0,y1), plot.data.axis, data) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_modifications.py", line 1639, in _get_region LE[zax] = data.center[zax].ndarray_view() - self.width*0.5 yt.utilities.exceptions.YTPlotCallbackError: annotate_particles callback failed with the following error: unsupported operand type(s) for *: 'EnzoDataset' and 'float'
I've tried adding all the keyword arguments and their parameters to the annotate_particles call (switching the commented line on my script), but this produces:
Traceback (most recent call last): File "plot_yt.py", line 35, in <module> plt.save("test.png") File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_container.py", line 78, in newfunc args[0]._setup_plots() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 949, in _setup_plots self.run_callbacks() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 997, in run_callbacks callback = CallbackMaker(*args[1:], **kwargs) TypeError: __init__() got multiple values for keyword argument 'p_size'
Any help on getting this to work would be vastly appreciated. I was also wondering whether it was possible to use the annotate_particles callback on OffAxisSlicePlots and OffAxisProjectionPlots, I've tried both and neither seems to support this functionality.
Many thanks, Sam Patrick
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
Hi Sam, I was a little hasty earlier. This isn't quite a bug and I was misunderstanding your script. So first of all, where you had the following: plt.annotate_particles(ds, 10000*pc, ptype=8) What you really wanted is something like this: plt.annotate_particles(10000*pc, ptype='black_hole') The error you got was because you passed in a dataset as the first argument to annotate_particles. I'm leaving my issue open since we should have given you a nicer error message. While it's true that particles with particle_type == 8 in Enzo datasets are black holes, yt only recognizes one particle type for Enzo out of the box, the "io" particle type. What you need to do in your script is set up a particle filter on the particle_type field to create a "black_hole" particle type. You can see more in the yt docs on how to create a particle filter here: http://yt-project.org/doc/analyzing/filtering.html#filtering-particle-fields Here's an example where I make a "star" particle type (particle_type == 2 in Enzo) using a particle filter, then use annotate_particles to draw the positions of the star particles. The dataset used in this script is available at yt-project.org/data: https://gist.github.com/ngoldbaum/5e4ed08122d605b37351e86b7544492e For your data, you'd need to modify that script to define a function named "black_holes", and use that particle filter instead of the "stars" particle filter. Hope that helps! On Tue, Jun 19, 2018 at 9:54 AM, Nathan Goldbaum <nathan12343@gmail.com> wrote:
Hi Sam,
I think you've run into a bug, I was able to reproduce the problem and have filed a github issue:
https://github.com/yt-project/yt/issues/1839
Thanks for the report!
I'll try to come up with a workaround for you but you may need to install yt from source to get the fix. I'll reply here when I have a pull request you can look at.
-Nathan
On Tue, Jun 19, 2018 at 8:40 AM, Sam Patrick <sam.patrick@port.ac.uk> wrote:
Hi all,
I'm trying to annotate BH particles on top of a regular yt SlicePlot. I'm loading from an Enzo dataset and using yt version 3.3.1, the plot field and width in parsecs are given as command line arguments (I tried using density and 3.0). Here is the script I'm working with:
import yt import sys from yt.units import pc, Msun, Myr import numpy as np
yt.enable_parallelism()
#get command line inputs, syntax is [field] [size] field = sys.argv[1] try : size = float(sys.argv[2]) except (TypeError, IndexError): print("Error, argument syntax is 'plot.py [field] [size]'") quit(0)
ds = yt.load("DD0121/output_0121") time = '{:.3f}'.format(round(ds.current_time.in_units('Myr') - 194.608*Myr, 4))
val, loc = ds.find_max('density') plt = yt.SlicePlot(ds, 'z', field, center= loc, width= (size, 'pc'))
plt.set_zlim(field, 1e-21, 1e-12) plt.annotate_particles(ds, size*pc, ptype= 8) #produces 1st error #plt.annotate_particles(ds, size*pc, p_size= 2.0, col= 'k', marker= 'o', stride= 1, ptype= 8, minimum_mass= None, alpha= 1.0) #produces 2nd error plt.annotate_text((0.05, 0.05), 't=' + time + 'Myr', coord_system= 'axis') plt.save("test.png")
The script seems to run ok until attempting to save the plot, when I get the following error:
Traceback (most recent call last): File "plot_yt.py", line 35, in <module> plt.save("test.png") File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_container.py", line 78, in newfunc args[0]._setup_plots() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 949, in _setup_plots self.run_callbacks() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1005, in run_callbacks sys.exc_info()[2]) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 999, in run_callbacks callback(cbw) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_modifications.py", line 53, in _check_geometry return func(self, plot) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_modifications.py", line 1575, in __call__ reg = self._get_region((x0,x1), (y0,y1), plot.data.axis, data) File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_modifications.py", line 1639, in _get_region LE[zax] = data.center[zax].ndarray_view() - self.width*0.5 yt.utilities.exceptions.YTPlotCallbackError: annotate_particles callback failed with the following error: unsupported operand type(s) for *: 'EnzoDataset' and 'float'
I've tried adding all the keyword arguments and their parameters to the annotate_particles call (switching the commented line on my script), but this produces:
Traceback (most recent call last): File "plot_yt.py", line 35, in <module> plt.save("test.png") File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/ visualization/plot_container.py", line 78, in newfunc args[0]._setup_plots() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 949, in _setup_plots self.run_callbacks() File "/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 997, in run_callbacks callback = CallbackMaker(*args[1:], **kwargs) TypeError: __init__() got multiple values for keyword argument 'p_size'
Any help on getting this to work would be vastly appreciated. I was also wondering whether it was possible to use the annotate_particles callback on OffAxisSlicePlots and OffAxisProjectionPlots, I've tried both and neither seems to support this functionality.
Many thanks, Sam Patrick
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
participants (2)
-
Nathan Goldbaum -
Sam Patrick