xarray-custom 0.2.0


pip install xarray-custom==0.2.0


Meta
Author: Akio Taniguchi
Requires Python: >=3.6,<4.0

Classifiers

License
  • OSI Approved :: MIT License

Programming Language
  • Python :: 3
  • Python :: 3.6
  • Python :: 3.7
  • Python :: 3.8

xarray-custom

PyPI Python Test License

:zap: Data classes for custom xarray constructors

TL;DR

xarray-custom is a 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 coordtype, dataarrayclass


@dataarrayclass(('x', 'y'), float, 'custom')
class CustomDataArray:
    x: coordtype('x', int)
    y: coordtype('y', int)
    z: coordtype(('x', 'y'), str) = 'spam'

    def double(self):
        """Custom DataArray method which doubles values."""
        return self * 2


dataarray = CustomDataArray([[0, 1], [2, 3]], x=[2, 2], y=[3, 3])
onesarray = CustomDataArray.ones(shape=(3, 3))
doubled = dataarray.custom.double()

The key points are:

  • Custom DataArray instances with fixed dimensions and coordinates can easily be created.
  • Default values and dtype can be specified via a class decorator and class variable annotations.
  • NumPy-like special factory functions like ones() are provided as class methods.
  • Custom DataArray methods can be used via a custom accessor.

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
numpy (<2.0,>=1.18)
xarray (<0.16,>=0.15)