Skip to content

Commit 964bd16

Browse files
authored
Simplify
1 parent a978fc1 commit 964bd16

File tree

1 file changed

+6
-14
lines changed
  • openpmd_viewer/openpmd_timeseries/data_reader/io_reader

1 file changed

+6
-14
lines changed

openpmd_viewer/openpmd_timeseries/data_reader/io_reader/utilities.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ def get_data(series, record_component, i_slice=None, pos_slice=None,
5959
# ADIOS2: Actual chunks, all other: one chunk
6060
chunks = record_component.available_chunks()
6161

62+
# mask invalid regions with NaN: fill value
63+
# note: NaN is only defined for floating point types
64+
NaN_value = np.nan if np.issubdtype(record_component.dtype, np.floating) or np.issubdtype(record_component.dtype, np.complexfloating) else 0
65+
6266
# read whole data set
6367
if pos_slice is None:
6468
# mask invalid regions with NaN
6569
# note: full_like triggers a full read, thus we avoid it #340
66-
# (only for floating-point types)
67-
if np.issubdtype(record_component.dtype, np.floating) or \
68-
np.issubdtype(record_component.dtype, np.complexfloating):
69-
data = np.full(record_component.shape, np.nan, record_component.dtype)
70-
else:
71-
# Other types do not support NaN
72-
data = np.full(record_component.shape, 0, record_component.dtype)
70+
data = np.full(record_component.shape, NaN_value, record_component.dtype)
7371

7472
for chunk in chunks:
7573
chunk_slice = chunk_to_slice(chunk)
@@ -97,13 +95,7 @@ def get_data(series, record_component, i_slice=None, pos_slice=None,
9795
del slice_shape[dir_index]
9896

9997
# mask invalid regions with NaN
100-
# (only for floating-point types)
101-
if np.issubdtype(record_component.dtype, np.floating) or \
102-
np.issubdtype(record_component.dtype, np.complexfloating):
103-
data = np.full(slice_shape, np.nan, dtype=record_component.dtype)
104-
else:
105-
# Other types do not support NaN
106-
data = np.full(slice_shape, 0, dtype=record_component.dtype)
98+
data = np.full(slice_shape, NaN_value, dtype=record_component.dtype)
10799

108100
# build requested ND slice with respect to full data
109101
s = []

0 commit comments

Comments
 (0)