From 5731b521cb6818fc8e9c1c231187cc2a7e4b7414 Mon Sep 17 00:00:00 2001 From: Markku Alho Date: Tue, 10 Nov 2020 11:52:55 +0200 Subject: [PATCH 1/2] Added read_variable_shaped to automate the read_variable reshaping chore --- pyVlsv/vlsvreader.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index 34a41d67..2cc6ea72 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -1004,6 +1004,26 @@ def calcLocalSize(globalCells, ntasks, my_n): return np.squeeze(orderedData) + + def read_variable_shaped(self, name, cellids=-1,operator="pass"): + ''' Read variables from the open vlsv file and reshape the output. + Arguments: + :param name: Name of the variable + :param cellids: a value of -1 reads all data + :param operator: Datareduction operator. "pass" does no operation on data + :returns: numpy array with the data + + .. seealso:: :func:`read` :func:`read_variable_info` + ''' + # Read variable as usual + data = self.read_variable(name, cellids=cellids,operator=operator) + # sort with CellID + data = data[self.read_variable("CellID").argsort()] + # reshape to mesh size + data = data.reshape(self.get_spatial_mesh_size()) + return data + + def read_variable(self, name, cellids=-1,operator="pass"): ''' Read variables from the open vlsv file. Arguments: From 49ea8591efff4c7fb84886f1bb2d229f7dc4dbb7 Mon Sep 17 00:00:00 2001 From: Markku Alho Date: Tue, 10 Nov 2020 13:49:56 +0200 Subject: [PATCH 2/2] Limited read_variable_shaped to full grid. --- pyVlsv/vlsvreader.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index 2cc6ea72..b0264085 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -1005,18 +1005,17 @@ def calcLocalSize(globalCells, ntasks, my_n): return np.squeeze(orderedData) - def read_variable_shaped(self, name, cellids=-1,operator="pass"): - ''' Read variables from the open vlsv file and reshape the output. + def read_variable_shaped(self, name, operator="pass"): + ''' Read variables from the open vlsv file for the full grid and reshape the output to match the grid. Arguments: :param name: Name of the variable - :param cellids: a value of -1 reads all data :param operator: Datareduction operator. "pass" does no operation on data :returns: numpy array with the data .. seealso:: :func:`read` :func:`read_variable_info` ''' # Read variable as usual - data = self.read_variable(name, cellids=cellids,operator=operator) + data = self.read_variable(name, cellids=-1,operator=operator) # sort with CellID data = data[self.read_variable("CellID").argsort()] # reshape to mesh size @@ -1111,7 +1110,7 @@ def read_variable_info(self, name, cellids=-1, operator="pass"): if operator=="magnitude": latex = r"$|$"+latex+r"$|$" else: - latex = latex+r"{$_{"+operator+r"}$}" + latex = latex+r"${_{"+operator+r"}}$" return VariableInfo(data_array=data, name=name + "_" + operator, units=units, latex=latex, latexunits=latexunits) else: return VariableInfo(data_array=data, name=name, units=units, latex=latex, latexunits=latexunits)