function wrapper for consolidating array/scalar handling in vlsvreader #365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #250
Added
wrap_arrayfunction wrapper that can be applied to a function with@wrap_array(dimensions,squeeze=True)decorator within theVlsvReaderclass.Applying this decorator to a function will ensure that the arguments passed to the function are numpy arrays with dimensions specified in
dimensions, which can be python list or integer.If the passed argument does not have the right dimensions, the output of the function will squeezed with
np.squeeze(). This ensure that if you pass a scalar to the function the output will be a scalar and not numpy 1D array with one element.For example, if you want to make sure that the function
self.foo(a,b)parameterbis a 2D numpy array regardless if you pass it a scalar, 1D numpy array or python list, you would add the decorator asThis will skip the handling for parameter
a, if instead you want to make sureais a 1D numpy array you would change the wrap_array parameter todimensions=[1,2]. Passing integer instead of a list todimensionswill default to applying this behavior to the first argumentaonly.This is applied to the functions
get_amr_level()get_cell_indices()get_cell_dx()get_cell_coordinates()get_cell_neighbor()