[yt-users] field value at a given location

Matthew Turk matthewturk at gmail.com
Mon Dec 6 14:43:40 PST 2010


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
>



More information about the yt-users mailing list