Skip to content

Commit 602dfa5

Browse files
committed
WIP: Try lazy loading scipp converter
1 parent adf15a1 commit 602dfa5

6 files changed

Lines changed: 28 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ if(openPMD_HAVE_PYTHON)
665665
__init__.py DaskArray.py DaskDataFrame.py DataFrame.py
666666
ls/__init__.py ls/__main__.py
667667
pipe/__init__.py pipe/__main__.py
668+
scipp/__init__.py scipp/loader.py scipp/mesh_loader.py scipp/utils.py
669+
ScippLazyInit.py
668670
)
669671
endif()
670672

@@ -720,6 +722,7 @@ set(openPMD_PYTHON_EXAMPLE_NAMES
720722
11_particle_dataframe
721723
12_span_write
722724
13_write_dynamic_configuration
725+
15_scipp_loader
723726
)
724727

725728
if(openPMD_USE_INVASIVE_TESTS)

examples/15_scipp_loader.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import openpmd_api as pmd
2+
3+
4+
def main():
5+
series = pmd.Series("./out.bp5", pmd.Access.read_only)
6+
scipp_loader = series.to_scipp()
7+
8+
if __name__ == "__main__":
9+
main()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def series_to_scipp(series):
2+
3+
import scipp
4+
5+
from .scipp import DataLoader
6+
7+
dl = DataLoader(series)
8+
return dl

src/binding/python/openpmd_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .DaskDataFrame import particles_to_daskdataframe
44
from .DataFrame import (iterations_to_cudf, iterations_to_dataframe,
55
particles_to_dataframe)
6+
from .ScippLazyInit import series_to_scipp
67
from .openpmd_api_cxx import * # noqa
78

89
__version__ = cxx.__version__
@@ -16,6 +17,7 @@
1617
Record_Component.to_dask_array = record_component_to_daskarray # noqa
1718
Series.to_df = iterations_to_dataframe # noqa
1819
Series.to_cudf = iterations_to_cudf # noqa
20+
Series.to_scipp = series_to_scipp
1921

2022
# TODO remove in future versions (deprecated)
2123
Access_Type = Access # noqa

src/binding/python/openpmd_api/scipp/loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DataLoader:
6161
6262
"""
6363

64-
def __init__(self, path):
64+
def __init__(self, series):
6565
"""Initialize the DataLoader with an openPMD series from the specified file path.
6666
6767
:param path: The file path to the openPMD data file.
@@ -71,13 +71,13 @@ def __init__(self, path):
7171
and the `iterations` attribute as a Scipp dataset containing iteration IDs
7272
and their corresponding times.
7373
"""
74-
self.series = pmd.Series(str(path), pmd.Access.read_only)
74+
self.series = series
7575
self.iterations = get_iterations(self.series)
7676

7777
def get_field(
7878
self,
7979
field,
80-
component=pmd.Mesh_Record_Component.SCALAR,
80+
component=None,
8181
time=None,
8282
iteration=None,
8383
relay=False,

src/binding/python/openpmd_api/scipp/mesh_loader.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99

1010
import numpy as np
11-
import openpmd_api as pmd
1211
import scipp as sc
1312

1413
from .utils import _unit_dimension_to_scipp
@@ -135,7 +134,7 @@ def load_data(self):
135134
return data_array
136135

137136

138-
def get_field_data_relay(series, iteration, field, component=pmd.Mesh_Record_Component.SCALAR):
137+
def get_field_data_relay(series, iteration, field, component=None):
139138
"""Get openPMD mesh as a data relay.
140139
141140
Create a DataRelay object for a specified field and component in an openPMD series.
@@ -152,7 +151,7 @@ def get_field_data_relay(series, iteration, field, component=pmd.Mesh_Record_Com
152151
:rtype: DataRelay
153152
"""
154153
record = series.iterations[iteration].meshes[field]
155-
rc = record[component]
154+
rc = record[component] if component else record
156155
dims = record.axis_labels
157156
time = (series.iterations[iteration].time + record.time_offset) * series.iterations[
158157
iteration
@@ -184,7 +183,7 @@ def get_field_data_relay(series, iteration, field, component=pmd.Mesh_Record_Com
184183
)
185184

186185

187-
def get_field(series, iteration, field, component=pmd.Mesh_Record_Component.SCALAR):
186+
def get_field(series, iteration, field, component=None):
188187
"""Retrieve and load openPMD mesh data without slicing.
189188
190189
This function creates a DataRelay object for a specified field and component in an openPMD

0 commit comments

Comments
 (0)