[yt-users] field value at a given location

Christine Simpson csimpson at astro.columbia.edu
Mon Dec 6 18:05:33 PST 2010


Thanks Matt, Stephen and Sam,

I was already using the derived quantity "MaxLocation" to get the
position and value of the peak density operating on a sphere I set up.
So Matt's 2nd solution worked well in my script.  Although, there's a
small typo, the fifth line should be 
i,j,k = na.unravel_index(vinfo[1], my_grid.ActiveDimensions)

Thanks also for the advice on memory usage and parallelization.  

Let me also note that I had Mike's problem when looking at the
documentation for MaxLocation.  I've been playing around with the
derived quantities recently and I was surprised when MaxLocation spat
out a bunch of info in addition to the position and value of the max
location.  I also had to go look in the source to tell what it was
returning.

Christine

On Mon, 2010-12-06 at 14:43 -0800, Matthew Turk wrote:
> Hi Christine,
> 
> If you have a data object that will fit into memory, you can use this idiom:
> 
> from yt.mods import *
> pf = load("RD0005-mine/RedshiftOutput0005")
> dd = pf.h.all_data()
> loc = na.argmax(dd["Density"])
> print dd["Metal_Density"][loc]
> 
> But, unfortunately, it's not terribly likely that in large simulations
> the entire data will fit into memory.  In that case, we'll have to be
> more clever.
> 
> The best way to do this is to get the location of the peak density of
> the gas using the derived quantity "MaxLocation", which returns the
> grid information as well as the value.  It's a bit tricky simply
> because of how the values are stored, but this is an idiom I should
> wrap into an easier-to-access function.
> 
> Here's a script that does this:
> 
> pf = load("RD0005-mine/RedshiftOutput0005")
> dd = pf.h.all_data()
> vinfo = dd.quantities["MaxLocation"]("Density")
> my_grid = pf.h.grids[vinfo[5]]
> i,j,k = na.unravel_index(vinfo[1], grid.ActiveDimensions)
> print my_grid["Metal_Density"][i,j,k]
> 
> This will work on data objects, but you can also use this function if
> you want it for the full simulation:
> 
> my_grid, pos_index, val, pos_float = pf.h.find_max_cell_location("Density")
> 
> which will return the grid itself, the (i,j,k) indices, the value, and
> float coordinates of the location of the maximum value.
> 
> Let me know if that doesn't work, or if anything is unclear.
> 
> -Matt
> 
> On Mon, Dec 6, 2010 at 2:31 PM, Christine Simpson
> <csimpson at astro.columbia.edu> wrote:
> > Hi all,
> >
> > This is a pretty simple issue and probably has a simple solution, but
> > I'm not sure how to do it.  I want to access the value of a field at a
> > given location.  For example, say I have the location of the peak gas
> > density and I want to find the value of the metallicity at that point.
> > How would I do that?
> >
> > Christine
> >
> >
> > _______________________________________________
> > yt-users mailing list
> > yt-users at lists.spacepope.org
> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> >
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> 





More information about the yt-users mailing list