From b6e71354b2b7e13552fa74ba826b3d848d757e66 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Wed, 18 Mar 2026 14:15:47 +0200 Subject: [PATCH 1/2] Added check for the datatype so data_avgs reshape does not try to reshape None type if data_avgs was not loaded --- analysator/vlsvfile/vlsvreader.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/analysator/vlsvfile/vlsvreader.py b/analysator/vlsvfile/vlsvreader.py index 12a5f414..ef912b59 100644 --- a/analysator/vlsvfile/vlsvreader.py +++ b/analysator/vlsvfile/vlsvreader.py @@ -3850,7 +3850,8 @@ def read_velocity_cells(self, cellid, pop="proton"): data_avgs = np.fromfile(fptr, dtype = np.float32, count = vector_size*num_of_blocks) if datatype == "float" and element_size == 8: data_avgs = np.fromfile(fptr, dtype = np.float64, count = vector_size*num_of_blocks) - data_avgs = data_avgs.reshape(num_of_blocks, vector_size) + if data_avgs: + data_avgs = data_avgs.reshape(num_of_blocks, vector_size) # Read in block coordinates: if ("name" in child.attrib) and (child.attrib["name"] == pop) and (child.tag == "BLOCKIDS"): vector_size = ast.literal_eval(child.attrib["vectorsize"]) @@ -3883,8 +3884,8 @@ def read_velocity_cells(self, cellid, pop="proton"): data_block_ids = np.fromfile(fptr, dtype = np.uint64, count = vector_size*num_of_blocks) else: raise TypeError("Error! Bad data type in blocks! datatype found was "+datatype) - - data_block_ids = data_block_ids.reshape(num_of_blocks, vector_size) + if data_block_ids: + data_block_ids = data_block_ids.reshape(num_of_blocks, vector_size) fptr.close() @@ -4359,4 +4360,4 @@ def cache_optimization_files(self, force=False): ''' Create cached optimization files for this reader object (e.g. spatial index) ''' - self.__metadata_cache.set_cellid_spatial_index(force) \ No newline at end of file + self.__metadata_cache.set_cellid_spatial_index(force) From dffbda4cb982e04f7a5a4acba956a537a581ec5e Mon Sep 17 00:00:00 2001 From: lassejsc Date: Wed, 18 Mar 2026 14:57:06 +0200 Subject: [PATCH 2/2] Im sure i tried to push this change earlier but it did not work, strange --- analysator/vlsvfile/vlsvreader.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/analysator/vlsvfile/vlsvreader.py b/analysator/vlsvfile/vlsvreader.py index ef912b59..281d3556 100644 --- a/analysator/vlsvfile/vlsvreader.py +++ b/analysator/vlsvfile/vlsvreader.py @@ -3848,10 +3848,11 @@ def read_velocity_cells(self, cellid, pop="proton"): if datatype == "float" and element_size == 4: data_avgs = np.fromfile(fptr, dtype = np.float32, count = vector_size*num_of_blocks) - if datatype == "float" and element_size == 8: + elif datatype == "float" and element_size == 8: data_avgs = np.fromfile(fptr, dtype = np.float64, count = vector_size*num_of_blocks) - if data_avgs: - data_avgs = data_avgs.reshape(num_of_blocks, vector_size) + else: + raise TypeError("Error! Bad data type in blocks! datatype found was "+datatype) + data_avgs = data_avgs.reshape(num_of_blocks, vector_size) # Read in block coordinates: if ("name" in child.attrib) and (child.attrib["name"] == pop) and (child.tag == "BLOCKIDS"): vector_size = ast.literal_eval(child.attrib["vectorsize"]) @@ -3884,8 +3885,8 @@ def read_velocity_cells(self, cellid, pop="proton"): data_block_ids = np.fromfile(fptr, dtype = np.uint64, count = vector_size*num_of_blocks) else: raise TypeError("Error! Bad data type in blocks! datatype found was "+datatype) - if data_block_ids: - data_block_ids = data_block_ids.reshape(num_of_blocks, vector_size) + + data_block_ids = data_block_ids.reshape(num_of_blocks, vector_size) fptr.close()