Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down Expand Up @@ -86,6 +88,7 @@ jobs:
coverage:
name: Coverage
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/hdf5"]
path = tests/hdf5
url = https://github.com/duqtools/hdf5_testdata
18 changes: 17 additions & 1 deletion docs/plotting_example.md → docs/examples.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
## Plotting example
# Examples

## Modify data

Below is an example of how to use **imas2xarray** to data in-place.

Note that **Imas2xarray** can only update data in-place, i.e. the new data must have the same shape as the existing data.

```python
{!../scripts/modify_data.py!}
```

[Source code](https://github.com/duqtools/imas2xarray/tree/main/scripts/modify_data.py)

## Plotting single dataset

Below is an example of how to use **imas2xarray** to plot data with [matplotlib](https://matplotlib.org/).

Expand All @@ -8,6 +22,8 @@ Below is an example of how to use **imas2xarray** to plot data with [matplotlib]

[Source code](https://github.com/duqtools/imas2xarray/tree/main/scripts/plot_with_matplotlib.py)

## Plotting multiple datasets

The code below shows how to make a plot with [matplotlib](https://matplotlib.org/) for multiple datasets.

For a more advanced example of how to concatenate data, check out the [example notebooks](../notebooks/xarray).
Expand Down
3 changes: 1 addition & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nav:
- Home: index.md
- Variables: variables.md
- Python API: api/index.md
- Plotting example: plotting_example.md
- Examples: examples.md
- Notebook - Variables: notebooks/xarray.ipynb
- Notebook - 2D data: notebooks/xarray-2D.ipynb
- Notebook - Ions: notebooks/xarray-ions.ipynb
Expand All @@ -17,7 +17,6 @@ nav:
- 🔗 Issues: https://github.com/duqtools/imas2xarray/issues
- 🔗 Duqtools: https://duqtools.readthedocs.io


theme:
name: material
primary: blue
Expand Down
20 changes: 20 additions & 0 deletions scripts/modify_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from imas2xarray import to_imas, to_xarray

variables = ('rho_tor_norm', 'time', 't_e')
ids = 'core_profiles'

dataset = to_xarray(
'/pfs/work/g2aho/public/imasdb/test/3/92436/1/',
ids=ids,
variables=variables,
)

print(dataset['t_e'])
dataset['t_e'] += 1

to_imas(
'/pfs/work/g2aho/public/imasdb/test/3/92436/1/',
dataset=dataset,
ids=ids,
variables=variables,
)
3 changes: 2 additions & 1 deletion src/imas2xarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ._io import H5Handle, to_xarray
from ._io import H5Handle, to_imas, to_xarray
from ._lookup import VariableConfigLoader, var_lookup
from ._models import IDSPath, VariableConfigModel
from ._models import IDSVariableModel as Variable
Expand Down Expand Up @@ -30,6 +30,7 @@
'standardize_grid',
'standardize_grid_and_time',
'to_xarray',
'to_imas',
'var_lookup',
'VariableConfigLoader',
'VariableConfigModel',
Expand Down
Loading