openPMD-viewer icon indicating copy to clipboard operation
openPMD-viewer copied to clipboard

How to open BP series?

Open pgrete opened this issue 3 months ago • 0 comments

Trying to open series with the viewer results in (same for trying the %T syntax directly):

from openpmd_viewer import OpenPMDTimeSeries
ts = OpenPMDTimeSeries("opmd.00007.bp/",backend="openpmd-api")
[AbstractIOHandlerImpl] IO Task READ_ATT failed with exception. Clearing IO queue and passing on the exception.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[3], line 1
----> 1 ts = OpenPMDTimeSeries("opmd.00007.bp[/](http://localhost:8798/)",backend="openpmd-api")

File [~/venv/lib/python3.11/site-packages/openpmd_viewer/openpmd_timeseries/main.py:73](python3.11/site-packages/openpmd_viewer/openpmd_timeseries/main.py#line=72), in OpenPMDTimeSeries.__init__(self, path_to_dir, check_all_files, backend)
     70 self.data_reader = DataReader(backend)
     72 # Extract the iterations available in this timeseries
---> 73 self.iterations = self.data_reader.list_iterations(path_to_dir)
     75 # Check that there are files in this directory
     76 if len(self.iterations) == 0:

File [~/venv/lib/python3.11/site-packages/openpmd_viewer/openpmd_timeseries/data_reader/data_reader.py:116](http://localhost:8798/home/pgrete/venv/lib/python3.11/site-packages/openpmd_viewer/openpmd_timeseries/data_reader/data_reader.py#line=115), in DataReader.list_iterations(self, path_to_dir)
    113         file_path = re.sub(r'(\d+)(\.(?!\d).+$)', r'%T\2', first_file_name)
    114         series_name = os.path.join( path_to_dir, file_path)
--> 116     self.series = io.Series(
    117         series_name,
    118         #"opmd.%T.bp,
    119         io.Access.read_only )
    120     iterations = np.array( self.series.iterations )
    122 return iterations

RuntimeError: [json.exception.type_error.305] cannot use operator[] with a string argument with array

Hardcoding the series name fixes it:

            if is_single_file:
                file_path = path_to_dir
                series_name = file_path
            else:
                # match last occurance of integers and replace with %T wildcards
                # examples: data00000100.h5 diag4_00000500.h5 io12.0.bp
                #           te42st.1234.yolo.json scan7_run14_data123.h5
                file_path = re.sub(r'(\d+)(\.(?!\d).+$)', r'%T\2', first_file_name)
                series_name = os.path.join( path_to_dir, file_path)

            self.series = io.Series(
                #series_name,
                "opmd.%T.bp/",
                io.Access.read_only )
            iterations = np.array( self.series.iterations )

Am I doing sth wrong or is the regex parsing not working as expected?

pgrete avatar Mar 14 '24 17:03 pgrete