Skip to content

Commit 6c02d79

Browse files
committed
#1 Update README
1 parent cb359e3 commit 6c02d79

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
11
# xarray-custom
2+
3+
[![PyPI](https://img.shields.io/pypi/v/xarray-custom.svg?label=PyPI&style=flat-square)](https://pypi.org/pypi/xarray-custom/)
4+
[![Python](https://img.shields.io/pypi/pyversions/xarray-custom.svg?label=Python&color=yellow&style=flat-square)](https://pypi.org/pypi/xarray-custom/)
5+
[![Test](https://img.shields.io/github/workflow/status/astropenguin/xarray-custom/Test?logo=github&label=Test&style=flat-square)](https://github.com/astropenguin/xarray-custom/actions)
6+
[![License](https://img.shields.io/badge/license-MIT-blue.svg?label=License&style=flat-square)](LICENSE)
7+
28
:zap: Data classes for custom xarray constructors
9+
10+
## TL;DR
11+
12+
xarray-custom is a Python package which helps to create custom DataArray classes in the same manner as [the Python's native dataclass](https://docs.python.org/3/library/dataclasses.html).
13+
Here is an introduction code of what the package provides:
14+
15+
```python
16+
from xarray_custom import coordtype, dataarrayclass
17+
18+
19+
@dataarrayclass(('x', 'y'), float, 'custom')
20+
class CustomDataArray:
21+
x: coordtype('x', int)
22+
y: coordtype('y', int)
23+
z: coordtype(('x', 'y'), str) = 'spam'
24+
25+
def double(self):
26+
"""Custom DataArray method which doubles values."""
27+
return self * 2
28+
29+
30+
dataarray = CustomDataArray([[0, 1], [2, 3]], x=[2, 2], y=[3, 3])
31+
onesarray = CustomDataArray.ones(shape=(3, 3))
32+
doubled = dataarray.custom.double()
33+
```
34+
35+
The key points are:
36+
37+
- Custom DataArray instances with fixed dimensions and coordinates can easily be created.
38+
- Default values and dtype can be specified via a class decorator and class variable annotations.
39+
- NumPy-like special factory functions like ``ones()`` are provided as class methods.
40+
- Custom DataArray methods can be used via a custom accessor.

0 commit comments

Comments
 (0)