Skip to content

Commit

Permalink
write and read hdf5
Browse files Browse the repository at this point in the history
  • Loading branch information
jzuhone committed Aug 21, 2023
1 parent bcb013f commit b0ae2f2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions content/40.units_and_quantities.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,26 @@ and `unyt.loadtxt` to read them back in:
>>> vel, mass = u.loadtxt("sphere.dat", usecols=(1,2), delimiter="\t")
```

`unyt_array`s can be written to HDF5 format using the `write_hdf5` method, where
one can optionally specify the HDF5 dataset and group where it can be stored:

```python
>>> # Store the "b" array to the dataset "array_data" at the top of the file
>>> b.write_hdf5("velocity1.hdf5")
>>> # Store the "b" array to the dataset "velocity" at the top of the file
>>> b.write_hdf5("velocity2.hdf5", dataset_name="velocity")
>>> # Store the "b" array to the dataset "velocity" in the group "fields"
>>> b.write_hdf5("velocity3.hdf5", dataset_name="velocity", group_name="fields")
```

and read back in using `from_hdf5`:

```python
>>> import unyt as u
>>> v1 = u.read_hdf5("velocity1.hdf5")
>>> v2 = u.read_hdf5("velocity2.hdf5", dataset_name="velocity")
>>> v3 = u.read_hdf5("velocity3.hdf5", dataset_name="velocity", group_name="fields")
```

#### Exporting `unyt_array`s to other unit packages

Expand Down

0 comments on commit b0ae2f2

Please sign in to comment.