... | ... | @@ -10,12 +10,25 @@ Example file: [cube_1e3.h5](/uploads/b6771c94baefbc4602e84ff0f4ca876a/cube_1e3.h |
|
|
```python
|
|
|
import h5py
|
|
|
def demo():
|
|
|
with h5py.File('cube_1e3.h5') as myfile:
|
|
|
# all data will always be in 'data' section
|
|
|
data = myfile['data']
|
|
|
# inspect data
|
|
|
data.keys()
|
|
|
# example: <KeysViewHDF5 ['D1_left_front_N1_right', 'Linear_1_to_minus1', 'MaterialIDs', 'geometry', 'pressure', 'topology', 'v']>
|
|
|
with h5py.File('square_5x5_tris_32.h5') as myfile:
|
|
|
# inspect what is inside the root of the file:
|
|
|
# Each HDF will contain a group 'meshes' (with 1 or more meshes) and a group 'times'
|
|
|
# with time series
|
|
|
myfile.keys()
|
|
|
# Output: <KeysViewHDF5 ['meshes', 'times']>
|
|
|
|
|
|
# Select the group 'meshes' and look what is inside and select a mesh
|
|
|
meshes = myfile['meshes']
|
|
|
meshes.keys()
|
|
|
# < KeysViewHDF5['square_5x5_tris_32', 'square_5x5_tris_32_left_boundary', 'square_5x5_tris_32_right_boundary'] >
|
|
|
|
|
|
# Select a mesh and check which attributes it contains
|
|
|
mesh = meshes['square_5x5_tris_32']
|
|
|
# Each mesh will contain 'geometry' and 'topology'. Optionally other attributes
|
|
|
< KeysViewHDF5['HydraulicFlow', 'MaterialIDs', 'geometry', 'pressure', 'topology', 'v'] >
|
|
|
|
|
|
# Select an attribute
|
|
|
pressure = mesh['pressure']lIDs', 'geometry', 'pressure', 'topology', 'v']>
|
|
|
|
|
|
# choose any key , here in example 'pressure', it is only a reference (no copy of data into memory)
|
|
|
pressure = data['pressure']
|
... | ... | |