Skip to content

Commit c5830d5

Browse files
committed
refactor docs from jupyter-execute to myst-nb
1 parent ed4ec42 commit c5830d5

6 files changed

Lines changed: 71 additions & 61 deletions

File tree

docs/_static/jupyter_padding.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/animation.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
---
2+
file_format: mystnb
3+
kernelspec:
4+
name: python3
5+
---
6+
17
# Animations
28

39
[`xarray.DataArray.epoch.animate`](project:#sdf_xarray.plotting.animate)
410
creates a <inv:#matplotlib.animation.FuncAnimation>; it is designed to
511
mimic <inv:#xarray.DataArray.plot>.
612

7-
```{jupyter-execute}
13+
```{code-cell} ipython3
814
import sdf_xarray as sdfxr
915
import xarray as xr
1016
import matplotlib.pyplot as plt
@@ -22,15 +28,12 @@ The type of plot that is animated is determined by the dimensionality of the
2228
resolved data has 2 dimensions.
2329
```
2430

25-
```{csv-table}
26-
:header: >
27-
: "Dimensions", "Plotting function", "Notes"
28-
:widths: "auto"
31+
| Dimensions | Plotting function | Notes |
32+
| ---------- | ----------------------------- | --------------------- |
33+
| `2` | <inv:#xarray.plot.line> | |
34+
| `3` | <inv:#xarray.plot.pcolormesh> | |
35+
| `>3` | <inv:#xarray.plot.hist> | Not fully implemented |
2936

30-
`2`, <inv:#xarray.plot.line>, ""
31-
`3`, <inv:#xarray.plot.pcolormesh>, ""
32-
`>3`, <inv:#xarray.plot.hist>, "Not fully implemented"
33-
```
3437

3538
### 1D simulation
3639

@@ -42,7 +45,7 @@ It is important to note that since the dataset is time resolved, it has
4245
`anim.show()` will only show the animation in a Jupyter notebook.
4346
```
4447

45-
```{jupyter-execute}
48+
```{code-cell} ipython3
4649
# Open the SDF files
4750
ds = sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
4851
@@ -76,7 +79,7 @@ plt.show()
7679

7780
Plotting a 2D simulation can be done in exactly the same way.
7881

79-
```{jupyter-execute}
82+
```{code-cell} ipython3
8083
ds = sdfxr.open_mfdataset("tutorial_dataset_2d/*.sdf")
8184
da = ds["Derived_Number_Density_Electron"]
8285
anim = da.epoch.animate()
@@ -86,7 +89,7 @@ anim.show()
8689
We can also take a lineout of a 2D simulation to create 2D data and
8790
plot it as a <inv:#xarray.plot.line>.
8891

89-
```{jupyter-execute}
92+
```{code-cell} ipython3
9093
da = ds["Derived_Number_Density_Electron"]
9194
da_lineout = da.sel(Y_Grid_mid = 1e-6, method = "nearest")
9295
anim = da_lineout.epoch.animate(title = "Y = 1e-6 [m]")
@@ -100,7 +103,7 @@ return a <inv:#xarray.plot.hist>. However, this may not be
100103
desirable. We can plot a 3D simulation along a certain plane in the
101104
same way a 2D simulation can be plotted along a line.
102105

103-
```{jupyter-execute}
106+
```{code-cell} ipython3
104107
ds = sdfxr.open_mfdataset("tutorial_dataset_3d/*.sdf")
105108
106109
da = ds["Derived_Number_Density"]
@@ -112,7 +115,7 @@ anim.show()
112115
A single SDF file can be animated by changing the time coordinate of
113116
the animation.
114117

115-
```{jupyter-execute}
118+
```{code-cell} ipython3
116119
ds = sdfxr.open_dataset("tutorial_dataset_3d/0005.sdf")
117120
da = ds["Derived_Number_Density"]
118121
anim = da.epoch.animate(t = "X_Grid_mid")
@@ -130,7 +133,7 @@ EPOCH allows for simulations that have a moving simulation window
130133
You must use <inv:#xarray.open_mfdataset> and specify arguments in the following way.
131134
```
132135

133-
```{jupyter-execute}
136+
```{code-cell} ipython3
134137
ds = xr.open_mfdataset(
135138
"tutorial_dataset_2d_moving_window/*.sdf",
136139
preprocess = sdfxr.SDFPreprocess(),
@@ -158,7 +161,7 @@ see [`xarray.DataArray.epoch.animate`](project:#sdf_xarray.plotting.animate) for
158161
The coordinate units can be converted before plotting as in [](./unit_conversion.md#unit-conversion).
159162
Some functionality such as `aspect` and `size` are not fully implemented yet.
160163

161-
```{jupyter-execute}
164+
```{code-cell} ipython3
162165
ds = sdfxr.open_mfdataset("tutorial_dataset_2d/*.sdf")
163166
164167
# Change the units of the coordinates
@@ -191,7 +194,7 @@ that contains multiple plots layered on top of each other.
191194
What follows is an example of how to combine multiple animations on the
192195
same axis.
193196

194-
```{jupyter-execute}
197+
```{code-cell} ipython3
195198
ds = sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
196199
197200
anim = ds.epoch.animate_multiple(
@@ -214,7 +217,7 @@ the `alpha` value which sets the opacity of the plot.
214217

215218
This also works with 2 dimensional data.
216219

217-
```{jupyter-execute}
220+
```{code-cell} ipython3
218221
import numpy as np
219222
from matplotlib.colors import LogNorm
220223

docs/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
"sphinx.ext.intersphinx",
4848
"sphinx.ext.todo",
4949
"sphinx_autodoc_typehints",
50-
"myst_parser",
51-
"jupyter_sphinx",
50+
"myst_nb",
5251
"sphinx_copybutton",
5352
"sphinx_togglebutton",
5453
]
5554

56-
source_suffix = {".rst": "restructuredtext", ".md": "markdown"}
55+
source_suffix = {".rst": "restructuredtext", ".md": "myst-nb"}
56+
5757
myst_heading_anchors = 3
5858

5959
autosummary_generate = True
@@ -106,7 +106,7 @@
106106
# relative to this directory. They are copied after the builtin static files,
107107
# so a file named "default.css" will overwrite the builtin "default.css".
108108
html_static_path = ["_static"]
109-
html_css_files = ["force_render_dark_xarray_objects.css", "jupyter_padding.css"]
109+
html_css_files = ["force_render_dark_xarray_objects.css"]
110110

111111
html_theme_options = {
112112
"repository_url": "https://github.com/epochpic/sdf-xarray",

docs/key_functionality.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
---
2+
file_format: mystnb
3+
kernelspec:
4+
name: python3
5+
---
6+
17
# Key Functionality
28

3-
```{jupyter-execute}
9+
```{code-cell} ipython3
410
import xarray as xr
511
import sdf_xarray as sdfxr
612
import matplotlib.pyplot as plt
@@ -10,15 +16,15 @@ import matplotlib.pyplot as plt
1016

1117
### Loading single files
1218

13-
```{jupyter-execute}
19+
```{code-cell} ipython3
1420
sdfxr.open_dataset("tutorial_dataset_1d/0010.sdf")
1521
```
1622

1723
You can also load the data in as a <inv:#xarray.DataTree>, which organises the data
1824
hierarchically into `groups` (for example grouping related quantities such as the individual
1925
components of the electric and magnetic fields) while keeping each item as a <inv:#xarray.Dataset>.
2026

21-
```{jupyter-execute}
27+
```{code-cell} ipython3
2228
sdfxr.open_datatree("tutorial_dataset_1d/0010.sdf")
2329
```
2430

@@ -29,7 +35,7 @@ sdfxr.open_datatree("tutorial_dataset_1d/0010.sdf")
2935
If you wish to load data directly from the `SDF.C` library and ignore
3036
the <inv:#xarray> interface layer.
3137

32-
```{jupyter-execute}
38+
```{code-cell} ipython3
3339
raw_ds = sdfxr.SDFFile("tutorial_dataset_1d/0010.sdf")
3440
raw_ds.variables.keys()
3541
```
@@ -46,7 +52,7 @@ to a nan value. To remove these nan values we suggest using the <inv:#xarray.Dat
4652
function or following our implmentation in [](#loading-sparse-data).
4753
```
4854

49-
```{jupyter-execute}
55+
```{code-cell} ipython3
5056
sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
5157
```
5258

@@ -55,7 +61,7 @@ all the files we have do some processing of the data so that we can correctly al
5561
the time dimension; This is done via the `preprocess` parameter utilising the
5662
<project:#sdf_xarray.SDFPreprocess> function.
5763

58-
```{jupyter-execute}
64+
```{code-cell} ipython3
5965
xr.open_mfdataset(
6066
"tutorial_dataset_1d/*.sdf",
6167
join="outer",
@@ -68,7 +74,7 @@ You can also load the data in as a <inv:#xarray.DataTree>, which organises the d
6874
hierarchically into `groups` (for example grouping related quantities such as the individual
6975
components of the electric and magnetic fields) while keeping each item as a <inv:#xarray.Dataset>.
7076

71-
```{jupyter-execute}
77+
```{code-cell} ipython3
7278
sdfxr.open_mfdatatree("tutorial_dataset_1d/*.sdf")
7379
```
7480

@@ -82,7 +88,7 @@ need for a single, large time dimension that would be filled with nan values. Th
8288
significantly reduces memory consumption, though it requires more deliberate handling
8389
if you need to compare variables that exist on these different time coordinates.
8490

85-
```{jupyter-execute}
91+
```{code-cell} ipython3
8692
sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf", separate_times=True)
8793
```
8894

@@ -109,7 +115,7 @@ Pass `keep_particles=True` as a keyword argument to
109115
<inv:#xarray.open_dataset> (for single files) or <inv:#xarray.open_mfdataset> (for
110116
multiple files).
111117

112-
```{jupyter-execute}
118+
```{code-cell} ipython3
113119
sdfxr.open_dataset("tutorial_dataset_1d/0010.sdf", keep_particles=True)
114120
```
115121

@@ -125,7 +131,7 @@ variables. This creates a dataset consisting only of the given variable(s)
125131
and the relevant coordinates/dimensions, significantly reducing memory
126132
consumption.
127133

128-
```{jupyter-execute}
134+
```{code-cell} ipython3
129135
sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf", data_vars=["Electric_Field_Ex"])
130136
```
131137

@@ -154,8 +160,9 @@ There are a few ways you can load an input deck:
154160

155161
An example of loading a deck can be seen below
156162

157-
````{toggle}
158-
```{jupyter-execute}
163+
```{code-cell} ipython3
164+
:tags: [hide-output]
165+
159166
import json
160167
from IPython.display import Code
161168
@@ -167,7 +174,6 @@ deck = ds.attrs["deck"]
167174
json_str = json.dumps(deck, indent=4)
168175
Code(json_str, language='json')
169176
```
170-
````
171177

172178
## Data interaction examples
173179

@@ -185,7 +191,7 @@ It is important to note here that <inv:#xarray> lazily loads the data
185191
meaning that it only explicitly loads the results your currently
186192
looking at when you call `.values`
187193

188-
```{jupyter-execute}
194+
```{code-cell} ipython3
189195
ds = sdfxr.open_mfdataset("tutorial_dataset_1d/*.sdf")
190196
191197
ds["Electric_Field_Ex"]
@@ -197,7 +203,7 @@ using the built-in <inv:#xarray.DataArray.plot> function (see
197203
a simple call to `matplotlib`. This also means that you can access
198204
all the methods from `matplotlib` to manipulate your plot.
199205

200-
```{jupyter-execute}
206+
```{code-cell} ipython3
201207
# This is discretized in both space and time
202208
ds["Electric_Field_Ex"].plot()
203209
plt.title("Electric field along the x-axis")
@@ -210,7 +216,7 @@ This dimension represents all the recorded simulation steps and allows
210216
for easy indexing. To quickly determine the number of time steps available,
211217
you can check the size of the time dimension.
212218

213-
```{jupyter-execute}
219+
```{code-cell} ipython3
214220
# This corresponds to the number of individual SDF files loaded
215221
print(f"There are a total of {ds['time'].size} time steps")
216222
@@ -224,7 +230,7 @@ index of the time step with the <inv:#xarray.Dataset.isel> function. This can be
224230
done by passsing the index to the `time` parameter (e.g., `time=0` for
225231
the first snapshot).
226232

227-
```{jupyter-execute}
233+
```{code-cell} ipython3
228234
# We can plot the variable at a given time index
229235
ds["Electric_Field_Ex"].isel(time=20)
230236
```
@@ -237,7 +243,7 @@ If you know roughly what time you wish to select but not the exact value
237243
you can use the parameter `method="nearest"`.
238244
```
239245

240-
```{jupyter-execute}
246+
```{code-cell} ipython3
241247
ds["Electric_Field_Ex"].sel(time=sim_time)
242248
```
243249

@@ -280,7 +286,7 @@ Below is an example gif of how this interfacing looks as seen on
280286
These datasets can also be easily manipulated the same way as you
281287
would with `numpy` arrays.
282288

283-
```{jupyter-execute}
289+
```{code-cell} ipython3
284290
ds["Laser_Absorption_Fraction_in_Simulation"] = (
285291
(ds["Total_Particle_Energy_in_Simulation"] - ds["Total_Particle_Energy_in_Simulation"][0])
286292
/ ds["Absorption_Total_Laser_Energy_Injected"]
@@ -298,15 +304,15 @@ plt.show()
298304
You can also call the `plot()` function on several variables with
299305
labels by delaying the call to `plt.show()`.
300306

301-
```{jupyter-execute}
307+
```{code-cell} ipython3
302308
ds["Total_Particle_Energy_Electron"].plot(label="Electron")
303309
ds["Total_Particle_Energy_Ion"].plot(label="Ion")
304310
plt.title("Particle Energy in Simulation per Species")
305311
plt.legend()
306312
plt.show()
307313
```
308314

309-
```{jupyter-execute}
315+
```{code-cell} ipython3
310316
print(f"Total laser energy injected: {ds["Absorption_Total_Laser_Energy_Injected"][-1].values:.1e} J")
311317
print(f"Total particle energy absorbed: {ds["Total_Particle_Energy_in_Simulation"][-1].values:.1e} J")
312318
print(f"The laser absorption fraction: {ds["Laser_Absorption_Fraction_in_Simulation"][-1].values:.1f} %")

0 commit comments

Comments
 (0)