Annotating particles in Flash with different sizes
Hello users, I've recently been using yt to plot gas and star Flash runs where the particle size is proportional to the log of the mass. I've noticed that using the annotate_particles method is occasionally seems to be giving me the wrong masses. Here's a plot with the annotate_particles method: ds = yt.load("./Runs/ProbStars/data/turbsph_hdf5_plt_cnt_0021") gr = yt.ProjectionPlot(ds, 'x', 'dens') gr.annotate_particles(ds.domain_width[0], p_size=np.multiply(20.0,np.log10(dd['particle_mass'].in_units('Msun').v)), col='b') gr.annotate_timestamp(corner='upper_left') gr.zoom(5) gr.save('ann_part_test.png') gr.show() Here's the plot: [image: ann_part_test.png] And if I manually add the stars (also, I'm not sure why I have to call proj.show() before the scatter plot to get this to work...): proj = yt.ProjectionPlot(ds, 'x', 'dens') proj.show() dens_plot = proj.plots['dens'] proj_ax = dens_plot.axes fig = dens_plot.figure proj_ax.scatter(dd['particle_position_y'].in_units('pc').v, dd['particle_position_z'].in_units('pc').v, s=np.multiply(20.0,np.log10(dd['particle_mass'].in_units('Msun').v)), c='k') proj_ax.set_xlim(-1.0, 1.0) proj_ax.set_ylim(-1.0, 1.0) proj.show() proj.save('man_ann_part.png') Here's the plot for this (which has the correct sized particles, note the one closest to 0,0 is about 1.4 Msun and much smaller in the plot below): [image: man_ann_part.png] I am currently re-writing my plotting routines (which I use to make movies) to account for this, but it is a lot uglier this way, especially since I run on a cluster without display and don't want to have to call proj.show() before I call for the scatter plot. I'm guessing I can probably also just call proj.save() twice with the same effect, but I haven't tested it yet. Any assistance would be appreciated, and thanks! Cordially, Josh Wall -- Joshua Wall Doctoral Candidate Department of Physics Drexel University 3141 Chestnut Street Philadelphia, PA 19104
Hi Josh, Sorry, it's not clear what the difference is, can you explain that a little bit more clearly? Is there any chance you can upload one of your datasets that has this issue so one of us can reproduce the issue locally? Nathan
Oh wait, I see, you want to specify the particle sizes when you call annotate_particles. Let me see if that's possible right now.... On Sat, Nov 19, 2016 at 8:02 PM Nathan Goldbaum <nathan12343@gmail.com> wrote:
Hi Josh,
Sorry, it's not clear what the difference is, can you explain that a little bit more clearly?
Is there any chance you can upload one of your datasets that has this issue so one of us can reproduce the issue locally?
Nathan
OK, sorry for the confusion earlier. Never reply to mailing list questions on your phone! The issue is that the ParticleCallback (the class that gets invoked when you call annotate_particles, see yt/visualization/plot_modifcations.py for more details) generates the list of particles to plot based on a region data object that it constructs inline, which is *not* necessarily the same as your "dd" data object that you're using to generate the list of particle sizes to pass to the p_size keyword argument. In fact, looking at the code, I suspect we've always expected p_size to be a scalar and it's basically an accident that it seems to work when you pass it an array of particle sizes. This means that the mapping from particles to particle sizes is basically random - it will only be exactly the same if the two data objects happen to be exactly the same. I think the best way forward here would be to allow you to specify a custom data object to gather the particles from, instead of only using the region generated by the _get_region function defined here: https://bitbucket.org/yt_analysis/yt/src/9f4dc27f7c8fd399a35e04d0423298753b2994c9/yt/visualization/plot_modifications.py?at=yt&fileviewer=file-view-default#plot_modifications.py-1640 It would also probably be a good idea to error out if you pass a non-scalar p_size without supplying a custom data object to avoid silently producing an incorrect result. I think this would be a relatively straightforward modification to yt, if you're willing to give it a shot it would be a welcome contribution. I'm happy to help out with getting your development environment set up and answering questions. If you don't want to do that, your custom call to ax.scatter should work fine. The reason you need to call prj.show() for it to work correctly is due to the design of the plotting system: plots aren't actually "valid" until just before they're displayed or saved to disk. You actually don't need to call prj.show(), you can instead call the lower level prj._setup_plots() function to get the same effect. In the long run, I'd like to hide this possibly confusing implementation detail from users, possibly by making the .plots attribute of the ProjectionPlot or the .ax attribute of the indifvidual plot objects a property that calls _setup_plots, so the plot is always constructed and valid before you do any custom modifications. I'd actually go so far as to call the need to call _setup_plots(), save(), or show() before doing custom modifications is a bug, please feel free to report this as such so we don't lose track. I have some time tomorrow, I might take a shot at fixing this since it is indeed quite confusing, and your e-mail here has popped up into the top of my stack of possible ways to improve yt :) Anyway, I hope that wasn't too much detail and that it was a helpful explanation. Best, Nathan Goldbaum On Sat, Nov 19, 2016 at 8:40 PM, Nathan Goldbaum <nathan12343@gmail.com> wrote:
Oh wait, I see, you want to specify the particle sizes when you call annotate_particles. Let me see if that's possible right now....
On Sat, Nov 19, 2016 at 8:02 PM Nathan Goldbaum <nathan12343@gmail.com> wrote:
Hi Josh,
Sorry, it's not clear what the difference is, can you explain that a little bit more clearly?
Is there any chance you can upload one of your datasets that has this issue so one of us can reproduce the issue locally?
Nathan
participants (2)
-
Joshua Wall
-
Nathan Goldbaum