Databases Reference
In-Depth Information
When you do this, HDF5 doesn't copy the type into the dataset; it actually makes a
reference to the named type object elsewhere in the file. So on top of helping you keep
data organized, it saves disk space as well.
For attributes, remember you'll have to explicitly supply the type via the create method.
For example, to create an attribute on the root group that uses our named type:
>>> f . attrs . create ( "attribute_demo" , 1.0 , dtype = f [ 'mytype' ])
Managing Named Types
You can't modify named types once they're created, although you can unlink them from
the file:
>>> del f [ 'mytype' ]
But don't try to trick HDF5 by replacing it with a new, different type. The stored type
information can't be unlinked from the datasets and attributes that point to it. It'll hang
around in the shadows until every dataset and attribute that used it is deleted from the
file:
>>> f [ 'mytype' ] = np . dtype ( 'int16' )
>>> dset = f [ 'typedemo' ]
>>> dset . dtype
dtype('float32')
Dimension Scales
Real-world data comes with units attached. Suppose we have a 3D dataset that is the
output from an atmospheric simulation, representing temperatures at various points
within a volume:
>>> dset = f . create_dataset ( 'temperatures' , ( 100 , 100 , 100 ), dtype = 'f' )
It's easy enough to recognize that dataset records “temperature”—we could even add an
attribute to record the scale:
>>> dset . attrs [ 'temp_units' ] = "C"
But there's a more subtle problem. Suppose our simulation is focused on a convection
process, and has much greater resolution in the z direction than either the x or y direc‐
tions; for example, the steps in the vertical direction might be 100 meters while the steps
in the horizontal direction might be 10 kilometers. We could add more attributes, per‐
haps by having a “step” attribute like so:
>>> dset . attrs [ 'steps' ] = [ 10000 , 10000 , 100 ]
By the way, which axis is which? Does the first axis represent the x direction, as we might
expect? Or does the simulation output z first? We could add another attribute, I guess,
which records this:
Search WWH ::




Custom Search