Databases Reference
In-Depth Information
It's worth taking a moment to see what actually happens when we do this. Let's inspect
the attributes of the scale_x dataset and see what's there:
>>> for key , val in f [ 'scale_x' ] . attrs . iteritems ():
... print key , ':' , val
CLASS : DIMENSION_SCALE
NAME : Simulation X (North) axis
That's really it. All create_scale did was attach a few attributes with standardized
names and values.
Attaching Scales to a Dataset
Now that we have our three scales, we can associate them with our dataset. Note, how‐
ever, that we have to associate each scale with a particular axis of the dataset. This is
expressed by using indexing on the Dataset.dims object:
>>> dset . dims [ 0 ] . attach_scale ( f [ 'scale_x' ])
>>> dset . dims [ 1 ] . attach_scale ( f [ 'scale_y' ])
>>> dset . dims [ 2 ] . attach_scale ( f [ 'scale_z' ])
The object at dims[N] is yet another little proxy, in this case keeping track of which
dimension scales are attached to the first axis of the dataset. Yes, you can have multiple
scales attached to a single axis! Good news for those of you who create plots with an
axis on every side.
The dims[N] proxy works like an ordered dictionary and supports access by both name
and index. In this case, the index refers to the order in which scales were added. For
example, to get the dataset containing our x scale, we could ask for the first scale asso‐
ciated with dimension 0 of the dataset:
>>> dset . dims [ 0 ][ 0 ]
<HDF5 dataset "scale_x": shape (100,), type "<f8">
And to get the actual axis values, simply slice into the dataset:
>>> dset . dims [ 0 ][ 0 ][ ... ]
array([ 0., 10000., 20000., 30000., 40000., 50000.,
60000., 70000., 80000., 90000., 100000., 110000.,
120000., 130000., 140000., 150000., 160000., 170000.,
180000., 190000., 200000., 210000., 220000., 230000.,
240000., 250000., 260000., 270000., 280000., 290000.,
300000., 310000., 320000., 330000., 340000., 350000.,
360000., 370000., 380000., 390000., 400000., 410000.,
420000., 430000., 440000., 450000., 460000., 470000.,
480000., 490000., 500000., 510000., 520000., 530000.,
540000., 550000., 560000., 570000., 580000., 590000.,
600000., 610000., 620000., 630000., 640000., 650000.,
660000., 670000., 680000., 690000., 700000., 710000.,
720000., 730000., 740000., 750000., 760000., 770000.,
780000., 790000., 800000., 810000., 820000., 830000.,
Search WWH ::




Custom Search