Skip to content

Commit 0efc066

Browse files
committed
Add preliminary example
1 parent 602dfa5 commit 0efc066

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

examples/15_scipp_loader.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
import openpmd_api as pmd
2+
import openpmd_api.scipp as pmdsc
3+
import scipp as sc
24

35

46
def main():
5-
series = pmd.Series("./out.bp5", pmd.Access.read_only)
7+
series = pmd.Series("../samples/git-sample/data%T.h5", pmd.Access.read_only)
8+
9+
time = 65 * sc.Unit("fs")
610
scipp_loader = series.to_scipp()
11+
print(scipp_loader.iterations)
12+
Ex = scipp_loader.get_field("E", "x", time=time)
13+
print(Ex)
14+
slicing_idx = pmdsc.closest(Ex, "x", 2 * sc.Unit("um"))
15+
Ex_slice = Ex["x", slicing_idx]
16+
print(Ex_slice)
17+
Ex_slice.plot().save("slice.png")
18+
Ex_line = Ex_slice["z", pmdsc.closest(Ex_slice, "z", 1.4e-5 * sc.Unit("m"))]
19+
print(Ex_line)
20+
Ex_line.plot().save("line.png")
21+
(Ex_line * Ex_line).plot().save("line_squared.png")
22+
23+
# The full 3D array is not loaded into memory at this point.
24+
Ex = scipp_loader.get_field("E", "x", time=time, relay=True)
25+
# This time we will select a range rather than a slice.
26+
# For a range there is no need for an exact match.
27+
# But, we could also select a slice just like in the previous example.
28+
Ex = Ex["x", -2e-6 * sc.Unit("m") : 2e-6 * sc.Unit("m")]
29+
# Only now the smaller subset wil be loaded into memory
30+
Ex = Ex.load_data()
31+
print(Ex)
32+
33+
Ex = sc.concat(
34+
[
35+
scipp_loader.get_field("E", "x", iteration=iteration.value, time_tolerance=None)
36+
for iteration in scipp_loader.iterations["iteration_id"]
37+
],
38+
dim="t",
39+
)
40+
print(Ex)
41+
42+
# Let us just slice at some points to get a 2D dataset
43+
Ex = Ex["x", 10]["y", 10]
44+
print(Ex)
45+
Ex.plot().save("moving_window.png")
746

847
if __name__ == "__main__":
948
main()

0 commit comments

Comments
 (0)