File: h5_compound.py

package info (click to toggle)
hdf5 1.14.5%2Brepack-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208,864 kB
  • sloc: ansic: 715,772; f90: 42,941; java: 38,102; sh: 30,925; xml: 18,706; cpp: 18,011; makefile: 2,423; perl: 2,383; yacc: 332; python: 262; javascript: 203; lex: 157; ruby: 24; csh: 22
file content (33 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# This example creates an HDF5 file compound.h5 and an empty datasets /DSC in it.
#
import h5py
import numpy as np
#
# Create a new file using default properties.
#
file = h5py.File('compound.h5','w')
#
# Create a dataset under the Root group.
#
comp_type = np.dtype([('Orbit', 'i'), ('Location', np.str_, 6), ('Temperature (F)', 'f8'), ('Pressure (inHg)', 'f8')])
dataset = file.create_dataset("DSC",(4,), comp_type)
data = np.array([(1153, "Sun   ", 53.23, 24.57), (1184, "Moon  ", 55.12, 22.95), (1027, "Venus ", 103.55, 31.23), (1313, "Mars  ", 1252.89, 84.11)], dtype = comp_type)
dataset[...] = data
#
# Close the file before exiting
#
file.close()
file = h5py.File('compound.h5', 'r')
dataset = file["DSC"]
print("Reading Orbit and Location fields...")
orbit = dataset['Orbit']
print("Orbit: ", orbit)
location = dataset['Location']
print("Location: ", location)
data = dataset[...]
print("Reading all records:")
print(data)
print("Second element of the third record:", dataset[2, 'Location'])
file.close()