[yt-users] basic question
Elizabeth Tasker
tasker at astro1.sci.hokudai.ac.jp
Tue Nov 8 00:33:29 PST 2011
Hi,
I have a basic question about the way yt handles data (or maybe the way python functions handle data).
If I have a function of the form:
def _MyFunction(field, data):
new_data = na.zeros(data["x"].shape, dtype='float64')
..... find xpos, ypos and zpos values of cells to be flagged as part of new_data
for n in range(nflaggedcells):
new_data[[data["x"] == xpos and data["y"] == ypos and data["z"] == zpos]] = 1.0
return new_data
add_field("MyFunction", function=_MyFunction, validators=[ValidateSpatial(1, ["x", "y", "z"])])
pf = load('data')
dd = pf.h.all_data()
regions = dd["MyFunction"]
Does yt call _MyFunction for each grid? So it runs through that routine many times, once per grid?
If so, is there an alternative? One sweep through the function will --using Sam's KD tree-- find the positions on every grid that I want to mark. The only reason to put it in a function, as opposed to the main body, is so I can then use yt's slice and projection tools on the data set.
I'd really like to create a new field I can use with add_slice that only is looped over a single time. I appreciate this line:
for n in range(nflaggedcells):
new_data[[data["x"] == xpos and data["y"] == ypos and data["z"] == zpos]] = 1.0
then won't work, but I can just store a list of the grids and cell numbers and mark up new_data using those instead.
Does that make sense?
Thanks!
Elizabeth
More information about the yt-users
mailing list