[yt-users] field value at a given location

Matthew Turk matthewturk at gmail.com
Mon Dec 6 14:51:54 PST 2010


Hi Sam,

On Mon, Dec 6, 2010 at 2:45 PM, Sam Skillman <samskillman at gmail.com> wrote:
> Hi Christine,
> In addition to Stephen's answer, in the past I have done:
> pf = load('data0005')
> max_loc = pf.h.find_max_cell_location('Density')
> temperature_at_max_den = max_loc[0].get_data('Temperature')[max_loc[1]]
> I'm not sure which is faster, but two methods are better than one!

It's not just about speed, in this case -- what happens is that with
accessing the entire dataset simultaneously, as in the standard field
access (data_obj[field]) it will all be loaded into memory.  For
something like the light cone, this will blow out the ram in a
standard node, and the operation will never complete.  When you use
find_max_cell_location, yt actually (in the backend) creates a data
container and then utilizes a derived quantity to operate in a
grid-by-grid fashion, returning only the final result.

So not only will this be able to work on even the largest datasets
without getting OOM errors, it will also parallelize nicely, as it's a
fully local operator with a finalize step at the end, whereas the
other operation will just load the entire array simultaneously on
every node.

-Matt

> Sam
> p.s. I just saw matt's email come through, and mine looks like the last
> option he gave..
> On Mon, Dec 6, 2010 at 3:38 PM, Stephen Skory <stephenskory at yahoo.com>
> wrote:
>>
>> Christine,
>>
>>
>> >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?
>>
>>
>>
>>
>>
>> you'll want to use numpy's argmax(), which gives the index of the maximum
>> value in an array. Here's an example:
>>
>> In [1]: pf = load("data0005")
>>
>> In [2]: dd = pf.h.all_data()
>> yt         INFO       2010-12-06 15:36:30,714 Getting the binary hierarchy
>> yt         INFO       2010-12-06 15:36:30,725 Finished with binary
>> hierarchy reading
>>
>> In [3]: D = dd['Density']
>> yt         INFO       2010-12-06 15:36:39,620 Getting field Density from
>> 32
>>
>> In [4]: max = na.argmax(D)
>>
>> In [5]: max
>> Out[5]: 911803
>>
>> In [6]: D[max]
>> Out[6]: 5.2503087194967203e-26
>>
>> In [7]: T = dd['Temperature']
>> yt         INFO       2010-12-06 15:36:58,377 Getting field Temperature
>> from 32
>>
>> In [8]: T[max]
>> Out[8]: 10597.077292396227
>>
>> Let me know if that's not clear enough!
>>
>>
>> Stephen Skory
>> stephenskory at yahoo.com
>> http://stephenskory.com/
>> 510.621.3687 (google voice)
>> _______________________________________________
>> 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