Data classes for custom xarray constructors
Project description
xarray-custom
:zap: Data classes for custom xarray constructors
TL;DR
xarray-custom is a third-party Python package which helps to create custom DataArray classes in the same manner as the Python's native dataclass. Here is an introduction code of what the package provides:
from xarray_custom import ctype, dataarrayclass
@dataarrayclass(accessor='img')
class Image:
"""DataArray class to represent images."""
dims = 'x', 'y'
dtype = float
x: ctype('x', int) = 0
y: ctype('y', int) = 0
def normalize(self):
return self / self.max()
# create a custom DataArray
image = Image([[0, 1], [2, 3]], x=[0, 1], y=[0, 1])
# use a custom method via an accessor
normalized = image.img.normalize()
# create a custom DataArray filled with ones
ones = Image.ones((2, 2), x=[0, 1], y=[0, 1])
The key points are:
- Custom DataArray instances with fixed dimensions, datatype, and coordinates can easily be created.
- NumPy-like special functions like
ones()
are provided as class methods. - Custom DataArray methods can be available via a custom accessor.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xarray-custom-0.4.0.tar.gz
(9.4 kB
view hashes)
Built Distribution
Close
Hashes for xarray_custom-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f11f4f26c89a3b7d8e2793417ee8f3b8878dfc159af035df3879ca8827959b71 |
|
MD5 | 7d853b812be8fe3a130c5e5e22166850 |
|
BLAKE2b-256 | 2bd83272b5c492434490fd5bccef328208937fa0485e81c91fb6e78ee0a35af9 |