earthkit.data.utils.array

Functions

adjust_array(v[, flatten, dtype])

flatten_array(array)

Flatten the array without copying the data.

outer_indexing(v, indices)

Performs an outer indexing of an array v.

reshape_array(v, shape)

Reshape the array to the required shape.

target_shape(array, flatten, field_shape)

Return the target shape of the array.

Module Contents

earthkit.data.utils.array.adjust_array(v, flatten=False, dtype=None)
earthkit.data.utils.array.flatten_array(array)

Flatten the array without copying the data.

Parameters:

array (array-like) – The array to be flattened.

Returns:

1-D array.

Return type:

array-like

earthkit.data.utils.array.outer_indexing(v, indices)

Performs an outer indexing of an array v. The parameter indices is a tuple of indices. Each index is either an int, a slice of an array of int’s. Each index form indices restricts/sub-selects the corresponding dimension of the array v, independently (orthogonally) to other indices (hence the name: “outer indexing”).

This function mimics the behaviour of xarray.DataArray(v)[indices].values, and in general it is different from the behaviour of e.g. the numpy indexing, i.e. v[indices] (see https://numpy.org/doc/stable/user/basics.indexing.html#advanced-indexing).

Parameters:
  • v (array-like) – The array to be reshaped.

  • indices (tuple of items, each being an int, a slice or an array-like of int's)

Returns:

Sub-selection of the array v according to indices

Return type:

array-like

earthkit.data.utils.array.reshape_array(v, shape)

Reshape the array to the required shape.

Parameters:
  • v (array-like) – The array to be reshaped.

  • shape (tuple) – The desired shape of the array.

Returns:

Reshaped array.

Return type:

array-like

earthkit.data.utils.array.target_shape(array, flatten, field_shape)

Return the target shape of the array.

Parameters:
  • array (array-like) – The array to be reshaped.

  • flatten (bool) – If True, return a flat shape.

Returns:

The target shape of the array.

Return type:

tuple