Databases Reference
In-Depth Information
>>> dset . attrs [ 'axes' ] = [ "x" , "y" , "z" ]
We would have to tell all of our colleagues about this convention, of course, and it would
look “squished” in viewers that don't know about our ad hoc naming convention, and
I suppose if we change to variable-sized steps in the z direction it would break…
It turns out this situation is common enough that a standard has arisen: the HDF5
Dimension Scales specification. Like the ad hoc system of attributes earlier, it's a feature
built on top of HDF5, using the machinery of datasets, attributes, and references in a
standardized way to build a more expressive object.
There are a lot of features like this, all standardized by the HDF Group (authors and
maintainers of the HDF5 software suite) in a series of RFCs. The big advantage of this
approach is that third-party applications know what to do with certain specific combi‐
nations of groups, datasets, attributes, and references. For example, a viewer program
would render our simulation “unsquished” by honoring the axes we create. Or, in the
case of the HDF5 Image standard, the viewer could determine the appropriate palette
to render an astronomical photograph.
Creating Dimension Scales
Let's revisit our dataset with 3D temperature measurements. First, we'll erase the at‐
tributes we applied, before using Dimension Scales to do it right:
>>> for name in dset . attrs :
... del dset . attrs [ name ]
There's a property attached to our dataset, which up until now we've ignored:
>>> dset . dims
<Dimensions of HDF5 object at 74374048>
This is our entry point for Dimension Scales. In HDF5, a “dimension scale” is a separate
“axis” dataset with some metadata, linked to the main dataset using references. In our
example, we want to create three dimension scales: one for x , with steps of 10 km, one
for y , also with steps of 10 km, and one for z , in steps of 100 m.
To record this, we first create three datasets in the file which will hold our Dimension
Scale “axes”:
>>> f . create_dataset ( 'scale_x' , data = np . arange ( 100 ) * 10e3 )
>>> f . create_dataset ( 'scale_y' , data = np . arange ( 100 ) * 10e3 )
>>> f . create_dataset ( 'scale_z' , data = np . arange ( 100 ) * 100.0 )
Now, we ask HDF5 to turn them into official “Dimension Scale” datasets by using the
create_scale method on dset.dims :
>>> dset . dims . create_scale ( f [ 'scale_x' ], "Simulation X (North) axis" )
>>> dset . dims . create_scale ( f [ 'scale_y' ], "Simulation Y (East) axis" )
>>> dset . dims . create_scale ( f [ 'scale_z' ], "Simulation Z (Vertical) axis" )
Search WWH ::




Custom Search