Skip to content

Commit c62fe8c

Browse files
committed
[Draft] Fix MR Reads
Start to fix MR reads on higher levels, where we have declared but undefined regions and need to filter by valid boxes.
1 parent 5a452d0 commit c62fe8c

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

openpmd_viewer/openpmd_timeseries/data_reader/io_reader/utilities.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
import numpy as np
1212

1313

14+
def chunk_to_slice(chunk):
15+
"""
16+
Convert an openPMD_api.ChunkInfo to np.s_
17+
"""
18+
#print("chunk={} {}".format(chunk, type(chunk)))
19+
stops = [a + b for a, b in zip(chunk.offset, chunk.extent)]
20+
indices_per_dim = zip(chunk.offset, stops)
21+
index_tuple = map(lambda s: slice(s[0], s[1], None), indices_per_dim)
22+
return tuple(index_tuple)
23+
1424
def get_data(series, record_component, i_slice=None, pos_slice=None,
1525
output_type=np.float64):
1626
"""
@@ -46,8 +56,21 @@ def get_data(series, record_component, i_slice=None, pos_slice=None,
4656
if i_slice is not None and not isinstance(i_slice, list):
4757
i_slice = [i_slice]
4858

59+
chunks = record_component.available_chunks()
60+
full_indices = np.indices(record_component.shape)[0]
61+
full_shape = full_indices.shape
62+
print("full_shape.shape={}".format(full_shape))
63+
print("full_shape={}".format(full_shape))
64+
4965
if pos_slice is None:
50-
data = record_component[()]
66+
# mask invalid regions with zero
67+
data = np.zeros_like(record_component)
68+
for chunk in chunks:
69+
s = chunk_to_slice(chunk)
70+
# read only valid region
71+
x = record_component[s]
72+
series.flush()
73+
data[s] = x
5174
else:
5275
# Get largest element of pos_slice
5376
max_pos = max(pos_slice)
@@ -60,8 +83,17 @@ def get_data(series, record_component, i_slice=None, pos_slice=None,
6083
list_index[dir_index] = i_slice[count]
6184
# Convert list_index into a tuple
6285
tuple_index = tuple(list_index)
63-
# Slice dset according to tuple_index
64-
data = record_component[tuple_index]
86+
print("tuple_index={}".format(tuple_index))
87+
88+
# prepare sliced data according to tuple_index
89+
#slice_indices = full_indices[tuple_index]
90+
#slice_shape = slice_indices.shape
91+
#data = np.zeros(slice_shape, dtype=output_type)
92+
# write now in index space between intersection of slice_indices and chunk indices
93+
#for chunk in chunks:
94+
# ...
95+
#data = record_component[tuple_index] # todo
96+
data = np.zeros_like(record_component)[tuple_index] # just avoid invalid reads for now
6597

6698
series.flush()
6799

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def run_tests(self):
3838
tests_require=['pytest', 'jupyter'],
3939
install_requires=install_requires,
4040
extras_require = {
41-
'all': ["ipympl", "ipywidgets", "matplotlib", "numba", "openpmd-api", "wget"],
41+
'all': ["ipympl", "ipywidgets", "matplotlib", "numba", "openpmd-api~=0.13.3,~=0.14.0", "wget"],
4242
'GUI': ["ipywidgets", "ipympl", "matplotlib"],
4343
'plot': ["matplotlib"],
4444
'tutorials': ["ipywidgets", "ipympl", "matplotlib", "wget"],
4545
'numba': ["numba"],
46-
'openpmd-api': ["openpmd-api"]
46+
'openpmd-api': ["openpmd-api~=0.13.3,~=0.14.0"]
4747
},
4848
cmdclass={'test': PyTest},
4949
platforms='any',

0 commit comments

Comments
 (0)