SciTools/iris — pull request #680 by esc24 (2013-08-09 11:02:29+00:00)
Title: Local and global attributes

This PR adds ```Cube.local_attributes``` and ```Cube.global_attributes```.

I've made a few decisions regarding the handling of collections of cubes:

1. The current philosophy of merge() is maintained so one cannot merge cubes with different local_attributes or different global_attributes. Changes to this behaviour should be the subject of a subsequent PR.

2. Saving a collection of cubes to a single netcdf file will raise an exception if the global_attributes are not equal across the entire collection. There is scope for alternatives here, but I propose they should be addressed in a subsequent PR.

Other points:

1. This PR would be an awful lot simpler if ```local_attributes``` was called ```attributes```. The changes would be more additive, would break less code and if in hindsight we decide this is a bad idea a lot easier to unpick. See all of the subsequent points.
2. I've modified the xml output of a cube to output the two sets of attributes. This produces a lot of changes (mostly ```attributes``` -> ```local_attributes```), but I've kept these changes in separate commits. This change highlights the benefits/differences when dealing with CF-netCDF in relation to attributes like 'history' and 'Conventions' and allows for more thorough testing of behaviour.
3. I've left the cube signature unchanged. The contents of the ```attributes``` keyword arg of the cube constructor are stored in the ```local_attributes``` dictionary. global attributes must therefore be set after instantiation.
4. As agreed I've added a 'read-only' ```Cube.attributes``` to access the combined set of attributes where local take precedence over global. This adds to complexity and in hindsight I'm a little sceptical.
5. ```AttributeConstraint``` and ```Cube.is_compatible()``` are untouched so operate on the combined, convenience ``Cube.attributes```. This may need changing, but I feel like changes to AttributeConstraint have a greater potential to break user-code.
6. ```history``` has moved to ```Cube.local_attributes```, differentiating it from the global attribute 'history' if present.
7. I'm aware the names of these new metadata collections is to be agreed upon. I'm happy to hear alternatives to local_attributes and global_attributes.