Skip to content

Conversation

@lassejsc
Copy link
Contributor

@lassejsc lassejsc commented Oct 24, 2025

See #250

Added wrap_array function wrapper that can be applied to a function with @wrap_array(dimensions,squeeze=True) decorator within the VlsvReader class.

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) parameter b is a 2D numpy array regardless if you pass it a scalar, 1D numpy array or python list, you would add the decorator as

@wrap_array(dimensions=[0,2])
def foo(self, a,b):
      bla

This will skip the handling for parameter a, if instead you want to make sure a is a 1D numpy array you would change the wrap_array parameter to dimensions=[1,2]. Passing integer instead of a list to dimensions will default to applying this behavior to the first argument a only.

This is applied to the functions

  • get_amr_level()
  • get_cell_indices()
  • get_cell_dx()
  • get_cell_coordinates()
  • get_cell_neighbor()

@lassejsc lassejsc marked this pull request as ready for review October 29, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant