pyne/pyne — pull request #172 by scopatz (2013-10-28 03:36:56+00:00)
Title: Super Awesome Tags To Blow Your Mind

I added a tagging interface to meshes that makes a heavy use of PyNE descriptors to intercept get, set, and del operations. There are four different tag classes (+ a base class) depending on where the data is stored:

* MaterialPropertyTag for material intrinsic variables.
* MaterialMethodTags for values that can be computed form materials with out needed extra arguments (such as molecular weight)
* MetadataTags for things variable length data types that get stored in Material.attrs
* IMeshTags for fixed-length data types that get stored on the iMesh.Mesh() instance.

Tags, like materials, are indexed based on the iteration index of the mesh. However, slicing, fancy indexing, and masking have been implemented across all tag types. This makes it very expressive. For a mesh `m`,

```python
# get/set a single tag
m.density[0] = 65.0
assert_equal(m.density[0], 65.0)

# get/set slices
m.density[::2] = 18.0
m.density[1::2] = [36.0, 54.0]
assert_array_equal(m.density[:], np.array([18.0, 36.0, 18.0, 54.0]))

# get/set masks
mask = np.array([True, False, True, True], dtype=bool)
m.density[mask] = 9.0

mask = np.array([True, True, False, False], dtype=bool)
m.density[mask] = (19.0, 29.0)

assert_array_equal(m.density[:], np.array([19.0, 29.0, 9.0, 9.0]))

# get / set fancy indexes
m.density[[2]] = 28.0
m.density[3, 1] = 6.0, 4128.0
```

Dammit, I just realized that computed tags would be awesome to have too. Feel free to merge this anyways.