https://github.com/astropenguin/xarray-compare
:zap: xarray extension for data comparison
https://github.com/astropenguin/xarray-compare
python python-package xarray
Last synced: about 1 year ago
JSON representation
:zap: xarray extension for data comparison
- Host: GitHub
- URL: https://github.com/astropenguin/xarray-compare
- Owner: astropenguin
- License: mit
- Created: 2020-08-12T05:07:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-20T07:12:35.000Z (almost 6 years ago)
- Last Synced: 2025-05-13T03:38:56.649Z (about 1 year ago)
- Topics: python, python-package, xarray
- Language: Python
- Homepage: https://astropenguin.github.io/xarray-compare/
- Size: 1.47 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xarray-compare
[](https://pypi.org/pypi/xarray-compare/)
[](https://pypi.org/pypi/xarray-compare/)
[](https://github.com/astropenguin/xarray-compare/actions)
[](LICENSE)
[](https://doi.org/10.5281/zenodo.3988924)
xarray extension for data comparison
## TL;DR
xarray-compare is a third-party Python package which provides extra data-comparison features.
After importing the package, several DataArray methods (`dataarray.is*()`) will be available.
## Requirements
- **Python:** 3.6, 3.7, or 3.8 (tested by the author)
- **Dependencies:** See [pyproject.toml](https://github.com/astropenguin/xarray-compare/blob/master/pyproject.toml)
## Installation
```shell
$ pip install xarray-compare
```
## List of available methods
- `.isbetween(lower, upper)`: Test whether each value in a DataArray falls within an interval
- `.ismatch(pattern)`: Test whether each string in a DataArray matches a regex pattern
Methods of "not-in" version are also provided for readability.
- `.isnotin(values)`: Equivalent to `~dataarray.isin(values)` (`.isin()` is an xarray's builtin)
- `.isnotbetween(lower, upper)`: Equivalent to `~dataarray.isbetween(lower, upper)`
- `.isnotmatch(pattern)`: Equivalent to `~dataarray.ismatch(pattern)`
## Examples
xarray-compare is a just-import package.
After importing it, methods become available from normal DataArray instances.
```python
import xarray as xr
import xarray_compare
```
A method returns a boolean DataArray each value of which is `True` where that of the input DataArray fulfills the condition and `False` otherwise.
This is why it works well with the `dataarray.where()` method.
```python
da = xr.DataArray([0, 1, 1, 2, 3, 5, 8, 13])
da.where(da.isbetween(1, 4), drop=True)
#
# array([1., 1., 2., 3.])
# Dimensions without coordinates: dim_0
```
```python
da = xr.DataArray(['a', 'aa', 'ab', 'bc'])
da.where(da.ismatch("^a+$"), drop=True)
#
# array(['a', 'aa'], dtype=object)
# Dimensions without coordinates: dim_0
```