coordax.Field

class coordax.Field(data: generic | bool | int | float | complex | ndarray | Array | NDArray | ShapeDtypeStruct, dims: tuple[str | None, ...] | None = None, axes: dict[str, Coordinate] | None = None)

An array with optional named dimensions and associated coordinates.

Examples

>>> import coordax as cx
>>> import jax.numpy as jnp
>>> x = cx.SizedAxis('x', 2)
>>> field = cx.Field(jnp.ones((2, 3, 4)), dims=('x', 'y', None), axes={'x': x})
>>> field
<Field dims=('x', 'y', None) shape=(2, 3, 4) axes={'x': SizedAxis} >
>>> field.data
Array([[[1., 1., 1., 1.],
        [1., 1., 1., 1.],
        [1., 1., 1., 1.]],

       [[1., 1., 1., 1.],
        [1., 1., 1., 1.],
        [1., 1., 1., 1.]]], dtype=float32)
>>> field.dims
('x', 'y', None)
>>> field.axes
{'x': coordax.SizedAxis('x', size=2)}
>>> field.shape
(2, 3, 4)
>>> field.named_shape
{'x': 2, 'y': 3}
>>> field.positional_shape
(4,)
>>> field.named_dims
('x', 'y')
>>> field.named_axes
{'x': 0, 'y': 1}
>>> field.coord_fields
{}
>>> field.coordinate
CartesianProduct(coordinates=(coordax.SizedAxis('x', size=2), coordax.DummyAxis('y', size=3), coordax.DummyAxis(None, size=4)))
__init__(data: generic | bool | int | float | complex | ndarray | Array | NDArray | ShapeDtypeStruct, dims: tuple[str | None, ...] | None = None, axes: dict[str, Coordinate] | None = None)[source]

Construct a Field.

Parameters:
  • data – the underlying data array.

  • dims – optional tuple of dimension names, with the same length as data.ndim. Strings indicate named axes, and may not be repeated. None indicates positional axes. If dims is not provided, all axes are positional.

  • axes – optional mapping from dimension names to associated coordax.Coordinate objects.

Examples

>>> import coordax as cx
>>> import jax.numpy as jnp
>>> cx.Field(jnp.ones((2, 3)), dims=('x', 'y'))
<Field dims=('x', 'y') shape=(2, 3) axes={} >

See also

coordax.field()

Methods

__init__(data[, dims, axes])

Construct a Field.

astype(dtype[, copy, device])

Name-vectorized version of array method astype <numpy.ndarray.astype>.

broadcast_like(other)

Returns a field broadcasted like other.

clip([min, max])

Name-vectorized version of array method clip <numpy.ndarray.clip>.

conj()

Name-vectorized version of array method conj <numpy.ndarray.conj>.

conjugate()

Name-vectorized version of array method conjugate <numpy.ndarray.conjugate>.

from_namedarray(named_array[, axes])

Creates a Field from a named array.

from_xarray(data_array[, coord_types])

Deprecated alias for coordax.from_xarray.

isel([indexers])

Returns a new Field with the given indexers applied.

order_as(*axis_order)

Returns a field with the axes in the given order.

round([decimals, out])

Name-vectorized version of array method round <numpy.ndarray.round>.

sel([indexers, method])

Returns a new Field with the given selection applied.

tag(*names)

Returns a Field with attached coordinates to the positional axes.

to_xarray()

Convert this Field to an xarray.DataArray with NumPy array data.

tree_flatten()

Flatten this object for JAX pytree operations.

tree_unflatten(axes, leaves)

Unflatten this object for JAX pytree operations.

untag(*axis_order)

Returns a view of the field with the requested axes made positional.

unwrap(*names)

Extracts underlying data from a field without named dimensions.

view([dtype, type])

Name-vectorized version of array method view <numpy.ndarray.view>.

Attributes

axes

This field's coordinates, as a dict of 1d coordinates.

coord_fields

A mapping from coordinate field names to their values.

coordinate

This field's coordinate, as a single Coordinate object.

data

The value of the underlying data array.

dims

Named and unnamed dimensions of this array.

dtype

The dtype of the field.

imag

Name-vectorized version of array method imag <numpy.ndarray.imag>.

named_array

The value of the underlying named array.

named_axes

Mapping from dimension names to axis positions.

named_dims

Named dimensions of this array.

named_shape

A mapping of axis names to their sizes.

ndim

Number of dimensions in the underlying data array.

positional_shape

A tuple of axis sizes for any anonymous axes.

real

Name-vectorized version of array method real <numpy.ndarray.real>.

shape

A tuple of axis sizes of the underlying data array.