[Yt-dev] boolean data container

Stephen Skory s at skory.us
Sat Oct 29 09:19:13 PDT 2011


Hi All,

yesterday I had a brain wave that it should be fairly simple to create
a new kind of data container that is a hybrid of existing ones, where
the mixing/cutting is done with boolean logic. I think I'm most of the
way there. Let me give you some examples of what this means.

>>> re1 = pf.h.region([0.5]*3, [0.4]*3, [0.6]*3)
>>> re2 = pf.h.region([0.5]*3, [0.5]*3, [0.6]*3)
>>> sp1 = pf.h.sphere([0.5]*3, 0.1)
>>> sp2 = pf.h.sphere([0.1]*3, 0.1)

This will give you the exact same region as re1:

>>> re = pf.h.boolean([re1, "OR'", re2])

This will give you the same as re2:

>>> re = pf.h.boolean([re1, "AND", re2])

This will give you the part of re1 that re2 does not cover, so re1
with a corner taken out:

>>> re = pf.h.boolean([re1, "NOT", re2])

Likewise, this will give you a box with a sphere cut out of it in the middle:

>>> re = pf.h.boolean([re1, "NOT", sp1])

This will combine the two disjoint spheres into one object:

>>> re = pf.h.boolean([sp1, "OR", sp2])

Nested logic should work using parentheses, where items in parentheses
are turned into new sub-hybrid regions before they are considered with
the others at a 'higher' level. This will give you a disjoint region,
with sp2 plus re2 with a corner cut out of it.

>>> re = pf.h.boolean([sp2, "OR", "(", re1, "NOT", re2, ")"])

This is all being done with cut_masks so it should work fairly
seamlessly. And so far, nearly everything seems to work. Except for
some reason that I don't fully grasp right now, I'm changing the
cut_masks of the starting regions, which is wrong. Here's an example
of what I mean. If I make a hybrid region:

In [1]: re1 = pf.h.region([0.5]*3, [0.4]*3, [0.6]*3)
In [2]: re2 = pf.h.region([0.5]*3, [0.5]*3, [0.6]*3)
In [3]: re = pf.h.boolean([re1, "AND", re2])
In [4]: re1['x'].shape
yt : [INFO     ] 2011-10-29 10:00:25,002 Getting field x from 4
Out[4]: (2197,)

I'm seeing that re1 is being modified. Here's what I should see for
the shape of ['x']:

In [1]: re1 = pf.h.region([0.5]*3, [0.4]*3, [0.6]*3)
In [2]: re1['x'].shape
yt : [INFO     ] 2011-10-29 10:14:04,730 Getting field x from 4
Out[2]: (17576,)

It's being changed to the dimensions of re2, which is what re is when
boolean is done.

I'm wondering if I could get a second pair of eyes on this, someone
who understands the subtleties of data_containers better than me. I've
pushed the current state of things to my branch.

https://bitbucket.org/sskory/yt/changeset/148e930ce903

Thanks to anyone who can spare the time, or for any comments on this
idea! Let me know if you have any questions.

-- 
Stephen Skory
s at skory.us
http://stephenskory.com/
510.621.3687 (google voice)



More information about the yt-dev mailing list